OSDN Git Service

Improve gradle script to allow input passphrase with GUI
authorHiroshi Miura <miurahr@linux.com>
Tue, 18 Oct 2016 00:52:13 +0000 (09:52 +0900)
committerHiroshi Miura <miurahr@linux.com>
Tue, 18 Oct 2016 00:54:28 +0000 (09:54 +0900)
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
build.gradle
build.publish.gradle [deleted file]

index a277eee..360c19a 100644 (file)
@@ -1,4 +1,5 @@
 import org.apache.tools.ant.filters.ReplaceTokens
+import groovy.swing.SwingBuilder
 
 plugins {
     // github
@@ -16,6 +17,7 @@ subprojects {
   apply plugin: 'co.riiid.gradle'
   apply plugin: 'com.jfrog.bintray'
   apply plugin: 'maven'
+  apply plugin: 'signing'
 
   sourceCompatibility = jdkVersion
   targetCompatibility = jdkVersion
@@ -69,6 +71,10 @@ subprojects {
       archives sourceJar
       archives javadocJar
   }
+    
+    signing {
+      sign configurations.archives
+    }
 }
 
 project(':dictzip-lib') {
@@ -158,7 +164,57 @@ project(':dictzip-cli') {
 task mandoc << {}
 task bintrayUpload(overwrite: true) << {}
 
+boolean validProperty(propertyName) {
+  try { project.property(propertyName) != null }
+  catch (MissingPropertyException) { false }
+}
+
+String askPassword(prompt) {
+    def keyPass = ''
+    if(System.console() == null) {
+        new SwingBuilder().edt {
+            dialog(modal: true, title: 'Enter password', alwaysOnTop: true, resizable: false, locationRelativeTo: null, pack: true, show: true) {
+                vbox {
+                    label(text: prompt)
+                    def input1 = passwordField()
+                    button(defaultButton: true, text: 'OK', actionPerformed: {
+                        keyPass = input1.password;
+                        dispose();
+                    })
+                }
+            }
+        }
+    } else {
+        keyPass = System.console().readPassword(prompt)
+    }
+    if (keyPass.size() <= 0) {
+        throw new InvalidUserDataException("You must enter the passwords to proceed.")
+    }
+    new String(keyPass)
+}
+
+github {
+    owner = projectOwner
+    repo = 'dictzip-java'
+    token = githubToken
+    tagName = projectTag
+    targetCommitish = 'master'
+    name = projectTag
+    draft = true
+    body = projectReleaseBody
+    assets = [
+            'dictzip-cli/build/distributions/dictzip-' + projectVersion + '.tgz',
+            'dictzip-cli/build/distributions/dictzip-' + projectVersion + '.zip',
+            'dictzip-lib/build/libs/dictzip-lib-' + projectVersion + '.jar',
+            'dictzip-lib/build/libs/dictzip-lib-' + projectVersion + '-sources.jar',
+            'dictzip-lib/build/libs/dictzip-lib-' + projectVersion + '-javadoc.jar'
+    ]
+}
+
 if (gradle.startParameter.taskNames.contains('bintrayUpload')  ||
     gradle.startParameter.taskNames.contains('githubRelease')) {
-  apply from: 'build.publish.gradle'
+    assert validProperty('signing.keyId'),             'properties for signing must be provided'
+    assert validProperty('signing.secretKeyRingFile'), 'properties for signing must be provided'
+    ext.'signing.password' = askPassword("Enter password for PGP key ${property('signing.keyId')}: ")
+
 }
diff --git a/build.publish.gradle b/build.publish.gradle
deleted file mode 100644 (file)
index de217eb..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-apply plugin: 'signing'
-import groovy.swing.SwingBuilder
-
-boolean validProperty(propertyName) {
-  try { project.property(propertyName) != null }
-  catch (MissingPropertyException) { false }
-}
-assert validProperty('signing.keyId'),             'properties for signing must be provided'
-assert validProperty('signing.secretKeyRingFile'), 'properties for signing must be provided'
-
-def keyPass = ''
-if(System.console() == null) {
-    new SwingBuilder().edt {
-        dialog(modal: true, title: 'Enter password', alwaysOnTop: true, resizable: false, locationRelativeTo: null, pack: true, show: true) {
-            vbox { // Put everything below each other
-                label(text: "Please enter passphrase for PGP key ${property('signing.keyId')}:")
-                def input2 = passwordField()
-                button(defaultButton: true, text: 'OK', actionPerformed: {
-                    keyPass = input2.password;
-                    dispose();
-                })
-            }
-        }
-    }
-} else {
-    keyPass = System.console().readPassword("Enter password for PGP key ${property('signing.keyId')}: ")
-}
-if (keyPass.size() <= 0) {
-    throw new InvalidUserDataException("You must enter the passwords to proceed.")
-}
-ext.'signing.password' = new String(keyPass)
-
-signing {
-  sign configurations.archives
-}
-
-github {
-    owner = projectOwner
-    repo = 'dictzip-java'
-    token = githubToken
-    tagName = projectTag
-    targetCommitish = 'master'
-    name = projectTag
-    draft = true
-    body = projectReleaseBody
-    assets = [
-            'dictzip-cli/build/distributions/dictzip-' + projectVersion + '.tgz',
-            'dictzip-cli/build/distributions/dictzip-' + projectVersion + '.zip',
-            'dictzip-lib/build/libs/dictzip-lib-' + projectVersion + '.jar',
-            'dictzip-lib/build/libs/dictzip-lib-' + projectVersion + '-sources.jar',
-            'dictzip-lib/build/libs/dictzip-lib-' + projectVersion + '-javadoc.jar'
-    ]
-}