Author: jdcasey
Date: Mon Aug 21 14:58:39 2006
New Revision: 433384
URL: http://svn.apache.org/viewvc?rev=433384&view=rev
Log:
Adding alternative deployment repository parameter for the deploy:deploy mojo,
and bumping the POM version to 2.3-SNAPSHOT to accommodate this new feature.
Modified:
maven/plugins/trunk/maven-deploy-plugin/pom.xml
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java
Modified: maven/plugins/trunk/maven-deploy-plugin/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/pom.xml?rev=433384&r1=433383&r2=433384&view=diff
==============================================================================
--- maven/plugins/trunk/maven-deploy-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-deploy-plugin/pom.xml Mon Aug 21 14:58:39 2006
@@ -8,7 +8,7 @@
<artifactId>maven-deploy-plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>Maven Deploy Plugin</name>
- <version>2.2.2-SNAPSHOT</version>
+ <version>2.3-SNAPSHOT</version>
<inceptionYear>2004</inceptionYear>
<prerequisites>
<maven>2.0</maven>
Modified:
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java?rev=433384&r1=433383&r2=433384&view=diff
==============================================================================
---
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java
(original)
+++
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java
Mon Aug 21 14:58:39 2006
@@ -20,6 +20,7 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
public abstract class AbstractDeployMojo
extends AbstractMojo
@@ -39,7 +40,7 @@
private ArtifactRepository localRepository;
public abstract void execute()
- throws MojoExecutionException;
+ throws MojoExecutionException, MojoFailureException;
/* Setters and Getters */
Modified:
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java?rev=433384&r1=433383&r2=433384&view=diff
==============================================================================
---
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java
(original)
+++
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java
Mon Aug 21 14:58:39 2006
@@ -20,16 +20,27 @@
import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import
org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import java.io.File;
import java.util.Iterator;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* Deploys an artifact to remote repository.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Emmanuel Venisse</a>
* @author <a href="mailto:[EMAIL PROTECTED]">John Casey (refactoring only)</a>
* @version $Id$
@@ -38,8 +49,11 @@
*/
public class DeployMojo
extends AbstractDeployMojo
+ implements Contextualizable
{
+ private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile(
"(.+)::(.+)::(.+)" );
+
/**
* @parameter expression="${project.artifact}"
* @required
@@ -68,6 +82,21 @@
private ArtifactRepository deploymentRepository;
/**
+ * Specifies an alternative repository to which the project artifacts
should be deployed ( other
+ * than those specified in <distributionManagement> ).
+ * <br/>
+ * Format: id::layout::url
+ *
+ * @parameter expression="${altDeploymentRepository}"
+ */
+ private String altDeploymentRepository;
+
+ /**
+ * @component
+ */
+ private ArtifactRepositoryFactory repoFactory;
+
+ /**
* @parameter expression="${project.attachedArtifacts}
* @required
* @readonly
@@ -76,33 +105,33 @@
/**
* Parameter used to update the metadata to make the artifact as release.
- *
+ *
* @parameter expression="${updateReleaseInfo}" default-value="false"
*/
private boolean updateReleaseInfo;
+ /**
+ * Contextualized.
+ */
+ private PlexusContainer container;
+
public void execute()
- throws MojoExecutionException
+ throws MojoExecutionException, MojoFailureException
{
- if ( deploymentRepository == null )
- {
- String msg = "Deployment failed: repository element was not
specified in the pom inside" +
- " distributionManagement element";
- throw new MojoExecutionException( msg );
- }
-
- String protocol = deploymentRepository.getProtocol();
-
- if( protocol.equals( "scp" ) )
+ ArtifactRepository repo = getDeploymentRepository();
+
+ String protocol = repo.getProtocol();
+
+ if ( protocol.equals( "scp" ) )
{
- File sshFile = new File( System.getProperty( "user.home" ),
".ssh" );
+ File sshFile = new File( System.getProperty( "user.home" ), ".ssh"
);
- if( !sshFile.exists() )
- {
- sshFile.mkdirs();
- }
+ if ( !sshFile.exists() )
+ {
+ sshFile.mkdirs();
+ }
}
-
+
// Deploy the POM
boolean isPomArtifact = "pom".equals( packaging );
if ( !isPomArtifact )
@@ -120,7 +149,7 @@
{
if ( isPomArtifact )
{
- getDeployer().deploy( pomFile, artifact, deploymentRepository,
getLocalRepository() );
+ getDeployer().deploy( pomFile, artifact, repo,
getLocalRepository() );
}
else
{
@@ -128,21 +157,78 @@
if ( file == null )
{
throw new MojoExecutionException(
- "The packaging for this project did not assign a file
to the build artifact" );
+ "The packaging for this
project did not assign a file to the build artifact" );
}
- getDeployer().deploy( file, artifact, deploymentRepository,
getLocalRepository() );
+ getDeployer().deploy( file, artifact, repo,
getLocalRepository() );
}
-
+
for ( Iterator i = attachedArtifacts.iterator(); i.hasNext(); )
- {
- Artifact attached = (Artifact) i.next();
-
- getDeployer().deploy( attached.getFile(), attached,
deploymentRepository, getLocalRepository() );
+ {
+ Artifact attached = ( Artifact ) i.next();
+
+ getDeployer().deploy( attached.getFile(), attached, repo,
getLocalRepository() );
}
}
catch ( ArtifactDeploymentException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
+ }
+
+ private ArtifactRepository getDeploymentRepository()
+ throws MojoExecutionException, MojoFailureException
+ {
+ if ( deploymentRepository == null && altDeploymentRepository == null )
+ {
+ String msg =
+ "Deployment failed: repository element was not specified in
the pom inside"
+ + " distributionManagement element or in
-DaltDeploymentRepository=id::layout::url parameter";
+
+ throw new MojoExecutionException( msg );
+ }
+
+ ArtifactRepository repo = null;
+
+ if ( altDeploymentRepository != null )
+ {
+ Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher(
altDeploymentRepository );
+
+ if ( !matcher.matches() )
+ {
+ throw new MojoFailureException( altDeploymentRepository,
"Invalid syntax for repository.",
+ "Invalid syntax for
alternative repository. Use \"id::layout::url\"." );
+ }
+ else
+ {
+ String id = matcher.group( 1 ).trim();
+ String layout = matcher.group( 2 ).trim();
+ String url = matcher.group( 3 ).trim();
+
+ ArtifactRepositoryLayout repoLayout;
+ try
+ {
+ repoLayout = ( ArtifactRepositoryLayout )
container.lookup( ArtifactRepositoryLayout.ROLE, layout );
+ }
+ catch ( ComponentLookupException e )
+ {
+ throw new MojoExecutionException( "Cannot find repository
layout: " + layout, e );
+ }
+
+ repo = repoFactory.createArtifactRepository( id, url,
repoLayout, null, null );
+ }
+ }
+
+ if ( repo == null )
+ {
+ repo = deploymentRepository;
+ }
+
+ return repo;
+ }
+
+ public void contextualize( Context context )
+ throws ContextException
+ {
+ this.container = (PlexusContainer) context.get(
PlexusConstants.PLEXUS_KEY );
}
}