Permalink
Browse files

Made the attachsignatures goal clean up the project after the gpg plu…

…gin execution.
  • Loading branch information...
1 parent 08e6f13 commit d126395ed33f160b30b4f43021e26c51b7ff4854 @nawroth committed May 9, 2012
Showing with 58 additions and 32 deletions.
  1. +1 −0 example-attach/pom.xml
  2. +57 −32 plugin/src/main/java/org/neo4j/build/plugins/ease/AttachSignaturesMojo.java
View
@@ -28,6 +28,7 @@
</execution>
<execution>
<id>attach-artifact-signatures</id>
+ <phase>none</phase>
<goals>
<goal>attachsignatures</goal>
</goals>
@@ -20,8 +20,9 @@
import java.io.File;
import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
@@ -31,8 +32,8 @@
import org.codehaus.plexus.util.FileUtils;
/**
- * Attaches all unattached signatures of signed artifacts in the build directory
- * with the project.
+ * Attaches all signatures of signed artifacts to the project. Will fail on
+ * missing signatures.
*
* @goal attachsignatures
* @requiresProject true
@@ -49,13 +50,6 @@
private MavenProject project;
/**
- * @parameter default-value="${project.attachedArtifacts}
- * @required
- * @readonly
- */
- private List attachedArtifacts;
-
- /**
* Used to create artifact instances.
*
* @component role="org.apache.maven.artifact.factory.ArtifactFactory"
@@ -64,40 +58,71 @@
*/
protected ArtifactFactory artifactFactory;
+ private final Set<String> attachedIds = new HashSet<String>();
+
@Override
public void execute() throws MojoExecutionException
{
- List<Artifact> artifacts = new ArrayList<Artifact>();
- for ( Iterator i = attachedArtifacts.iterator(); i.hasNext(); )
- {
- Artifact artifact = (Artifact) i.next();
- artifacts.add( artifact );
- }
- // simply attach the signature of all non-signature artifacts
+ List<Artifact> artifacts = new ArrayList<Artifact>(
+ project.getAttachedArtifacts() );
+ project.getAttachedArtifacts()
+ .clear();
for ( Artifact artifact : artifacts )
{
String type = artifact.getType();
- if ( !type.endsWith( ".asc" ) )
+ if ( artifact.getArtifactId()
+ .equals( project.getArtifactId() ) && artifact.getGroupId()
+ .equals( project.getGroupId() ) )
{
- File artifactFile = artifact.getFile();
- String signaturePath = artifactFile.getAbsolutePath() + ".asc";
- File signatureFile = FileUtils.getFile( signaturePath );
- if ( signatureFile.exists() )
+ // only add back the project artifacts we want
+ if ( type.equals( "pom.asc" ) || type.equals( "pom" ) )
{
- String classifier = null;
- if ( artifact.hasClassifier() )
+ attach( artifact );
+ }
+ }
+ else
+ {
+ // re-attach and check if there's a signature to attach as well
+ attach( artifact );
+ if ( !type.endsWith( ".asc" ) )
+ {
+ File artifactFile = artifact.getFile();
+ String signaturePath = artifactFile.getAbsolutePath()
+ + ".asc";
+ File signatureFile = FileUtils.getFile( signaturePath );
+ if ( signatureFile.exists() )
{
- classifier = artifact.getClassifier();
+ String classifier = null;
+ if ( artifact.hasClassifier() )
+ {
+ classifier = artifact.getClassifier();
+ }
+ Artifact signatureArtifact = artifactFactory.createArtifactWithClassifier(
+ artifact.getGroupId(),
+ artifact.getArtifactId(),
+ artifact.getVersion(), type + ".asc",
+ classifier );
+ signatureArtifact.setFile( signatureFile );
+ attach( signatureArtifact );
+ }
+ else
+ {
+ throw new MojoExecutionException(
+ "Missing signature for artifact: " + artifact );
}
- Artifact signatureArtifact = artifactFactory.createArtifactWithClassifier(
- artifact.getGroupId(), artifact.getArtifactId(),
- artifact.getVersion(), type + ".asc", classifier );
- signatureArtifact.setFile( signatureFile );
- project.addAttachedArtifact( signatureArtifact );
- getLog().info(
- "Attached signature: " + signatureArtifact.getId() );
}
}
}
}
+
+ private void attach( Artifact artifact )
+ {
+ String id = artifact.getId();
+ if ( !attachedIds.contains( id ) )
+ {
+ project.addAttachedArtifact( artifact );
+ attachedIds.add( id );
+ getLog().info( "Attached: " + id );
+ }
+ }
}

0 comments on commit d126395

Please sign in to comment.