You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by cc...@apache.org on 2017/12/16 20:57:44 UTC

[4/4] groovy git commit: Build grooid jar using the new jarjar task

Build grooid jar using the new jarjar task


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/b836c2cf
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/b836c2cf
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/b836c2cf

Branch: refs/heads/master
Commit: b836c2cff6f59f201eb176a59a47ad7809ecd074
Parents: eab7d0a
Author: Cedric Champeau <cc...@apache.org>
Authored: Sat Dec 16 21:54:00 2017 +0100
Committer: Cedric Champeau <cc...@apache.org>
Committed: Sat Dec 16 21:54:00 2017 +0100

----------------------------------------------------------------------
 .../codehaus/groovy/gradle/JarJarTask.groovy    | 68 ++++++++++++++------
 gradle/assemble.gradle                          | 67 +++++++++----------
 gradle/upload.gradle                            |  2 +-
 3 files changed, 82 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/b836c2cf/buildSrc/src/main/groovy/org/codehaus/groovy/gradle/JarJarTask.groovy
----------------------------------------------------------------------
diff --git a/buildSrc/src/main/groovy/org/codehaus/groovy/gradle/JarJarTask.groovy b/buildSrc/src/main/groovy/org/codehaus/groovy/gradle/JarJarTask.groovy
index 4a3c4ca..37fb67c 100644
--- a/buildSrc/src/main/groovy/org/codehaus/groovy/gradle/JarJarTask.groovy
+++ b/buildSrc/src/main/groovy/org/codehaus/groovy/gradle/JarJarTask.groovy
@@ -19,14 +19,14 @@
 package org.codehaus.groovy.gradle
 
 import groovy.transform.CompileStatic
+import org.gradle.api.Action
 import org.gradle.api.DefaultTask
 import org.gradle.api.file.FileCollection
+import org.gradle.api.java.archives.Manifest
 import org.gradle.api.tasks.CacheableTask
 import org.gradle.api.tasks.Input
 import org.gradle.api.tasks.OutputFile
 import org.gradle.api.tasks.TaskAction
