HelpMojo class.
*
* @author Vincent Siveton
* @version $Id$
- * @since 2.4
* @goal helpmojo
* @phase generate-sources
+ * @since 2.4
*/
public class HelpGeneratorMojo
extends AbstractGeneratorMojo
@@ -47,7 +48,7 @@ public class HelpGeneratorMojo
/**
* The name of the package for the generated HelpMojo. By default, the package will be calculated based
* on the packages of the other plugin goals.
- *
+ *
* @parameter
* @since 2.6
*/
@@ -61,19 +62,35 @@ public class HelpGeneratorMojo
*/
private boolean useJava5;
- /** {@inheritDoc} */
+ /**
+ * Velocity component.
+ *
+ * @component
+ * @readonly
+ * @required
+ */
+ private VelocityComponent velocity;
+
+ /**
+ * {@inheritDoc}
+ */
protected File getOutputDirectory()
{
return outputDirectory;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
protected Generator createGenerator()
{
- return new PluginHelpGenerator().setHelpPackageName( helpPackageName ).setUseJava5( useJava5 );
+ return new PluginHelpGenerator().setHelpPackageName( helpPackageName ).setUseJava5(
+ useJava5 ).setVelocityComponent( this.velocity );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void execute()
throws MojoExecutionException
{
@@ -83,5 +100,7 @@ public class HelpGeneratorMojo
{
project.addCompileSourceRoot( outputDirectory.getAbsolutePath() );
}
+
}
+
}
diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
index b2ee032..ec0bbf1 100644
--- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
+++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
@@ -19,15 +19,6 @@ package org.apache.maven.plugin.plugin;
* under the License.
*/
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.ResourceBundle;
-
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.siterenderer.Renderer;
import org.apache.maven.model.Plugin;
@@ -42,21 +33,30 @@ import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.extractor.ExtractionException;
+import org.apache.maven.tools.plugin.generator.GeneratorException;
import org.apache.maven.tools.plugin.generator.PluginXdocGenerator;
import org.apache.maven.tools.plugin.scanner.MojoScanner;
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+
/**
* Generates the Plugin's documentation report.
*
* @author Stephane Nicoll
* @author Vincent Siveton
* @version $Id$
- * @since 2.0
* @goal report
* @execute phase="compile"
+ * @since 2.0
*/
public class PluginReport
extends AbstractMavenReport
@@ -91,13 +91,12 @@ public class PluginReport
*/
protected MojoScanner mojoScanner;
- /**
- * The file encoding of the source files.
- *
- * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
- *
- * @since 2.7
- */
+ /**
+ * The file encoding of the source files.
+ *
+ * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
+ * @since 2.7
+ */
private String encoding;
@@ -124,10 +123,10 @@ public class PluginReport
private Requirements requirements;
/**
- * The goal prefix that will appear before the ":".
- * By default, this plugin applies a heuristic to derive a heuristic from
- * the plugin's artifactId.
- *
+ * The goal prefix that will appear before the ":".
+ * By default, this plugin applies a heuristic to derive a heuristic from
+ * the plugin's artifactId.
+ *
* It removes any occurrences of the regular expression -?maven-?,
* and then removes any occurrences of -?plugin-?.
*
@@ -158,31 +157,41 @@ public class PluginReport
*/
private boolean skipReport;
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
protected Renderer getSiteRenderer()
{
return siteRenderer;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
protected String getOutputDirectory()
{
return outputDirectory.getPath();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
protected MavenProject getProject()
{
return project;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public boolean canGenerateReport()
{
return "maven-plugin".equals( project.getPackaging() );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@SuppressWarnings( "unchecked" )
protected void executeReport( Locale locale )
throws MavenReportException
@@ -205,8 +214,7 @@ public class PluginReport
}
else
{
- getLog().warn(
- "\n\nGoal prefix is specified as: '" + goalPrefix + "'. Maven currently expects it to be '"
+ getLog().warn( "\n\nGoal prefix is specified as: '" + goalPrefix + "'. Maven currently expects it to be '"
+ defaultGoalPrefix + "'.\n" );
}
@@ -224,11 +232,11 @@ public class PluginReport
try
{
pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) );
-
+
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
request.setEncoding( encoding );
- try
+ try
{
mojoScanner.populatePluginDescriptor( request );
}
@@ -243,11 +251,11 @@ public class PluginReport
generatePluginDocumentation( pluginDescriptor, locale );
// Write the overview
- PluginOverviewRenderer r = new PluginOverviewRenderer( project, requirements, getSink(), pluginDescriptor,
- locale );
+ PluginOverviewRenderer r =
+ new PluginOverviewRenderer( project, requirements, getSink(), pluginDescriptor, locale );
r.render();
}
-
+
catch ( ExtractionException e )
{
throw new MavenReportException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'",
@@ -255,19 +263,25 @@ public class PluginReport
}
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getDescription( Locale locale )
{
return getBundle( locale ).getString( "report.plugin.description" );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getName( Locale locale )
{
return getBundle( locale ).getString( "report.plugin.name" );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getOutputName()
{
return "plugin-info";
@@ -275,7 +289,7 @@ public class PluginReport
/**
* @param pluginDescriptor not null
- * @param locale not null
+ * @param locale not null
* @throws MavenReportException if any
*/
private void generatePluginDocumentation( PluginDescriptor pluginDescriptor, Locale locale )
@@ -287,9 +301,10 @@ public class PluginReport
outputDir.mkdirs();
PluginXdocGenerator generator = new PluginXdocGenerator( project, locale );
- generator.execute( outputDir, pluginDescriptor );
+ PluginToolsRequest pluginToolsRequest = new DefaultPluginToolsRequest( project, pluginDescriptor );
+ generator.execute( outputDir, pluginToolsRequest );
}
- catch ( IOException e )
+ catch ( GeneratorException e )
{
throw new MavenReportException( "Error writing plugin documentation", e );
}
@@ -321,11 +336,11 @@ public class PluginReport
private final Locale locale;
/**
- * @param project not null
- * @param requirements not null
- * @param sink not null
+ * @param project not null
+ * @param requirements not null
+ * @param sink not null
* @param pluginDescriptor not null
- * @param locale not null
+ * @param locale not null
*/
public PluginOverviewRenderer( MavenProject project, Requirements requirements, Sink sink,
PluginDescriptor pluginDescriptor, Locale locale )
@@ -341,13 +356,17 @@ public class PluginReport
this.locale = locale;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public String getTitle()
{
return getBundle( locale ).getString( "report.plugin.title" );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@SuppressWarnings( { "unchecked", "rawtypes" } )
public void renderBody()
{
@@ -362,7 +381,6 @@ public class PluginReport
paragraph( getBundle( locale ).getString( "report.plugin.goals.intro" ) );
-
boolean hasMavenReport = false;
for ( Iterator Repeat a String java.specification.version.
*
- * @param project not null
+ * @param project not null
* @param requirements not null
* @return the JDK version
*/
@@ -686,11 +707,11 @@ public class PluginReport
jdk = pluginConf.getChild( "target" ).getValue();
}
- if ( jdk == null )
+ if ( jdk == null )
{
return backupJdk;
}
- else
+ else
{
return jdk;
}
diff --git a/maven-plugin-tools-api/pom.xml b/maven-plugin-tools-api/pom.xml
index bf66edb..28803f5 100644
--- a/maven-plugin-tools-api/pom.xml
+++ b/maven-plugin-tools-api/pom.xml
@@ -71,6 +71,22 @@
null.
+ * @return The mojo descriptor for the generated help goal, never null.
*/
+ private MojoDescriptor makeHelpDescriptor( PluginDescriptor pluginDescriptor, String packageName )
+ {
+ MojoDescriptor descriptor = new MojoDescriptor();
+
+ descriptor.setPluginDescriptor( pluginDescriptor );
+
+ descriptor.setLanguage( "java" );
+
+ descriptor.setGoal( "help" );
+
+ if ( StringUtils.isEmpty( packageName ) )
+ {
+ packageName = discoverPackageName( pluginDescriptor );
+ }
+ if ( StringUtils.isNotEmpty( packageName ) )
+ {
+ descriptor.setImplementation( packageName + '.' + "HelpMojo" );
+ }
+ else
+ {
+ descriptor.setImplementation( "HelpMojo" );
+ }
+
+ descriptor.setDescription(
+ "Display help information on " + pluginDescriptor.getArtifactId() + ".
Call mvn "
+ + descriptor.getFullGoalName()
+ + " -Ddetail=true -Dgoal=<goal-name>
to display parameter details." );
+
+ try
+ {
+ Parameter param = new Parameter();
+ param.setName( "detail" );
+ param.setType( "boolean" );
+ param.setDescription( "If true, display all settable properties for each goal." );
+ param.setDefaultValue( "false" );
+ param.setExpression( "${detail}" );
+ descriptor.addParameter( param );
+
+ param = new Parameter();
+ param.setName( "goal" );
+ param.setType( "java.lang.String" );
+ param.setDescription(
+ "The name of the goal for which to show help." + " If unspecified, all goals will be displayed." );
+ param.setExpression( "${goal}" );
+ descriptor.addParameter( param );
+
+ param = new Parameter();
+ param.setName( "lineLength" );
+ param.setType( "int" );
+ param.setDescription( "The maximum length of a display line, should be positive." );
+ param.setDefaultValue( "80" );
+ param.setExpression( "${lineLength}" );
+ descriptor.addParameter( param );
+
+ param = new Parameter();
+ param.setName( "indentSize" );
+ param.setType( "int" );
+ param.setDescription( "The number of spaces per indentation level, should be positive." );
+ param.setDefaultValue( "2" );
+ param.setExpression( "${indentSize}" );
+ descriptor.addParameter( param );
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "Failed to setup parameters for help goal", e );
+ }
+
+ return descriptor;
+ }
+
+ /**
+ * Find the best package name, based on the number of hits of actual Mojo classes.
+ *
+ * @param pluginDescriptor not null
+ * @return the best name of the package for the generated mojo
+ */
+ private static String discoverPackageName( PluginDescriptor pluginDescriptor )
+ {
+ Map packageNames = new HashMap();
+ for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
+ {
+ MojoDescriptor descriptor = (MojoDescriptor) it.next();
+
+ String impl = descriptor.getImplementation();
+ if ( impl.lastIndexOf( '.' ) != -1 )
+ {
+ String name = impl.substring( 0, impl.lastIndexOf( '.' ) );
+ if ( packageNames.get( name ) != null )
+ {
+ int next = ( (Integer) packageNames.get( name ) ).intValue() + 1;
+ packageNames.put( name, new Integer( next ) );
+ }
+ else
+ {
+ packageNames.put( name, new Integer( 1 ) );
+ }
+ }
+ else
+ {
+ packageNames.put( "", new Integer( 1 ) );
+ }
+ }
+
+ String packageName = "";
+ int max = 0;
+ for ( Iterator it = packageNames.keySet().iterator(); it.hasNext(); )
+ {
+ String key = it.next().toString();
+ int value = ( (Integer) packageNames.get( key ) ).intValue();
+ if ( value > max )
+ {
+ max = value;
+ packageName = key;
+ }
+ }
+
+ return packageName;
+ }
+
protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w )
+ {
+ processMojoDescriptor( mojoDescriptor, w, false );
+ }
+
+ /**
+ * @param mojoDescriptor not null
+ * @param w not null
+ * @param cleanDescription will clean html content from description fields
+ */
+ protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, boolean cleanDescription )
{
w.startElement( "mojo" );
@@ -152,7 +324,14 @@ public class PluginDescriptorGenerator
if ( description != null )
{
w.startElement( "description" );
- w.writeText( mojoDescriptor.getDescription() );
+ if ( cleanDescription )
+ {
+ w.writeText( PluginUtils.toText( mojoDescriptor.getDescription() ) );
+ }
+ else
+ {
+ w.writeText( mojoDescriptor.getDescription() );
+ }
w.endElement();
}
@@ -323,8 +502,7 @@ public class PluginDescriptorGenerator
// Parameters
// ----------------------------------------------------------------------
- @SuppressWarnings( "unchecked" )
- ListHelpMojo class.
@@ -56,20 +56,30 @@ public class PluginHelpGenerator
extends AbstractLogEnabled
implements Generator
{
- /** Line separator */
+ /**
+ * Line separator
+ */
private static final String LS = System.getProperty( "line.separator" );
- /** Default generated class name */
+ /**
+ * Default generated class name
+ */
private static final String HELP_MOJO_CLASS_NAME = "HelpMojo";
- /** Default goal */
+ /**
+ * Default goal
+ */
private static final String HELP_GOAL = "help";
private String helpPackageName;
-
- /** Flag to indicate if the generated help mojo should use Java 5 features */
+
+ /**
+ * Flag to indicate if the generated help mojo should use Java 5 features
+ */
private boolean useJava5;
+ private VelocityComponent velocityComponent;
+
/**
* Default constructor
*/
@@ -82,39 +92,29 @@ public class PluginHelpGenerator
// Public methods
// ----------------------------------------------------------------------
- /** {@inheritDoc} */
- public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor )
- throws IOException
- {
- execute( destinationDirectory, new DefaultPluginToolsRequest( null, pluginDescriptor ) );
- }
-
- /** {@inheritDoc} */
+
+ /**
+ * {@inheritDoc}
+ */
public void execute( File destinationDirectory, PluginToolsRequest request )
- throws IOException
+ throws GeneratorException
{
PluginDescriptor pluginDescriptor = request.getPluginDescriptor();
-
- if ( pluginDescriptor.getMojos() == null || pluginDescriptor.getMojos().size() < 1 )
- {
- return;
- }
MojoDescriptor helpDescriptor = makeHelpDescriptor( pluginDescriptor );
// Verify that no help goal already exists
- for ( @SuppressWarnings( "unchecked" )
- Iteratornull.
+ * null.
* @return The mojo descriptor for the generated help goal, never null.
*/
private MojoDescriptor makeHelpDescriptor( PluginDescriptor pluginDescriptor )
@@ -187,9 +260,10 @@ public class PluginHelpGenerator
descriptor.setImplementation( HELP_MOJO_CLASS_NAME );
}
- descriptor.setDescription( "Display help information on " + pluginDescriptor.getArtifactId()
- + ".
Call mvn " + descriptor.getFullGoalName()
- + " -Ddetail=true -Dgoal=<goal-name>
to display parameter details." );
+ descriptor.setDescription(
+ "Display help information on " + pluginDescriptor.getArtifactId() + ".
Call mvn "
+ + descriptor.getFullGoalName()
+ + " -Ddetail=true -Dgoal=<goal-name>
to display parameter details." );
try
{
@@ -204,8 +278,8 @@ public class PluginHelpGenerator
param = new Parameter();
param.setName( "goal" );
param.setType( "java.lang.String" );
- param.setDescription( "The name of the goal for which to show help."
- + " If unspecified, all goals will be displayed." );
+ param.setDescription(
+ "The name of the goal for which to show help." + " If unspecified, all goals will be displayed." );
param.setExpression( "${goal}" );
descriptor.addParameter( param );
@@ -241,595 +315,45 @@ public class PluginHelpGenerator
*/
private static String discoverPackageName( PluginDescriptor pluginDescriptor )
{
- MapHelpMojo class.
- *
- * @param writer not null
- * @param pluginDescriptor not null
- * @param helpDescriptor not null
- * @param useJava5 If the generated code should use Java5 features
- * @throws IOException if any
- */
- private static void writeClass( Writer writer, PluginDescriptor pluginDescriptor, MojoDescriptor helpDescriptor,
- boolean useJava5 )
- throws IOException
- {
- String packageName = "";
- String simpleName = helpDescriptor.getImplementation();
- int dot = simpleName.lastIndexOf( '.' );
- if ( dot >= 0 )
- {
- packageName = simpleName.substring( 0, dot );
- simpleName = simpleName.substring( dot + 1 );
- }
-
- if ( packageName.length() > 0 )
- {
- writer.write( "package " + packageName + ";" + LS );
- writer.write( LS );
- }
-
- writeImports( writer );
- writer.write( LS );
-
- writeMojoJavadoc( writer, pluginDescriptor, helpDescriptor );
-
- if ( useJava5 )
- {
- writer.write( "@SuppressWarnings( \"all\" )" + LS );
- }
-
- writer.write( "public class " + simpleName + LS );
- writer.write( " extends AbstractMojo" + LS );
- writer.write( "{" + LS );
-
- writeVariables( writer, helpDescriptor );
-
- writer.write( LS );
-
- writeExecute( writer, pluginDescriptor, helpDescriptor );
-
- writer.write( LS );
- writeUtilities( writer, useJava5 );
- writer.write( "}" + LS );
- }
-
- /**
- * @param writer not null
- * @throws IOException if any
- */
- private static void writeImports( Writer writer )
- throws IOException
- {
- writer.write( "import java.util.ArrayList;" + LS );
- writer.write( "import java.util.Iterator;" + LS );
- writer.write( "import java.util.List;" + LS );
- writer.write( LS );
- writer.write( "import org.apache.maven.plugin.AbstractMojo;" + LS );
- writer.write( "import org.apache.maven.plugin.MojoExecutionException;" + LS );
- }
-
- /**
- * @param writer not null
- * @param pluginDescriptor not null
- * @param helpDescriptor not null
- * @throws IOException if any
- */
- private static void writeMojoJavadoc( Writer writer, PluginDescriptor pluginDescriptor,
- MojoDescriptor helpDescriptor )
- throws IOException
- {
- StringBuffer author = new StringBuffer();
- author.append( PluginHelpGenerator.class.getName() );
-
- String resource = "META-INF/maven/org.apache.maven.plugin-tools/maven-plugin-tools-api/pom.properties";
- InputStream resourceAsStream = PluginHelpGenerator.class.getClassLoader().getResourceAsStream( resource );
-
- if ( resourceAsStream != null )
- {
- try
- {
- Properties properties = new Properties();
- properties.load( resourceAsStream );
-
- author.append( " (version " ).append( properties.getProperty( "version", "unknown" ) ).append( ")" );
- }
- catch ( IOException e )
- {
- // nope
- }
- finally
- {
- IOUtil.close( resourceAsStream );
- }
- }
-
- writer.write( "/**" + LS );
- writer.write( " * " + helpDescriptor.getDescription() + LS );
- writer.write( " *" + LS );
- writer.write( " * @version generated on " + new Date() + LS );
- writer.write( " * @author " + author.toString() + LS );
- writer.write( " * @goal " + helpDescriptor.getGoal() + LS );
- writer.write( " * @requiresProject false" + LS );
- writer.write( " * @threadSafe" + LS );
- writer.write( " */" + LS );
- }
-
- /**
- * @param writer not null
- * @param helpDescriptor not null
- * @throws IOException if any
- */
- private static void writeVariables( Writer writer, MojoDescriptor helpDescriptor )
- throws IOException
- {
- for ( @SuppressWarnings( "unchecked" )
- Iteratorn times to form a new string.repeat < 0" + LS );
- writer.write( " * @throws NullPointerException if str is null" + LS );
- writer.write( " */" + LS );
- writer.write( " private static String repeat( String str, int repeat )" + LS );
- writer.write( " {" + LS );
- writer.write( " StringBuffer buffer = new StringBuffer( repeat * str.length() );" + LS );
- writer.write( LS );
- writer.write( " for ( int i = 0; i < repeat; i++ )" + LS );
- writer.write( " {" + LS );
- writer.write( " buffer.append( str );" + LS );
- writer.write( " }" + LS );
- writer.write( LS );
- writer.write( " return buffer.toString();" + LS );
- writer.write( " }" + LS );
-
- writer.write( LS );
- writer.write( " /** " + LS );
- writer.write( " * Append a description to the buffer by respecting the indentSize and lineLength "
- + "parameters." + LS );
- writer.write( " * Note: The last character is always a new line." + LS );
- writer.write( " * " + LS );
- writer.write( " * @param sb The buffer to append the description, not null." + LS );
- writer.write( " * @param description The description, not null." + LS );
- writer.write( " * @param indent The base indentation level of each line, must not be negative." + LS );
- writer.write( " */" + LS );
- writer.write( " private void append( StringBuffer sb, String description, int indent )" + LS );
- writer.write( " {" + LS );
- writer.write( " for ( Iterator it = toLines( description, indent, indentSize, lineLength )"
- + ".iterator(); it.hasNext(); )" + LS );
- writer.write( " {" + LS );
- writer.write( " sb.append( it.next().toString() ).append( '\\n' );" + LS );
- writer.write( " }" + LS );
- writer.write( " }" + LS );
-
- writer.write( LS );
- writer.write( " /** " + LS );
- writer.write( " * Splits the specified text into lines of convenient display length." + LS );
- writer.write( " * " + LS );
- writer.write( " * @param text The text to split into lines, must not be null." + LS );
- writer.write( " * @param indent The base indentation level of each line, must not be negative." + LS );
- writer.write( " * @param indentSize The size of each indentation, must not be negative." + LS );
- writer.write( " * @param lineLength The length of the line, must not be negative." + LS );
- writer.write( " * @return The sequence of display lines, never null." + LS );
- writer.write( " * @throws NegativeArraySizeException if indent < 0" + LS );
- writer.write( " */" + LS );
- writer.write( " private static List toLines( String text, int indent, int indentSize, int lineLength )"
- + LS );
- writer.write( " {" + LS );
- if ( useJava5 )
- {
- writer.write( " Listnull." + LS );
- writer.write( " * @param line The line to add, must not be null." + LS );
- writer.write( " * @param indentSize The size of each indentation, must not be negative." + LS );
- writer.write( " * @param lineLength The length of the line, must not be negative." + LS );
- writer.write( " */" + LS );
- if ( useJava5 )
- {
- writer.write( " private static void toLines( Listnull." + LS );
- writer.write( " * @return The indentation level of the line." + LS );
- writer.write( " */" + LS );
- writer.write( " private static int getIndentLevel( String line )" + LS );
- writer.write( " {" + LS );
- writer.write( " int level = 0;" + LS );
- writer.write( " for ( int i = 0; i < line.length() && line.charAt( i ) == '\\t'; i++ )" + LS );
- writer.write( " {" + LS );
- writer.write( " level++;" + LS );
- writer.write( " }" + LS );
- writer.write( " for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )" + LS );
- writer.write( " {" + LS );
- writer.write( " if ( line.charAt( i ) == '\\t' )" + LS );
- writer.write( " {" + LS );
- writer.write( " level++;" + LS );
- writer.write( " break;" + LS );
- writer.write( " }" + LS );
- writer.write( " }" + LS );
- writer.write( " return level;" + LS );
- writer.write( " }" + LS );
- }
-
- /**
- * Gets the effective string to use for the plugin/mojo/parameter description.
- *
- * @param description The description of the element, may be null.
- * @return The effective description string, never null.
- */
- private static String toDescription( String description )
- {
- if ( StringUtils.isNotEmpty( description ) )
- {
- return StringUtils.escape( PluginUtils.toText( description ) );
- }
-
- return "(no description available)";
- }
-
- /**
- * Converts a HTML fragment as extracted from a javadoc comment to a plain text string. This method tries to retain
- * as much of the text formatting as possible by means of the following transformations:
- *
- *
- *
- * @param html The HTML fragment to convert to plain text, may be null.
- * @return A string with HTML tags converted into pure text, never null.
- * @deprecated since 2.4.3, using {@link PluginUtils#toText(String)} instead of.
- */
- protected static String toText( String html )
- {
- return PluginUtils.toText( html );
- }
}
diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
index 899d70e..fbd3a1c 100644
--- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
+++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
@@ -19,6 +19,17 @@ package org.apache.maven.tools.plugin.generator;
* under the License.
*/
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
+import org.apache.maven.tools.plugin.PluginToolsRequest;
+import org.apache.maven.tools.plugin.util.PluginUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -32,30 +43,21 @@ import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
-import org.apache.maven.plugin.descriptor.MojoDescriptor;
-import org.apache.maven.plugin.descriptor.Parameter;
-import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
-import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
-import org.apache.maven.tools.plugin.PluginToolsRequest;
-import org.apache.maven.tools.plugin.util.PluginUtils;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
/**
- * @todo add example usage tag that can be shown in the doco
* @version $Id$
+ * @todo add example usage tag that can be shown in the doco
*/
public class PluginXdocGenerator
implements Generator
{
- /** locale */
+ /**
+ * locale
+ */
private final Locale locale;
- /** project */
+ /**
+ * project
+ */
private final MavenProject project;
/**
@@ -81,7 +83,7 @@ public class PluginXdocGenerator
/**
* @param project not null.
- * @param locale not null wanted locale.
+ * @param locale not null wanted locale.
*/
public PluginXdocGenerator( MavenProject project, Locale locale )
{
@@ -96,31 +98,35 @@ public class PluginXdocGenerator
}
}
- /** {@inheritDoc} */
- public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor )
- throws IOException
- {
- execute( destinationDirectory, new DefaultPluginToolsRequest( project, pluginDescriptor ) );
- }
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void execute( File destinationDirectory, PluginToolsRequest request )
- throws IOException
+ throws GeneratorException
{
- if ( request.getPluginDescriptor().getMojos() != null )
+ try
{
- for ( @SuppressWarnings( "unchecked" )
- Iteratortrue for required parameters, false otherwise.
+ * @param required true for required parameters, false otherwise.
* @param parameterList not null
* @return list of parameters depending the value of required
*/
@@ -792,21 +797,21 @@ public class PluginXdocGenerator
/**
* Convenience method.
*
- * @param key not null
+ * @param key not null
* @param arg1 not null
* @return Localized, formatted text identified by key.
* @see #format(String, Object[])
*/
private String format( String key, Object arg1 )
{
- return format( key, new Object[] { arg1 } );
+ return format( key, new Object[]{ arg1 } );
}
/**
* Looks up the value for key in the ResourceBundle,
* then formats that value for the specified Locale using args.
*
- * @param key not null
+ * @param key not null
* @param args not null
* @return Localized, formatted text identified by key.
*/
diff --git a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
index e987068..0087e1c 100644
--- a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
+++ b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
@@ -19,11 +19,13 @@ package org.apache.maven.tools.plugin.generator;
* under the License.
*/
-import junit.framework.TestCase;
+import org.apache.maven.model.Build;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
+import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.component.repository.ComponentDependency;
import org.codehaus.plexus.util.FileUtils;
@@ -38,7 +40,7 @@ import java.util.List;
* jdcasey Exp $
*/
public abstract class AbstractGeneratorTestCase
- extends TestCase
+ extends PlexusTestCase
{
protected Generator generator;
@@ -47,6 +49,7 @@ public abstract class AbstractGeneratorTestCase
protected void setUp()
throws Exception
{
+ super.setUp();
basedir = System.getProperty( "basedir" );
}
@@ -93,7 +96,25 @@ public abstract class AbstractGeneratorTestCase
FileUtils.deleteDirectory( destinationDirectory );
destinationDirectory.mkdir();
- generator.execute( destinationDirectory, new DefaultPluginToolsRequest( null, pluginDescriptor ) );
+ MavenProject mavenProject = new MavenProject();
+ mavenProject.setGroupId( "foo" );
+ mavenProject.setArtifactId( "bar" );
+ mavenProject.setBuild( new Build()
+ {
+ @Override
+ public String getDirectory()
+ {
+ return basedir + "/target";
+ }
+
+ @Override
+ public String getOutputDirectory()
+ {
+ return basedir + "/target";
+ }
+ } );
+
+ generator.execute( destinationDirectory, new DefaultPluginToolsRequest( mavenProject, pluginDescriptor ) );
validate( destinationDirectory );
@@ -120,8 +141,8 @@ public abstract class AbstractGeneratorTestCase
catch ( Exception e )
{
throw new Exception( "Cannot find " + generatorClassName +
- "! Make sure your test case is named in the form ${generatorClassName}Test " +
- "or override the setupPlugin() method to instantiate the mojo yourself." );
+ "! Make sure your test case is named in the form ${generatorClassName}Test " +
+ "or override the setupPlugin() method to instantiate the mojo yourself." );
}
}
diff --git a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginHelpGeneratorTest.java b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginHelpGeneratorTest.java
index 78565f2..725967b 100644
--- a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginHelpGeneratorTest.java
+++ b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginHelpGeneratorTest.java
@@ -19,6 +19,8 @@ package org.apache.maven.tools.plugin.generator;
* under the License.
*/
+import org.codehaus.plexus.velocity.VelocityComponent;
+
/**
* @author Vincent Siveton
* @version $Id$
@@ -27,4 +29,12 @@ public class PluginHelpGeneratorTest
extends AbstractGeneratorTestCase
{
// inherits tests from base class
+ protected void setupGenerator()
+ throws Exception
+ {
+
+ generator =
+ new PluginHelpGenerator().setVelocityComponent( (VelocityComponent) lookup( VelocityComponent.ROLE ) );
+
+ }
}
diff --git a/pom.xml b/pom.xml
index d603983..1feec30 100644
--- a/pom.xml
+++ b/pom.xml
@@ -233,6 +233,24 @@