[MPLUGIN-231] Switch to plugin annotations for the generated help-mojo if the Maven Plugin depends on maven-plugin-annotations

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1405371 13f79535-47bb-0310-9956-ffa450edef68
master
Robert Scholte 2012-11-03 15:54:02 +00:00
parent 27581ab1ee
commit 0435027899
3 changed files with 33 additions and 8 deletions

View File

@ -32,12 +32,12 @@ import java.io.File;
/** /**
* Generates a <code>HelpMojo</code> class. * Generates a <code>HelpMojo</code> class.
* *
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a> * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
* @version $Id$ * @version $Id$
* @since 2.4 * @since 2.4
*/ */
@Mojo( name = "helpmojo", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true ) @Mojo( name = "helpmojo", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true /*, requiresDependencyResolution = ResolutionScope.COMPILE */ )
public class HelpGeneratorMojo public class HelpGeneratorMojo
extends AbstractGeneratorMojo extends AbstractGeneratorMojo
{ {
@ -50,7 +50,7 @@ public class HelpGeneratorMojo
/** /**
* The name of the package for the generated <code>HelpMojo</code>. By default, the package will be calculated based * The name of the package for the generated <code>HelpMojo</code>. By default, the package will be calculated based
* on the packages of the other plugin goals. * on the packages of the other plugin goals.
* *
* @since 2.6 * @since 2.6
*/ */
@Parameter @Parameter
@ -75,7 +75,7 @@ public class HelpGeneratorMojo
*/ */
protected Generator createGenerator() protected Generator createGenerator()
{ {
return new PluginHelpGenerator().setHelpPackageName( helpPackageName ).setVelocityComponent( this.velocity ); return new PluginHelpGenerator().setHelpPackageName( helpPackageName ).setUseAnnotations( project.getArtifactMap().containsKey( "org.apache.maven.plugin-tools:maven-plugin-annotations" ) ).setVelocityComponent( this.velocity );
} }
/** /**

View File

@ -88,6 +88,8 @@ public class PluginHelpGenerator
private String helpPackageName; private String helpPackageName;
private boolean useAnnotations;
private VelocityComponent velocityComponent; private VelocityComponent velocityComponent;
/** /**
@ -157,6 +159,12 @@ public class PluginHelpGenerator
this.helpPackageName = helpPackageName; this.helpPackageName = helpPackageName;
return this; return this;
} }
public PluginHelpGenerator setUseAnnotations( boolean useAnnotations )
{
this.useAnnotations = useAnnotations;
return this;
}
public VelocityComponent getVelocityComponent() public VelocityComponent getVelocityComponent()
{ {
@ -188,6 +196,7 @@ public class PluginHelpGenerator
properties.put( "pluginHelpPath", pluginHelpPath ); properties.put( "pluginHelpPath", pluginHelpPath );
properties.put( "artifactId", pluginDescriptor.getArtifactId() ); properties.put( "artifactId", pluginDescriptor.getArtifactId() );
properties.put( "goalPrefix", pluginDescriptor.getGoalPrefix() ); properties.put( "goalPrefix", pluginDescriptor.getGoalPrefix() );
properties.put( "useAnnotations", useAnnotations );
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();

View File

@ -34,33 +34,49 @@ public class HelpMojo
/** /**
* If <code>true</code>, display all settable properties for each goal. * If <code>true</code>, display all settable properties for each goal.
* *
#if ( !$useAnnotations )
* @parameter property="detail" default-value="false" * @parameter property="detail" default-value="false"
#end
*/ */
//@Parameter( property = "detail", defaultValue = "false" ) #if ( $useAnnotations )
@Parameter( property = "detail", defaultValue = "false" )
#end
private boolean detail; private boolean detail;
/** /**
* The name of the goal for which to show help. If unspecified, all goals will be displayed. * The name of the goal for which to show help. If unspecified, all goals will be displayed.
* *
#if ( !$useAnnotations )
* @parameter property="goal" * @parameter property="goal"
#end
*/ */
//@Parameter( property = "goal" ) #if ( $useAnnotations )
@Parameter( property = "goal" )
#end
private java.lang.String goal; private java.lang.String goal;
/** /**
* The maximum length of a display line, should be positive. * The maximum length of a display line, should be positive.
* *
#if ( !$useAnnotations )
* @parameter property="lineLength" default-value="80" * @parameter property="lineLength" default-value="80"
#end
*/ */
//@Parameter( property = "lineLength", defaultValue = "80" ) #if ( $useAnnotations )
@Parameter( property = "lineLength", defaultValue = "80" )
#end
private int lineLength; private int lineLength;
/** /**
* The number of spaces per indentation level, should be positive. * The number of spaces per indentation level, should be positive.
* *
#if ( !$useAnnotations )
* @parameter property="indentSize" default-value="2" * @parameter property="indentSize" default-value="2"
#end
*/ */
//@Parameter( property = "indentSize", defaultValue = "2" ) #if ( $useAnnotations )
@Parameter( property = "indentSize", defaultValue = "2" )
#end
private int indentSize; private int indentSize;
// groupId/artifactId/plugin-help.xml // groupId/artifactId/plugin-help.xml