| import org.apache.tools.ant.filters.ReplaceTokens |
| |
| apply plugin: 'osgi' |
| |
| group = 'org.codehaus.groovy' |
| archivesBaseName = 'groovy' |
| |
| 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', |
| '**/*.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 |
| } |
| |
| 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': groovyBundleVersion, |
| 'Specification-Vendor': 'The Codehaus', |
| 'Implementation-Title': 'Groovy: a powerful, dynamic language for the JVM', |
| 'Implementation-Version': groovyBundleVersion, |
| 'Implementation-Vendor': 'The Codehaus', |
| 'Bundle-ManifestVersion': '2', |
| 'Bundle-Name': 'Groovy Runtime', |
| 'Bundle-Description': 'Groovy Runtime', |
| 'Bundle-Version': groovyBundleVersion, |
| 'Bundle-Vendor': 'The Codehaus', |
| 'Bundle-ClassPath': '.', |
| 'Eclipse-BuddyPolicy': 'dependent', |
| 'DynamicImport-Package': '*', |
| 'Main-class': 'groovy.ui.GroovyMain') |
| } |
| |
| ext.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=${groovyBundleVersion}" |
| classpath = sourceSets.main.runtimeClasspath |
| } |
| |
| ext.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=${groovyBundleVersion}" |
| 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) |
| } |
| } |
| |
| exclude '**/package-info.class', 'META-INF/groovy-release-info.properties' |
| |
| } |
| |
| allprojects { |
| task jarjar(type:Jar, dependsOn: jar) { |
| destinationDir = jar.destinationDir |
| baseName = jar.baseName |
| appendix = jar.appendix?"${jar.appendix}-jarjar":"jarjar" |
| classifier = jar.classifier |
| includeEmptyDirs = false |
| def target = new File("${archivePath}.tmp") |
| def targetTmp = new File("${archivePath}.tmp.1.tmp") |
| |
| doFirst { |
| from zipTree(target) |
| |
| def keepUntouched = [ |
| 'org/codehaus/groovy/cli/GroovyPosixParser*.class', |
| 'groovy/util/CliBuilder*.class', |
| 'groovy/util/OptionAccessor*.class', |
| 'org/codehaus/groovy/tools/shell/util/HelpFormatter*.class' |
| ].join(',') |
| boolean isRoot = project == rootProject |
| def gradleProject = project |
| ant { |
| taskdef name: 'jarjar', classname: 'com.tonicsystems.jarjar.JarJarTask', classpath: rootProject.configurations.tools.asPath |
| jarjar(jarfile: targetTmp) { |
| zipfileset( |
| src: jar.archivePath, |
| excludes: keepUntouched) |
| |
| // only groovy core will include the dependencies repackaged |
| if (isRoot) { |
| 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/Printer.class,org/objectweb/asm/util/Textifier.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' |
| } |
| } |
| |
| def manifestSpec = isRoot ? groovyOsgiManifest : subprojectOsgiManifest |
| manifest = osgiManifest { |
| symbolicName = gradleProject.name |
| instruction 'Import-Package', '*;resolution:=optional' |
| classesDir = targetTmp |
| } |
| manifest(manifestSpec) |
| |
| def manifestPath = "${temporaryDir}/META-INF/MANIFEST.MF" |
| manifest.writeTo(manifestPath) |
| |
| ant.copy(file: targetTmp, tofile: target) |
| ant.jar(destfile: target, update: true, manifest: manifestPath) { |
| zipfileset( |
| src: jar.archivePath, |
| includes: keepUntouched) |
| } |
| |
| } |
| doLast { |
| target.delete() |
| ant.delete(file: targetTmp, quiet: true, deleteonexit: true) |
| } |
| } |
| |
| if (project.name in ['groovy', 'groovy-test']) { |
| task grooidjar(type: Jar) { |
| onlyIf { |
| !rootProject.useIndy() |
| } |
| destinationDir = jar.destinationDir |
| baseName = jar.baseName |
| appendix = jar.appendix |
| classifier = jar.classifier ? "${jar.classifier}grooid" : 'grooid' |
| includeEmptyDirs = false |
| def target = new File("${archivePath}.tmp") |
| boolean isRootProject = project==rootProject |
| |
| doFirst { |
| from zipTree(target) |
| ant { |
| taskdef name: 'jarjar', classname: 'com.tonicsystems.jarjar.JarJarTask', classpath: rootProject.configurations.tools.asPath |
| jarjar(jarfile: target) { |
| zipfileset(src: jarjar.archivePath) |
| if (isRootProject) { |
| zipfileset(src: rootProject.configurations.runtime.files.find { it.name.startsWith('openbeans') }) |
| } |
| rule pattern: 'com.googlecode.openbeans.**', result: 'groovyjarjaropenbeans.@1' |
| rule pattern: 'org.apache.harmony.beans.**', result: 'groovyjarjarharmonybeans.@1' |
| rule pattern: 'java.beans.**', result: 'groovyjarjaropenbeans.@1' |
| } |
| } |
| |
| } |
| doLast { |
| target.delete() |
| } |
| } |
| jarjar.finalizedBy(grooidjar) |
| } |
| } |
| |
| 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) |
| } |
| } |
| 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 replaceJarWithJarJar(dependsOn: allprojects.jarjar ) { |
| description = "Overwrites normal JAR files with their JARJAR version" |
| doLast { |
| allprojects { |
| def jarjarFile = tasks.jarjar.archivePath |
| if (jarjarFile) { |
| file(jar.archivePath).delete() |
| ant.copy(file: jarjarFile, tofile: jar.archivePath) |
| jarjarFile.delete() |
| } |
| } |
| } |
| inputs.files(allprojects.jarjar.archivePath) |
| outputs.files(allprojects.jar.archivePath) |
| } |
| |
| task jarAll(type: Jar, dependsOn: replaceJarWithJarJar) { |
| |
| inputs.files(allprojects.jar.archivePath) |
| |
| 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' |
| |
| def archivePathTmp = new File("${archivePath}.1.tmp") |
| ant { |
| taskdef name: 'jarjar', classname: 'com.tonicsystems.jarjar.JarJarTask', classpath: configurations.tools.asPath |
| jarjar(jarfile: archivePathTmp, manifest: "$owner.ext.metaInfDir/MANIFEST.MF") { |
| zipfileset(dir: "$owner.ext.metaInfDir", prefix: 'META-INF', excludes: 'META-INF') |
| zipfileset(src: jar.archivePath) |
| moduleJars().each { |
| zipfileset(src: it) |
| } |
| } |
| } |
| |
| manifest = osgiManifest { |
| symbolicName = 'groovy-all' |
| instruction 'Import-Package', '*;resolution:=optional' |
| classesDir = archivePathTmp |
| } |
| manifest groovyOsgiManifest |
| manifestPath = "${temporaryDir}/META-INF/MANIFEST.MF" |
| manifest.writeTo(manifestPath) |
| |
| ant { |
| copy(file: archivePathTmp, tofile: archivePath) |
| jar(destfile: archivePath, update:true, manifest: manifestPath) { |
| zipfileset(src: jar.archivePath) |
| } |
| delete(file: archivePathTmp, quiet: true, deleteonexit: true) |
| } |
| } |
| } |
| |
| 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') && !it.name.startsWith('asm-') && !it.name.startsWith('antlr-') } + |
| modules()*.jar.archivePath + |
| modules().configurations.runtime*.findAll { |
| it.name.endsWith('jar') && !it.name.contains('livetribe-jsr223') && !it.name.matches(/groovy-\d.*/) && !it.name.startsWith('asm-') && !it.name.startsWith('antlr-') |
| }.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, replaceJarWithJarJar]) { |
| 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") |
| } |
| } |