o Decoupled from plexus
authorBenjamin Bentmann <bentmann@apache.org>
Sun, 20 Dec 2009 18:44:42 +0000 (18:44 +0000)
committerBenjamin Bentmann <bentmann@apache.org>
Sun, 20 Dec 2009 18:44:42 +0000 (18:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@892638 13f79535-47bb-0310-9956-ffa450edef68

src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java
src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java

index a72416f..66350b4 100644 (file)
@@ -19,10 +19,14 @@ package org.apache.maven.plugin.deploy;
  * under the License.
  */
 
+import java.util.Map;
+
 import org.apache.maven.artifact.deployer.ArtifactDeployer;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 
 /**
@@ -44,6 +48,13 @@ public abstract class AbstractDeployMojo
     protected ArtifactFactory artifactFactory;
 
     /**
+     * Map that contains the layouts.
+     *
+     * @component role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout"
+     */
+    private Map repositoryLayouts;
+
+    /**
      * @parameter default-value="${localRepository}"
      * @required
      * @readonly
@@ -96,4 +107,17 @@ public abstract class AbstractDeployMojo
         }
     }
 
+    ArtifactRepositoryLayout getLayout( String id )
+        throws MojoExecutionException
+    {
+        ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( id );
+
+        if ( layout == null )
+        {
+            throw new MojoExecutionException( "Invalid repository layout: " + id );
+        }
+
+        return layout;
+    }
+
 }
index f0df72d..a4a1ff8 100644 (file)
@@ -45,7 +45,6 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
-import java.util.Map;
 
 /**
  * Installs the artifact in the remote repository.
@@ -119,13 +118,6 @@ public class DeployFileMojo
     private String repositoryLayout;
 
     /**
-     * Map that contains the layouts
-     *
-     * @component role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout"
-     */
-    private Map repositoryLayouts;
-
-    /**
      * URL where the artifact will be deployed. <br/>
      * ie ( file://C:\m2-repo or scp://host.com/path/to/repo )
      *
@@ -206,9 +198,7 @@ public class DeployFileMojo
             throw new MojoExecutionException( file.getPath() + " not found." );
         }
 
-        ArtifactRepositoryLayout layout;
-
-        layout = ( ArtifactRepositoryLayout ) repositoryLayouts.get( repositoryLayout );
+        ArtifactRepositoryLayout layout = getLayout( repositoryLayout );
 
         ArtifactRepository deploymentRepository =
             repositoryFactory.createDeploymentArtifactRepository( repositoryId, url, layout, uniqueVersion );
index b14ac57..0c77ca4 100644 (file)
@@ -29,12 +29,6 @@ import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 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;
@@ -53,7 +47,6 @@ import java.util.regex.Pattern;
  */
 public class DeployMojo
     extends AbstractDeployMojo
-    implements Contextualizable
 {
 
     private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile( "(.+)::(.+)::(.+)" );
@@ -102,11 +95,6 @@ public class DeployMojo
      * @readonly
      */
     private List attachedArtifacts;
-
-    /**
-     * Contextualized.
-     */
-    private PlexusContainer container;
     
     /**
      * Set this to 'true' to bypass artifact deploy
@@ -224,16 +212,8 @@ public class DeployMojo
                 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 );
-                }
+
+                ArtifactRepositoryLayout repoLayout = getLayout( layout );
                 
                 repo = new DefaultArtifactRepository( id, url, repoLayout );
             }
@@ -255,9 +235,4 @@ public class DeployMojo
         return repo;
     }
 
-    public void contextualize( Context context )
-        throws ContextException
-    {
-        this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
-    }
 }