You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2005/10/05 02:33:17 UTC

svn commit: r294957 - in /maven/components/trunk: maven-core/src/main/java/org/apache/maven/plugin/version/ maven-plugin-descriptor/ maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/ maven-plugins/maven-plugin-plugin/ maven-plug...

Author: jdcasey
Date: Tue Oct  4 17:33:03 2005
New Revision: 294957

URL: http://svn.apache.org/viewcvs?rev=294957&view=rev
Log:
Fixing it0013 and it0020, and adding next installment of describe mojo implementation.

Modified:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java
    maven/components/trunk/maven-plugin-descriptor/pom.xml
    maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
    maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
    maven/components/trunk/maven-plugins/maven-plugin-plugin/pom.xml
    maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
    maven/components/trunk/maven-plugins/maven-projecthelp-plugin/pom.xml
    maven/components/trunk/maven-plugins/maven-projecthelp-plugin/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java?rev=294957&r1=294956&r2=294957&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java Tue Oct  4 17:33:03 2005
@@ -90,6 +90,14 @@
                                          ArtifactRepository localRepository, boolean resolveAsReportPlugin )
         throws PluginVersionResolutionException
     {
+        // before we do anything else, if this is a self-reference we need to short-circuit the resolution process.
+        String projectKey = constructPluginKey( project.getGroupId(), project.getArtifactId() );
+        
+        if ( projectKey.equals( constructPluginKey( groupId, artifactId ) ) )
+        {
+            return project.getVersion();
+        }
+        
         // first pass...if the plugin is specified in the pom, try to retrieve the version from there.
         String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin );
 

Modified: maven/components/trunk/maven-plugin-descriptor/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-descriptor/pom.xml?rev=294957&r1=294956&r2=294957&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-descriptor/pom.xml (original)
+++ maven/components/trunk/maven-plugin-descriptor/pom.xml Tue Oct  4 17:33:03 2005
@@ -14,7 +14,6 @@
       <plugin>
         <groupId>org.codehaus.modello</groupId>
         <artifactId>modello-maven-plugin</artifactId>
-        <version>RELEASE</version>
         <executions>
           <execution>
             <goals>
@@ -47,4 +46,4 @@
       <artifactId>plexus-container-default</artifactId>
     </dependency>
   </dependencies>
-</project>
\ No newline at end of file
+</project>

Modified: maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java?rev=294957&r1=294956&r2=294957&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java (original)
+++ maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java Tue Oct  4 17:33:03 2005
@@ -29,13 +29,12 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.Collection;
-import java.util.Collections;
 
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@@ -59,7 +58,7 @@
     private boolean inheritedByDefault = true;
 
     private List artifacts;
-
+    
     private Map lifecycleMappings;
 
     private ClassRealm classRealm;
@@ -69,6 +68,10 @@
 
     private Set introducedDependencyArtifacts;
 
+    private String name;
+
+    private String description;
+
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------
@@ -321,5 +324,25 @@
     public Set getIntroducedDependencyArtifacts()
     {
         return introducedDependencyArtifacts != null ? introducedDependencyArtifacts : Collections.EMPTY_SET;
+    }
+    
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+    
+    public String getName()
+    {
+        return name;
+    }
+    
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+    
+    public String getDescription()
+    {
+        return description;
     }
 }

Modified: maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java?rev=294957&r1=294956&r2=294957&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java (original)
+++ maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java Tue Oct  4 17:33:03 2005
@@ -37,6 +37,9 @@
         pluginDescriptor.setArtifactId( c.getChild( "artifactId" ).getValue() );
         pluginDescriptor.setVersion( c.getChild( "version" ).getValue() );
         pluginDescriptor.setGoalPrefix( c.getChild( "goalPrefix" ).getValue() );
+        
+        pluginDescriptor.setName( c.getChild( "name" ).getValue() );
+        pluginDescriptor.setDescription( c.getChild( "description" ).getValue() );
 
         String isolatedRealm = c.getChild( "isolatedRealm" ).getValue();
 

Modified: maven/components/trunk/maven-plugins/maven-plugin-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-plugin-plugin/pom.xml?rev=294957&r1=294956&r2=294957&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-plugin-plugin/pom.xml (original)
+++ maven/components/trunk/maven-plugins/maven-plugin-plugin/pom.xml Tue Oct  4 17:33:03 2005
@@ -24,6 +24,11 @@
       <timezone>-5</timezone>
     </developer>
   </developers>
