Rework how the "indy" jars are built This gets rid of the ugly `GradleBuild` call which was extremely slow and causes cache misses. This still lacks support for running tests with indy, it will be added in a subsequent commit.
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/e94d43ee Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/e94d43ee Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/e94d43ee Branch: refs/heads/master Commit: e94d43ee410106c2d2bc7f165b844aa792515391 Parents: af49c2e Author: Cedric Champeau <cchamp...@apache.org> Authored: Mon Dec 11 00:48:03 2017 +0100 Committer: Cedric Champeau <cchamp...@apache.org> Committed: Mon Dec 11 19:17:11 2017 +0100 ---------------------------------------------------------------------- build.gradle | 33 ++--- gradle.properties | 3 + gradle/assemble.gradle | 233 ++++++++++++++---------------- gradle/binarycompatibility.gradle | 2 +- gradle/indy.gradle | 53 ------- gradle/test.gradle | 8 - gradle/upload.gradle | 17 +-- subprojects/performance/build.gradle | 1 - 8 files changed, 128 insertions(+), 222 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/e94d43ee/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index 580fb0e..a50b24b 100644 --- a/build.gradle +++ b/build.gradle @@ -79,7 +79,6 @@ apply plugin: "com.github.jk1.dependency-license-report" File javaHome = new File(System.getProperty('java.home')) logger.lifecycle "Using Java from $javaHome (version ${System.getProperty('java.version')})" -indyBanner() allprojects { apply plugin: 'java' @@ -424,8 +423,6 @@ task bootstrapJar(type:Jar ) { from compileJava.destinationDir from dgmConverter.outputDir - inputs.property('indy', useIndy()) - destinationDir = file("$buildDir/bootstrap") classifier = 'bootstrap' } @@ -438,6 +435,15 @@ allprojects { options.encoding = 'UTF-8' } + task compileGroovyWithIndy(type:GroovyCompile) { + source = sourceSets.main.groovy + classpath = compileGroovy.classpath + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + groovyOptions.optimizationOptions['indy'] = true + destinationDir = file("$buildDir/classes/indy") + } + tasks.withType(GroovyCompile) { groovyOptions.fork(memoryMaximumSize: groovycMain_mx) groovyOptions.encoding = 'UTF-8' @@ -449,27 +455,6 @@ allprojects { // TODO: this null check was required after adding JMH plugin to performance project classpath = (classpath != null) ? classpath + groovyClasspath : groovyClasspath } - - if (useIndy()) { - tasks.withType(GroovyCompile) { - logger.info("Building ${project.name}:${name} with InvokeDynamic support activated") - groovyOptions.optimizationOptions.indy = true - sourceCompatibility = 1.8 - targetCompatibility = 1.8 - } - tasks.withType(JavaCompile) { - if (project.name=='performance') { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 - } else { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 - } - } - jar { - classifier = 'indy' - } - } } compileTestGroovy { http://git-wip-us.apache.org/repos/asf/groovy/blob/e94d43ee/gradle.properties ---------------------------------------------------------------------- diff --git a/gradle.properties b/gradle.properties index 058b5eb..54141a8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -34,3 +34,6 @@ javaDoc_mx=1g #org.gradle.jvmargs=-ea -Xmx1500m # jdk 6-8 org.gradle.jvmargs=-Xms800m -Xmx1500m -XX:MaxPermSize=512m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled + +# enable the Gradle build cache +org.gradle.caching=true \ No newline at end of file http://git-wip-us.apache.org/repos/asf/groovy/blob/e94d43ee/gradle/assemble.gradle ---------------------------------------------------------------------- diff --git a/gradle/assemble.gradle b/gradle/assemble.gradle index 762b043..470c8aa 100644 --- a/gradle/assemble.gradle +++ b/gradle/assemble.gradle @@ -132,111 +132,121 @@ ext.subprojectOsgiManifest = { classpath = sourceSets.main.runtimeClasspath } -jar { - dependsOn('dgmConverter') - from files(dgmConverter.outputDir) - metaInf { - from("$projectDir/licenses/LICENSE-JARJAR") - from("$projectDir/licenses") { - into('licenses') - include('asm-license.txt') - include('antlr2-license.txt') - include('antlr4-license.txt') - } - from("$projectDir/notices/NOTICE-JARJAR") - from('src/resources/META-INF/groovy-release-info.properties') { - filter(rootProject.propertiesFilter, org.apache.tools.ant.filters.ReplaceTokens) +allprojects { + jar { + appendix = 'raw' + } + task jarWithIndy(type: Jar) { + dependsOn compileGroovyWithIndy + classifier = 'indy' + appendix = 'raw' + from sourceSets.main.java.outputDir + from compileGroovyWithIndy.destinationDir + } + [jar, jarWithIndy].each { arch -> + arch.metaInf { + from("$projectDir/licenses/LICENSE-JARJAR") + from("$projectDir/licenses") { + into('licenses') + include('asm-license.txt') + include('antlr2-license.txt') + include('antlr4-license.txt') + } + from("$projectDir/notices/NOTICE-JARJAR") + from('src/resources/META-INF/groovy-release-info.properties') { + filter(rootProject.propertiesFilter, org.apache.tools.ant.filters.ReplaceTokens) + } + rename { String filename -> filename == 'LICENSE-JARJAR' ? 'LICENSE' : filename == 'NOTICE-JARJAR' ? 'NOTICE' : filename } } - rename { String filename -> filename == 'LICENSE-JARJAR' ? 'LICENSE' : filename == 'NOTICE-JARJAR' ? 'NOTICE' : filename } - } - exclude '**/package-info.class' -} + arch.exclude '**/package-info.class' -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: jarjarTaskClassName, 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 -> - // explanation of excludes: - // GROOVY-7386: stop copy of incorrect maven meta info - // GROOVY-8332: stop copy of annotation processor which is for some reason included in antlr runtime artifact - // GROOVY-8387: we don't want module-info.class from any dependencies - zipfileset(src: jarjarFile, - excludes: 'META-INF/maven/commons-cli/commons-cli/*,META-INF/*,META-INF/services/javax.annotation.processing.Processor,module-info.class') - } + task "jar${arch.name}"(type:Jar, dependsOn: arch) { + outputs.cacheIf { + // caching JarJar because it's quite expensive to create + true + } + destinationDir = arch.destinationDir + baseName = arch.baseName + classifier = arch.classifier + includeEmptyDirs = false + def target = new File("${archivePath}.tmp") + def targetTmp = new File("${archivePath}.tmp.1.tmp") + inputs.file(arch.archivePath) + + doFirst { + from zipTree(target) - 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/ASMifier.class,org/objectweb/asm/util/Trace*') + 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: jarjarTaskClassName, classpath: rootProject.configurations.tools.asPath + jarjar(jarfile: targetTmp) { + zipfileset( + src: arch.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 -> + // explanation of excludes: + // GROOVY-7386: stop copy of incorrect maven meta info + // GROOVY-8332: stop copy of annotation processor which is for some reason included in antlr runtime artifact + // GROOVY-8387: we don't want module-info.class from any dependencies + zipfileset(src: jarjarFile, + excludes: 'META-INF/maven/commons-cli/commons-cli/*,META-INF/*,META-INF/services/javax.annotation.processing.Processor,module-info.class') + } + + 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/ASMifier.class,org/objectweb/asm/util/Trace*') + } + rule pattern: 'antlr.**', result: 'groovyjarjarantlr.@1' // antlr2 + rule pattern: 'org.antlr.**', result: 'groovyjarjarantlr4.@1' // antlr4 + rule pattern: 'org.objectweb.**', result: 'groovyjarjarasm.@1' + rule pattern: 'org.apache.commons.cli.**', result: 'groovyjarjarcommonscli.@1' } - rule pattern: 'antlr.**', result: 'groovyjarjarantlr.@1' // antlr2 - rule pattern: 'org.antlr.**', result: 'groovyjarjarantlr4.@1' // antlr4 - 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 - def moduleName = "org.codehaus.${it.name.replace('-', '.')}" - attributes('Automatic-Module-Name': moduleName) - } - manifest(manifestSpec) + def manifestSpec = isRoot ? groovyOsgiManifest : subprojectOsgiManifest + manifest = osgiManifest { + symbolicName = gradleProject.name + instruction 'Import-Package', '*;resolution:=optional' + classesDir = targetTmp + def moduleName = "org.codehaus.${it.name.replace('-', '.')}" + attributes('Automatic-Module-Name': moduleName) + } + manifest(manifestSpec) - def manifestPath = "${temporaryDir}/META-INF/MANIFEST.MF" - manifest.writeTo(manifestPath) + 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) - } + ant.copy(file: targetTmp, tofile: target) + ant.jar(destfile: target, update: true, manifest: manifestPath) { + zipfileset( + src: arch.archivePath, + includes: keepUntouched) + } + } + doLast { + target.delete() + ant.delete(file: targetTmp, quiet: true, deleteonexit: true) + } } - 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 @@ -270,6 +280,11 @@ allprojects { } } +[jar, jarWithIndy].each { + it.dependsOn('dgmConverter') + it.from files(dgmConverter.outputDir) +} + subprojects { sp -> jar { metaInf { @@ -292,35 +307,8 @@ subprojects { sp -> } } -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) -} - allprojects { - rootProject.replaceJarWithJarJar.mustRunAfter(test) -} - -allprojects { - task jarWithIndy(type: GradleBuild) { - onlyIf rootProject.indyCapable - description = 'Triggers an external build generating the indy jar' - buildFile = 'build.gradle' - startParameter.projectProperties['indy'] = true - startParameter.projectCacheDir = file("$buildDir/indyCacheDir") - tasks = ['jar'] - } + rootProject.jarjar.mustRunAfter(test) } task sourceAllJar(type: Jar, dependsOn: { modules()*.sourceJar + rootProject.sourceJar }) { @@ -329,29 +317,24 @@ task sourceAllJar(type: Jar, dependsOn: { modules()*.sourceJar + rootProject.sou with it.rootSpec } baseName = 'groovy-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) { baseName = 'groovy-all' - classifier = rootProject.useIndy() ? 'indy-javadoc' : 'javadoc' from javadocAll.destinationDir } task groovydocAllJar(type: Jar, dependsOn: groovydocAll) { baseName = 'groovy-all' - classifier = rootProject.useIndy() ? 'indy-groovydoc' : 'groovydoc' from groovydocAll.destinationDir } @@ -419,7 +402,7 @@ ext.distSpec = copySpec { } } -task distBin(type: Zip, dependsOn: [jar, replaceJarWithJarJar]) { +task distBin(type: Zip, dependsOn: [jarjar]) { baseName = 'apache-groovy' appendix = 'binary' into("groovy-$version") { http://git-wip-us.apache.org/repos/asf/groovy/blob/e94d43ee/gradle/binarycompatibility.gradle ---------------------------------------------------------------------- diff --git a/gradle/binarycompatibility.gradle b/gradle/binarycompatibility.gradle index b822d11..7ed12df 100644 --- a/gradle/binarycompatibility.gradle +++ b/gradle/binarycompatibility.gradle @@ -147,7 +147,7 @@ allprojects { } task japicmp(type: me.champeau.gradle.ArtifactJapicmpTask) { - dependsOn replaceJarWithJarJar + dependsOn jarjar baseline = "org.codehaus.groovy:${project.name}:${referenceMinorVersion}@jar" to = jar.archivePath accessModifier = 'protected' http://git-wip-us.apache.org/repos/asf/groovy/blob/e94d43ee/gradle/indy.gradle ---------------------------------------------------------------------- diff --git a/gradle/indy.gradle b/gradle/indy.gradle index 75b7422..f2262c1 100644 --- a/gradle/indy.gradle +++ b/gradle/indy.gradle @@ -23,56 +23,3 @@ rootProject.ext.indyCapable = { !rootProject.hasProperty('skipIndy') } - -rootProject.ext.useIndy = { - boolean indy = false - - // first, check if a system property activates indy support - indy |= System.hasProperty('indy') && Boolean.valueOf(System.getProperty('indy')) - - // ultimately, check if the main project has an extension property setting indy to true - // which is the case if the build is started with -Pindy=true or during install/dist tasks - indy |= rootProject.hasProperty('indy') && (Boolean.valueOf(rootProject.indy)) - - indy && rootProject.indyCapable() -} -rootProject.ext.indyBanner = { - if (project==rootProject && useIndy()) { - logger.lifecycle ''' - - DM .N$? - $I?7OM. - .7+?II77MZ ,:~~ - +I$7O$8? .M..DMMNNMMNZ. - ONDOMI. 7MMMMMMOO$I. - DOM87= ZMNM8NMI77$. - .MNDO?$8$? 8MMNMMMN7II. - MMMO. O$7Z. OI8?MDNNM$$$$7OM - M8 ZZ7$. MMMMMDD7I77I777MMMM. - ZZ$7$ DMM$N$ZNMZDMODNDM. DD - .Z$$I$$ .ZI777777II778 ?D. - 8$$7I$I+ .$I7?I7II7D. ?Z - .O$$7I$78 N77O+??I?$. Z - =7$7777$7 . .=7NZ?I$7I+$. O - ~:7$$7$7D+$~:=Z:=~++77Z$?IIZ~. N - $Z$7O8D8=Z8I7==I~I:+~OZ887$MOI$O .7 - :O$I+~=?:O8?I$=++=:===Z$77ZN++$+~. Z. - :7$78ZZZZZ=ZZ$~?==~+DD$8O$OO$7+?:. $ - .=~=+Z7I7?7I$+~=:~+~O~???77?~+??~ O - +=IZ7$7OI$=Z:~:~=8I?I?+$Z8++: N. - =$+8ZO$$==+=~=?=8$IIIIID$ZZ. Z - - INDY ENABLED ! -''' - - } -} - -if (useIndy()) { - gradle.taskGraph.whenReady { graph -> - graph.allTasks.findAll { it instanceof org.gradle.process.JavaForkOptions }.unique().each { task -> - logger.debug "Adding indy target to project ${task.project.name} task ${task.name}" - task.systemProperties 'groovy.target.indy': true - } - } -} http://git-wip-us.apache.org/repos/asf/groovy/blob/e94d43ee/gradle/test.gradle ---------------------------------------------------------------------- diff --git a/gradle/test.gradle b/gradle/test.gradle index a61d75f..e91a9a8 100644 --- a/gradle/test.gradle +++ b/gradle/test.gradle @@ -16,9 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - -import org.apache.tools.ant.taskdefs.condition.Os - allprojects { test { if (JavaVersion.current().isJava8Compatible()) { @@ -89,11 +86,6 @@ tasks.addRule('Pattern: testSingle<Name> will test **/<Name>.class') { String ta def buildExcludeFilter() { def excludes = [] - // if not compiled with indy support, disable indy tests - if (!rootProject.useIndy()) { - excludes += ['indy', 'Indy'] - } - // if no network available, disable Grapes if (!System.properties['junit.network']) { excludes << 'groovy/grape/' http://git-wip-us.apache.org/repos/asf/groovy/blob/e94d43ee/gradle/upload.gradle ---------------------------------------------------------------------- diff --git a/gradle/upload.gradle b/gradle/upload.gradle index 6078d01..683a6d3 100644 --- a/gradle/upload.gradle +++ b/gradle/upload.gradle @@ -94,23 +94,20 @@ allprojects { } artifacts { - archives jar + archives jarjar archives sourceJar archives javadocJar archives groovydocJar } + configurations.archives.with { + artifacts.removeAll(artifacts.find { it.name =~ 'raw' } ) + } + [uploadArchives, install]*.with { - dependsOn([jar, jarWithIndy, sourceJar, javadocJar, groovydocJar]) + dependsOn([jar, jarjarWithIndy, sourceJar, javadocJar, groovydocJar]) doFirst { - if (rootProject.useIndy()) { - new GradleException('You cannot use uploadArchives or install task with the flag [indy] turned' - + ' on because the build handles indy artifacts by itself in that case.') - } - def indyJar = rootProject.ext.deriveFile(jar.archivePath, 'indy') - if (indyJar.exists()) { - project.artifacts.add('archives', indyJar) - } + project.artifacts.add('archives', jarjarWithIndy) def grooidJar = rootProject.ext.deriveFile(jar.archivePath, 'grooid') if (grooidJar.exists()) { project.artifacts.add('archives', grooidJar) http://git-wip-us.apache.org/repos/asf/groovy/blob/e94d43ee/subprojects/performance/build.gradle ---------------------------------------------------------------------- diff --git a/subprojects/performance/build.gradle b/subprojects/performance/build.gradle index b4c089e..d1f5ff4 100644 --- a/subprojects/performance/build.gradle +++ b/subprojects/performance/build.gradle @@ -40,7 +40,6 @@ jmh { include = ['.*' + project.benchInclude + '.*'] } includeTests = true - resultsFile = project.file("target/results${useIndy() ? '_indy' : ''}.txt") } jmhClasses.dependsOn clean