From a96c8a76924706558fed67a6d2729c02723cd34f Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 5 Oct 2005 00:33:03 +0000 Subject: [PATCH] Fixing it0013 and it0020, and adding next installment of describe mojo implementation. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@294957 13f79535-47bb-0310-9956-ffa450edef68 --- .../version/DefaultPluginVersionManager.java | 8 + maven-plugin-descriptor/pom.xml | 3 +- .../plugin/descriptor/PluginDescriptor.java | 29 +- .../descriptor/PluginDescriptorBuilder.java | 3 + maven-plugins/maven-plugin-plugin/pom.xml | 12 +- .../plugin/plugin/AbstractGeneratorMojo.java | 4 + .../maven-projecthelp-plugin/pom.xml | 9 +- .../plugins/projecthelp/DescribeMojo.java | 289 ++++++++++++------ 8 files changed, 252 insertions(+), 105 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java index db541fe400..7fb62ff598 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java @@ -90,6 +90,14 @@ public class DefaultPluginVersionManager 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 ); diff --git a/maven-plugin-descriptor/pom.xml b/maven-plugin-descriptor/pom.xml index c179fc4d90..e90b4e88b7 100755 --- a/maven-plugin-descriptor/pom.xml +++ b/maven-plugin-descriptor/pom.xml @@ -14,7 +14,6 @@ org.codehaus.modello modello-maven-plugin - RELEASE @@ -47,4 +46,4 @@ plexus-container-default - \ No newline at end of file + diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java index 553878c7c5..a1afad078b 100644 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java @@ -29,13 +29,12 @@ import java.io.FileNotFoundException; 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 Jason van Zyl @@ -59,7 +58,7 @@ public class PluginDescriptor private boolean inheritedByDefault = true; private List artifacts; - + private Map lifecycleMappings; private ClassRealm classRealm; @@ -69,6 +68,10 @@ public class PluginDescriptor private Set introducedDependencyArtifacts; + private String name; + + private String description; + // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @@ -322,4 +325,24 @@ public class PluginDescriptor { 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; + } } diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java index 72bbe5afdd..ad3eb976da 100755 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java @@ -37,6 +37,9 @@ public class PluginDescriptorBuilder 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(); diff --git a/maven-plugins/maven-plugin-plugin/pom.xml b/maven-plugins/maven-plugin-plugin/pom.xml index b13e945634..41422bafb1 100644 --- a/maven-plugins/maven-plugin-plugin/pom.xml +++ b/maven-plugins/maven-plugin-plugin/pom.xml @@ -24,6 +24,11 @@ -5 + + + 2.0-beta-4-SNAPSHOT + + org.apache.maven @@ -39,10 +44,15 @@ maven-plugin-registry 2.0-beta-3 + + org.apache.maven + maven-plugin-descriptor + 2.0-beta-4-SNAPSHOT + org.apache.maven maven-plugin-tools-api - 2.0-beta-3 + 2.0-beta-4-SNAPSHOT org.apache.maven diff --git a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java index 0240b11ce3..0ef75c40be 100644 --- a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java +++ b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java @@ -87,6 +87,10 @@ public abstract class AbstractGeneratorMojo pluginDescriptor.setVersion( project.getVersion() ); pluginDescriptor.setGoalPrefix( goalPrefix ); + + pluginDescriptor.setName( project.getName() ); + + pluginDescriptor.setDescription( project.getDescription() ); try { diff --git a/maven-plugins/maven-projecthelp-plugin/pom.xml b/maven-plugins/maven-projecthelp-plugin/pom.xml index b4ad8835db..60a3b7404d 100644 --- a/maven-plugins/maven-projecthelp-plugin/pom.xml +++ b/maven-plugins/maven-projecthelp-plugin/pom.xml @@ -12,7 +12,7 @@ 2001 - 2.0-beta-3 + 2.0-beta-4-SNAPSHOT @@ -26,10 +26,15 @@ maven-core 2.0-beta-3 + + org.apache.maven + maven-plugin-descriptor + 2.0-beta-4-SNAPSHOT + org.apache.maven maven-plugin-tools-api - 2.0-beta-1 + 2.0-beta-4-SNAPSHOT diff --git a/maven-plugins/maven-projecthelp-plugin/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java b/maven-plugins/maven-projecthelp-plugin/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java index 39ecdddabc..bbed2176de 100644 --- a/maven-plugins/maven-projecthelp-plugin/src/main/java/org/apache/maven/plugins/projecthelp/DescribeMojo.java +++ b/maven-plugins/maven-projecthelp-plugin/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 @@ -71,6 +74,13 @@ public class DescribeMojo */ private Settings settings; + /** + * @parameter expression="${session}" + * @required + * @readonly + */ + private MavenSession session; + /** * @parameter expression="${localRepository}" * @required @@ -84,92 +94,13 @@ public class DescribeMojo private File output; public void execute() - throws MojoExecutionException + throws MojoExecutionException, MojoFailureException { - String pluginPrefix = null; - - if ( plugin != null && plugin.length() > 0 ) - { - if ( plugin.indexOf( ":" ) > -1 ) - { - String[] pluginParts = plugin.split( ":" ); - - switch ( pluginParts.length ) - { - case ( 1 ): - { - pluginPrefix = pluginParts[0]; - break; - } - case ( 2 ): - { - groupId = pluginParts[0]; - artifactId = pluginParts[1]; - break; - } - case ( 3 ): - { - groupId = pluginParts[0]; - artifactId = pluginParts[1]; - version = pluginParts[2]; - break; - } - default: - { - throw new MojoExecutionException( - "plugin parameter must be a plugin prefix, or conform to: 'groupId:artifactId[:version]." ); - } - } - } - else - { - pluginPrefix = plugin; - } - } - - PluginDescriptor descriptor; - - if ( pluginPrefix != null ) - { - descriptor = pluginManager.getPluginDescriptorForPrefix( pluginPrefix ); - } - else if ( groupId != null && artifactId != null ) - { - Plugin plugin = new Plugin(); - - plugin.setGroupId( groupId ); - plugin.setArtifactId( artifactId ); - - if ( version != null ) - { - plugin.setVersion( version ); - } - - try - { - descriptor = pluginManager.verifyPlugin( plugin, project, settings, localRepository ); - } - catch ( ArtifactResolutionException e ) - { - throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId - + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e ); - } - catch ( PluginManagerException e ) - { - throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId - + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e ); - } - catch ( PluginVersionResolutionException e ) - { - throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId - + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e ); - } - } - else - { - throw new MojoExecutionException( - "You must either specify \'groupId\' and \'artifactId\', or a valid \'plugin\' parameter." ); - } + PluginInfo pi = new PluginInfo(); + + parsePluginLookupInfo( pi ); + + PluginDescriptor descriptor = lookupPluginDescriptor( pi ); StringBuffer descriptionBuffer = new StringBuffer(); @@ -182,11 +113,18 @@ public class DescribeMojo describePlugin( descriptor, descriptionBuffer ); } + writeDescription( descriptionBuffer ); + } + + private void writeDescription( StringBuffer descriptionBuffer ) throws MojoExecutionException + { if ( output != null ) { Writer out = null; try { + output.getParentFile().mkdirs(); + out = new FileWriter( output ); out.write( descriptionBuffer.toString() ); @@ -212,40 +150,185 @@ public class DescribeMojo } else { - System.out.println( descriptionBuffer.toString() ); + getLog().info( descriptionBuffer.toString() ); + } + } + + private PluginDescriptor lookupPluginDescriptor( PluginInfo pi ) throws MojoExecutionException, MojoFailureException + { + PluginDescriptor descriptor = null; + + Plugin forLookup = null; + + if ( pi.prefix != null ) + { + 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 ( pi.groupId != null && pi.artifactId != null ) + { + forLookup = new Plugin(); + + forLookup.setGroupId( pi.groupId ); + forLookup.setArtifactId( pi.artifactId ); + + if ( pi.version != null ) + { + 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( forLookup, project, settings, localRepository ); + } + catch ( ArtifactResolutionException e ) + { + throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId + + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e ); + } + catch ( PluginManagerException e ) + { + throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId + + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e ); + } + catch ( PluginVersionResolutionException e ) + { + throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId + + "\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e ); + } + } + + return descriptor; + } + + private void parsePluginLookupInfo( PluginInfo pi ) throws MojoFailureException + { + if ( plugin != null && plugin.length() > 0 ) + { + if ( plugin.indexOf( ":" ) > -1 ) + { + String[] pluginParts = plugin.split( ":" ); + + switch ( pluginParts.length ) + { + case ( 1 ): + { + pi.prefix = pluginParts[0]; + break; + } + case ( 2 ): + { + 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 + { + 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; + } }