Author: dkulp
Date: Thu Mar  1 10:28:41 2007
New Revision: 513428

URL: http://svn.apache.org/viewvc?view=rev&rev=513428
Log:
Provide a way to "store" passphrase in reactor build.


Modified:
    
maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/GpgSignAttachedMojo.java

Modified: 
maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/GpgSignAttachedMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/GpgSignAttachedMojo.java?view=diff&rev=513428&r1=513427&r2=513428
==============================================================================
--- 
maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/GpgSignAttachedMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/GpgSignAttachedMojo.java
 Thu Mar  1 10:28:41 2007
@@ -135,13 +135,14 @@
         throws MojoExecutionException
     {
 
+        String pass = passphrase;
         if ( skip ) 
         {
             //We're skipping the signing stuff
             return;
         }
         
-        if ( !useAgent && null == passphrase )
+        if ( !useAgent && null == pass )
         {
             if ( !settings.isInteractiveMode() )
             {
@@ -149,7 +150,7 @@
             }
             try 
             {
-                getPassphrase();
+                pass = getPassphrase();
             }
             catch (IOException e) 
             {
@@ -172,7 +173,7 @@
 
             File projectArtifact = project.getArtifact().getFile();
 
-            File projectArtifactSignature = generateSignatureForArtifact( 
projectArtifact );
+            File projectArtifactSignature = generateSignatureForArtifact( 
projectArtifact, pass );
 
             signingBundles.add( new SigningBundle( 
project.getArtifact().getType(), projectArtifactSignature ) );
         }
@@ -192,7 +193,7 @@
             throw new MojoExecutionException( "Error copying POM for 
signing.", e );
         }
 
-        File pomSignature = generateSignatureForArtifact( pomToSign );
+        File pomSignature = generateSignatureForArtifact( pomToSign, pass );
 
         signingBundles.add( new SigningBundle( "pom", pomSignature ) );
 
@@ -206,7 +207,7 @@
 
             File file = artifact.getFile();
 
-            File signature = generateSignatureForArtifact( file );
+            File signature = generateSignatureForArtifact( file, pass );
 
             signingBundles.add( new SigningBundle( artifact.getType(), 
artifact.getClassifier(), signature ) );
         }
@@ -242,7 +243,7 @@
         }
     }
 
-    private File generateSignatureForArtifact( File file )
+    private File generateSignatureForArtifact( File file , String pass)
         throws MojoExecutionException
     {
         File signature = new File( file + SIGNATURE_EXTENSION );
@@ -266,14 +267,14 @@
         }
 
         InputStream in = null;
-        if ( null != passphrase) 
+        if ( null != pass) 
         {
             cmd.createArgument().setValue( "--passphrase-fd" );
 
             cmd.createArgument().setValue( "0" );
 
             // Prepare the input stream which will be used to pass the 
passphrase to the executable
-            in = new ByteArrayInputStream( passphrase.getBytes() );
+            in = new ByteArrayInputStream( pass.getBytes() );
         }
 
         if ( null != keyname)
@@ -317,20 +318,42 @@
         return new File( basedir, finalName + ".jar" );
     }
     
-    protected void getPassphrase() throws IOException
+    private MavenProject findReactorProject(MavenProject prj) {
+        if ( prj.getParent() != null )
+        {
+            if ( prj.getParent().getBasedir() != null && 
prj.getParent().getBasedir().exists() )
+            {
+                return findReactorProject( prj.getParent() );
+            }
+        }
+        return prj;
+    }
+    
+    protected String getPassphrase() throws IOException
     {
-        //TODO: with JDK 1.6, we could call System.console().readPassword("GPG 
Passphrase: ", null);
-        
-        System.out.print("GPG Passphrase: ");
-        MaskingThread thread = new MaskingThread();
-        thread.start();
-
-        BufferedReader in = new BufferedReader(new 
InputStreamReader(System.in));
-
-        passphrase = in.readLine();
-
-        // stop masking
-        thread.stopMasking();
+        String pass = project.getProperties().getProperty("gpg.passphrase");
+        if (pass == null) 
+        {
+            MavenProject prj2 = findReactorProject(project);
+            pass = prj2.getProperties().getProperty("gpg.passphrase");
+        }
+        if (pass == null) 
+        {
+            //TODO: with JDK 1.6, we could call 
System.console().readPassword("GPG Passphrase: ", null);
+            
+            System.out.print("GPG Passphrase: ");
+            MaskingThread thread = new MaskingThread();
+            thread.start();
+    
+            BufferedReader in = new BufferedReader(new 
InputStreamReader(System.in));
+    
+            pass = in.readLine();
+    
+            // stop masking
+            thread.stopMasking();
+        }
+        
findReactorProject(project).getProperties().setProperty("gpg.passphrase", pass);
+        return pass;
     }
     
     


Reply via email to