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
This commit is contained in:
John Dennis Casey 2005-10-05 00:33:03 +00:00
parent 22f8256ed8
commit a96c8a7692
8 changed files with 252 additions and 105 deletions

View File

@ -90,6 +90,14 @@ public class DefaultPluginVersionManager
ArtifactRepository localRepository, boolean resolveAsReportPlugin ) ArtifactRepository localRepository, boolean resolveAsReportPlugin )
throws PluginVersionResolutionException 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. // first pass...if the plugin is specified in the pom, try to retrieve the version from there.
String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin ); String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin );

View File

@ -14,7 +14,6 @@
<plugin> <plugin>
<groupId>org.codehaus.modello</groupId> <groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId> <artifactId>modello-maven-plugin</artifactId>
<version>RELEASE</version>
<executions> <executions>
<execution> <execution>
<goals> <goals>
@ -47,4 +46,4 @@
<artifactId>plexus-container-default</artifactId> <artifactId>plexus-container-default</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -29,13 +29,12 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Collection;
import java.util.Collections;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -59,7 +58,7 @@ public class PluginDescriptor
private boolean inheritedByDefault = true; private boolean inheritedByDefault = true;
private List artifacts; private List artifacts;
private Map lifecycleMappings; private Map lifecycleMappings;
private ClassRealm classRealm; private ClassRealm classRealm;
@ -69,6 +68,10 @@ public class PluginDescriptor
private Set introducedDependencyArtifacts; private Set introducedDependencyArtifacts;
private String name;
private String description;
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -322,4 +325,24 @@ public class PluginDescriptor
{ {
return introducedDependencyArtifacts != null ? introducedDependencyArtifacts : Collections.EMPTY_SET; 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;
}
} }

View File

