[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

@ -37,7 +37,7 @@ import java.io.File;
* @version $Id$
* @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
extends AbstractGeneratorMojo
{
@ -75,7 +75,7 @@ public class HelpGeneratorMojo
*/
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 boolean useAnnotations;
private VelocityComponent velocityComponent;
/**
@ -158,6 +160,12 @@ public class PluginHelpGenerator
return this;
}
public PluginHelpGenerator setUseAnnotations( boolean useAnnotations )
{
this.useAnnotations = useAnnotations;
return this;
}
public VelocityComponent getVelocityComponent()
{
return velocityComponent;
@ -188,6 +196,7 @@ public class PluginHelpGenerator
properties.put( "pluginHelpPath", pluginHelpPath );
properties.put( "artifactId", pluginDescriptor.getArtifactId() );
properties.put( "goalPrefix", pluginDescriptor.getGoalPrefix() );
properties.put( "useAnnotations", useAnnotations );
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 ( !$useAnnotations )
* @parameter property="detail" default-value="false"
#end
*/
//@Parameter( property = "detail", defaultValue = "false" )
#if ( $useAnnotations )
@Parameter( property = "detail", defaultValue = "false" )
#end
private boolean detail;
/**
* The name of the goal for which to show help. If unspecified, all goals will be displayed.
*
#if ( !$useAnnotations )
* @parameter property="goal"
#end
*/
//@Parameter( property = "goal" )
#if ( $useAnnotations )
@Parameter( property = "goal" )
#end
private java.lang.String goal;
/**
* The maximum length of a display line, should be positive.
*
#if ( !$useAnnotations )
* @parameter property="lineLength" default-value="80"
#end
*/
//@Parameter( property = "lineLength", defaultValue = "80" )
#if ( $useAnnotations )
@Parameter( property = "lineLength", defaultValue = "80" )
#end
private int lineLength;
/**
* The number of spaces per indentation level, should be positive.
*
#if ( !$useAnnotations )
* @parameter property="indentSize" default-value="2"
#end
*/
//@Parameter( property = "indentSize", defaultValue = "2" )
#if ( $useAnnotations )
@Parameter( property = "indentSize", defaultValue = "2" )
#end
private int indentSize;
// groupId/artifactId/plugin-help.xml