-import org.gradle.api.Action
-import org.gradle.api.java.archives.Manifest
 
 @CacheableTask
 class JarJarTask extends DefaultTask {
@@ -46,20 +46,35 @@ class JarJarTask extends DefaultTask {
     FileCollection jarjarToolClasspath
 
     @Input
-    List<String> untouchedFiles
+    @org.gradle.api.tasks.Optional
+    List<String> untouchedFiles = []
+
+    @Input
+    @org.gradle.api.tasks.Optional
+    List<String> excludes = []
 
     @Input
     Map<String, String> patterns
 
     @Input
-    Map<String, List<String>> excludesPerLibrary
+    @org.gradle.api.tasks.Optional
+    Map<String, List<String>> excludesPerLibrary = [:]
 
     @Input
-    Map<String, List<String>> includesPerLibrary
+    @org.gradle.api.tasks.Optional
+    Map<String, List<String>> includesPerLibrary = [:]
+
+    @Input
+    @org.gradle.api.tasks.Optional
+    Map<String, String> includedResources = [:]
 
     @OutputFile
     File outputFile
 
+    @Input
+    @org.gradle.api.tasks.Optional
+    boolean createManifest = true
+
     void withManifest(Action<? super Manifest> action) {
         manifestTweaks << action
     }
@@ -82,8 +97,12 @@ class JarJarTask extends DefaultTask {
                 jarjar(jarfile: tmpJar, filesonly: true) {
                     zipfileset(
                             src: originalJar,
-                            excludes: untouchedFiles.join(','))
-
+                            excludes: (untouchedFiles+excludes).join(','))
+                    includedResources.each { String resource, String path ->
+                        String dir = resource.substring(0, resource.lastIndexOf('/') + 1)
+                        String filename = resource.substring(resource.lastIndexOf('/') + 1)
+                        zipfileset(dir: dir, includes: filename, fullpath: path)
+                    }
                     repackagedLibraries.files.each { File library ->
                         def libraryName = JarJarTask.baseName(library)
                         def includes = includesPerLibrary[libraryName]
@@ -102,19 +121,24 @@ class JarJarTask extends DefaultTask {
                 }
             }
 
-            // next step is to generate an OSGI manifest using the newly repackaged classes
-            def mf = project.rootProject.convention.plugins.osgi.osgiManifest {
-                symbolicName = project.name
-                instruction 'Import-Package', '*;resolution:=optional'
-                classesDir = tmpJar
-            }
+            if (createManifest) {
+                // next step is to generate an OSGI manifest using the newly repackaged classes
+                def mf = project.rootProject.convention.plugins.osgi.osgiManifest {
+                    symbolicName = project.name
+                    instruction 'Import-Package', '*;resolution:=optional'
+                    classesDir = tmpJar
+                }
 
-            manifestTweaks.each {
-                it.execute(mf)
-            }
+                manifestTweaks.each {
+                    it.execute(mf)
+                }
 
-            // then we need to generate the manifest file
-            mf.writeTo(manifestFile)
+                // then we need to generate the manifest file
+                mf.writeTo(manifestFile)
+
+            } else {
+                manifestFile << ''
+            }
 
             // so that we can put it into the final jar
             project.ant.copy(file: tmpJar, tofile: outputFile)
@@ -124,9 +148,11 @@ class JarJarTask extends DefaultTask {
                     // introduce cache misses
                     attribute(name:'Created-By', value:'Gradle')
                 }
-                zipfileset(
-                        src: originalJar,
-                        includes: untouchedFiles.join(','))
+                if (untouchedFiles) {
+                    zipfileset(
+                            src: originalJar,
+                            includes: untouchedFiles.join(','))
+                }
             }
         } finally {
             manifestFile.delete()

http://git-wip-us.apache.org/repos/asf/groovy/blob/b836c2cf/gradle/assemble.gradle
----------------------------------------------------------------------
diff --git a/gradle/assemble.gradle b/gradle/assemble.gradle
index ac0d6fb..55c1a8b 100644
--- a/gradle/assemble.gradle
+++ b/gradle/assemble.gradle
@@ -211,13 +211,13 @@ allprojects {
                     'org/codehaus/groovy/tools/shell/util/HelpFormatter*.class'
             ]
             patterns = [
-                    'antlr.**': 'groovyjarjarantlr.@1', // antlr2
-                    'org.antlr.**': 'groovyjarjarantlr4.@1', // antlr4
-                    'org.objectweb.**': 'groovyjarjarasm.@1',
+                    'antlr.**'                 : 'groovyjarjarantlr.@1', // antlr2
+                    'org.antlr.**'             : 'groovyjarjarantlr4.@1', // antlr4
+                    'org.objectweb.**'         : 'groovyjarjarasm.@1',
                     'org.apache.commons.cli.**': 'groovyjarjarcommonscli.@1'
             ]
             excludesPerLibrary = [
-                    '*': ['META-INF/maven/**','META-INF/*','META-INF/services/javax.annotation.processing.Processor','module-info.class']
+                    '*': ['META-INF/maven/**', 'META-INF/*', 'META-INF/services/javax.annotation.processing.Processor', 'module-info.class']
             ]
             includesPerLibrary = [
                     'asm-util': ['org/objectweb/asm/util/Printer.class',
@@ -225,7 +225,7 @@ allprojects {
                                  'org/objectweb/asm/util/ASMifier.class',
                                  'org/objectweb/asm/util/Trace*']
             ]
-            outputFile = file("$buildDir/libs/${arch.baseName}-${arch.version}${arch.classifier?'-'+arch.classifier:''}.jar")
+            outputFile = file("$buildDir/libs/${arch.baseName}-${arch.version}${arch.classifier ? '-' + arch.classifier : ''}.jar")
 
             withManifest {
                 def moduleName = "org.codehaus.${project.name.replace('-', '.')}"
@@ -244,36 +244,36 @@ allprojects {
     }
 
     if (project.name in ['groovy', 'groovy-test']) {
-        task grooidjar(type: Jar) {
-            destinationDir = jar.destinationDir
-            baseName = jar.baseName
-            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: jarjarTaskClassName, classpath: rootProject.configurations.tools.asPath
-                    jarjar(jarfile: target) {
-                        zipfileset(dir: "$rootProject.projectDir/notices/", includes: isRootProject ? 'NOTICE-GROOIDJARJAR' : 'NOTICE-GROOID', fullpath: 'META-INF/NOTICE')
-                        zipfileset(src: jarjar.outputFile, excludes: 'META-INF/NOTICE')
-                        if (isRootProject) {
-                            zipfileset(src: rootProject.configurations.runtime.files.find {
-                                it.name.startsWith('openbeans')
-                            }, excludes: 'META-INF/*')
+        task grooidjar(type: JarJarTask) {
+            dependsOn jarjar
+            from = file(jarjar.outputFile)
+            if (isRoot) {
+                repackagedLibraries = files(configurations.runtime.incoming.artifactView {
+                    componentFilter { component ->
+                        if (component instanceof ModuleComponentIdentifier) {
+                            return component.module in ['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'
+                        return false
                     }
-                }
-
-            }
-            doLast {
-                target.delete()
+                }.files)
+            } else {
+                repackagedLibraries = files()
             }
+            jarjarToolClasspath = rootProject.configurations.tools
+            patterns = [
+                    'com.googlecode.openbeans.**': 'groovyjarjaropenbeans.@1',
+                    'org.apache.harmony.beans.**': 'groovyjarjarharmonybeans.@1',
+                    'java.beans.**'              : 'groovyjarjaropenbeans.@1'
+            ]
+            excludesPerLibrary = [
+                    '*': ['META-INF/NOTICE']
+            ]
+            excludes = ['META-INF/NOTICE']
+            createManifest = false
+            includedResources = [
+                    ("$rootProject.projectDir/notices/${isRoot ? 'NOTICE-GROOIDJARJAR' : 'NOTICE-GROOID'}".toString()): 'META-INF/NOTICE'
+            ]
+            outputFile = file("$buildDir/libs/${jar.baseName}-${jar.version}-grooid.jar")
         }
     }
 }
@@ -349,7 +349,8 @@ ext.distSpec = copySpec {
         from jarjar
         from modules()*.jarjar
         from(configurations.runtime) {
-            exclude {   it.file.name.startsWith('openbeans-') ||
+            exclude {
+                it.file.name.startsWith('openbeans-') ||
                         it.file.name.startsWith('asm-') ||
                         it.file.name.startsWith('antlr-') ||
                         it.file.name.startsWith('antlr4-')

http://git-wip-us.apache.org/repos/asf/groovy/blob/b836c2cf/gradle/upload.gradle
----------------------------------------------------------------------
diff --git a/gradle/upload.gradle b/gradle/upload.gradle
index c06cad6..8d21a75 100644
--- a/gradle/upload.gradle
+++ b/gradle/upload.gradle
@@ -115,7 +115,7 @@ allprojects {
                 }
                 def grooidJar = rootProject.ext.deriveFile(jar.archivePath, 'grooid')
                 if (grooidJar.exists()) {
-                    project.artifacts.add('archives', grooidJar)
+                    project.artifacts.add('archives', grooidJar.outputFile)
                 }
             }
         }