@ -37,6 +37,9 @@ public class PluginDescriptorBuilder
pluginDescriptor.setArtifactId( c.getChild( "artifactId" ).getValue() ); pluginDescriptor.setArtifactId( c.getChild( "artifactId" ).getValue() );
pluginDescriptor.setVersion( c.getChild( "version" ).getValue() ); pluginDescriptor.setVersion( c.getChild( "version" ).getValue() );
pluginDescriptor.setGoalPrefix( c.getChild( "goalPrefix" ).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(); String isolatedRealm = c.getChild( "isolatedRealm" ).getValue();

View File

@ -24,6 +24,11 @@
<timezone>-5</timezone> <timezone>-5</timezone>
</developer> </developer>
</developers> </developers>
<prerequisites>
<maven>2.0-beta-4-SNAPSHOT</maven>
</prerequisites>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
@ -39,10 +44,15 @@
<artifactId>maven-plugin-registry</artifactId> <artifactId>maven-plugin-registry</artifactId>
<version>2.0-beta-3</version> <version>2.0-beta-3</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-descriptor</artifactId>
<version>2.0-beta-4-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-tools-api</artifactId> <artifactId>maven-plugin-tools-api</artifactId>
<version>2.0-beta-3</version> <version>2.0-beta-4-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>

View File

@ -87,6 +87,10 @@ public abstract class AbstractGeneratorMojo
pluginDescriptor.setVersion( project.getVersion() ); pluginDescriptor.setVersion( project.getVersion() );
pluginDescriptor.setGoalPrefix( goalPrefix ); pluginDescriptor.setGoalPrefix( goalPrefix );
pluginDescriptor.setName( project.getName() );
pluginDescriptor.setDescription( project.getDescription() );
try try
{ {

View File

@ -12,7 +12,7 @@
<inceptionYear>2001</inceptionYear> <inceptionYear>2001</inceptionYear>
<prerequisites> <prerequisites>
<maven>2.0-beta-3</maven> <maven>2.0-beta-4-SNAPSHOT</maven>
</prerequisites> </prerequisites>
<dependencies> <dependencies>
@ -26,10 +26,15 @@
<artifactId>maven-core</artifactId> <artifactId>maven-core</artifactId>
<version>2.0-beta-3</version> <version>2.0-beta-3</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-descriptor</artifactId>
<version>2.0-beta-4-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-tools-api</artifactId> <artifactId>maven-plugin-tools-api</artifactId>
<version>2.0-beta-1</version> <version>2.0-beta-4-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -2,9 +2,11 @@ package org.apache.maven.plugins.projecthelp;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginManager; import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.PluginManagerException; import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -18,6 +20,7 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
/** /**
* @goal describe * @goal describe
@ -71,6 +74,13 @@ public class DescribeMojo
*/ */
private Settings settings; private Settings settings;
/**
* @parameter expression="${session}"
* @required
* @readonly
*/
private MavenSession session;
/** /**
* @parameter expression="${localRepository}" * @parameter expression="${localRepository}"
* @required * @required
@ -84,92 +94,13 @@ public class DescribeMojo
private File output; private File output;
public void execute() public void execute()
throws MojoExecutionException throws MojoExecutionException, MojoFailureException
{ {
String pluginPrefix = null; PluginInfo pi = new PluginInfo();
if ( plugin != null && plugin.length() > 0 ) parsePluginLookupInfo( pi );
{
if ( plugin.indexOf( ":" ) > -1 ) PluginDescriptor descriptor = lookupPluginDescriptor( pi );
{
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." );
}
StringBuffer descriptionBuffer = new StringBuffer(); StringBuffer descriptionBuffer = new StringBuffer();
@ -182,11 +113,18 @@ public class DescribeMojo
describePlugin( descriptor, descriptionBuffer ); describePlugin( descriptor, descriptionBuffer );
} }
writeDescription( descriptionBuffer );
}
private void writeDescription( StringBuffer descriptionBuffer ) throws MojoExecutionException
{
if ( output != null ) if ( output != null )
{ {
Writer out = null; Writer out = null;
try try
{ {
output.getParentFile().mkdirs();
out = new FileWriter( output ); out = new FileWriter( output );
out.write( descriptionBuffer.toString() ); out.write( descriptionBuffer.toString() );
@ -212,40 +150,185 @@ public class DescribeMojo
} }
else 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 ) private void describePlugin( PluginDescriptor pd, StringBuffer buffer )
{ {
buffer.append( "Description of Plugin" ).append( "\n-----------------------------------------------" ) buffer.append( "Plugin: \'" ).append( pd.getName() ).append( '\'' );
.append( "\n\nGroup Id: " ).append( pd.getGroupId() ).append( "\nArtifact Id: " ) buffer.append( "\n-----------------------------------------------" );
.append( pd.getArtifactId() ).append( "\nVersion: " ).append( pd.getVersion() ) buffer.append( "\nGroup Id: " ).append( pd.getGroupId() );
.append( "\nGoal Prefix: " ).append( pd.getGoalPrefix() ).append( "\n\nMojos:" ) buffer.append( "\nArtifact Id: " ).append( pd.getArtifactId() );
.append( "\n-----------------------------------------------" ).append( "\n\n" ); 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(); ) for ( Iterator it = pd.getMojos().iterator(); it.hasNext(); )
{ {
MojoDescriptor md = (MojoDescriptor) it.next(); MojoDescriptor md = (MojoDescriptor) it.next();
buffer.append( "\nGoal: \'" ).append( md.getGoal() ).append( '\'' );
buffer.append( "\n========================================" );
describeMojoGuts( md, buffer ); describeMojoGuts( md, buffer );
buffer.append( "\n-----------------------------------------------" ).append( "\n\n" ); buffer.append( "\n\n" );
} }
} }
private void describeMojo( MojoDescriptor md, StringBuffer buffer ) private void describeMojo( MojoDescriptor md, StringBuffer buffer )
{ {
buffer.append( "Description of Mojo" ).append( "\n-----------------------------------------------" ) buffer.append( "Mojo: \'" ).append( md.getFullGoalName() ).append( '\'' );
.append( "\n\n" ); buffer.append( "\n-----------------------------------------------" );
buffer.append( "\nGoal: \'" ).append( md.getGoal() ).append( "\'" );
describeMojoGuts( md, buffer ); describeMojoGuts( md, buffer );
buffer.append( "\n\n" );
} }
private void describeMojoGuts( MojoDescriptor md, StringBuffer buffer ) private void describeMojoGuts( MojoDescriptor md, StringBuffer buffer )
{ {
// TODO Complete mojo description dump. buffer.append( "\nDescription:\n\n" ).append( md.getDescription() ).append( "\n" );
buffer.append( "TODO!" );
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() public final String getPlugin()
@ -347,5 +430,17 @@ public class DescribeMojo
{ {
this.version = version; this.version = version;
} }
private static class PluginInfo
{
String prefix;
String groupId;
String artifactId;
String version;
String mojo;
Plugin plugin;
PluginDescriptor pluginDescriptor;
}
} }