maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject svn commit: r482716 - in /maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg: GpgSignAttachedMojo.java SigningBundle.java
Date Tue, 05 Dec 2006 17:25:28 GMT
Author: jvanzyl
Date: Tue Dec  5 09:25:27 2006
New Revision: 482716

URL: http://svn.apache.org/viewvc?view=rev&rev=482716
Log:
o sign project artifact
o sign POM
o sign all attached artifacts

Added:
    maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/SigningBundle.java
  (with props)
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=482716&r1=482715&r2=482716
==============================================================================
--- 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
Tue Dec  5 09:25:27 2006
@@ -19,36 +19,39 @@
  * under the License.
  */
 
-import java.util.List;
-import java.util.Iterator;
-import java.util.ArrayList;
-
-import java.io.File;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
+import org.apache.commons.lang.SystemUtils;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectHelper;
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.commons.lang.SystemUtils;
-
-import org.codehaus.plexus.util.cli.Commandline;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
 import org.codehaus.plexus.util.cli.DefaultConsumer;
-import org.codehaus.plexus.util.cli.CommandLineException;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
- * Sign project attached artifacts with GnuPG.
+ * Sign project artifact, the POM, and attached artifacts with GnuPG for deployment.
  *
- * @version $Rev: 470156 $ $Date$
- * @goal gpg-sign-attached
- * @phase verify
+ * @goal sign
+ * @execute phase="verify"
+ * @author Jason van Zyl
+ * @author Jason Dillon
  */
 public class GpgSignAttachedMojo
     extends AbstractMojo
 {
+    public static final String SIGNATURE_EXTENSION = ".asc";
+
     /**
      * The passphrase to use when signing.
      *
@@ -73,33 +76,80 @@
      * @required
      * @readonly
      */
-    private MavenProjectHelper projectHelper = null;
+    private MavenProjectHelper projectHelper;
+
+    /**
+     * Maven ProjectHelper
+     *
+     * @component
+     * @required
+     * @readonly
+     */
+    private ArtifactHandlerManager artifactHandlerManager;
+
 
     public void execute()
         throws MojoExecutionException
     {
-        List artifacts = new ArrayList();
+        // ----------------------------------------------------------------------------
+        // What we need to generateSignatureForArtifact here
+        // ----------------------------------------------------------------------------
+
+        List signingBundles = new ArrayList();
+
+        // ----------------------------------------------------------------------------
+        // Project artifact
+        // ---------------------------------------------------------------------------- 
              
+
+        File projectArtifact = getProjectFile( project.getBuild().getDirectory(), project.getBuild().getFinalName()
);
+
+        File projectArtifactSignature = generateSignatureForArtifact( projectArtifact );
+
+        signingBundles.add( new SigningBundle( project.getArtifact().getType(), projectArtifactSignature
) );
+
+        // ----------------------------------------------------------------------------
+        // POM
+        // ----------------------------------------------------------------------------
 
-        artifacts.add( project.getArtifact() );
+        File pomSignature = generateSignatureForArtifact( project.getFile() );
 
-        artifacts.addAll( project.getAttachedArtifacts() );
+        signingBundles.add( new SigningBundle( "pom", pomSignature ) );
 
-        for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+        // ----------------------------------------------------------------------------
+        // Attached artifacts
+        // ----------------------------------------------------------------------------
+
+        for ( Iterator i = project.getAttachedArtifacts().iterator(); i.hasNext(); )
         {
             Artifact artifact = (Artifact) i.next();
 
             File file = artifact.getFile();
 
-            File signature = sign( file );
-            
-            projectHelper.attachArtifact( project, artifact.getType() + ".asc", "asc", signature
);
+            File signature = generateSignatureForArtifact( file );
+
+            signingBundles.add( new SigningBundle( artifact.getType(), signature ) );
+        }
+
+        // ----------------------------------------------------------------------------
+        // Attach all the signatures
+        // ----------------------------------------------------------------------------
+
+        for ( Iterator i = signingBundles.iterator(); i.hasNext(); )
+        {
+            SigningBundle bundle = (SigningBundle) i.next();
+
+            // Get the correct artifact handler to we can create the right extension.
+            ArtifactHandler ah = artifactHandlerManager.getArtifactHandler( bundle.getArtifactType()
);
+
+            // We don't want a classifier, we just want to add the extension ".asc" 
+            projectHelper.attachArtifact( project, ah.getExtension() + SIGNATURE_EXTENSION,
"", bundle.getSignature() );
         }
     }
 
-    private File sign( File file )
+    private File generateSignatureForArtifact( File file )
         throws MojoExecutionException
     {
-        File signature = new File( file + ".asc" );
+        File signature = new File( file + SIGNATURE_EXTENSION );
 
         if ( signature.exists() )
         {
@@ -107,11 +157,11 @@
         }
 
         Commandline cmd = new Commandline();
-        
+
         cmd.setExecutable( "gpg" + ( SystemUtils.IS_OS_WINDOWS ? ".exe" : "" ) );
 
         cmd.createArgument().setValue( "--passphrase-fd" );
-        
+
         cmd.createArgument().setValue( "0" );
 
         cmd.createArgument().setValue( "--armor" );
@@ -138,5 +188,15 @@
         }
 
         return signature;
+    }
+
+    //TODO: This must be made to work generally or the packaging plugins must
+    // set the project artifact as part of what they do. We should not have to
+    // guess or synthesize what project artifact is here. It should have happened
+    // already. We'll settle for JAR files right now.
+    protected File getProjectFile( String basedir,
+                                   String finalName )
+    {
+        return new File( basedir, finalName + ".jar" );
     }
 }

Added: maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/SigningBundle.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/SigningBundle.java?view=auto&rev=482716
==============================================================================
--- maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/SigningBundle.java
(added)
+++ maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/SigningBundle.java
Tue Dec  5 09:25:27 2006
@@ -0,0 +1,29 @@
+package org.apache.maven.plugin.gpg;
+
+import java.io.File;
+
+/** @author Jason van Zyl */
+public class SigningBundle
+{
+    private String artifactType;
+
+    private File signature;
+
+    public SigningBundle( String artifactType,
+                          File signature )
+    {
+        this.artifactType = artifactType;
+
+        this.signature = signature;
+    }
+
+    public String getArtifactType()
+    {
+        return artifactType;
+    }
+
+    public File getSignature()
+    {
+        return signature;
+    }
+}

Propchange: maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/SigningBundle.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/SigningBundle.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message