-
Notifications
You must be signed in to change notification settings - Fork 578
/
build.gradle
538 lines (483 loc) · 19.2 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
import static groovy.io.FileType.FILES
// TODO: deploy not only jar but also sources and javadoc, to pass validation by Sonatype nexus
// apply from: "$rootDir/gradle/maven.gradle"
plugins {
id 'org.ajoberstar.grgit' version '4.1.1'
id "eclipse-convention"
}
def readLastCommitHash() {
// Same as 'git log -1 --pretty=format:"%h"'.execute().getText()
org.ajoberstar.grgit.Grgit.open(dir: rootDir).head().abbreviatedId
}
if (version.endsWith('-SNAPSHOT')) {
// eclipse doesn't like the `-SNAPSHOT`, so we timestamp uniquely
version = version - '-SNAPSHOT' + '.' + new Date().format('yyyyMMddHHmm') + '-' + readLastCommitHash()
} else if (version.contains('-RC')) {
// eclipse doesn't like the `-RC`, so we timestamp uniquely
version = version.substring(0, version.lastIndexOf('-RC')) + '.' + new Date().format('yyyyMMddHHmm') + '-' + readLastCommitHash()
} else if (version.contains('-beta')) {
// eclipse doesn't like the `-beta`, so we timestamp uniquely
version = version.substring(0, version.lastIndexOf('-beta')) + '.' + new Date().format('yyyyMMddHHmm') + '-' + readLastCommitHash()
} else {
// A release build version like 3.0.0 without qualifier will always be smaller
// then nightly build 3.0.0.20171023-1508734123102, but to update from nightlies
// we must give Eclipse a higher version number.
// The "r" makes the release version to be always higher then nightly builds
version = version + '.r' + new Date().format('yyyyMMddHHmm') + '-' + readLastCommitHash()
}
sourceSets {
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['src']
include '**/*.properties'
include '**/*.xml'
}
}
}
def findEclipseExecutable() {
if (!file("$projectDir/local.properties").exists()) {
return null
}
def localProps = new Properties()
localProps.load(new FileInputStream("$projectDir/local.properties"))
def eclipseRootDir = file(localProps.getProperty('eclipseRoot.dir'))
// Eclipse 4.5+ uses a different directory layout under macOS. Try to detect this first.
def eclipseExecutable = new File(eclipseRootDir, "Contents/MacOS/eclipse")
if (!eclipseExecutable.exists()) {
// Fall back to non-macOS directory layout.
eclipseExecutable = new File(eclipseRootDir, "eclipse")
}
return eclipseExecutable
}
def eclipsePluginId = 'com.github.spotbugs.plugin.eclipse'
def eclipseExecutable = findEclipseExecutable()
dependencies {
api (project(':spotbugs')) {
transitive = true
}
}
tasks.named('clean', Delete).configure {
delete "lib", "build"
}
// This disables hundreds of javadoc warnings on missing tags etc, see #340
tasks.named('javadoc', Javadoc).configure {
// This is supposed to enable everything except "missing" but doesn't work with gradle
// See http://docs.oracle.com/javase/8/docs/technotes/tools/unix/javadoc.html
options.addBooleanOption('Xdoclint:all,-missing', true)
// TODO remove command and warning below if the doclint can be properly configured
options.addStringOption('Xmaxwarns', '3')
doLast {
logger.warn('Javadoc: too many warnings, only first 3 are shown, see #340!')
}
}
def copyLibsForEclipse = tasks.register('copyLibsForEclipse', Copy) {
from (configurations.runtimeClasspath) {
include "*.jar"
}
into "lib"
}
def distSrcZip = tasks.register('distSrcZip', Exec) {
def out = "${buildDir}/distributions/${eclipsePluginId}_${project.version}-source.zip"
outputs.file out
commandLine 'git', 'archive', '-o', out, 'HEAD'
}
def updateManifest = tasks.register('updateManifest') {
inputs.file "$projectDir/META-INF/MANIFEST-TEMPLATE.MF"
outputs.file "$projectDir/META-INF/MANIFEST.MF"
outputs.file "$projectDir/META-INF/MANIFEST-DIST.MF"
inputs.file "$projectDir/build-template.properties"
outputs.file "$projectDir/build.properties"
dependsOn ':spotbugs:updateManifest', copyLibsForEclipse
doLast {
def manifestSpec = manifest {
from "$projectDir/META-INF/MANIFEST-TEMPLATE.MF"
attributes 'Bundle-SymbolicName': "$eclipsePluginId; singleton:=true",
'Bundle-Version': project.version,
'Bundle-ClassPath': ".,spotbugs-plugin.jar," + fileTree(dir: 'lib').collect {
projectDir.toPath().relativize(it.toPath()).toString().replace('\\', '/') }.join(',')
}
def distManifestSpec = manifest {
from "$projectDir/META-INF/MANIFEST-TEMPLATE.MF"
attributes 'Bundle-SymbolicName': "$eclipsePluginId; singleton:=true",
'Bundle-Version': project.version,
'Bundle-ClassPath': "spotbugs-plugin.jar," + fileTree(dir: 'lib').collect {
projectDir.toPath().relativize(it.toPath()).toString().replace('\\', '/') }.join(',')
}
// write manifests
manifestSpec.writeTo("$projectDir/META-INF/MANIFEST.MF")
distManifestSpec.writeTo("$projectDir/META-INF/MANIFEST-DIST.MF")
// write build.properties
def propsTemplate = file("$projectDir/build-template.properties")
def props = new Properties()
props.load(propsTemplate.newDataInputStream())
props.setProperty('bin.includes', props.getProperty('bin.includes') + ',' +
fileTree(dir: 'lib').collect { projectDir.toPath().relativize(it.toPath()).toString().replace('\\', '/') }.join(','))
props.store(file('build.properties').newWriter(), null)
}
}
tasks.named('compileJava').configure { dependsOn ':spotbugs:jar' }
// create manifest when importing to eclipse
tasks.named('eclipse').configure { dependsOn copyLibsForEclipse, updateManifest }
class FileRef implements org.gradle.plugins.ide.eclipse.model.FileReference {
def file;
def FileRef(File file){
this.file = file
}
def File getFile(){
return file;
}
def String getJarURL(){
return "jar:" + file
}
def String getPath(){
return file.toString().replace('\\', '/')
}
def boolean isRelativeToPathVariable(){
return false
}
}
eclipse.classpath.file {
whenMerged {
classpath ->
classpath.entries.removeAll {
entry -> entry.kind == 'lib'
}
copyLibsForEclipse
fileTree(dir: 'lib').forEach {
file ->
def rel = projectDir.toPath().relativize(java.nio.file.Paths.get(file.toString())).toFile()
org.gradle.plugins.ide.eclipse.model.ClasspathEntry entry =
new org.gradle.plugins.ide.eclipse.model.Library(new FileRef(rel))
classpath.entries.add(entry)
}
}
}
def jar = tasks.named('jar', Jar) {
// Make sure we always update the manifest when building
dependsOn updateManifest
includeEmptyDirs = false
from sourceSets.main.output
archiveFileName = 'spotbugs-plugin.jar'
}
def distSpec = copySpec {
from jar.map { it.outputs.files }
from(project.projectDir) {
include 'RELEASENOTES'
include 'plugin.xml'
include '.options'
include 'OSGI-INF/l10n/*.properties'
include '*.png'
include 'about.*'
include 'doc/*.*'
include 'plugin/*.*'
include 'icons/*.*'
include 'lib/'
}
from('../spotbugs/') { // FIXME : Ugly... but those plugin are gonna die anyway...
include 'plugin/**'
}
from('META-INF/MANIFEST-DIST.MF') {
filter { line ->
if (line.startsWith('Bundle-Version:')) {
return "Bundle-Version: ${project.version}"
}
line
}
into 'META-INF/'
rename {
'MANIFEST.MF'
}
}
}
def distZip = tasks.register('distZip', Zip) {
dependsOn jar
with distSpec
into "${eclipsePluginId}_${project.version}"
archiveFileName = "${eclipsePluginId}_${project.version}.zip"
}
def testPluginJar = tasks.register('testPluginJar') {
def jarFile = "$buildDir/site/eclipse/plugins/${eclipsePluginId}_${project.version}.jar"
inputs.file jarFile
doLast {
def spotbugsJar = zipTree(jarFile)
.matching { include 'lib/spotbugs.jar' }
.singleFile
if (!spotbugsJar.exists()) {
throw new TaskInstantiationException('Eclipse plugin does not contain spotbugs.jar');
} else {
println 'Eclipse plugin contains spotbugs.jar'
}
}
}
def pluginJar = tasks.register('pluginJar', Zip) { // use Zip task, we already provide a manifest
with distSpec
dependsOn jar
archiveFileName = "${eclipsePluginId}_${project.version}.jar"
destinationDirectory = file("${buildDir}/site/eclipse/plugins/")
finalizedBy testPluginJar
}
def pluginCandidateJar = tasks.register('pluginCandidateJar', Copy) {
dependsOn pluginJar
from pluginJar.map { it.outputs.files }
into "${buildDir}/site/eclipse-candidate/plugins/"
}
def pluginDailyJar = tasks.register('pluginDailyJar', Copy) {
dependsOn pluginJar
from pluginJar.map { it.outputs.files }
into "${buildDir}/site/eclipse-daily/plugins/"
}
def pluginStableLatestJar = tasks.register('pluginStableLatestJar', Copy) {
dependsOn pluginJar
from pluginJar.map { it.outputs.files }
into "${buildDir}/site/eclipse-stable-latest/plugins/"
}
def siteFilterTokens = [
'PLUGIN_ID': eclipsePluginId,
'PLUGIN_VERSION':"${project.version}".toString(),
'FEATURE_ID': eclipsePluginId,
'FEATURE_VERSION':"${project.version}".toString()
]
def featureJar = tasks.register('featureJar', Zip) {
archiveFileName = "${eclipsePluginId}_${project.version}.jar"
entryCompression = ZipEntryCompression.STORED // no compression, this is a jar with no manifest
from('plugin_feature.xml') {
filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
rename { 'feature.xml' }
}
from('feature_p2.inf') {
filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
rename { 'p2.inf' }
}
destinationDirectory = file("${buildDir}/site/eclipse/features/")
}
def featureCandidateJar = tasks.register('featureCandidateJar', Zip) {
archiveFileName = "${eclipsePluginId}_${project.version}.jar"
entryCompression = ZipEntryCompression.STORED // no compression, this is a jar with no manifest
from('plugin_feature-candidate.xml') {
filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
rename { 'feature.xml' }
}
from('feature_p2.inf') {
filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
rename { 'p2.inf' }
}
destinationDirectory = file("${buildDir}/site/eclipse-candidate/features/")
}
def featureDailyJar = tasks.register('featureDailyJar', Zip) {
archiveFileName = "${eclipsePluginId}_${project.version}.jar"
entryCompression = ZipEntryCompression.STORED // no compression, this is a jar with no manifest
from('plugin_feature-daily.xml') {
filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
rename { 'feature.xml' }
}
from('feature_p2.inf') {
filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
rename { 'p2.inf' }
}
destinationDirectory = file("${buildDir}/site/eclipse-daily/features/")
}
def featureStableLatestJar = tasks.register('featureStableLatestJar', Zip) {
archiveFileName = "${eclipsePluginId}_${project.version}.jar"
entryCompression = ZipEntryCompression.STORED // no compression, this is a jar with no manifest
from('plugin_feature-stable_latest.xml') {
filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
rename { 'feature.xml' }
}
from('feature_p2.inf') {
filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
rename { 'p2.inf' }
}
destinationDirectory = file("${buildDir}/site/eclipse-stable-latest/features/")
}
def siteHtml = tasks.register('siteHtml', Copy) {
filter(tokens:[
'URL': 'https://spotbugs.github.io/eclipse/'
] + siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
from 'plugin_site.html'
destinationDir = file("${buildDir}/site/eclipse")
rename { 'index.html' }
outputs.upToDateWhen {
// even if we have generated file, we should rerun this task to overwrite it.
false
}
}
def siteCandidateHtml = tasks.register('siteCandidateHtml', Copy) {
filter(tokens:[
'URL': 'https://spotbugs.github.io/eclipse-candidate/'
] + siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
from 'plugin_site.html'
destinationDir = file("${buildDir}/site/eclipse-candidate")
rename { 'index.html' }
outputs.upToDateWhen {
// even if we have generated file, we should rerun this task to overwrite it.
false
}
}
def siteDailyHtml = tasks.register('siteDailyHtml', Copy) {
filter(tokens:[
'URL': 'https://spotbugs.github.io/eclipse-latest/'
] + siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
from 'plugin_site.html'
destinationDir = file("${buildDir}/site/eclipse-daily")
rename { 'index.html' }
outputs.upToDateWhen {
// even if we have generated file, we should rerun this task to overwrite it.
false
}
}
def siteStableLatestHtml = tasks.register('siteStableLatestHtml', Copy) {
filter(tokens:[
'URL': 'https://spotbugs.github.io/eclipse-stable-latest/'
] + siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
from 'plugin_site.html'
destinationDir = file("${buildDir}/site/eclipse-stable-latest")
rename { 'index.html' }
outputs.upToDateWhen {
// even if we have generated file, we should rerun this task to overwrite it.
false
}
}
def siteXml = tasks.register('siteXml', Copy) {
filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
from 'plugin_site.xml'
destinationDir = file("${buildDir}/site/eclipse")
rename { 'site.xml' }
outputs.upToDateWhen {
// even if we have generated file, we should rerun this task to overwrite it.
false
}
}
def siteCandidateXml = tasks.register('siteCandidateXml', Copy) {
filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
from 'plugin_site-candidate.xml'
destinationDir = file("${buildDir}/site/eclipse-candidate")
rename { 'site.xml' }
outputs.upToDateWhen {
// even if we have generated file, we should rerun this task to overwrite it.
false
}
}
def siteDailyXml = tasks.register('siteDailyXml', Copy) {
filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
from 'plugin_site-daily.xml'
destinationDir = file("${buildDir}/site/eclipse-daily")
rename { 'site.xml' }
outputs.upToDateWhen {
// even if we have generated file, we should rerun this task to overwrite it.
false
}
}
def siteStableLatestXml = tasks.register('siteStableLatestXml', Copy) {
filter(tokens:siteFilterTokens, org.apache.tools.ant.filters.ReplaceTokens)
from 'plugin_site-stable_latest.xml'
destinationDir = file("${buildDir}/site/eclipse-stable-latest")
rename { 'site.xml' }
outputs.upToDateWhen {
// even if we have generated file, we should rerun this task to overwrite it.
false
}
}
// sign all .jar file under specified dir
ext.signJar = { File dir ->
def keystorepass = project.hasProperty('keystorepass') ? keystorepass : '';
if (keystorepass.isEmpty()) {
print 'to sign eclipse plugins, set "keystorepass" project property'
return
}
dir.traverse(type: FILES, nameFilter: ~/.*\.jar$/) {
def relativePath = rootDir.toPath().relativize( it.toPath() )
println "signing ${relativePath}"
ant.signjar(
destDir: it.parentFile,
jar: it,
alias: 'eclipse-plugin',
keystore: "$rootDir/spotbugs.jks",
storepass: keystorepass,
tsaurl: 'http://timestamp.digicert.com',
verbose: true
)
}
}
def confirmEclipse = tasks.register('confirmEclipse') {
doFirst {
if (eclipseExecutable == null || !eclipseExecutable.exists()) {
throw new GradleScriptException("No eclipse found in local")
}
}
}
def generateP2Metadata = tasks.register('generateP2Metadata', Exec) {
doFirst {
project.delete "${buildDir}/site/eclipse/artifacts.xml"
project.delete "${buildDir}/site/eclipse/content.xml"
signJar(file("${buildDir}/site/eclipse"))
}
inputs.file 'local.properties'
dependsOn confirmEclipse, pluginJar, featureJar, siteXml, siteHtml
commandLine "${eclipseExecutable}", '-nosplash',
'-application', 'org.eclipse.equinox.p2.publisher.UpdateSitePublisher',
'-metadataRepository', "file:${buildDir}/site/eclipse", // TODO : May not work on Windows
'-artifactRepository', "file:${buildDir}/site/eclipse", // TODO : May not work on Windows
'-source', "${buildDir}/site/eclipse"
}
def generateCandidateP2Metadata = tasks.register('generateCandidateP2Metadata', Exec) {
doFirst {
project.delete "${buildDir}/site/eclipse-candidate/artifacts.xml"
project.delete "${buildDir}/site/eclipse-candidate/content.xml"
signJar(file("${buildDir}/site/eclipse-candidate"))
}
inputs.file 'local.properties'
dependsOn confirmEclipse, pluginCandidateJar, featureCandidateJar, siteCandidateXml, siteCandidateHtml
commandLine "${eclipseExecutable}", '-nosplash',
'-application', 'org.eclipse.equinox.p2.publisher.UpdateSitePublisher',
'-metadataRepository', "file:${buildDir}/site/eclipse-candidate", // TODO : May not work on Windows
'-artifactRepository', "file:${buildDir}/site/eclipse-candidate", // TODO : May not work on Windows
'-source', "${buildDir}/site/eclipse-candidate"
}
def generateP2MetadataDaily = tasks.register('generateP2MetadataDaily', Exec) {
doFirst {
project.delete "${buildDir}/site/eclipse-daily/artifacts.xml"
project.delete "${buildDir}/site/eclipse-daily/content.xml"
signJar(file("${buildDir}/site/eclipse-daily"))
}
inputs.file 'local.properties'
dependsOn confirmEclipse, pluginDailyJar, featureDailyJar, siteDailyXml, siteDailyHtml
commandLine "${eclipseExecutable}", '-nosplash',
'-application', 'org.eclipse.equinox.p2.publisher.UpdateSitePublisher',
'-metadataRepository', "file:${buildDir}/site/eclipse-daily", // TODO : May not work on Windows
'-artifactRepository', "file:${buildDir}/site/eclipse-daily", // TODO : May not work on Windows
'-source', "${buildDir}/site/eclipse-daily"
}
def generateP2MetadataStableLatest = tasks.register('generateP2MetadataStableLatest', Exec) {
doFirst {
project.delete "${buildDir}/site/eclipse-stable-latest/artifacts.xml"
project.delete "${buildDir}/site/eclipse-stable-latest/content.xml"
signJar(file("${buildDir}/site/eclipse-stable-latest"))
}
inputs.file 'local.properties'
dependsOn confirmEclipse, pluginStableLatestJar, featureStableLatestJar, siteStableLatestXml, siteStableLatestHtml
commandLine "${eclipseExecutable}", '-nosplash',
'-application', 'org.eclipse.equinox.p2.publisher.UpdateSitePublisher',
'-metadataRepository', "file:${buildDir}/site/eclipse-stable-latest", // TODO : May not work on Windows
'-artifactRepository', "file:${buildDir}/site/eclipse-stable-latest", // TODO : May not work on Windows
'-source', "${buildDir}/site/eclipse-stable-latest"
}
def eclipseSite = tasks.register('eclipseSite') {
dependsOn generateP2Metadata, generateCandidateP2Metadata, generateP2MetadataDaily, generateP2MetadataStableLatest
}
// create zip file to upload to GitHub release page
def eclipseSiteZip = tasks.register('eclipseSiteZip', Zip) {
dependsOn eclipseSite
from("${buildDir}/site/eclipse")
archiveFileName = "eclipsePlugin.zip"
}
if (eclipseExecutable == null) {
println "Create local.properties to build eclipse site"
} else {
tasks.named('assemble').configure { dependsOn eclipseSiteZip }
}
spotbugs {
ignoreFailures = true
}