You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2017/01/26 05:31:09 UTC

[35/50] groovy git commit: push signing of artifacts into the main build instead of the groovy-release repo

push signing of artifacts into the main build instead of the groovy-release repo


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

Branch: refs/heads/GROOVY_2_4_X
Commit: e3288bde7027a96b840e2cfec30179d44290aa2e
Parents: a9c4126
Author: paulk <pa...@asert.com.au>
Authored: Fri Jan 6 00:00:44 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Fri Jan 6 00:00:44 2017 +1000

----------------------------------------------------------------------
 build.gradle                              |  12 ++-
 gradle/assemble.gradle                    |  10 +--
 gradle/backports.gradle                   |   1 +
 gradle/signing.gradle                     |  92 +++++++++++++++++++++
 gradle/upload.gradle                      | 108 ++++++++++++++++++++++---
 subprojects/groovy-templates/build.gradle |   2 +-
 6 files changed, 203 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/e3288bde/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index 18f63d1..ca8506b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -54,6 +54,8 @@ indyBanner()
 // TODO use antlr plugin
 //apply plugin: 'antlr'
 
+ext.isReleaseVersion = !groovyVersion.toLowerCase().endsWith("snapshot")
+
 allprojects {
     apply plugin: 'java'
 
@@ -451,6 +453,8 @@ apply from: 'gradle/idea.gradle'
 apply from: 'gradle/eclipse.gradle'
 apply from: 'gradle/codehaus.gradle'
 apply from: 'gradle/quality.gradle'
+apply from: 'gradle/signing.gradle'
+
 // If a local configuration file for tweaking the build is present, apply it
 if (file('user.gradle').exists()) {
     apply from: 'user.gradle'
@@ -458,10 +462,10 @@ if (file('user.gradle').exists()) {
 
 if (!JavaVersion.current().java7Compatible) {
     logger.lifecycle '''
-    **************************************** WARNING **********************************************
-    ****** You are running the build with an older JDK. NEVER try to release with 1.6.       ******
-    ****** You must use a JDK 1.7+ in order to compile all features of the language.         ******
-    ***********************************************************************************************
+    **************************************** WARNING ********************************************
+    ******   You are running the build with an older JDK. NEVER try to release with 1.6.   ******
+    ******   You must use a JDK 1.7+ in order to compile all features of the language.     ******
+    *********************************************************************************************
 '''
 }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/e3288bde/gradle/assemble.gradle
----------------------------------------------------------------------
diff --git a/gradle/assemble.gradle b/gradle/assemble.gradle
index 8a91a28..38c7252 100644
--- a/gradle/assemble.gradle
+++ b/gradle/assemble.gradle
@@ -340,7 +340,7 @@ task jarAll(type: Jar, dependsOn: replaceJarWithJarJar) {
     inputs.files(allprojects.jar.archivePath)
 
     ext.metaInfDir = "$buildDir/tmp/groovy-all-metainf"
-    appendix = 'all'
+    baseName = 'groovy-all'
     includeEmptyDirs = false
     if (rootProject.useIndy()) {
         classifier = 'indy'
@@ -445,7 +445,7 @@ task sourceAllJar(type: Jar, dependsOn: { modules()*.sourceJar + rootProject.sou
     modules()*.sourceJar.each {
         with it.rootSpec
     }
-    appendix = 'all'
+    baseName = 'groovy-all'
     classifier = rootProject.useIndy() ? 'indy-sources' : 'sources'
 }
 
@@ -461,13 +461,13 @@ allprojects {
 }
 
 task javadocAllJar(type: Jar, dependsOn: javadocAll) {
-    appendix = 'all'
+    baseName = 'groovy-all'
     classifier = rootProject.useIndy() ? 'indy-javadoc' : 'javadoc'
     from javadocAll.destinationDir
 }
 
 task groovydocAllJar(type: Jar, dependsOn: groovydocAll) {
-    appendix = 'all'
+    baseName = 'groovy-all'
     classifier = rootProject.useIndy() ? 'indy-groovydoc' : 'groovydoc'
     from groovydocAll.destinationDir
 }
@@ -529,7 +529,7 @@ ext.distSpec = copySpec {
     }
     into('embeddable') {
         from jarAll.archivePath
-        from { new File(jarAll.archivePath.parent, "${jarAll.baseName}-${jarAll.appendix}-${jarAll.version}-indy.jar") }
+        from { new File(jarAll.destinationDir, "${jarAll.baseName}-${jarAll.version}-indy.jar") }
     }
 }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/e3288bde/gradle/backports.gradle
----------------------------------------------------------------------
diff --git a/gradle/backports.gradle b/gradle/backports.gradle
index de4223a..1402e50 100644
--- a/gradle/backports.gradle
+++ b/gradle/backports.gradle
@@ -42,6 +42,7 @@ backports.each { pkg, classList ->
         from zipTree(jar.archivePath)
         include classList
         baseName = "groovy-backports-$pkg"
+        classifier = ''
     }
 
     // the following two jars are empty. No wonder, Maven Central *requires* a javadoc and sources classifier

http://git-wip-us.apache.org/repos/asf/groovy/blob/e3288bde/gradle/signing.gradle
----------------------------------------------------------------------
diff --git a/gradle/signing.gradle b/gradle/signing.gradle
new file mode 100644
index 0000000..89c3a01
--- /dev/null
+++ b/gradle/signing.gradle
@@ -0,0 +1,92 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+import org.gradle.plugins.signing.Sign
+
+allprojects {
+    apply plugin: 'signing'
+    signing {
+        required {
+            isReleaseVersion &&
+                    (gradle.taskGraph.hasTask('artifactoryPublish') || project.hasProperty('forceSign'))
+        }
+    }
+}
+
+gradle.taskGraph.whenReady { taskGraph ->
+    if (taskGraph.allTasks.any { it instanceof Sign } || project.hasProperty('forceSign')) {
+        // Use Java 6's console or Swing to read input (not suitable for CI)
+        if (!project.hasProperty('signing.keyId') ||
+                !project.hasProperty('signing.secretKeyRingFile') ||
+                !project.hasProperty('signing.password')) {
+            printf "\n\nWe have to sign some things in this build." +
+                    "\n\nPlease enter your signing details.\n\n"
+            System.out.flush()
+
+            if (!project.hasProperty('signing.keyId')) {
+                project.ext.'signing.keyId' = promptUser('PGP Key Id')
+            }
+            if (!project.hasProperty('signing.secretKeyRingFile')) {
+                project.ext.'signing.secretKeyRingFile' = promptUser('PGP Secret Key Ring File (absolute path)')
+            }
+            if (!project.hasProperty('signing.password')) {
+                project.ext.'signing.password' = promptUser('PGP Private Key Password')
+            }
+
+            printf "\nThanks.\n\n"
+            System.out.flush()
+        }
+        allprojects { ext.'signing.keyId' = project.getProperty('signing.keyId') }
+        allprojects { ext.'signing.secretKeyRingFile' = project.getProperty('signing.secretKeyRingFile') }
+        allprojects { ext.'signing.password' = project.getProperty('signing.password') }
+    }
+}
+
+def promptUser(String prompt) {
+    def response = ''
+    if (System.console() == null) {
+        new groovy.swing.SwingBuilder().edt {
+            dialog(modal: true, //Otherwise the build will continue running
+                    title: 'Reponse required', //Dialog title
+                    alwaysOnTop: true,
+                    resizable: false,
+                    locationRelativeTo: null, //Place dialog in center of the screen
+                    pack: true, //We need to pack the dialog (so it will take the size of its children)
+                    show: true
+            ){
+                vbox { //Put everything below each other
+                    label(text: "$prompt:")
+                    input = passwordField()
+                    button(defaultButton: true, text: 'OK', actionPerformed: {
+                        response = new String(input.password); //set pass variable to value of input field
+                        dispose(); //close dialog
+                    })
+                }
+            }
+        }
+    }
+    else{
+        response = new String(System.console().readPassword("\n$prompt: "))
+    }
+
+    if(response.size() <= 0){
+        throw new InvalidUserDataException("Null response detected!")
+    }
+    response
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/e3288bde/gradle/upload.gradle
----------------------------------------------------------------------
diff --git a/gradle/upload.gradle b/gradle/upload.gradle
index bd64084..f653d31 100644
--- a/gradle/upload.gradle
+++ b/gradle/upload.gradle
@@ -39,7 +39,25 @@ allprojects {
 
 apply from: 'gradle/backports.gradle'
 
+ext.basename = { String s -> s.take(s.lastIndexOf('.')) }
+ext.deriveFile = { File archive, String suffix -> new File(archive.parent, basename(archive.name) + "-${suffix}.jar") }
+
 allprojects {
+    ext.signWithClassifier = { String c, File f ->
+        signing.sign(c, f)
+        project.artifacts.add('archives', new File(f.parent, f.name + '.asc')) {
+            classifier = c
+            type = 'jar.asc'
+        }
+    }
+
+    ext.signArchiveTask = { archiveTask ->
+        signing.sign(archiveTask.classifier, archiveTask.archivePath)
+        project.artifacts.add('archives', new File(archiveTask.destinationDir, archiveTask.archiveName + '.asc')) {
+            classifier = archiveTask.classifier
+            type = archiveTask.extension + '.asc'
+        }
+    }
 
     configurations {
         deployerJars
@@ -50,6 +68,7 @@ allprojects {
             mavenDeployer {
                 configuration = configurations.deployerJars
                 pom pomConfigureClosure
+                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
             }
         }
     }
@@ -58,6 +77,7 @@ allprojects {
         repositories {
             mavenInstaller {
                 pom pomConfigureClosure
+                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
             }
         }
     }
@@ -78,49 +98,111 @@ allprojects {
                 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 archive = jar.archivePath
-            def indyJar = new File(archive.parent, archive.name[0..archive.name.lastIndexOf('.')-1]+'-indy.jar')
+            def indyJar = rootProject.ext.deriveFile(jar.archivePath, 'indy')
             if (indyJar.exists()) {
                 project.artifacts.add('archives', indyJar)
             }
-            def grooidJar = new File(archive.parent, archive.name[0..archive.name.lastIndexOf('.')-1]+'-grooid.jar')
+            def grooidJar = rootProject.ext.deriveFile(jar.archivePath, 'grooid')
             if (grooidJar.exists()) {
                 project.artifacts.add('archives', grooidJar)
             }
         }
     }
+
+    install {
+        doFirst {
+            signArchiveTask(jar)
+            signArchiveTask(sourceJar)
+            signArchiveTask(javadocJar)
+            signArchiveTask(groovydocJar)
+            def indyJar = rootProject.ext.deriveFile(jar.archivePath, 'indy')
+            if (indyJar.exists()) {
+                signWithClassifier('indy', indyJar)
+            }
+            def grooidJar = rootProject.ext.deriveFile(jar.archivePath, 'grooid')
+            if (grooidJar.exists()) {
+                signWithClassifier('grooid', grooidJar)
+            }
+        }
+    }
 }
 
 // the root project generates an alternate 'groovy-all' artifact
 [uploadArchives, install]*.with {
     dependsOn([sourceAllJar, javadocAllJar, groovydocAllJar, distBin])
     doFirst {
-        project.artifacts.add('archives', jarAll)
-        project.artifacts.add('archives', sourceAllJar)
-        project.artifacts.add('archives', javadocAllJar)
-        project.artifacts.add('archives', groovydocAllJar)
-        project.artifacts.add('archives', distBin)
+        project.artifacts.add('archives', jarAll) {
+            name = 'groovy-all'
+        }
+        project.artifacts.add('archives', sourceAllJar) {
+            name = 'groovy-all'
+        }
+        project.artifacts.add('archives', javadocAllJar) {
+            name = 'groovy-all'
+        }
+        project.artifacts.add('archives', groovydocAllJar) {
+            name = 'groovy-all'
+        }
+        project.artifacts.add('archives', distBin) {
+            name = 'groovy-binary'
+        }
         tasks.withType(Jar).matching { it.name.startsWith('backport') }.each { t ->
             project.artifacts.add('archives', t.archivePath) {
                 name = t.baseName
                 type = 'jar'
+                classifier = t.classifier
             }
         }
 
-        def archive = jarAll.archivePath
-        def indyJar = new File(archive.parent, archive.name[0..archive.name.lastIndexOf('.')-1] + '-indy.jar')
+        def indyJar = deriveFile(jarAll.archivePath, 'indy')
         if (indyJar.exists()) {
             project.artifacts.add('archives', indyJar)
         }
-        def grooidJar = new File(archive.parent, archive.name[0..archive.name.lastIndexOf('.')-1]+'-grooid.jar')
+        def grooidJar = deriveFile(jarAll.archivePath, 'grooid')
         if (grooidJar.exists()) {
             project.artifacts.add('archives', grooidJar)
         }
     }
 }
+
+install {
+    doFirst {
+        signArchiveTask(jarAll)
+        signArchiveTask(sourceAllJar)
+        signArchiveTask(javadocAllJar)
+        signArchiveTask(groovydocAllJar)
+        signArchiveTask(distBin)
+
+        // next three are done as a side effect since it was the easiest approach
+        signing.sign(distSrc.archivePath)
+        signing.sign(distDoc.archivePath)
+        signing.sign(dist.archivePath)
+
+        tasks.withType(Jar).matching { it.name.startsWith('backport') }.each { t ->
+            signing.sign(t.classifier, t.archivePath)
+            project.artifacts.add('archives', new File(t.destinationDir, t.archiveName + '.asc')) {
+                name = t.baseName
+                classifier = t.classifier
+                type = t.extension + '.asc'
+            }
+        }
+
+        def indyJar = deriveFile(jarAll.archivePath, 'indy')
+        if (indyJar.exists()) {
+            signWithClassifier('indy', indyJar)
+        }
+        def grooidJar = deriveFile(jarAll.archivePath, 'grooid')
+        if (grooidJar.exists()) {
+            signWithClassifier('grooid', grooidJar)
+        }
+    }
+}
+
 ext.pomAll = {
     addFilter('groovy') { artifact, file ->
-        !(artifact.name.contains('groovy-all')) && !(artifact.name.contains('groovy-binary')) && !(artifact.name.contains('backport'))
+        !(artifact.name.contains('groovy-all')) &&
+                !(artifact.name.contains('groovy-binary')) &&
+                !(artifact.name.contains('backport'))
     }
     addFilter('all') { artifact, file ->
         artifact.name.contains('groovy-all')
@@ -173,6 +255,8 @@ ext.pomAll = {
     binarypom.whenConfigured { p ->
         p.dependencies.clear()
     }
+
+    beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
 }
 
 install {

http://git-wip-us.apache.org/repos/asf/groovy/blob/e3288bde/subprojects/groovy-templates/build.gradle
----------------------------------------------------------------------
diff --git a/subprojects/groovy-templates/build.gradle b/subprojects/groovy-templates/build.gradle
index cb670ad..3a21668 100644
--- a/subprojects/groovy-templates/build.gradle
+++ b/subprojects/groovy-templates/build.gradle
@@ -27,7 +27,7 @@ dependencies {
 }
 
 task backportJar(type:Jar) {
-    appendix = 'markup-backport'
+    name = 'groovy-markup-backport'
     dependsOn classes
     from sourceSets.main.output
     include 'groovy/text/markup/**'