Skip to content

Commit

Permalink
Update build.gradle to use AWT to ask for passphrase
Browse files Browse the repository at this point in the history
  • Loading branch information
ndw committed Jun 8, 2015
1 parent 63e36c3 commit 8ba0d63
Showing 1 changed file with 54 additions and 16 deletions.
70 changes: 54 additions & 16 deletions build.gradle
@@ -1,3 +1,6 @@
import groovy.swing.SwingBuilder
import java.awt.Point

buildscript {
repositories {
mavenCentral()
Expand Down Expand Up @@ -77,22 +80,6 @@ jar {
}
}

// I refuse to put my PGP password in a file, so there's no way to
// make this work from a CI environment.
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(":uploadArchives")) {
Console console = System.console()
console.printf "\n\nWe have to sign some things in this build." +
"\n\nPlease enter your signing details.\n\n"

def password = console.readPassword("PGP Private Key Password: ")

allprojects { ext."signing.password" = password }

console.printf "\nThanks.\n\n"
}
}

task copyNotices(type: Copy) {
from 'resources/notices'
into 'build/dist/docs/notices'
Expand Down Expand Up @@ -162,6 +149,57 @@ signing {
sign configurations.archives
}

// I refuse to put my PGP password in a file.
//
// Adapted from
// https://www.timroes.de/2014/01/19/using-password-prompts-with-gradle-build-files/
//
// N.B. This can't work in a CI environment so there's no way to
// automatically publish the artifacts from, for example, Travis CI.
//
gradle.taskGraph.whenReady { taskGraph ->
if(taskGraph.hasTask(':uploadArchives')) {

def pass = ''
if(System.console() == null) {
new SwingBuilder().edt {
dialog(modal: true,
title: 'Enter password',
alwaysOnTop: true,
resizable: false,
locationRelativeTo: null,
locationByPlatform: true,
// On my Linux multi-monitor setup, the dialog "appears" at
// the top of the virtual desktop below my desktop. So move
// the damned thing somewhere visible. Meh.
location: new Point(100,100),
pack: true,
show: true
) {
vbox { //
label(text: "Please enter key passphrase:")
input = passwordField()
button(defaultButton: true, text: 'OK', actionPerformed: {
pass = input.password;
dispose();
})
}
}
}
} else {
pass = System.console().readPassword("\nPlease enter key passphrase: ")
pass = new String(pass)
}

if (pass.size() <= 0) {
throw new InvalidUserDataException("You must enter a password to proceed.")
}

allprojects { ext."signing.password" = pass }

}
}

uploadArchives {
repositories {
mavenDeployer {
Expand Down

0 comments on commit 8ba0d63

Please sign in to comment.