+
+  <prerequisites>
+    <maven>2.0-beta-4-SNAPSHOT</maven>
+  </prerequisites>
+
   <dependencies>
     <dependency>
       <groupId>org.apache.maven</groupId>
@@ -41,8 +46,13 @@
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-descriptor</artifactId>
+      <version>2.0-beta-4-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-tools-api</artifactId>
-      <version>2.0-beta-3</version>
+      <version>2.0-beta-4-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>

Modified: maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java?rev=294957&r1=294956&r2=294957&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java Tue Oct  4 17:33:03 2005
@@ -87,6 +87,10 @@
         pluginDescriptor.setVersion( project.getVersion() );
 
         pluginDescriptor.setGoalPrefix( goalPrefix );
+        
+        pluginDescriptor.setName( project.getName() );
+        
+        pluginDescriptor.setDescription( project.getDescription() );
 
         try
         {

Modified: maven/components/trunk/maven-plugins/maven-projecthelp-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-projecthelp-plugin/pom.xml?rev=294957&r1=294956&r2=294957&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-projecthelp-plugin/pom.xml (original)
+++ maven/components/trunk/maven-plugins/maven-projecthelp-plugin/pom.xml Tue Oct  4 17:33:03 2005
@@ -12,7 +12,7 @@
   <inceptionYear>2001</inceptionYear>
   
   <prerequisites>
-    <maven>2.0-beta-3</maven>
+    <maven>2.0-beta-4-SNAPSHOT</maven>
   </prerequisites>
   
   <dependencies>
@@ -28,8 +28,13 @@
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-descriptor</artifactId>
+      <version>2.0-beta-4-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-tools-api</artifactId>
-      <version>2.0-beta-1</version>
+      <version>2.0-beta-4-SNAPSHOT</version>
     </dependency>
   </dependencies>
 </project>

Modified: maven/components/trunk/maven-plugins/maven-projecthelp-plugin/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-projecthelp-plugin/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java?rev=294957&r1=294956&r2=294957&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-projecthelp-plugin/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-projecthelp-plugin/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java Tue Oct  4 17:33:03 2005
@@ -2,9 +2,11 @@
 
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.PluginManager;
 import org.apache.maven.plugin.PluginManagerException;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
@@ -18,6 +20,7 @@
 import java.io.IOException;
 import java.io.Writer;
 import java.util.Iterator;
+import java.util.List;
 
 /**
  * @goal describe
@@ -72,6 +75,13 @@
     private Settings settings;
 
     /**
+     * @parameter expression="${session}"
+     * @required
+     * @readonly
+     */
+    private MavenSession session;
+
+    /**
      * @parameter expression="${localRepository}"
      * @required
      * @readonly
@@ -84,70 +94,111 @@
     private File output;
 
     public void execute()
-        throws MojoExecutionException
+        throws MojoExecutionException, MojoFailureException
     {
-        String pluginPrefix = null;
+        PluginInfo pi = new PluginInfo();
+        
+        parsePluginLookupInfo( pi );
+        
+        PluginDescriptor descriptor = lookupPluginDescriptor( pi );
 
-        if ( plugin != null && plugin.length() > 0 )
+        StringBuffer descriptionBuffer = new StringBuffer();
+
+        if ( mojo != null && mojo.length() > 0 )
         {
-            if ( plugin.indexOf( ":" ) > -1 )
+            describeMojo( descriptor.getMojo( mojo ), descriptionBuffer );
+        }
+        else
+        {
+            describePlugin( descriptor, descriptionBuffer );
+        }
+
+        writeDescription( descriptionBuffer );
+    }
+
+    private void writeDescription( StringBuffer descriptionBuffer ) throws MojoExecutionException
+    {
+        if ( output != null )
+        {
+            Writer out = null;
+            try
             {
-                String[] pluginParts = plugin.split( ":" );
+                output.getParentFile().mkdirs();
+                
+                out = new FileWriter( output );
 
-                switch ( pluginParts.length )
+                out.write( descriptionBuffer.toString() );
+            }
+            catch ( IOException e )
+            {
+                throw new MojoExecutionException( "Cannot write plugin/mojo description.", e );
+            }
+            finally
+            {
+                if ( out != null )
                 {
-                    case ( 1 ):
-                    {
-                        pluginPrefix = pluginParts[0];
-                        break;
-                    }
-                    case ( 2 ):
-                    {
-                        groupId = pluginParts[0];
-                        artifactId = pluginParts[1];
-                        break;
-                    }
-                    case ( 3 ):
+                    try
                     {
-                        groupId = pluginParts[0];
-                        artifactId = pluginParts[1];
-                        version = pluginParts[2];
-                        break;
+                        out.close();
                     }
-                    default:
+                    catch ( IOException e )
                     {
-                        throw new MojoExecutionException(
-                                                          "plugin parameter must be a plugin prefix, or conform to: 'groupId:artifactId[:version]." );
+                        getLog().debug( "Error closing file output.", e );
                     }
                 }
             }
-            else
-            {
-                pluginPrefix = plugin;
-            }
         }
+        else
+        {
+            getLog().info( descriptionBuffer.toString() );
+        }
+    }
 
-        PluginDescriptor descriptor;
-
-        if ( pluginPrefix != null )
+    private PluginDescriptor lookupPluginDescriptor( PluginInfo pi ) throws MojoExecutionException, MojoFailureException
+    {
+        PluginDescriptor descriptor = null;
+        
+        Plugin forLookup = null;
+        
+        if ( pi.prefix != null )
         {
-            descriptor = pluginManager.getPluginDescriptorForPrefix( pluginPrefix );
+            descriptor = pluginManager.getPluginDescriptorForPrefix( pi.prefix );
+            
+            if ( descriptor == null )
+            {
+                try
+                {
+                    forLookup = pluginManager.getPluginDefinitionForPrefix( pi.prefix, session, project );
+                }
+                catch ( PluginManagerException e )
+                {
+                    throw new MojoExecutionException(
+                        "Cannot resolve plugin-prefix: \'" + pi.prefix + "\' from plugin mappings metadata.", e );
+                }
+            }
         }
-        else if ( groupId != null && artifactId != null )
+        else if ( pi.groupId != null && pi.artifactId != null )
         {
-            Plugin plugin = new Plugin();
+            forLookup = new Plugin();
+            
+            forLookup.setGroupId( pi.groupId );
+            forLookup.setArtifactId( pi.artifactId );
 
-            plugin.setGroupId( groupId );
-            plugin.setArtifactId( artifactId );
-
-            if ( version != null )
+            if ( pi.version != null )
             {
-                plugin.setVersion( version );
+                forLookup.setVersion( pi.version );
             }
-
+        }
+        else
+        {
+            throw new MojoFailureException("You must either specify \'groupId\' and \'artifactId\', or a valid \'plugin\' parameter." );
+        }
+        
+        if ( descriptor == null && forLookup != null )
+        {
             try
             {
-                descriptor = pluginManager.verifyPlugin( plugin, project, settings, localRepository );
+                descriptor = pluginManager.verifyPlugin( forLookup, project, settings, localRepository );
             }
             catch ( ArtifactResolutionException e )
             {
@@ -165,87 +216,119 @@
                     + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
             }
         }
-        else
-        {
-            throw new MojoExecutionException(
-                                              "You must either specify \'groupId\' and \'artifactId\', or a valid \'plugin\' parameter." );
-        }
-
-        StringBuffer descriptionBuffer = new StringBuffer();
-
-        if ( mojo != null && mojo.length() > 0 )
-        {
-            describeMojo( descriptor.getMojo( mojo ), descriptionBuffer );
-        }
-        else
-        {
-            describePlugin( descriptor, descriptionBuffer );
-        }
+        
+        return descriptor;
+    }
 
-        if ( output != null )
+    private void parsePluginLookupInfo( PluginInfo pi ) throws MojoFailureException
+    {
+        if ( plugin != null && plugin.length() > 0 )
         {
-            Writer out = null;
-            try
+            if ( plugin.indexOf( ":" ) > -1 )
             {
-                out = new FileWriter( output );
+                String[] pluginParts = plugin.split( ":" );
 
-                out.write( descriptionBuffer.toString() );
-            }
-            catch ( IOException e )
-            {
-                throw new MojoExecutionException( "Cannot write plugin/mojo description.", e );
-            }
-            finally
-            {
-                if ( out != null )
+                switch ( pluginParts.length )
                 {
-                    try
+                    case ( 1 ):
                     {
-                        out.close();
+                        pi.prefix = pluginParts[0];
+                        break;
                     }
-                    catch ( IOException e )
+                    case ( 2 ):
                     {
-                        getLog().debug( "Error closing file output.", e );
+                        pi.groupId = pluginParts[0];
+                        pi.artifactId = pluginParts[1];
+                        break;
+                    }
+                    case ( 3 ):
+                    {
+                        pi.groupId = pluginParts[0];
+                        pi.artifactId = pluginParts[1];
+                        pi.version = pluginParts[2];
+                        break;
+                    }
+                    default:
+                    {
+                        throw new MojoFailureException("plugin parameter must be a plugin prefix, or conform to: 'groupId:artifactId[:version]." );
                     }
                 }
             }
+            else
+            {
+                pi.prefix = plugin;
+            }
         }
         else
         {
-            System.out.println( descriptionBuffer.toString() );
+            pi.groupId = groupId;
+            pi.artifactId = artifactId;
+            pi.version = version;
         }
     }
 
     private void describePlugin( PluginDescriptor pd, StringBuffer buffer )
     {
-        buffer.append( "Description of Plugin" ).append( "\n-----------------------------------------------" )
-            .append( "\n\nGroup Id:  " ).append( pd.getGroupId() ).append( "\nArtifact Id: " )
-            .append( pd.getArtifactId() ).append( "\nVersion:     " ).append( pd.getVersion() )
-            .append( "\nGoal Prefix: " ).append( pd.getGoalPrefix() ).append( "\n\nMojos:" )
-            .append( "\n-----------------------------------------------" ).append( "\n\n" );
+        buffer.append( "Plugin: \'" ).append( pd.getName() ).append( '\'' );
+        buffer.append( "\n-----------------------------------------------" );
+        buffer.append( "\nGroup Id:  " ).append( pd.getGroupId() );
+        buffer.append( "\nArtifact Id: " ).append( pd.getArtifactId() );
+        buffer.append( "\nVersion:     " ).append( pd.getVersion() );
+        buffer.append( "\nGoal Prefix: " ).append( pd.getGoalPrefix() );
+        buffer.append( "\nDescription:\n\n" ).append( pd.getDescription() ).append( "\n" );
+        buffer.append( "\nMojos:\n" );
 
         for ( Iterator it = pd.getMojos().iterator(); it.hasNext(); )
         {
             MojoDescriptor md = (MojoDescriptor) it.next();
 
+            buffer.append( "\nGoal: \'" ).append( md.getGoal() ).append( '\'' );
+            buffer.append( "\n========================================" );
+            
             describeMojoGuts( md, buffer );
-
-            buffer.append( "\n-----------------------------------------------" ).append( "\n\n" );
+            
+            buffer.append( "\n\n" );
         }
     }
 
     private void describeMojo( MojoDescriptor md, StringBuffer buffer )
     {
-        buffer.append( "Description of Mojo" ).append( "\n-----------------------------------------------" )
-            .append( "\n\n" );
+        buffer.append( "Mojo: \'" ).append( md.getFullGoalName() ).append( '\'' );
+        buffer.append( "\n-----------------------------------------------" );
+        buffer.append( "\nGoal: \'" ).append( md.getGoal() ).append( "\'" );
 
         describeMojoGuts( md, buffer );
+        
+        buffer.append( "\n\n" );
     }
 
     private void describeMojoGuts( MojoDescriptor md, StringBuffer buffer )
     {
-        // TODO Complete mojo description dump.
-        buffer.append( "TODO!" );
+        buffer.append( "\nDescription:\n\n" ).append( md.getDescription() ).append( "\n" );
+        
+        String deprecation = md.getDeprecated();
+        
+        if ( deprecation != null )
+        {
+            buffer.append( "\n\nNOTE: This mojo is deprecated.\n" ).append( deprecation ).append( "\n" );
+        }
+        
+        buffer.append( "\nImplementation: " ).append( md.getImplementation() );
+        buffer.append( "\nLanguage: " ).append( md.getLanguage() );
+        
+        String phase = md.getPhase();
+        if ( phase != null )
+        {
+            buffer.append( "\nBound to Phase: " ).append( phase );
+        }
+        
+        String eGoal = md.getExecuteGoal();
+        String eLife = md.getExecuteLifecycle();
+        String ePhase = md.getExecutePhase();
+        
+        List parameters = md.getParameters();
+        
+        List requirements = md.getRequirements();
     }
 
     public final String getPlugin()
@@ -346,6 +429,18 @@
     public final void setVersion( String version )
     {
         this.version = version;
+    }
+    
+    private static class PluginInfo
+    {
+        String prefix;
+        String groupId;
+        String artifactId;
+        String version;
+        String mojo;
+        
+        Plugin plugin;
+        PluginDescriptor pluginDescriptor;
     }
 
 }