/
assemble.gradle
422 lines (382 loc) · 14.3 KB
/
assemble.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
import org.apache.tools.ant.filters.ReplaceTokens
apply plugin: 'osgi'
group = 'org.codehaus.groovy'
archivesBaseName = 'groovy'
ext.allManifest = manifest {
attributes('Built-By': System.properties['user.name'],
'Extension-Name': 'groovy',
'Specification-Title': 'Groovy: a powerful, dynamic language for the JVM',
'Specification-Version': project.version,
'Specification-Vendor': 'The Codehaus',
'Implementation-Title': 'Groovy: a powerful, dynamic language for the JVM',
'Implementation-Version': project.version,
'Implementation-Vendor': 'The Codehaus',
'Bundle-ManifestVersion': '2',
'Bundle-Name': 'Groovy Runtime',
'Bundle-Description': 'Groovy Runtime',
'Bundle-Version': groovyBundleVersion,
'Bundle-Vendor': 'The Codehaus',
'Bundle-ClassPath': '.',
'Bundle-RequiredExecutionEnvironment': 'J2SE-1.5',
'Eclipse-BuddyPolicy': 'dependent',
'DynamicImport-Package': '*',
'Main-class': 'groovy.ui.GroovyMain')
}
ext.licenseSpec = copySpec {
from 'config/build'
from(zipTree(configurations.compile.fileCollection { it.name.startsWith 'commons-cli' }.singleFile).matching {
include 'META-INF/LICENSE.txt'
}) {
eachFile { details ->
details.path = details.path - 'META-INF'
details.name = 'CLI-LICENSE.txt'
}
}
}
ext.srcSpec = copySpec {
from(projectDir) {
exclude 'target',
'subprojects/*/target',
'buildSrc/target',
buildDir.path,
'classes/**',
'cruise/**',
'.clover/*',
'local.build.properties',
'cobertura.ser',
'junitvmwatcher*.properties',
'out',
'bintray.properties', // generated by the CI server
'gradle.properties.gz', // generated by the CI server
'**/*.iml', // used by Intellij IDEA
'**/*.ipr', // used by Intellij IDEA
'**/*.iws', // used by Intellij IDEA
'.settings', // used by Eclipse
'.gradle', // used by Gradle
'buildSrc/.gradle' // used by Gradle
}
}
ext.docSpec = copySpec {
into('pdf') {
from 'src/wiki-snapshot.pdf'
}
into('html/api') {
from javadocAll.destinationDir
}
into('html/gapi') {
from groovydocAll.destinationDir
}
into('html/documentation') {
from "$buildDir/asciidoc"
}
into('html/groovy-jdk') {
from docGDK.destinationDir
}
}
task copy(type: Copy) {
into "$buildDir/meta"
with licenseSpec
}
def groovyOsgiManifest, subprojectOsgiManifest
groovyOsgiManifest = {
// Exclude the Bnd-LastModified attribute as it always triggers a rebuild without being really needed.
from(allManifest) {
eachEntry { details ->
if (details.key == 'Bnd-LastModified') {
details.exclude()
}
}
}
version = groovyBundleVersion
instruction '-nouses', 'true'
instruction 'Export-Package', "*;version=${version}"
classpath = sourceSets.main.runtimeClasspath
}
subprojectOsgiManifest = {
// Exclude attributes not needed for subprojects.
from(allManifest) {
eachEntry { details ->
if (details.key in ['Bnd-LastModified', 'Extension-Name', 'Bundle-Name', 'Bundle-Description', 'Main-class']) {
details.exclude()
}
}
}
version = groovyBundleVersion
instruction '-nouses', 'true'
instruction 'Export-Package', "*;version=${version}"
classpath = sourceSets.main.runtimeClasspath
}
jar {
dependsOn('dgmConverter')
metaInf {
from 'LICENSE.txt'
from('src/main/META-INF/groovy-release-info.properties') {
filter(rootProject.propertiesFilter, org.apache.tools.ant.filters.ReplaceTokens)
}
}
manifest = osgiManifest {
symbolicName = 'groovy'
instruction 'Import-Package', 'antlr', 'org.objectweb.asm', '*;resolution:=optional'
classesDir = sourceSets.main.output.classesDir
}
manifest groovyOsgiManifest
exclude '**/package-info.class', 'META-INF/groovy-release-info.properties'
}
subprojects {
jar {
metaInf {
from "${rootProject.projectDir}/LICENSE.txt"
from("${rootProject.projectDir}/src/main/META-INF/groovy-release-info.properties") {
filter(rootProject.propertiesFilter, org.apache.tools.ant.filters.ReplaceTokens)
}
}
manifest = osgiManifest {
symbolicName = project.name
classesDir = sourceSets.main.output.classesDir
}
manifest subprojectOsgiManifest
exclude '**/package-info.class', 'META-INF/groovy-release-info.properties'
}
}
def moduleJars() {
modules()*.jar.archivePath
}
def mergeModuleDescriptors() {
new File("$buildDir/tmp/").mkdirs()
def extensionClasses = []
def staticExtensionClasses = []
modules().collect {
new File("${it.buildDir}/classes/main/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule")
}.findAll { it.exists() }.each {
def props = new Properties()
props.load(it.newInputStream())
extensionClasses += props.get('extensionClasses').split(',').findAll { it }
staticExtensionClasses += props.get('staticExtensionClasses').split(',').findAll { it }
}
def descriptor = new File("$buildDir/tmp/org.codehaus.groovy.runtime.ExtensionModule")
descriptor.withWriter('UTF-8') {
it << '# This is a generated file, do not edit\n'
it << 'moduleName=groovy-all\n'
it << "moduleVersion=${project.version}\n"
it << "extensionClasses=${extensionClasses.join(',')}\n"
it << "staticExtensionClasses=${staticExtensionClasses.join(',')}\n"
}
descriptor
}
task jarAll(type: Jar, dependsOn: { modules()*.jar }) {
ext.metaInfDir = "$buildDir/tmp/groovy-all-metainf"
appendix = 'all'
includeEmptyDirs = false
if (rootProject.useIndy()) {
classifier = 'indy'
}
doLast {
def manifestPath = "$ext.metaInfDir/MANIFEST.MF"
manifest.writeTo(manifestPath)
copy {
from(mergeModuleDescriptors())
into "$owner.ext.metaInfDir/services"
}
copy {
into "$owner.ext.metaInfDir"
with licenseSpec
}
logger.info 'Packaging with jarjar'
project.ant {
taskdef name: 'jarjar', classname: 'com.tonicsystems.jarjar.JarJarTask', classpath: configurations.tools.asPath
jarjar(jarfile: archivePath, manifest: "$owner.ext.metaInfDir/MANIFEST.MF") {
zipfileset(dir: "$owner.ext.metaInfDir", prefix: 'META-INF', excludes: 'META-INF')
zipfileset(
src: jar.archivePath,
excludes: 'org/codehaus/groovy/cli/GroovyPosixParser*.class,groovy/util/CliBuilder*.class,groovy/util/OptionAccessor*.class')
moduleJars().each {
// HelpFormatter only found in groovy-groovysh but no harm for other modules
zipfileset(
src: it,
excludes: '**/org.codehaus.groovy.runtime.ExtensionModule,org/codehaus/groovy/tools/shell/util/HelpFormatter*.class')
}
configurations.runtime.files.findAll { file ->
['antlr', 'asm', 'commons-cli'].any { file.name.startsWith(it) } && ['asm-attr', 'asm-util', 'asm-analysis'].every { !file.name.startsWith(it) }
}.each { jarjarFile ->
zipfileset(src: jarjarFile)
}
zipfileset(src: configurations.runtime.files.find { file -> file.name.startsWith('asm-util') },
includes: 'org/objectweb/asm/util/AbstractVisitor.class,org/objectweb/asm/util/Trace*')
rule pattern: 'antlr.**', result: 'groovyjarjarantlr.@1'
rule pattern: 'org.objectweb.**', result: 'groovyjarjarasm.@1'
rule pattern: 'org.apache.commons.cli.**', result: 'groovyjarjarcommonscli.@1'
}
}
// We exclude the Bnd-LastModified attribute as it always triggers a rebuild without being really needed.
manifest = osgiManifest {
symbolicName = 'groovy-all'
instruction 'Import-Package', '*;resolution:=optional'
classesDir = archivePath
}
manifest groovyOsgiManifest
manifestPath = "${temporaryDir}/META-INF/MANIFEST.MF"
manifest.writeTo(manifestPath)
project.ant {
jar(destfile: archivePath, update:true, manifest: manifestPath) {
zipfileset(
src: jar.archivePath,
includes: 'org/codehaus/groovy/cli/GroovyPosixParser*.class,groovy/util/CliBuilder*.class,groovy/util/OptionAccessor*.class')
moduleJars().each {
// HelpFormatter only found in groovy-groovysh but have left all modules here to allow future expansion
zipfileset(src: it, includes: 'org/codehaus/groovy/tools/shell/util/HelpFormatter*.class')
}
}
}
}
}
allprojects {
task jarWithIndy(type: GradleBuild) {
onlyIf rootProject.indyCapable
description = 'Triggers an external build generating the indy jar'
buildFile = 'build.gradle'
startParameter.projectProperties['indy'] = true
tasks = ['jar']
}
}
task jarAllWithIndy(type: GradleBuild) {
onlyIf rootProject.indyCapable
description = 'Triggers an external build generating the indy jarAll'
buildFile = 'build.gradle'
startParameter.projectProperties['indy'] = true
tasks = ['jarAll']
}
task jarAllAll(dependsOn: [jarAll, jarAllWithIndy]) {
description = 'Generates groovy-all and groovy-all-indy jars'
doFirst {
if (useIndy()) {
logger.lifecycle('InvokeDynamic support was activated but needs to be off for this pass. Disabling.')
ext.useIndy = false
}
}
}
task sourceAllJar(type: Jar, dependsOn: { modules()*.sourceJar + rootProject.sourceJar }) {
with sourceJar.rootSpec
modules()*.sourceJar.each {
with it.rootSpec
}
appendix = 'all'
classifier = rootProject.useIndy() ? 'indy-sources' : 'sources'
}
allprojects {
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = rootProject.useIndy() ? 'indy-javadoc' : 'javadoc'
from javadoc.destinationDir
}
task groovydocJar(type: Jar, dependsOn: groovydoc) {
classifier = rootProject.useIndy() ? 'indy-groovydoc' : 'groovydoc'
from groovydoc.destinationDir
}
}
task javadocAllJar(type: Jar, dependsOn: javadocAll) {
appendix = 'all'
classifier = rootProject.useIndy() ? 'indy-javadoc' : 'javadoc'
from javadocAll.destinationDir
}
task groovydocAllJar(type: Jar, dependsOn: groovydocAll) {
appendix = 'all'
classifier = rootProject.useIndy() ? 'indy-groovydoc' : 'groovydoc'
from groovydocAll.destinationDir
}
ext.distSpec = copySpec {
from("$projectDir") {
include 'LICENSE.txt', 'NOTICE.txt'
}
into('lib') {
from jar.archivePath
from({
configurations.runtime.findAll { it.name.endsWith 'jar' } +
modules()*.jar.archivePath +
modules().configurations.runtime*.findAll {
it.name.endsWith('jar') && !it.name.contains('livetribe-jsr223') && !it.name.matches(/groovy-\d.*/)
}.flatten() as Set
})
from('src/bin/groovy.icns')
}
into('indy') {
from { new File(jar.archivePath.parent, "${jar.baseName}-${jar.version}-indy.jar") }
from {
modules()*.jar.collect { j ->
new File(j.archivePath.parent, "${j.baseName}-${j.version}-indy.jar")
}
}
}
into('conf') {
from 'src/conf'
}
into('bin') {
from('src/bin') {
filter(ReplaceTokens, tokens: [GROOVYJAR:jar.archiveName])
fileMode = 0755
exclude 'groovy.icns'
}
from('src/tools/org/codehaus/groovy/tools/groovy.ico')
}
into('embeddable') {
from jarAll.archivePath
from { new File(jarAll.archivePath.parent, "${jarAll.baseName}-${jarAll.appendix}-${jarAll.version}-indy.jar") }
}
}
task distBin(type: Zip, dependsOn: [jar, jarAllAll]) {
appendix = 'binary'
into("groovy-$version") {
with distSpec
with licenseSpec
}
}
task distDoc(type: Zip, dependsOn: doc) {
appendix = 'docs'
into("groovy-$version")
with docSpec
}
task syncDoc(type: Copy, dependsOn: doc) {
inputs.files javadoc.outputs.files
inputs.files groovydoc.outputs.files
destinationDir(file("$buildDir/html"))
into('api') {
from javadoc.destinationDir
}
into('gapi') {
from groovydoc.destinationDir
}
// groovy-jdk already at the good place
}
task distSrc(type: Zip) {
appendix = 'src'
into("groovy-$version")
with srcSpec
}
def installDir = {
project.hasProperty('groovy_installPath')?project.groovy_installPath:
System.properties.installDirectory ?: "$buildDir/install"
}
task installGroovy(type: Sync, dependsOn: distBin) {
description 'Generates a groovy distribution into an install directory'
doLast {
logger.lifecycle "Groovy installed under ${installDir()}"
}
with distSpec
with licenseSpec
into installDir
}
task dist(type: Zip, dependsOn: [distBin, distSrc, distDoc, syncDoc]) {
description = 'Generates the binary, sources, documentation and full distributions'
appendix 'sdk'
into "groovy-$version"
with distSpec
with licenseSpec
into('doc') {
with docSpec
}
into('src') {
with srcSpec
}
if ((version.endsWith('SNAPSHOT') && !groovyBundleVersion.endsWith('SNAPSHOT'))
|| (!version.endsWith('SNAPSHOT') && groovyBundleVersion.endsWith('SNAPSHOT'))) {
throw new GradleException("Incoherent versions. Found groovyVersion=$version and groovyBundleVersion=$groovyBundleVersion")
}
}