forked from inspectIT/inspectIT
-
Notifications
You must be signed in to change notification settings - Fork 2
/
inspectit.agent.java.gradle
263 lines (218 loc) · 6.61 KB
/
inspectit.agent.java.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/**
* Gradle build file for the inspectit.agent.java project.
*
* @author Rene Kugel
* @author Ivan Senic
*/
plugins {
id "com.moowork.node" version "1.2.0"
}
evaluationDependsOn(':inspectit.shared.all')
defaultTasks 'releaseAndAnalyze'
/** used by the eclipse buildship plugin */
sourceCompatibility = '1.6'
targetCompatibility = '1.6'
/** defined to have it included in Eclipse as source */
sourceSets {
externalResources {
resources {
srcDir mainExtResources
}
}
}
/** Some agent specific properties */
ext {
distJarName = 'inspectit-agent'
releaseName = "inspectit-agent-java6-${versionInfo}.zip"
}
/** Setting compile configuration as plugin in Eclipse needs it */
configurations {
compile {
extendsFrom configurations.agentJavaProd
}
testCompile {
extendsFrom configurations.agentJavaTest
extendsFrom configurations.jmhbase
}
}
/** Depend on inspectit.shared.all, testCompile must depend on shared all test sources because of TestBase class */
dependencies {
compile project(':inspectit.shared.all')
compile project(':inspectit.agent.java.sdk')
testCompile project (path: ':inspectit.shared.all', configuration: 'testArchives')
}
/** Compile compatibility to 1.6 for all compile tasks */
tasks.withType(JavaCompile) { t ->
sourceCompatibility = '1.6'
targetCompatibility = '1.6'
options.bootClasspath = configurations.java16rt.asPath
}
/**
* Creates the jar. Excludes libs from the configurations.agentJavaProd that are not Java5 compatible. Uses existing manifest.
*/
jar {
// use jarCheck to make sure all classes in our dependencies are at maximum in version 1.6
doFirst {
def jarCheckOutput = new File("$buildRoot/jarCheck")
jarCheckOutput.mkdirs()
configurations.agentJavaProd.each { file ->
def name = file.name
javaexec {
classpath configurations.jarCheck
main = 'com.mindprod.jarcheck.JarCheck'
args = ["$file", "1.0", "1.6"]
standardOutput = new File(jarCheckOutput, "$name-check.log").newOutputStream()
}
}
}
archivesBaseName = distJarName
into('libs') {
from project(':inspectit.shared.all').jar.outputs
from project(':inspectit.agent.java.sdk').jar.outputs
from configurations.agentJavaProd
}
manifest {
from file("${mainResources}/META-INF/MANIFEST.MF")
}
}
/**
* Compilation and minification of the browser Agent.
*/
node {
download = true
}
def nodeWorkingDir = "${buildRoot}/node";
task npmInstallLocal(type: NpmTask) {
description = "Installs dependencies from package.json"
workingDir = file(nodeWorkingDir)
args = ['install']
inputs.file "${mainRoot}/ts/package.json"
outputs.dir nodeWorkingDir
doFirst {
copy {
from "${mainRoot}/ts"
into nodeWorkingDir
include "package.json"
}
}
}
task compileTS {
description = 'Compile TypeScript Sources'
dependsOn(npmInstallLocal)
def compileTSProject = { projectFile ->
def runner = new com.moowork.gradle.node.exec.NodeExecRunner(project)
runner.arguments = []
runner.arguments.add(file("${nodeWorkingDir}/node_modules/typescript/lib/tsc.js").absolutePath )
runner.arguments.addAll( ['--project', projectFile.absolutePath] )
runner.execute().rethrowFailure();
}
def inputDir = "${mainRoot}/ts"
//build folder
def buildDir = "${buildRoot}/ts"
//folder to copy the JS-files to
def outputDir = "${buildRoot}/resources/main/js"
inputs.dir file(inputDir)
outputs.dir file(outputDir)
//compile the core project first
doFirst {
compileTSProject(file("${inputDir}/core"));
copy {
from "${buildDir}/core"
into outputDir
include "*.js"
}
}
//compile and copy all plugins
fileTree(dir: "${inputDir}/plugins", include:"**/tsconfig.json").each {File projectFile ->
doLast {
compileTSProject(projectFile);
}
}
doLast {
copy {
from "${buildDir}/plugins"
into "${outputDir}/plugins"
include "*.js"
}
}
}
task lintTS {
description = 'Run TSLint on TypeScript Sources'
dependsOn(compileTS)
def resultsFile = file("${buildQAAnalysis}/tslint/results.txt");
inputs.dir "${mainRoot}/ts"
outputs.file resultsFile
doFirst {
//create an empty log
resultsFile.getParentFile().mkdirs();
resultsFile.createNewFile();
}
def lintTSProject = { lintConfig ->
def runner = new com.moowork.gradle.node.exec.NodeExecRunner(project)
runner.ignoreExitValue = true;
runner.arguments = []
runner.arguments.add(file("${nodeWorkingDir}/node_modules/tslint/lib/tslint-cli.js").absolutePath )
runner.arguments.addAll( ['--project', lintConfig.getParentFile().absolutePath] )
runner.arguments.addAll( ['--out', resultsFile.absolutePath] )
def result = runner.execute();
if(result.getExitValue() != 0) {
println "tslint found some issues, see QA/tslint/results.txt:"
println resultsFile.text
}
result.assertNormalExitValue();
}
fileTree(dir: "${mainRoot}/ts", include:"**/tslint.json").each {File lintConfig ->
doLast {
lintTSProject(lintConfig);
}
}
}
task minifyJS {
description = 'Minify JS Agent sources'
dependsOn lintTS
def inputDir = file("${buildRoot}/resources/main/js")
def outputDir = file("${buildRoot}/resources/main/js_min")
inputs.dir file("${mainRoot}/ts")
outputs.dir outputDir
def inputDirPath = java.nio.file.Paths.get(inputDir.path);
def outputDirPath = java.nio.file.Paths.get(outputDir.path)
doLast {
fileTree(dir: inputDirPath.toString(), include:"**/*.js").each {File file ->
def relativeInputFilePath = inputDirPath.relativize(file.toPath());
def outputFilePath = outputDirPath.resolve(relativeInputFilePath);
//create the directory if required
outputFilePath.getParent().toFile().mkdirs()
javaexec {
workingDir = inputDirPath.toString()
classpath configurations.closureCompiler
main = 'com.google.javascript.jscomp.CommandLineRunner'
def closureArgs = []
closureArgs << "--compilation_level=SIMPLE_OPTIMIZATIONS"
closureArgs << "--language_in=ECMASCRIPT5"
closureArgs << "--js_output_file=" + outputFilePath.toString()
closureArgs << relativeInputFilePath.toString()
args closureArgs
}
}
}
}
jar.dependsOn(minifyJS)
/**
* Creates the release package.
*/
task release (type: Zip, dependsOn: jar) {
description = "Releases the ${releaseName} package."
group = 'Release'
destinationDir = file(buildReleasePackages)
archiveName = releaseName
into('agent') {
from jar.outputs
from file(mainExtResources)
from file(sharedResourcesLicense)
}
}
task releaseAndAnalyze {
description = "Runs all unit tests, all checks and releases the ${releaseName} package."
group = 'Release'
dependsOn(analyze, release)
}