-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
607 lines (513 loc) · 21 KB
/
build.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
buildscript {
repositories {
mavenCentral()
jcenter()
// Goomph
// make it easy to test a snapshot version of goomph
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
// grab dependencies from the gradle plugin portal
maven { url 'https://plugins.gradle.org/m2/' }
}
// make sure we don't cache stale snapshot versions
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
// maven { url "https://plugins.gradle.org/m2/" } // shadow
}
dependencies {
classpath "com.bmuschko:gradle-clover-plugin:$cloverPluginVersion"
classpath "com.github.jengelman.gradle.plugins:shadow:2.0.3"
////////// Goomph //////////
// a bunch of eclipse stuff
classpath "com.diffplug.gradle:goomph:${VER_GOOMPH}"
// creates a targetplatform
classpath "org.standardout:bnd-platform:${VER_BND_PLATFORM}"
}
}
plugins {
id 'java'
id 'eclipse'
id 'maven-publish'
id 'signing'
id 'com.bmuschko.clover' version "$cloverPluginVersion"
}
// checking the presence of an Eclipse API baseline repositorsy
if (project.properties['api.baseline'] == null || project.properties['api.baseline'].isEmpty()) {
System.err.println("Cannot find an Eclipse API baseline repository")
System.err.println("Create file iobserve-analysis/gradle.properties if missing.")
System.err.println("Add the property api.baseline=path to the repository")
System.err.println("Use / for path separation")
System.err.println("The repository can be found at [email protected]:research-iobserve/iobserve-repository.git")
} else {
println "iObserve API baseline repository is at: " + project.properties['api.baseline']
}
tasks.withType(GroovyCompile) {
configure(groovyOptions.forkOptions) {
memoryMaximumSize = '4g'
jvmArgs = ['-Xms4048m', '-Xmx8g']
}
}
def confDir = "${project.rootDir}/qa-configurations"
repositories {
maven {url project.properties['api.baseline']
metadataSources {
mavenPom()
artifact()
}
}
mavenCentral()
jcenter()
}
clover {
targetPercentage = cloverCoverage
report {
html = true
}
excludes = [ "**/package-info.java" ]
testExcludes = [ "**/package-info.java" ]
}
subprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'eclipse'
apply plugin: 'com.bmuschko.clover'
apply plugin: 'pmd'
apply plugin: 'checkstyle'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '0.0.4-SNAPSHOT'
group = 'org.iobserve'
repositories {
maven {url project.properties['api.baseline']
metadataSources {
mavenPom()
artifact()
}
}
mavenCentral()
jcenter()
maven {url "https://mvnrepository.com/artifact/org.hyperic/sigar"}
maven {url "https://repo.eclipse.org/content/groups/releases/" }
maven {url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven {url "https://oss.sonatype.org/content/repositories/releases/" }
maven {url "https://mvnrepository.com/artifact/org.eclipse.emf/org.eclipse.emf.ecore" }
maven {url "https://oss.sonatype.org/content/groups/public/"}
maven {url "https://jitpack.io"}
maven {url "https://mvnrepository.com/artifact/org.eclipse/ocl" }
maven {url "https://mvnrepository.com/artifact/org.eclipselabs/cdo.p2"}
maven {url "https://mvnrepository.com/artifact/org.eclipselabs/cdo"}
maven {url "https://mvnrepository.com/artifact/org.eclipselabs/cdo-maven"}
maven {url "https://mvnrepository.com/artifact/commons-daemon/commons-daemon"}
maven {url "https://mvnrepository.com/artifact/commons-cli/commons-cli"}
maven {url "https://mvnrepository.com/artifact/org.antlr/antlr-runtime"}
////////// Goomph //////////
// SNAPSHOT versions are free to rely on other SNAPSHOT libraries
if (project.version.endsWith('SNAPSHOT')) {
maven {url 'https://oss.sonatype.org/content/repositories/snapshots/'}
}
// local eclipse maven (created by Goomph)
maven {url rootProject.file('target.p2/build/p2asmaven/maven')}
}
dependencies {
// logging
api 'org.slf4j:slf4j-api:1.7.25'
compile 'org.slf4j:slf4j-log4j12:1.7.25'
// central
testCompile "junit:junit:4.12"
}
clover {
excludes = [ '**/package-info.java' ]
testExcludes = [ '**/package-info.java' ]
debug = true
targetPercentage = cloverCoverage
report {
html=true
}
compiler {
debug = true
}
}
// --- quality assurance plugins ---
pmd {
// the used PMD version should be the same version as the PMD Eclipse plugin (https://marketplace.eclipse.org/content/eclipse-pmd) uses
toolVersion = pmdAndCpdVersion
ignoreFailures = true
// Clear the rule set first. Otherwise we would have a lot of additional rules in our rule set.
ruleSets = []
ruleSetFiles = files(resolveRelativeToParent(confDir, 'pmdrules.xml'))
}
checkstyle {
toolVersion = checkstyleVersion
ignoreFailures = true
showViolations = false
configFile = new File(confDir, "checkstyle-rules.xml")
configDirectory = file(confDir)
}
tasks.withType(Pmd) {
reports {
xml.enabled = true
html.enabled = false
}
}
tasks.withType(Checkstyle) {
reports {
xml.enabled = true
}
}
ext {
appName = "org.iobserve"
}
eclipse {
classpath {
downloadSources=true
downloadJavadoc=true
}
}
}
task reports {
doLast {
def reportCollection = ""
subprojects.each { s ->
reportCollection += "\t\t<h2>" + s.name + "</h2>\n"
reportCollection += "\t\t<ul>\n"
def folder = new File ("$projectDir/" + s.name + "/build/reports/checkstyle")
if (folder.exists()) {
reportCollection += "\t\t\t<li><a href=\"" + s.name + "/build/reports/checkstyle/main.html\">checkstyle main</a></li>\n"
reportCollection += "\t\t\t<li><a href=\"" + s.name + "/build/reports/checkstyle/test.html\">checkstyle test</a></li>\n"
}
folder = new File ("$projectDir/" + s.name + "/build/reports/tests")
if (folder.exists()) {
reportCollection += "\t\t\t<li><a href=\"" + s.name + "/build/reports/tests/test/index.html\">JUnit tests</a></li>\n"
}
folder = new File ("$projectDir/" + s.name + "/build/reports/clover")
if (folder.exists()) {
reportCollection += "\t\t\t<li><a href=\"" + s.name + "/build/reports/clover/html/index.html\">Test coverage</a></li>\n"
}
folder = new File ("$projectDir/" + s.name + "/build/reports/pmd")
if (folder.exists()) {
def mainFile = new File ("$projectDir/" + s.name + "/build/reports/pmd/main.html")
def testFile = new File ("$projectDir/" + s.name + "/build/reports/pmd/test.html")
if (mainFile.exists()) {
reportCollection += "\t\t\t<li><a href=\"" + s.name + "/build/reports/pmd/main.html\">PMD main</a></li>\n"
}
if (testFile.exists()) {
reportCollection += "\t\t\t<li><a href=\"" + s.name + "/build/reports/pmd/test.html\">PMD test</a></li>\n"
}
}
reportCollection += "\t\t</ul>\n"
}
new File("$projectDir/reports.html").text = """
<html>
<head>
<title>Project Summary</title>
</head>
<body>
<h1>Project Summary</h1>
$reportCollection
</body>
</html>
"""
}
}
def resolveRelativeToParent(String directory, String file) {
return rootProject.file(directory + '/' + file)
}
// the following code is derived from Kieker
def parseCheckstyleReport(File reportFile) {
def errors = 0
def warnings = 0
def infos = 0
if (reportFile.exists()) {
def xmlFile = (new XmlParser()).parse(reportFile)
xmlFile.'file'.'error'.each { issue ->
switch (issue.attribute("severity")) {
case "error":
errors++
break;
case "warning":
warnings++
break;
default:
infos++
break;
}
}
}
return [errors, warnings, infos]
}
def parseFindbugsReport(File reportFile) {
def errors = 0
def warnings = 0
def infos = 0
if (reportFile.exists()) {
def xmlFile = (new XmlParser()).parse(reportFile)
xmlFile.'FindBugsSummary'.each { issue ->
def prio1Bugs = issue.attribute("priority_1")
def prio2Bugs = issue.attribute("priority_2")
def bugsTotal = issue.attribute("total_bugs")
def prio1BugsInt = 0
def prio2BugsInt = 0
def bugsTotalInt = 0
if (prio1Bugs != null) {
prio1BugsInt = Integer.valueOf(prio1Bugs)
}
if (prio2Bugs != null) {
prio2BugsInt = Integer.valueOf(prio2Bugs)
}
if (bugsTotal != null) {
bugsTotalInt = Integer.valueOf(bugsTotal)
}
errors += prio1BugsInt
warnings += prio2BugsInt
infos += bugsTotalInt - (prio1BugsInt + prio2BugsInt)
}
}
return [errors, warnings, infos]
}
def parsePmdReport(File reportFile) {
def errors = 0
def warnings = 0
def infos = 0
if (reportFile.exists()) {
def xmlFile = (new XmlParser()).parse(reportFile)
xmlFile.'file'.'violation'.each { issue ->
// https://github.com/jenkinsci/pmd-plugin/blob/master/src/main/java/hudson/plugins/pmd/parser/PmdParser.java#L26-L29
switch (issue.attribute("priority")) {
case "1":
case "2":
errors++
break;
case "3":
case "4":
warnings++;
break;
case "5":
default:
infos++
break;
}
}
}
return [errors, warnings, infos]
}
def parseCpdReport(File reportFile) {
def errors = 0
def warnings = 0
def infos = 0
if (reportFile.exists()) {
def xmlFile = (new XmlParser()).parse(reportFile)
xmlFile.'duplication'.each { issue ->
errors++
}
} else {
println 'Could not find CPD report file at ' + reportFile
}
return [errors, warnings, infos]
}
rootProject.subprojects.each { project -> configure(project) {
task checkThresholds(dependsOn: ["build"]) {
doLast {
def reportTypes = ['main', 'test']
// Begin Checkstyle report parsing
def csErrors = 0
def csWarnings = 0
def csInfos = 0
def p = project
reportTypes.each { String type ->
def reportFile = file(p.projectDir.path + '/build/reports/checkstyle/' + type + '.xml')
def reportResults = parseCheckstyleReport(reportFile)
csErrors += reportResults[0]
csWarnings += reportResults[1]
csInfos += reportResults[2]
}
// End Checkstyle report parsing
// Begin Findbugs report parsing
def fbErrors = 0
def fbWarnings = 0
def fbInfos = 0
reportTypes.each { String type ->
def reportFile = file(p.projectDir.path + '/build/reports/findbugs/' + type + '.xml')
def reportResults = parseFindbugsReport(reportFile)
fbErrors += reportResults[0]
fbWarnings += reportResults[1]
fbInfos += reportResults[2]
}
// End Findbugs report parsing
// Begin PMD report parsing
def pmdErrors = 0
def pmdWarnings = 0
def pmdInfos = 0
reportTypes.each { String type ->
def reportFile = file(p.projectDir.path + '/build/reports/pmd/' + type + '.xml')
def reportResults = parsePmdReport(reportFile)
pmdErrors += reportResults[0]
pmdWarnings += reportResults[1]
pmdInfos += reportResults[2]
}
// End PMD report parsing
// Begin CPD report parsing
def cpdErrors = 0
p = rootProject
// cpd only produces one single file in the root project without any report types, such as main and test.
def reportFile = file(p.projectDir.path + '/build/reports/cpd/cpdCheck.xml')
def reportResults = parseCpdReport(reportFile)
cpdErrors += reportResults[0]
// End CPD report parsing
// Print results
println("Static analysis results:")
println()
println(" Checkstyle:")
println(" Errors: " + csErrors + " (Threshold: " + checkstyleErrorThreshold + ")")
println(" Warnings: " + csWarnings + " (Threshold: " + checkstyleWarningThreshold + ")")
println(" Info: " + csInfos)
println()
println(" Findbugs:")
println(" Errors: " + fbErrors + " (Threshold: " + findbugsErrorThreshold + ")")
println(" Warnings: " + fbWarnings + " (Threshold: " + findbugsWarningThreshold + ")")
println(" Info: " + fbInfos)
println()
println(" PMD:")
println(" Errors: " + pmdErrors + " (Threshold: " + pmdErrorThreshold + ")")
println(" Warnings: " + pmdWarnings + " (Threshold: " + pmdWarningThreshold + ")")
println(" Info: " + pmdInfos)
println()
println(" CPD (counts for all Kieker components):")
println(" Errors: " + cpdErrors + " (Threshold: " + cpdErrorThreshold + ")")
// Fail build if Checkstyle thresholds are violated
if (csWarnings > Integer.valueOf(checkstyleWarningThreshold)) {
throw new GradleException("There were checkstyle warnings exceeding the warning threshold! Warnings: " + csWarnings + " Threshold: " + checkstyleWarningThreshold)
}
if (csErrors > Integer.valueOf(checkstyleErrorThreshold)) {
throw new GradleException("There were checkstyle errors exceeding the error threshold! Errors: " + csErrors + " Threshold: " + checkstyleErrorThreshold)
}
// Fail build if Findbugs thresholds are violated
if (fbWarnings > Integer.valueOf(findbugsWarningThreshold)) {
throw new GradleException("There were findbugs warnings exceeding the warning threshold! Warnings: " + fbWarnings + " Threshold: " + findbugsWarningThreshold)
}
if (fbErrors > Integer.valueOf(findbugsErrorThreshold)) {
throw new GradleException("There were findbugs errors exceeding the error threshold! Errors: " + fbErrors + " Threshold: " + findbugsErrorThreshold)
}
// Fail build if PMD thresholds are violated
if (pmdWarnings > Integer.valueOf(pmdWarningThreshold)) {
throw new GradleException("There were pmd warnings exceeding the warning threshold! Warnings: " + pmdWarnings + " Threshold: " + pmdWarningThreshold)
}
if (pmdErrors > Integer.valueOf(pmdErrorThreshold)) {
throw new GradleException("There were pmd errors exceeding the error threshold! Errors: " + pmdErrors + " Threshold: " + pmdErrorThreshold)
}
// Fail build if CPD thresholds are violated
if (cpdErrors > Integer.valueOf(cpdErrorThreshold)) {
throw new GradleException("There were cpd errors exceeding the error threshold! Errors: " + cpdErrors + " Threshold: " + cpdErrorThreshold)
}
}
}
tasks.check.finalizedBy(checkThresholds)
}
}
//////////////////////////
// GOOMPH configuration //
//////////////////////////
/////////////
// PLUGINS //
/////////////
// tasks to clean and jar all of the plugins
Closure IS_PLUGIN = { it.name.startsWith('peropteryx') }
configure(subprojects.findAll(IS_PLUGIN)) {
// we need the maven repo from p2
evaluationDependsOn(':target.p2')
def PROJECT_NAME = it.name
//////////
// JAVA //
//////////
apply plugin: 'java'
sourceSets {
main { java {
srcDir 'src'
} }
test { java {
srcDir 'test'
} }
}
sourceCompatibility = VER_JAVA
targetCompatibility = VER_JAVA
// Add SWT and the appropriate platform-native SWT for building and testing
// (We removed the dependencies resolved from p2 repository with goomph because they inconsistently caused
// build failures. However, they will be needed to export an peropteryx product with goomph)
// dependencies {
// compile "eclipse-deps:org.eclipse.swt:+"
// compile "eclipse-deps:org.eclipse.swt.${com.diffplug.common.swt.os.SwtPlatform.getNative()}:+"
// }
//////////
// OSGI //
//////////
// create the manifest
apply plugin: 'com.diffplug.gradle.osgi.bndmanifest'
osgiBndManifest {
copyTo 'META-INF/MANIFEST.MF'
}
// configure the OSGi bundle
jar.manifest.attributes(
'-exportcontents': 'peropteryx.*',
'-removeheaders': 'Bnd-LastModified,Bundle-Name,Created-By,Tool,Private-Package,Require-Capability',
'Import-Package': '!javax.annotation.*,*',
'Bundle-SymbolicName': project.name,
'Bundle-RequiredExecutionEnvironment': 'JavaSE-1.8',
'Require-Capability': 'osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"',
'Bundle-Vendor': 'iObserve',
'Bundle-License': "http://www.apache.org/licenses/LICENSE-2.0",
'Export-Package': 'org.iobserve.peropteryx.rcp'
)
//////////////////////
// ECLIPSE PROJECTS //
//////////////////////
apply plugin: 'eclipse'
// remove the build folder
apply plugin: 'com.diffplug.gradle.eclipse.excludebuildfolder'
// improve the project deps
apply plugin: 'com.diffplug.gradle.eclipse.projectdeps'
// handle build.properties correctly
apply plugin: 'com.diffplug.gradle.eclipse.buildproperties'
eclipse {
project {
natures 'org.eclipse.pde.PluginNature'
natures 'org.eclipse.jdt.core.javanature'
buildCommand 'org.eclipse.jdt.core.javabuilder'
buildCommand 'org.eclipse.pde.ManifestBuilder'
buildCommand 'org.eclipse.pde.SchemaBuilder'
}
classpath {
downloadSources true
downloadJavadoc true
}
jdt {
sourceCompatibility VER_JAVA
targetCompatibility VER_JAVA
}
}
// always create "fresh" projects
tasks.eclipse.dependsOn(cleanEclipse)
}
/////////////////////////////////////////////////////////
// Root eclipse project for tinkering with build files //
/////////////////////////////////////////////////////////
apply plugin: 'com.diffplug.gradle.eclipse.resourcefilters'
eclipseResourceFilters {
exclude().folders().name('com.diffplug.*')
}
/////////////////////////////
// Setup a headless launch //
/////////////////////////////
apply plugin: 'com.diffplug.gradle.equinoxlaunch'
// Multiple versions of dependencies have to be specified here and in target.maven/build.gradle
equinoxLaunch {
codegenSetup {
//source.addProject(project(':peropteryx.rcp'))
source.addMaven('extra:org.antlr.runtime:4.3.0.v201502022030')
source.addMaven('extra:org.antlr.runtime:3.2.0.v201101311130')
source.addMaven('extra:org.apache.batik.css:1.7.0.v201011041433')
source.addMaven('extra:org.apache.batik.css:1.8.0.v20170214-1941')
source.addMaven('extra:org.apache.batik.util:1.7.0.v201011041433')
source.addMaven('extra:org.apache.batik.util:1.8.0.v20170214-1941')
source.addMaven('extra:org.apache.batik.util.gui:1.7.0.v200903091627')
source.addMaven('extra:org.apache.batik.util.gui:1.8.0.v20170214-1941')
}
}