This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to annotated tag maven-help-plugin-2.0
in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git

commit a948cf94cd2dfe1837eb96e8e52d678319abb4a3
Author: John Dennis Casey <jdca...@apache.org>
AuthorDate: Wed Oct 5 00:33:03 2005 +0000

    Fixing it0013 and it0020, and adding next installment of describe mojo 
implementation.
    
    git-svn-id: 
https://svn.apache.org/repos/asf/maven/components/trunk/maven-plugins/maven-projecthelp-plugin@294957
 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |   9 +-
 .../maven/plugins/projecthelp/DescribeMojo.java    | 269 ++++++++++++++-------
 2 files changed, 189 insertions(+), 89 deletions(-)

diff --git a/pom.xml b/pom.xml
index b4ad883..60a3b74 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
diff --git 
a/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java 
b/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java
index 39ecddd..bbed217 100644
--- a/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java
+++ b/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java
@@ -2,9 +2,11 @@ package org.apache.maven.plugins.projecthelp;
 
 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.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
 import java.util.Iterator;
+import java.util.List;
 
 /**
  * @goal describe
@@ -72,6 +75,13 @@ public class DescribeMojo
     private Settings settings;
 
     /**
+     * @parameter expression="${session}"
+     * @required
+     * @readonly
+     */
+    private MavenSession session;
+
+    /**
      * @parameter expression="${localRepository}"
      * @required
      * @readonly
@@ -84,70 +94,111 @@ public class DescribeMojo
     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 @@ public class DescribeMojo
                     + "\'\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()
@@ -347,5 +430,17 @@ public class DescribeMojo
     {
         this.version = version;
     }
+    
+    private static class PluginInfo
+    {
+        String prefix;
+        String groupId;
+        String artifactId;
+        String version;
+        String mojo;
+        
+        Plugin plugin;
+        PluginDescriptor pluginDescriptor;
+    }
 
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <commits@maven.apache.org>.

Reply via email to