You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2011/05/23 11:33:13 UTC
svn commit: r1126405 - in /maven/plugins/trunk/maven-gpg-plugin/src:
it/sign-and-deploy-file-with-extras/ main/java/org/apache/maven/plugin/gpg/
Author: stephenc
Date: Mon May 23 09:33:13 2011
New Revision: 1126405
URL: http://svn.apache.org/viewvc?rev=1126405&view=rev
Log:
[MGPG-35] and [MGPG-36]
Added:
maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/
maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/invoker.properties
maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/setup.bsh
maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test-javadoc.jar (with props)
maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test-sources.jar (with props)
maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.jar (with props)
maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.pom
maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.properties
maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/verify.bsh
maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/AttachedSignedArtifact.java
Modified:
maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/SignAndDeployFileMojo.java
Added: maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/invoker.properties?rev=1126405&view=auto
==============================================================================
--- maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/invoker.properties (added)
+++ maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/invoker.properties Mon May 23 09:33:13 2011
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:sign-and-deploy-file
Added: maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/setup.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/setup.bsh?rev=1126405&view=auto
==============================================================================
--- maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/setup.bsh (added)
+++ maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/setup.bsh Mon May 23 09:33:13 2011
@@ -0,0 +1,24 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+import org.codehaus.plexus.util.*;
+
+FileUtils.deleteDirectory( new File( basedir, "target" ) );
Added: maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test-javadoc.jar
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test-javadoc.jar?rev=1126405&view=auto
==============================================================================
Binary file - no diff available.
Propchange: maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test-javadoc.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test-sources.jar
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test-sources.jar?rev=1126405&view=auto
==============================================================================
Binary file - no diff available.
Propchange: maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test-sources.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.jar
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.jar?rev=1126405&view=auto
==============================================================================
Binary file - no diff available.
Propchange: maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.pom
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.pom?rev=1126405&view=auto
==============================================================================
--- maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.pom (added)
+++ maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.pom Mon May 23 09:33:13 2011
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.gpg.sadfwe</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0</version>
+ <packaging>jar</packaging>
+
+ <name>MGPG-12</name>
+ <description>
+ Tests the signing and deployment of a simple release JAR along with its POM.
+ </description>
+</project>
Added: maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.properties?rev=1126405&view=auto
==============================================================================
--- maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.properties (added)
+++ maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/test.properties Mon May 23 09:33:13 2011
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+file = test.jar
+pomFile = test.pom
+url = file:target/repo
+gpg.passphrase = TEST
+sources = test-sources.jar
+javadoc = test-javadoc.jar
Added: maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/verify.bsh?rev=1126405&view=auto
==============================================================================
--- maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/verify.bsh (added)
+++ maven/plugins/trunk/maven-gpg-plugin/src/it/sign-and-deploy-file-with-extras/verify.bsh Mon May 23 09:33:13 2011
@@ -0,0 +1,46 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+
+File artifactDir = new File( basedir, "target/repo/org/apache/maven/its/gpg/sadfwe/test/1.0" );
+
+String[] expectedFiles = {
+ "test-1.0.jar",
+ "test-1.0.jar.asc",
+ "test-1.0-sources.jar",
+ "test-1.0-sources.jar.asc",
+ "test-1.0-javadoc.jar",
+ "test-1.0-javadoc.jar.asc",
+ "test-1.0.pom",
+ "test-1.0.pom.asc",
+};
+
+for ( String expectedFile : expectedFiles )
+{
+ File file = new File( artifactDir, expectedFile );
+
+ System.out.println( "Checking for existence of " + file );
+
+ if ( !file.isFile() )
+ {
+ throw new Exception( "Missing file " + file );
+ }
+}
Added: maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/AttachedSignedArtifact.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/AttachedSignedArtifact.java?rev=1126405&view=auto
==============================================================================
--- maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/AttachedSignedArtifact.java (added)
+++ maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/AttachedSignedArtifact.java Mon May 23 09:33:13 2011
@@ -0,0 +1,292 @@
+package org.apache.maven.plugin.gpg;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
+import org.apache.maven.artifact.versioning.VersionRange;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A wrapper class for attached artifacts which have a GPG signature. Needed as attached artifacts in general do not
+ * have metadata.
+ */
+public class AttachedSignedArtifact
+ implements Artifact
+{
+ private final Artifact delegate;
+
+ private final AscArtifactMetadata signature;
+
+ public AttachedSignedArtifact( Artifact delegate, AscArtifactMetadata signature )
+ {
+ this.delegate = delegate;
+ this.signature = signature;
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ delegate.setArtifactId( artifactId );
+ }
+
+ public List getAvailableVersions()
+ {
+ return delegate.getAvailableVersions();
+ }
+
+ public void setAvailableVersions( List availableVersions )
+ {
+ delegate.setAvailableVersions( availableVersions );
+ }
+
+ public String getBaseVersion()
+ {
+ return delegate.getBaseVersion();
+ }
+
+ public void setBaseVersion( String baseVersion )
+ {
+ delegate.setBaseVersion( baseVersion );
+ }
+
+ public String getDownloadUrl()
+ {
+ return delegate.getDownloadUrl();
+ }
+
+ public void setDownloadUrl( String downloadUrl )
+ {
+ delegate.setDownloadUrl( downloadUrl );
+ }
+
+ public void setGroupId( String groupId )
+ {
+ delegate.setGroupId( groupId );
+ }
+
+ public ArtifactRepository getRepository()
+ {
+ return delegate.getRepository();
+ }
+
+ public void setRepository( ArtifactRepository repository )
+ {
+ delegate.setRepository( repository );
+ }
+
+ public String getScope()
+ {
+ return delegate.getScope();
+ }
+
+ public void setScope( String scope )
+ {
+ delegate.setScope( scope );
+ }
+
+ public String getVersion()
+ {
+ return delegate.getVersion();
+ }
+
+ public void setVersion( String version )
+ {
+ delegate.setVersion( version );
+ }
+
+ public VersionRange getVersionRange()
+ {
+ return delegate.getVersionRange();
+ }
+
+ public void setVersionRange( VersionRange range )
+ {
+ delegate.setVersionRange( range );
+ }
+
+ public boolean isRelease()
+ {
+ return delegate.isRelease();
+ }
+
+ public void setRelease( boolean release )
+ {
+ delegate.setRelease( release );
+ }
+
+ public boolean isSnapshot()
+ {
+ return delegate.isSnapshot();
+ }
+
+ public void addMetadata( ArtifactMetadata metadata )
+ {
+ delegate.addMetadata( metadata );
+ }
+
+ public String getClassifier()
+ {
+ return delegate.getClassifier();
+ }
+
+ public boolean hasClassifier()
+ {
+ return delegate.hasClassifier();
+ }
+
+ public String getGroupId()
+ {
+ return delegate.getGroupId();
+ }
+
+ public String getArtifactId()
+ {
+ return delegate.getArtifactId();
+ }
+
+ public String getType()
+ {
+ return delegate.getType();
+ }
+
+ public void setFile( File file )
+ {
+ delegate.setFile( file );
+ }
+
+ public File getFile()
+ {
+ return delegate.getFile();
+ }
+
+ public String getId()
+ {
+ return delegate.getId();
+ }
+
+ public String getDependencyConflictId()
+ {
+ return delegate.getDependencyConflictId();
+ }
+
+ public String toString()
+ {
+ return delegate.toString();
+ }
+
+ public int hashCode()
+ {
+ return delegate.hashCode();
+ }
+
+ public boolean equals( Object o )
+ {
+ return delegate.equals( o );
+ }
+
+ public int compareTo( Object o )
+ {
+ return delegate.compareTo( o );
+ }
+
+ public void updateVersion( String version, ArtifactRepository localRepository )
+ {
+ delegate.updateVersion( version, localRepository );
+ }
+
+ public ArtifactFilter getDependencyFilter()
+ {
+ return delegate.getDependencyFilter();
+ }
+
+ public void setDependencyFilter( ArtifactFilter artifactFilter )
+ {
+ delegate.setDependencyFilter( artifactFilter );
+ }
+
+ public ArtifactHandler getArtifactHandler()
+ {
+ return delegate.getArtifactHandler();
+ }
+
+ public List getDependencyTrail()
+ {
+ return delegate.getDependencyTrail();
+ }
+
+ public void setDependencyTrail( List dependencyTrail )
+ {
+ delegate.setDependencyTrail( dependencyTrail );
+ }
+
+ public void selectVersion( String version )
+ {
+ delegate.selectVersion( version );
+ }
+
+ public void setResolved( boolean resolved )
+ {
+ delegate.setResolved( resolved );
+ }
+
+ public boolean isResolved()
+ {
+ return delegate.isResolved();
+ }
+
+ public void setResolvedVersion( String version )
+ {
+ delegate.setResolvedVersion( version );
+ }
+
+ public void setArtifactHandler( ArtifactHandler artifactHandler )
+ {
+ delegate.setArtifactHandler( artifactHandler );
+ }
+
+ public boolean isOptional()
+ {
+ return delegate.isOptional();
+ }
+
+ public ArtifactVersion getSelectedVersion()
+ throws OverConstrainedVersionException
+ {
+ return delegate.getSelectedVersion();
+ }
+
+ public boolean isSelectedVersionKnown()
+ throws OverConstrainedVersionException
+ {
+ return delegate.isSelectedVersionKnown();
+ }
+
+ public void setOptional( boolean optional )
+ {
+ delegate.setOptional( optional );
+ }
+
+ public Collection getMetadataList()
+ {
+ List result = new ArrayList( delegate.getMetadataList() );
+ boolean alreadySigned = false;
+ for ( Iterator i = result.iterator(); i.hasNext() && !alreadySigned; )
+ {
+ ArtifactMetadata metadata = (ArtifactMetadata) i.next();
+ alreadySigned = alreadySigned | signature.getKey().equals( metadata.getKey() );
+ }
+ if ( !alreadySigned )
+ {
+ result.add( signature );
+ }
+ return result;
+ }
+}
Modified: maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/SignAndDeployFileMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/SignAndDeployFileMojo.java?rev=1126405&r1=1126404&r2=1126405&view=diff
==============================================================================
--- maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/SignAndDeployFileMojo.java (original)
+++ maven/plugins/trunk/maven-gpg-plugin/src/main/java/org/apache/maven/plugin/gpg/SignAndDeployFileMojo.java Mon May 23 09:33:13 2011
@@ -19,13 +19,6 @@ package org.apache.maven.plugin.gpg;
* under the License.
*/
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.Map;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
@@ -40,15 +33,28 @@ import org.apache.maven.model.io.xpp3.Ma
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.project.artifact.AttachedArtifact;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
+import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
/**
* Signs artifacts and installs the artifact in the remote repository.
*
@@ -100,7 +106,8 @@ public class SignAndDeployFileMojo
/**
* Type of the artifact to be deployed. Retrieved from POM file if specified.
- *
+ * Defaults to file extension if not specified via command line or POM.
+ *
* @parameter expression="${packaging}"
*/
private String packaging;
@@ -213,6 +220,57 @@ public class SignAndDeployFileMojo
*/
private ModelValidator modelValidator;
+ /**
+ * The default Maven project created when building the plugin
+ *
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ * @since 1.3
+ */
+ private MavenProject project;
+
+ /**
+ * Used for attaching the source and javadoc jars to the project.
+ *
+ * @component
+ * @since 1.3
+ */
+ private MavenProjectHelper projectHelper;
+
+ /**
+ * The bundled API docs for the artifact.
+ *
+ * @parameter expression="${javadoc}"
+ * @since 1.3
+ */
+ private File javadoc;
+
+ /**
+ * The bundled sources for the artifact.
+ *
+ * @parameter expression="${sources}"
+ * @since 1.3
+ */
+ private File sources;
+
+ /**
+ * Parameter used to control how many times a failed deployment will be retried before giving up and failing.
+ * If a value outside the range 1-10 is specified it will be pulled to the nearest value within the range 1-10.
+ *
+ * @parameter expression="${retryFailedDeploymentCount}" default-value="1"
+ * @since 1.3
+ */
+ private int retryFailedDeploymentCount;
+
+ /**
+ * Parameter used to update the metadata to make the artifact as release.
+ *
+ * @parameter expression="${updateReleaseInfo}" default-value="false"
+ * @since 1.3
+ */
+ protected boolean updateReleaseInfo;
+
private void initProperties()
throws MojoExecutionException
{
@@ -225,6 +283,11 @@ public class SignAndDeployFileMojo
processModel( model );
}
+
+ if ( packaging == null && file != null )
+ {
+ packaging = FileUtils.getExtension( file.getName() );
+ }
}
public void execute()
@@ -291,14 +354,51 @@ public class SignAndDeployFileMojo
}
}
+ if ( updateReleaseInfo )
+ {
+ artifact.setRelease( true );
+ }
+
+ project.setArtifact( artifact );
+
try
{
- deployer.deploy( file, artifact, deploymentRepository, localRepository );
+ deploy( file, artifact, deploymentRepository, localRepository );
}
catch ( ArtifactDeploymentException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
+
+ if ( sources != null )
+ {
+ projectHelper.attachArtifact( project, "jar", "sources", sources );
+ }
+
+ if ( javadoc != null )
+ {
+ projectHelper.attachArtifact( project, "jar", "javadoc", javadoc );
+ }
+
+ List attachedArtifacts = project.getAttachedArtifacts();
+
+ for ( Iterator i = attachedArtifacts.iterator(); i.hasNext(); )
+ {
+ Artifact attached = (Artifact) i.next();
+
+ fileSig = signer.generateSignatureForArtifact( attached.getFile() );
+ attached = new AttachedSignedArtifact(attached, new AscArtifactMetadata( attached, fileSig, false ) );
+ try
+ {
+ deploy( attached.getFile(), attached, deploymentRepository, localRepository );
+ }
+ catch ( ArtifactDeploymentException e )
+ {
+ throw new MojoExecutionException(
+ "Error deploying attached artifact " + attached.getFile() + ": " + e.getMessage(), e );
+ }
+ }
+
}
/**
@@ -416,8 +516,27 @@ public class SignAndDeployFileMojo
}
/**
- * Generates a minimal model from the user-supplied artifact information.
+ * Validates the user-supplied artifact information.
*
+ * @throws MojoFailureException If any artifact coordinate is invalid.
+ */
+ private void validateArtifactInformation()
+ throws MojoFailureException
+ {
+ Model model = generateModel();
+
+ ModelValidationResult result = modelValidator.validate( model );
+
+ if ( result.getMessageCount() > 0 )
+ {
+ throw new MojoFailureException( "The artifact information is incomplete or not valid:\n"
+ + result.render( " " ) );
+ }
+ }
+
+ /**
+ * Generates a minimal model from the user-supplied artifact information.
+ *
* @return The generated model, never <code>null</code>.
*/
private Model generateModel()
@@ -437,22 +556,51 @@ public class SignAndDeployFileMojo
}
/**
- * Validates the user-supplied artifact information.
- *
- * @throws MojoFailureException If any artifact coordinate is invalid.
- */
- private void validateArtifactInformation()
- throws MojoFailureException
+ * Deploy an artifact from a particular file.
+ *
+ * @param source the file to deploy
+ * @param artifact the artifact definition
+ * @param deploymentRepository the repository to deploy to
+ * @param localRepository the local repository to install into
+ * @throws ArtifactDeploymentException if an error occurred deploying the artifact
+ */
+ protected void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository,
+ ArtifactRepository localRepository )
+ throws ArtifactDeploymentException
{
- Model model = generateModel();
-
- ModelValidationResult result = modelValidator.validate( model );
-
- if ( result.getMessageCount() > 0 )
+ int retryFailedDeploymentCount = Math.max( 1, Math.min( 10, this.retryFailedDeploymentCount ) );
+ ArtifactDeploymentException exception = null;
+ for ( int count = 0; count < retryFailedDeploymentCount; count++ )
{
- throw new MojoFailureException( "The artifact information is incomplete or not valid:\n"
- + result.render( " " ) );
+ try
+ {
+ if (count > 0)
+ {
+ getLog().info(
+ "Retrying deployment attempt " + ( count + 1 ) + " of " + retryFailedDeploymentCount );
+ }
+ deployer.deploy( source, artifact, deploymentRepository, localRepository );
+ for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
+ {
+ ArtifactMetadata metadata = (ArtifactMetadata) i.next();
+ getLog().info( "Metadata[" + metadata.getKey() + "].filename = " + metadata.getRemoteFilename());
+ }
+ exception = null;
+ }
+ catch ( ArtifactDeploymentException e )
+ {
+ if (count + 1 < retryFailedDeploymentCount) {
+ getLog().warn( "Something went wrong with the deployment, will try again", e );
+ }
+ if ( exception == null )
+ {
+ exception = e;
+ }
+ }
+ }
+ if ( exception != null )
+ {
+ throw exception;
}
}
-
}