svn commit: r169220 - /maven/components/trunk/maven-archetype/maven-archetype-plugin/src/main/java/org/apache/maven/plugin/archetype

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r169220 - /maven/components/trunk/maven-archetype/maven-archetype-plugin/src/main/java/org/apache/maven/plugin/archetype

brettporter
Administrator
Author: brett
Date: Sun May  8 19:13:08 2005
New Revision: 169220

URL: http://svn.apache.org/viewcvs?rev=169220&view=rev
Log:
update to latest mojo API

Added:
    maven/components/trunk/maven-archetype/maven-archetype-plugin/src/main/java/org/apache/maven/plugin/archetype/MavenArchetypeMojo.java
      - copied, changed from r169170, maven/components/trunk/maven-archetype/maven-archetype-plugin/src/main/java/org/apache/maven/plugin/archetype/MavenArchetypePlugin.java
Removed:
    maven/components/trunk/maven-archetype/maven-archetype-plugin/src/main/java/org/apache/maven/plugin/archetype/MavenArchetypePlugin.java

Copied: maven/components/trunk/maven-archetype/maven-archetype-plugin/src/main/java/org/apache/maven/plugin/archetype/MavenArchetypeMojo.java (from r169170, maven/components/trunk/maven-archetype/maven-archetype-plugin/src/main/java/org/apache/maven/plugin/archetype/MavenArchetypePlugin.java)
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-archetype/maven-archetype-plugin/src/main/java/org/apache/maven/plugin/archetype/MavenArchetypeMojo.java?p2=maven/components/trunk/maven-archetype/maven-archetype-plugin/src/main/java/org/apache/maven/plugin/archetype/MavenArchetypeMojo.java&p1=maven/components/trunk/maven-archetype/maven-archetype-plugin/src/main/java/org/apache/maven/plugin/archetype/MavenArchetypePlugin.java&r1=169170&r2=169220&rev=169220&view=diff
==============================================================================
--- maven/components/trunk/maven-archetype/maven-archetype-plugin/src/main/java/org/apache/maven/plugin/archetype/MavenArchetypePlugin.java (original)
+++ maven/components/trunk/maven-archetype/maven-archetype-plugin/src/main/java/org/apache/maven/plugin/archetype/MavenArchetypeMojo.java Sun May  8 19:13:08 2005
@@ -17,89 +17,88 @@
  */
 
 import org.apache.maven.archetype.Archetype;
+import org.apache.maven.archetype.ArchetypeDescriptorException;
+import org.apache.maven.archetype.ArchetypeNotFoundException;
+import org.apache.maven.archetype.ArchetypeTemplateProcessingException;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.plugin.AbstractPlugin;
-import org.apache.maven.plugin.PluginExecutionException;
-import org.apache.maven.plugin.PluginExecutionRequest;
-import org.apache.maven.plugin.PluginExecutionResponse;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
 
 import java.io.File;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
+ * Builds archetype containers.
+ *
  * @goal create
- * @description Builds archetype containers.
- * @parameter name="archetype"
- * type="org.apache.maven.archetype.Archetype"
- * required="true"
- * validator=""
- * expression="#component.org.apache.maven.archetype.Archetype"
- * description=""
- * @parameter name="localRepository"
- * type="org.apache.maven.artifact.ArtifactRepository"
- * required="true"
- * validator=""
- * expression="#localRepository"
- * description=""
- * @parameter name="archetypeGroupId"
- * type="String"
- * required="true"
- * validator=""
- * expression="#archetypeGroupId"
- * default="org.apache.maven.archetypes"
- * description=""
- * @parameter name="archetypeArtifactId"
- * type="String"
- * required="true"
- * validator=""
- * expression="#archetypeArtifactId"
- * default="maven-archetype-quickstart"
- * description=""
- * @parameter name="archetypeVersion"
- * type="String"
- * required="true"
- * validator=""
- * expression="#archetypeVersion"
- * default="1.0-alpha-1-SNAPSHOT"
- * description=""
- * @parameter name="groupId"
- * type="String"
- * required="true"
- * validator=""
- * expression="#groupId"
- * description=""
- * @parameter name="artifactId"
- * type="String"
- * required="true"
- * validator=""
- * expression="#artifactId"
- * description=""
- * @parameter name="version"
- * type="String"
- * required="true"
- * validator=""
- * expression="#version"
- * default="1.0-SNAPSHOT"
- * description=""
- * @parameter name="package"
- * type="String"
- * required="true"
- * validator=""
- * expression="#package"
- * default="com.mycompany.app"
- * description=""
- * @parameter name="remoteRepositories"
- * type="java.util.List"
- * required="true"
- * validator=""
- * expression="#project.remoteArtifactRepositories"
- * description=""
  */
