blob: 32acd3992ebb734eddbaaaa14d902e607e2af166 [file] [log] [blame]
import org.apache.tools.ant.filters.ReplaceTokens
if (!rootProject.useIndy()) {
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', '**/*.iml', '**/*.ipr', '**/*.iws', // used by Intellij IDEA
'.settings', // used by Eclipse
'.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/groovy-jdk") {
from docGDK.destinationDir
}
}
task copy(type: Copy) {
into "$buildDir/meta"
with licenseSpec
}
def groovyOsgiManifest, subprojectOsgiManifest
if (!rootProject.useIndy()) {
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)
}
}
if (!rootProject.useIndy()) {
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)
}
}
if (!rootProject.useIndy() && project.name != 'groovy-all-tests') {
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 = "$metaInfDir/MANIFEST.MF"
manifest.writeTo(manifestPath)
copy {
from(mergeModuleDescriptors())
into "$buildDir/tmp/groovy-all-metainf/services"
}
copy {
into "$buildDir/tmp/groovy-all-metainf"
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: "$metaInfDir/MANIFEST.MF") {
zipfileset(dir: "$ext.metaInfDir", prefix: 'META-INF')
zipfileset(
src: jar.archivePath,
excludes: 'groovy/util/CliBuilder*.class,groovy/util/OptionAccessor*.class,org/codehaus/groovy/tools/shell/util/HelpFormatter*.class')
moduleJars().each {
zipfileset(src: it, excludes: '**/org.codehaus.groovy.runtime.ExtensionModule')
}
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"
}
}
if (!rootProject.useIndy()) {
// 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, filesonly:true, manifest: manifestPath) {
zipfileset(
src: jar.archivePath,
includes: 'groovy/util/CliBuilder*.class,groovy/util/OptionAccessor*.class,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
})
}
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/bin/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) {
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
}
}