-public class MavenArchetypePlugin
-    extends AbstractPlugin
+public class MavenArchetypeMojo
+    extends AbstractMojo
 {
-    public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
-        throws Exception
+    /**
+     * @parameter expression="${component.org.apache.maven.archetype.Archetype}"
+     * @required
+     */
+    private Archetype archetype;
+
+    /**
+     * @parameter expression="${localRepository}"
+     * @required
+     */
+    private ArtifactRepository localRepository;
+
+    /**
+     * @parameter expression="${archetypeGroupId}"
+     * @required
+     */
+    private String archetypeGroupId = "org.apache.maven.archetypes";
+
+    /**
+     * @parameter expression="${archetypeArtifactId}"
+     * @required
+     */
+    private String archetypeArtifactId = "maven-archetype-quickstart";
+
+    /**
+     * @parameter expression="${archetypeVersion}"
+     * @required
+     */
+    private String archetypeVersion = "1.0-alpha-1-SNAPSHOT";
+
+    /**
+     * @parameter expression="${groupId}"
+     * @required
+     */
+    private String groupId = "org.apache.maven.archetypes";
+
+    /**
+     * @parameter expression="${artifactId}"
+     * @required
+     */
+    private String artifactId = "maven-archetype-quickstart";
+
+    /**
+     * @parameter expression="${version}"
+     * @required
+     */
+    private String version = "1.0-SNAPSHOT";
+
+    /**
+     * @parameter expression="${packageName}"
+     * @required
+     */
+    private String packageName = "com.mycompany.app";
+
+    /**
+     * @parameter expression="${project.remoteArtifactRepositories}"
+     * @required
+     */
+    private List remoteRepositories;
+
+    public void execute()
+        throws MojoExecutionException
     {
         // TODO: prompt for missing values
         // TODO: use new plugin type
@@ -115,32 +114,42 @@
         // parameters
         // ----------------------------------------------------------------------
 
-        ArtifactRepository localRepository = (ArtifactRepository) request.getParameter( "localRepository" );
-
-        // From the super POM
-        List remoteRepositories = (List) request.getParameter( "remoteRepositories" );
-
-        String archetypeGroupId = (String) request.getParameter( "archetypeGroupId" );
-
-        String archetypeArtifactId = (String) request.getParameter( "archetypeArtifactId" );
-
-        String archetypeVersion = (String) request.getParameter( "archetypeVersion" );
-
-        Archetype archetype = (Archetype) request.getParameter( "archetype" );
-
         String basedir = System.getProperty( "user.dir" );
 
         // TODO: allow this to be configured
-        File outputDirectory = new File( basedir, (String) request.getParameter( "artifactId" ) );
-        request.getParameters().put( "outputDirectory", outputDirectory.getAbsolutePath() );
+        File outputDirectory = new File( basedir, artifactId );
 
         if ( outputDirectory.exists() )
         {
-            throw new PluginExecutionException(
-                outputDirectory.getName() + " already exists - please run from a clean directory" );
+            throw new MojoExecutionException( outputDirectory.getName() +
+                " already exists - please run from a clean directory" );
         }
 
-        archetype.createArchetype( archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository,
-                                   remoteRepositories, request.getParameters() );
+        // TODO: context mojo more appropriate?
+        Map map = new HashMap();
+        map.put( "outputDirectory", outputDirectory.getAbsolutePath() );
+        map.put( "package", packageName );
+        map.put( "packageName", packageName );
+        map.put( "groupId", groupId );
+        map.put( "artifactId", artifactId );
+        map.put( "version", version );
+
+        try
+        {
+            archetype.createArchetype( archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository,
+                                       remoteRepositories, map );
+        }
+        catch ( ArchetypeNotFoundException e )
+        {
+            throw new MojoExecutionException( "Error creating from archetype", e );
+        }
+        catch ( ArchetypeDescriptorException e )
+        {
+            throw new MojoExecutionException( "Error creating from archetype", e );
+        }
+        catch ( ArchetypeTemplateProcessingException e )
+        {
+            throw new MojoExecutionException( "Error creating from archetype", e );
+        }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]