[MPLUGIN-189] push some stuff on help for annotations

the goal is to have a generic class which will read the descriptor.
Copy of the descriptor with cleaning html for description fields (copy in a path META-INF/maven/${groupId}/${artifactId}/plugin-description.xml

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1337273 13f79535-47bb-0310-9956-ffa450edef68
master
Olivier Lamy 2012-05-11 16:44:59 +00:00
parent ba66d8def7
commit 4ec2eaf3a5
28 changed files with 716 additions and 839 deletions

View File

@ -111,6 +111,24 @@
<artifactId>plexus-archiver</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-velocity</artifactId>
<version>1.1.8</version>
<exclusions>
<exclusion>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- other -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
</dependencyManagement>
@ -218,6 +236,23 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-velocity</artifactId>
<exclusions>
<exclusion>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- other -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -54,6 +54,7 @@ under the License.
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>@project.version@</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>

View File

@ -59,6 +59,7 @@ under the License.
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>@project.version@</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>

View File

@ -1,6 +1,4 @@
invoker.goals.1 = install
invoker.goals.2 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0:it0014
invoker.goals.3 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0:first
#FIXME disabled need to find a solution for the chicken and eggs issue.
#help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning
#invoker.goals.3 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0::help
invoker.goals.1 = clean install -DskipTests
invoker.goals.2 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0-SNAPSHOT:it0014
invoker.goals.3 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0-SNAPSHOT:first
invoker.goals.4 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0-SNAPSHOT:help

View File

@ -24,7 +24,7 @@ under the License.
<groupId>org.apache.maven.its.annotation-with-inheritance</groupId>
<artifactId>annotation-with-inheritance</artifactId>
<version>1.0</version>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>Maven Integration Test :: annotation-with-inheritance</name>
@ -54,6 +54,7 @@ under the License.
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>@project.version@</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
@ -96,6 +97,12 @@ under the License.
<goal>descriptor</goal>
</goals>
</execution>
<execution>
<id>help-goal</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

View File

@ -32,7 +32,7 @@ import org.apache.maven.plugins.annotations.Parameter;
* @since 1.2
* @deprecated Don't use!
*/
@Mojo( name = "first", requiresDependencyResolution = "test", defaultPhase = LifecyclePhase.INTEGRATION_TEST )
@Mojo( name = "first", requiresDependencyResolution = "test", defaultPhase = LifecyclePhase.INTEGRATION_TEST)
@Execute( phase = LifecyclePhase.GENERATE_SOURCES, lifecycle = "cobertura" )
public class FirstMojo
extends AbstractFirstMojo

View File

@ -1,2 +1,2 @@
invoker.goals.1 = install -DskipTests
invoker.goals.1 = clean install -DskipTests
invoker.goals.2 = org.apache.maven.its.plugin:help:1.0:help

View File

@ -41,6 +41,12 @@ under the License.
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@ -1 +1 @@
invoker.goals = compile
invoker.goals = clean compile

View File

@ -41,6 +41,12 @@ under the License.
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@ -1,4 +1,4 @@
invoker.goals.1 = clean install
invoker.goals.1 = clean install -DskipTests
invoker.profiles.1 = setup
invoker.goals.2 = clean process-classes

View File

@ -1,4 +1,4 @@
invoker.goals.1 = install
invoker.goals.1 = clean install -DskipTests
invoker.goals.2 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0:it0014
#FIXME disabled need to find a solution for the chicken and eggs issue.
#help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning

View File

@ -1,3 +1,3 @@
invoker.goals.1 = install
invoker.goals.1 = install -DskipTests
invoker.goals.2 = org.apache.maven.its.it0013:maven-it-it0013:1.0:it0013

View File

@ -1 +1 @@
invoker.goals = clean plugin:report
invoker.goals = clean plugin:report -DskipTests

View File

@ -1 +1 @@
invoker.goals = clean site
invoker.goals = clean site -DskipTests

View File

@ -1 +1 @@
invoker.goals = clean site
invoker.goals = clean site -DskipTests

View File

@ -1,2 +1,2 @@
invoker.goals = install
invoker.goals = install -DskipTests
invoker.mavenOpts = -Dmaven.plugin.skip=true

View File

@ -30,12 +30,14 @@ 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.Generator;
import org.apache.maven.tools.plugin.generator.GeneratorException;
import org.apache.maven.tools.plugin.scanner.MojoScanner;
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.util.ReaderFactory;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Documented;
import java.util.List;
import java.util.Set;
@ -248,7 +250,7 @@ public abstract class AbstractGeneratorMojo
createGenerator().execute( getOutputDirectory(), request );
}
catch ( IOException e )
catch ( GeneratorException e )
{
throw new MojoExecutionException( "Error writing plugin descriptor", e );
}

View File

@ -19,20 +19,21 @@ package org.apache.maven.plugin.plugin;
* under the License.
*/
import java.io.File;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.tools.plugin.generator.Generator;
import org.apache.maven.tools.plugin.generator.PluginHelpGenerator;
import org.codehaus.plexus.velocity.VelocityComponent;
import java.io.File;
/**
* Generates a <code>HelpMojo</code> class.
*
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
* @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 <code>HelpMojo</code>. 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() );
}
}
}

View File

@ -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 <a href="snicoll@apache.org">Stephane Nicoll</a>
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
* @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.
* <p/>
* It removes any occurrences of the regular expression <strong>-?maven-?</strong>,
* and then removes any occurrences of <strong>-?plugin-?</strong>.
* <p>
@ -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<MojoDescriptor> i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
{
@ -381,11 +399,11 @@ public class PluginReport
String descriptionColumnName = getBundle( locale ).getString( "report.plugin.goals.column.description" );
if ( hasMavenReport )
{
tableHeader( new String[] { goalColumnName, isMavenReport, descriptionColumnName } );
tableHeader( new String[]{ goalColumnName, isMavenReport, descriptionColumnName } );
}
else
{
tableHeader( new String[] { goalColumnName, descriptionColumnName } );
tableHeader( new String[]{ goalColumnName, descriptionColumnName } );
}
List<MojoDescriptor> mojos = new ArrayList<MojoDescriptor>();
@ -449,15 +467,16 @@ public class PluginReport
String maven = discoverMavenRequirement( project, requirements );
sink.tableRow();
tableCell( getBundle( locale ).getString( "report.plugin.systemrequirements.maven" ) );
tableCell( ( maven != null ? maven : getBundle( locale )
.getString( "report.plugin.systemrequirements.nominimum" ) ) );
tableCell( ( maven != null
? maven
: getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) );
sink.tableRow_();
String jdk = discoverJdkRequirement( project, requirements );
sink.tableRow();
tableCell( getBundle( locale ).getString( "report.plugin.systemrequirements.jdk" ) );
tableCell( ( jdk != null ? jdk : getBundle( locale )
.getString( "report.plugin.systemrequirements.nominimum" ) ) );
tableCell(
( jdk != null ? jdk : getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) );
sink.tableRow_();
sink.tableRow();
@ -482,9 +501,9 @@ public class PluginReport
sink.tableRow();
tableCell( key );
tableCell( ( StringUtils.isNotEmpty( requirements.getOthers().getProperty( key ) ) ? requirements
.getOthers().getProperty( key ) : getBundle( locale )
.getString( "report.plugin.systemrequirements.nominimum" ) ) );
tableCell( ( StringUtils.isNotEmpty( requirements.getOthers().getProperty( key ) )
? requirements.getOthers().getProperty( key )
: getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) );
sink.tableRow_();
}
}
@ -515,31 +534,32 @@ public class PluginReport
sb.append( "<project>" ).append( '\n' );
sb.append( " ..." ).append( '\n' );
sb.append( " <build>" ).append( '\n' );
sb.append( " <!-- " + getBundle( locale ).getString( "report.plugin.usage.pluginManagement" ) + " -->" )
.append( '\n' );
sb.append(
" <!-- " + getBundle( locale ).getString( "report.plugin.usage.pluginManagement" ) + " -->" ).append(
'\n' );
sb.append( " <pluginManagement>" ).append( '\n' );
sb.append( " <plugins>" ).append( '\n' );
sb.append( " <plugin>" ).append( '\n' );
sb.append( " <groupId>" ).append( pluginDescriptor.getGroupId() ).append( "</groupId>" )
.append( '\n' );
sb.append( " <artifactId>" ).append( pluginDescriptor.getArtifactId() ).append( "</artifactId>" )
.append( '\n' );
sb.append( " <version>" ).append( pluginDescriptor.getVersion() ).append( "</version>" )
.append( '\n' );
sb.append( " <groupId>" ).append( pluginDescriptor.getGroupId() ).append( "</groupId>" ).append(
'\n' );
sb.append( " <artifactId>" ).append( pluginDescriptor.getArtifactId() ).append(
"</artifactId>" ).append( '\n' );
sb.append( " <version>" ).append( pluginDescriptor.getVersion() ).append( "</version>" ).append(
'\n' );
sb.append( " </plugin>" ).append( '\n' );
sb.append( " ..." ).append( '\n' );
sb.append( " </plugins>" ).append( '\n' );
sb.append( " </pluginManagement>" ).append( '\n' );
sb.append( " <!-- " + getBundle( locale ).getString( "report.plugin.usage.plugins" ) + " -->" )
.append( '\n' );
sb.append( " <!-- " + getBundle( locale ).getString( "report.plugin.usage.plugins" ) + " -->" ).append(
'\n' );
sb.append( " <plugins>" ).append( '\n' );
sb.append( " <plugin>" ).append( '\n' );
sb.append( " <groupId>" ).append( pluginDescriptor.getGroupId() ).append( "</groupId>" )
.append( '\n' );
sb.append( " <artifactId>" ).append( pluginDescriptor.getArtifactId() ).append( "</artifactId>" )
.append( '\n' );
sb.append( " <version>" ).append( pluginDescriptor.getVersion() ).append( "</version>" )
.append( '\n' );
sb.append( " <groupId>" ).append( pluginDescriptor.getGroupId() ).append( "</groupId>" ).append(
'\n' );
sb.append( " <artifactId>" ).append( pluginDescriptor.getArtifactId() ).append(
"</artifactId>" ).append( '\n' );
sb.append( " <version>" ).append( pluginDescriptor.getVersion() ).append( "</version>" ).append(
'\n' );
sb.append( " </plugin>" ).append( '\n' );
sb.append( " ..." ).append( '\n' );
sb.append( " </plugins>" ).append( '\n' );
@ -548,17 +568,18 @@ public class PluginReport
if ( hasMavenReport )
{
sb.append( " ..." ).append( '\n' );
sb.append( " <!-- " + getBundle( locale ).getString( "report.plugin.usage.reporting" ) + " -->" )
.append( '\n' );
sb.append(
" <!-- " + getBundle( locale ).getString( "report.plugin.usage.reporting" ) + " -->" ).append(
'\n' );
sb.append( " <reporting>" ).append( '\n' );
sb.append( " <plugins>" ).append( '\n' );
sb.append( " <plugin>" ).append( '\n' );
sb.append( " <groupId>" ).append( pluginDescriptor.getGroupId() ).append( "</groupId>" )
.append( '\n' );
sb.append( " <artifactId>" ).append( pluginDescriptor.getArtifactId() ).append( "</artifactId>" )
.append( '\n' );
sb.append( " <version>" ).append( pluginDescriptor.getVersion() ).append( "</version>" )
.append( '\n' );
sb.append( " <groupId>" ).append( pluginDescriptor.getGroupId() ).append( "</groupId>" ).append(
'\n' );
sb.append( " <artifactId>" ).append( pluginDescriptor.getArtifactId() ).append(
"</artifactId>" ).append( '\n' );
sb.append( " <version>" ).append( pluginDescriptor.getVersion() ).append( "</version>" ).append(
'\n' );
sb.append( " </plugin>" ).append( '\n' );
sb.append( " ..." ).append( '\n' );
sb.append( " </plugins>" ).append( '\n' );
@ -581,7 +602,7 @@ public class PluginReport
* Try to lookup on the Maven prerequisites property.
* If not specified, uses the value defined by the user.
*
* @param project not null
* @param project not null
* @param requirements not null
* @return the Maven version
*/
@ -606,7 +627,7 @@ public class PluginReport
* If not specified, uses the value defined by the user.
* If not specified, uses the value of the system property <code>java.specification.version</code>.
*
* @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;
}

View File

@ -71,6 +71,22 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-velocity</artifactId>
<exclusions>
<exclusion>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- other -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</dependency>
<!-- misc -->
<dependency>
@ -93,6 +109,20 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<java.io.tmpdir>${project.build.outputDirectory}</java.io.tmpdir>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>reporting</id>

View File

@ -33,18 +33,7 @@ import java.io.IOException;
*/
public interface Generator
{
/**
* Execute the generation for a given plugin descriptor.
*
* @param destinationDirectory required
* @param pluginDescriptor required
* @throws IOException if any
*
* @deprecated Use {@link Generator#execute(File, PluginToolsRequest)} instead.
*/
void execute( File destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException;
/**
* Execute the generation for a given plugin descriptor.
*
@ -55,5 +44,5 @@ public interface Generator
* @since 2.5
*/
void execute( File destinationDirectory, PluginToolsRequest request )
throws IOException;
throws GeneratorException;
}

View File

@ -19,11 +19,12 @@ package org.apache.maven.tools.plugin.generator;
* under the License.
*/
import org.apache.maven.plugin.descriptor.DuplicateMojoDescriptorException;
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.plugin.descriptor.Requirement;
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
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;
@ -33,53 +34,91 @@ import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
/**
* @version $Id$
* @todo add example usage tag that can be shown in the doco
* @todo need to add validation directives so that systems embedding maven2 can
* get validation directives to help users in IDEs.
*
* @version $Id$
*/
public class PluginDescriptorGenerator
implements Generator
{
/** {@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
{
try
{
File f = new File( destinationDirectory, "plugin.xml" );
writeDescriptor( f, request, false );
MavenProject mavenProject = request.getProject();
String pluginDescriptionFilePath =
"META-INF/maven/" + mavenProject.getGroupId() + "/" + mavenProject.getArtifactId()
+ "/plugin-description.xml";
f = new File( request.getProject().getBuild().getOutputDirectory(), pluginDescriptionFilePath );
writeDescriptor( f, request, true );
}
catch ( IOException e )
{
throw new GeneratorException( e.getMessage(), e );
}
catch ( DuplicateMojoDescriptorException e )
{
throw new GeneratorException( e.getMessage(), e );
}
}
public void writeDescriptor( File destinationFile, PluginToolsRequest request, boolean cleanDescription )
throws IOException, DuplicateMojoDescriptorException
{
PluginDescriptor pluginDescriptor = request.getPluginDescriptor();
String encoding = "UTF-8";
File f = new File( destinationDirectory, "plugin.xml" );
File tmpPropertiesFile =
new File( request.getProject().getBuild().getDirectory(), "maven-plugin-help.properties" );
if ( !f.getParentFile().exists() )
if ( tmpPropertiesFile.exists() )
{
f.getParentFile().mkdirs();
Properties properties = new Properties();
properties.load( new FileInputStream( tmpPropertiesFile ) );
//MojoDescriptor mojoDescriptor =
// makeHelpDescriptor( pluginDescriptor, properties.getProperty( "helpPackageName" ) );
//pluginDescriptor.addMojo( mojoDescriptor );
}
if ( destinationFile.exists() )
{
destinationFile.delete();
}
else
{
if ( !destinationFile.getParentFile().exists() )
{
destinationFile.getParentFile().mkdirs();
}
}
String encoding = "UTF-8";
Writer writer = null;
try
{
writer = new OutputStreamWriter( new FileOutputStream( f ), encoding );
writer = new OutputStreamWriter( new FileOutputStream( destinationFile ), encoding );
XMLWriter w = new PrettyPrintXMLWriter( writer, encoding, null );
@ -105,11 +144,11 @@ public class PluginDescriptorGenerator
if ( pluginDescriptor.getMojos() != null )
{
for ( @SuppressWarnings( "unchecked" )
Iterator<MojoDescriptor> it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
for ( @SuppressWarnings( "unchecked" ) Iterator<MojoDescriptor> it =
pluginDescriptor.getMojos().iterator(); it.hasNext(); )
{
MojoDescriptor descriptor = it.next();
processMojoDescriptor( descriptor, w );
processMojoDescriptor( descriptor, w, cleanDescription );
}
}
@ -120,6 +159,7 @@ public class PluginDescriptorGenerator
w.endElement();
writer.flush();
}
finally
{
@ -128,10 +168,142 @@ public class PluginDescriptorGenerator
}
/**
* @param mojoDescriptor not null
* @param w not null
* Creates a minimalistic mojo descriptor for the generated help goal.
*
* @param pluginDescriptor The descriptor of the plugin for which to generate a help goal, must not be
* <code>null</code>.
* @return The mojo descriptor for the generated help goal, never <code>null</code>.
*/
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() + ".<br/> Call <pre> mvn "
+ descriptor.getFullGoalName()
+ " -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details." );
try
{
Parameter param = new Parameter();
param.setName( "detail" );
param.setType( "boolean" );
param.setDescription( "If <code>true</code>, 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" )
List<Parameter> parameters = mojoDescriptor.getParameters();
@SuppressWarnings( "unchecked" ) List<Parameter> parameters = mojoDescriptor.getParameters();
w.startElement( "parameters" );
@ -397,11 +575,17 @@ public class PluginDescriptorGenerator
PluginUtils.element( w, "required", Boolean.toString( parameter.isRequired() ) );
PluginUtils.element( w, "editable", Boolean.toString( parameter.isEditable() ) );
if ( cleanDescription )
{
PluginUtils.element( w, "description", PluginUtils.toText( parameter.getDescription() ) );
}
else
{
PluginUtils.element( w, "description", parameter.getDescription() );
}
PluginUtils.element( w, "description", parameter.getDescription() );
if ( StringUtils.isNotEmpty( parameter.getDefaultValue() )
|| StringUtils.isNotEmpty( parameter.getExpression() ) )
if ( StringUtils.isNotEmpty( parameter.getDefaultValue() ) || StringUtils.isNotEmpty(
parameter.getExpression() ) )
{
configuration.add( parameter );
}

View File

@ -19,31 +19,31 @@ package org.apache.maven.tools.plugin.generator;
* under the License.
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
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.tools.plugin.DefaultPluginToolsRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.apache.velocity.VelocityContext;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.velocity.VelocityComponent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
/**
* Generates an <code>HelpMojo</code> 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" )
Iterator<MojoDescriptor> it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
for ( @SuppressWarnings( "unchecked" ) Iterator<MojoDescriptor> it = pluginDescriptor.getMojos().iterator();
it.hasNext(); )
{
MojoDescriptor descriptor = it.next();
if ( descriptor.getGoal().equals( helpDescriptor.getGoal() )
&& !descriptor.getImplementation().equals( helpDescriptor.getImplementation() ) )
if ( descriptor.getGoal().equals( helpDescriptor.getGoal() ) && !descriptor.getImplementation().equals(
helpDescriptor.getImplementation() ) )
{
if ( getLogger().isWarnEnabled() )
{
getLogger().warn(
"\n\nA help goal (" + descriptor.getImplementation()
getLogger().warn( "\n\nA help goal (" + descriptor.getImplementation()
+ ") already exists in this plugin. SKIPPED THE "
+ helpDescriptor.getImplementation() + " GENERATION.\n" );
}
@ -123,6 +123,36 @@ public class PluginHelpGenerator
}
}
Properties properties = new Properties();
properties.put( "helpPackageName", helpPackageName == null ? "" : helpPackageName );
MavenProject mavenProject = request.getProject();
String propertiesFilePath = "META-INF/maven/" + mavenProject.getGroupId() + "/" + mavenProject.getArtifactId();
File tmpPropertiesFile =
new File( request.getProject().getBuild().getDirectory(), "maven-plugin-help.properties" );
if ( tmpPropertiesFile.exists() )
{
tmpPropertiesFile.delete();
}
else
{
if ( !tmpPropertiesFile.getParentFile().exists() )
{
tmpPropertiesFile.getParentFile().mkdirs();
}
}
try
{
properties.store( new FileOutputStream( tmpPropertiesFile ), "maven plugin help generation informations" );
}
catch ( IOException e )
{
throw new GeneratorException( e.getMessage(), e );
}
String sourcePath = helpDescriptor.getImplementation().replace( '.', File.separatorChar ) + ".java";
File helpClass = new File( destinationDirectory, sourcePath );
helpClass.getParentFile().mkdirs();
@ -131,13 +161,19 @@ public class PluginHelpGenerator
try
{
writer = new OutputStreamWriter( new FileOutputStream( helpClass ), request.getEncoding() );
writeClass( writer, pluginDescriptor, helpDescriptor, useJava5 );
writer.write( getHelpClassSources( propertiesFilePath ) );
writer.flush();
}
catch ( IOException e )
{
throw new GeneratorException( e.getMessage(), e );
}
finally
{
IOUtil.close( writer );
}
}
public PluginHelpGenerator setHelpPackageName( String helpPackageName )
@ -152,15 +188,52 @@ public class PluginHelpGenerator
return this;
}
public VelocityComponent getVelocityComponent()
{
return velocityComponent;
}
public PluginHelpGenerator setVelocityComponent( VelocityComponent velocityComponent )
{
this.velocityComponent = velocityComponent;
return this;
}
// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
protected String getHelpClassSources( String propertiesFilePath )
{
Properties properties = new Properties();
VelocityContext context = new VelocityContext( properties );
if ( this.helpPackageName != null )
{
properties.put( "helpPackageName", this.helpPackageName );
}
else
{
properties.put( "helpPackageName", "" );
}
properties.put( "propertiesFilePath", propertiesFilePath + "/plugin-description.xml" );
// FIXME encoding !
StringWriter stringWriter = new StringWriter();
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( "help-class-source.vm" );
InputStreamReader isReader = new InputStreamReader( is );
velocityComponent.getEngine().evaluate( context, stringWriter, "", isReader );
return stringWriter.toString();
}
/**
* Creates a minimalistic mojo descriptor for the generated help goal.
*
* @param pluginDescriptor The descriptor of the plugin for which to generate a help goal, must not be
* <code>null</code>.
* <code>null</code>.
* @return The mojo descriptor for the generated help goal, never <code>null</code>.
*/
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()
+ ".<br/> Call <pre> mvn " + descriptor.getFullGoalName()
+ " -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details." );
descriptor.setDescription(
"Display help information on " + pluginDescriptor.getArtifactId() + ".<br/> Call <pre> mvn "
+ descriptor.getFullGoalName()
+ " -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> 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 )
{
Map<String, Integer> packageNames = new HashMap<String, Integer>();
for ( @SuppressWarnings( "unchecked" )
Iterator<MojoDescriptor> it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
Map packageNames = new HashMap();
for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
{
MojoDescriptor descriptor = it.next();
String name = "";
int next = 1;
MojoDescriptor descriptor = (MojoDescriptor) it.next();
String impl = descriptor.getImplementation();
if ( impl.lastIndexOf( '.' ) != -1 )
{
name = impl.substring( 0, impl.lastIndexOf( '.' ) );
Integer count = packageNames.get( name );
if ( count != null )
String name = impl.substring( 0, impl.lastIndexOf( '.' ) );
if ( packageNames.get( name ) != null )
{
next = count.intValue() + 1;
int next = ( (Integer) packageNames.get( name ) ).intValue() + 1;
packageNames.put( name, new Integer( next ) );
}
else
{
packageNames.put( name, new Integer( 1 ) );
}
}
packageNames.put( name, next );
else
{
packageNames.put( "", new Integer( 1 ) );
}
}
String packageName = "";
int max = 0;
for ( Map.Entry<String, Integer> entry : packageNames.entrySet() )
for ( Iterator it = packageNames.keySet().iterator(); it.hasNext(); )
{
int value = entry.getValue().intValue();
String key = it.next().toString();
int value = ( (Integer) packageNames.get( key ) ).intValue();
if ( value > max )
{
max = value;
packageName = entry.getKey();
packageName = key;
}
}
return packageName;
}
/**
* Generates the <code>HelpMojo</code> 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" )
Iterator<Parameter> it = helpDescriptor.getParameters().iterator(); it.hasNext(); )
{
Parameter param = it.next();
writer.write( " /**" + LS );
writer.write( " * " + StringUtils.escape( param.getDescription() ) + LS );
writer.write( " * " + LS );
writer.write( " * @parameter" );
if ( StringUtils.isNotEmpty( param.getExpression() ) )
{
writer.write( " expression=\"" );
writer.write( StringUtils.escape( param.getExpression() ) );
writer.write( "\"" );
}
if ( StringUtils.isNotEmpty( param.getDefaultValue() ) )
{
writer.write( " default-value=\"" );
writer.write( StringUtils.escape( param.getDefaultValue() ) );
writer.write( "\"" );
}
writer.write( LS );
writer.write( " */" + LS );
writer.write( " private " + param.getType() + " " + param.getName() + ";" + LS );
writer.write( LS );
}
}
/**
* @param writer not null
* @param pluginDescriptor not null
* @param helpDescriptor not null
* @throws IOException if any
*/
private static void writeExecute( Writer writer, PluginDescriptor pluginDescriptor, MojoDescriptor helpDescriptor )
throws IOException
{
List<MojoDescriptor> mojoDescriptors = new ArrayList<MojoDescriptor>();
mojoDescriptors.add( helpDescriptor );
for ( @SuppressWarnings( "unchecked" )
Iterator<MojoDescriptor> it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
{
MojoDescriptor mojoDescriptor = it.next();
if ( !helpDescriptor.getGoal().equals( mojoDescriptor.getGoal() ) )
{
mojoDescriptors.add( mojoDescriptor );
}
}
PluginUtils.sortMojos( mojoDescriptors );
writer.write( " /** {@inheritDoc} */" + LS );
writer.write( " public void execute()" + LS );
writer.write( " throws MojoExecutionException" + LS );
writer.write( " {" + LS );
writer.write( " if ( lineLength <= 0 )" + LS );
writer.write( " {" + LS );
writer.write( " getLog().warn( \"The parameter 'lineLength' should be positive, using '80' as "
+ "default.\" );" + LS );
writer.write( " lineLength = 80;" + LS );
writer.write( " }" + LS );
writer.write( " if ( indentSize <= 0 )" + LS );
writer.write( " {" + LS );
writer.write( " getLog().warn( \"The parameter 'indentSize' should be positive, using '2' as "
+ "default.\" );" + LS );
writer.write( " indentSize = 2;" + LS );
writer.write( " }" + LS );
writer.write( LS );
writer.write( " StringBuffer sb = new StringBuffer();" + LS );
writer.write( LS );
writer.write( " append( sb, \"" + StringUtils.escape( pluginDescriptor.getId() ) + "\", 0 );" + LS );
writer.write( " append( sb, \"\", 0 );" + LS );
writer.write( LS );
if ( StringUtils.isNotEmpty( pluginDescriptor.getName() )
&& ( pluginDescriptor.getName().indexOf( pluginDescriptor.getId() ) != -1 ) )
{
writer.write( " append( sb, \""
+ StringUtils.escape( pluginDescriptor.getName() + " " + pluginDescriptor.getVersion() )
+ "\", 0 );" + LS );
}
else
{
if ( StringUtils.isNotEmpty( pluginDescriptor.getName() ) )
{
writer.write( " append( sb, \"" + StringUtils.escape( pluginDescriptor.getName() )
+ "\", 0 );" + LS );
}
else
{
writer.write( " append( sb, \"" + StringUtils.escape( pluginDescriptor.getId() )
+ "\", 0 );" + LS );
}
}
writer.write( " append( sb, \"" + toDescription( pluginDescriptor.getDescription() ) + "\", 1 );"
+ LS );
writer.write( " append( sb, \"\", 0 );" + LS );
writer.write( LS );
writer.write( " if ( goal == null || goal.length() <= 0 )" + LS );
writer.write( " {" + LS );
writer.write( " append( sb, \"This plugin has " + mojoDescriptors.size() + " "
+ ( mojoDescriptors.size() > 1 ? "goals" : "goal" ) + ":\", 0 );" + LS );
writer.write( " append( sb, \"\", 0 );" + LS );
writer.write( " }" + LS );
writer.write( LS );
for ( MojoDescriptor descriptor : mojoDescriptors )
{
writeGoal( writer, descriptor );
}
writer.write( " if ( getLog().isInfoEnabled() )" + LS );
writer.write( " {" + LS );
writer.write( " getLog().info( sb.toString() );" + LS );
writer.write( " }" + LS );
writer.write( " }" + LS );
}
/**
* @param writer not null
* @param descriptor not null
* @throws IOException if any
*/
private static void writeGoal( Writer writer, MojoDescriptor descriptor )
throws IOException
{
String goalDescription = toDescription( descriptor.getDescription() );
writer.write( " if ( goal == null || goal.length() <= 0 || \""
+ StringUtils.escape( descriptor.getGoal() ) + "\".equals( goal ) )" + LS );
writer.write( " {" + LS );
writer.write( " append( sb, \"" + StringUtils.escape( descriptor.getFullGoalName() ) + "\", 0 );"
+ LS );
if ( StringUtils.isNotEmpty( descriptor.getDeprecated() ) )
{
writer.write( " append( sb, \"Deprecated. " + toDescription( descriptor.getDeprecated() )
+ "\", 1 );" + LS );
writer.write( " if ( detail )" + LS );
writer.write( " {" + LS );
writer.write( " append( sb, \"\", 0 );" + LS );
writer.write( " append( sb, \"" + goalDescription + "\", 1 );" + LS );
writer.write( " }" + LS );
}
else
{
writer.write( " append( sb, \"" + goalDescription + "\", 1 );" + LS );
}
writer.write( " append( sb, \"\", 0 );" + LS );
if ( descriptor.getParameters() != null && descriptor.getParameters().size() > 0 )
{
@SuppressWarnings( "unchecked" )
List<Parameter> params = descriptor.getParameters();
PluginUtils.sortMojoParameters( params );
writer.write( " if ( detail )" + LS );
writer.write( " {" + LS );
writer.write( " append( sb, \"Available parameters:\", 1 );" + LS );
writer.write( " append( sb, \"\", 0 );" + LS );
for ( Parameter parameter : params )
{
if ( parameter.isEditable() )
{
writer.write( LS );
writeParameter( writer, parameter );
}
}
writer.write( " }" + LS );
}
writer.write( " }" + LS );
writer.write( LS );
}
/**
* @param writer not null
* @param parameter not null
* @throws IOException if any
*/
private static void writeParameter( Writer writer, Parameter parameter )
throws IOException
{
String expression = parameter.getExpression();
if ( expression == null || !expression.startsWith( "${component." ) )
{
String parameterName = StringUtils.escape( parameter.getName() );
String parameterDescription = toDescription( parameter.getDescription() );
String parameterDefaultValue = "";
if ( StringUtils.isNotEmpty( parameter.getDefaultValue() ) )
{
parameterDefaultValue = " (Default: " + StringUtils.escape( parameter.getDefaultValue() ) + ")";
}
writer.write( " append( sb, \"" + parameterName + parameterDefaultValue + "\", 2 );" + LS );
if ( StringUtils.isNotEmpty( parameter.getDeprecated() ) )
{
writer.write( " append( sb, \"Deprecated. " + toDescription( parameter.getDeprecated() )
+ "\", 3 );" + LS );
writer.write( " append( sb, \"\", 0 );" + LS );
}
writer.write( " append( sb, \"" + parameterDescription + "\", 3 );" + LS );
if ( parameter.isRequired() )
{
writer.write( " append( sb, \"Required: Yes\", 3 );" + LS );
}
if ( StringUtils.isNotEmpty( parameter.getExpression() ) )
{
writer.write( " append( sb, \"Expression: "
+ StringUtils.escape( parameter.getExpression() ) + "\", 3 );" + LS );
}
writer.write( " append( sb, \"\", 0 );" + LS );
}
}
/**
* @param writer not null
* @param useJava5 If the generated code should use Java5 features
* @throws IOException if any
*/
private static void writeUtilities( Writer writer, boolean useJava5 )
throws IOException
{
writer.write( " /**" + LS );
writer.write( " * <p>Repeat a String <code>n</code> times to form a new string.</p>" + LS );
writer.write( " *" + LS );
writer.write( " * @param str String to repeat" + LS );
writer.write( " * @param repeat number of times to repeat str" + LS );
writer.write( " * @return String with repeated String" + LS );
writer.write( " * @throws NegativeArraySizeException if <code>repeat < 0</code>" + LS );
writer.write( " * @throws NullPointerException if str is <code>null</code>" + 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( " * <b>Note</b>: The last character is always a new line." + LS );
writer.write( " * " + LS );
writer.write( " * @param sb The buffer to append the description, not <code>null</code>." + LS );
writer.write( " * @param description The description, not <code>null</code>." + 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 <code>null</code>." + 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 <code>null</code>." + LS );
writer.write( " * @throws NegativeArraySizeException if <code>indent < 0</code>" + 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( " List<String> lines = new ArrayList<String>();" + LS );
}
else
{
writer.write( " List lines = new ArrayList();" + LS );
}
writer.write( LS );
writer.write( " String ind = repeat( \"\\t\", indent );" + LS );
writer.write( " String[] plainLines = text.split( \"(\\r\\n)|(\\r)|(\\n)\" );" + LS );
writer.write( " for ( int i = 0; i < plainLines.length; i++ )" + LS );
writer.write( " {" + LS );
writer.write( " toLines( lines, ind + plainLines[i], indentSize, lineLength );" + LS );
writer.write( " }" + LS );
writer.write( LS );
writer.write( " return lines;" + LS );
writer.write( " }" + LS );
writer.write( LS );
writer.write( " /** " + LS );
writer.write( " * Adds the specified line to the output sequence, performing line wrapping if necessary."
+ LS );
writer.write( " * " + LS );
writer.write( " * @param lines The sequence of display lines, must not be <code>null</code>." + LS );
writer.write( " * @param line The line to add, must not be <code>null</code>." + 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( List<String> lines, String line, int indentSize, int lineLength )"
+ LS );
}
else
{
writer.write( " private static void toLines( List lines, String line, int indentSize, int lineLength )"
+ LS );
}
writer.write( " {" + LS );
writer.write( " int lineIndent = getIndentLevel( line );" + LS );
writer.write( " StringBuffer buf = new StringBuffer( 256 );" + LS );
writer.write( " String[] tokens = line.split( \" +\" );" + LS );
writer.write( " for ( int i = 0; i < tokens.length; i++ )" + LS );
writer.write( " {" + LS );
writer.write( " String token = tokens[i];" + LS );
writer.write( " if ( i > 0 )" + LS );
writer.write( " {" + LS );
writer.write( " if ( buf.length() + token.length() >= lineLength )" + LS );
writer.write( " {" + LS );
writer.write( " lines.add( buf.toString() );" + LS );
writer.write( " buf.setLength( 0 );" + LS );
writer.write( " buf.append( repeat( \" \", lineIndent * indentSize ) );" + LS );
writer.write( " }" + LS );
writer.write( " else" + LS );
writer.write( " {" + LS );
writer.write( " buf.append( ' ' );" + LS );
writer.write( " }" + LS );
writer.write( " }" + LS );
writer.write( " for ( int j = 0; j < token.length(); j++ )" + LS );
writer.write( " {" + LS );
writer.write( " char c = token.charAt( j );" + LS );
writer.write( " if ( c == '\\t' )" + LS );
writer.write( " {" + LS );
writer.write( " buf.append( repeat( \" \", indentSize - buf.length() % indentSize ) );"
+ LS );
writer.write( " }" + LS );
writer.write( " else if ( c == '\\u00A0' )" + LS );
writer.write( " {" + LS );
writer.write( " buf.append( ' ' );" + LS );
writer.write( " }" + LS );
writer.write( " else" + LS );
writer.write( " {" + LS );
writer.write( " buf.append( c );" + LS );
writer.write( " }" + LS );
writer.write( " }" + LS );
writer.write( " }" + LS );
writer.write( " lines.add( buf.toString() );" + LS );
writer.write( " }" + LS );
writer.write( LS );
writer.write( " /** " + LS );
writer.write( " * Gets the indentation level of the specified line." + LS );
writer.write( " * " + LS );
writer.write( " * @param line The line whose indentation level should be retrieved, must not be "
+ "<code>null</code>." + 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 <code>null</code>.
* @return The effective description string, never <code>null</code>.
*/
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:
* <ul>
* <li>List items are converted to leading tabs (U+0009), followed by the item number/bullet, another tab and
* finally the item contents. Each tab denotes an increase of indentation.</li>
* <li>Flow breaking elements as well as literal line terminators in preformatted text are converted to a newline
* (U+000A) to denote a mandatory line break.</li>
* <li>Consecutive spaces and line terminators from character data outside of preformatted text will be normalized
* to a single space. The resulting space denotes a possible point for line wrapping.</li>
* <li>Each space in preformatted text will be converted to a non-breaking space (U+00A0).</li>
* </ul>
*
* @param html The HTML fragment to convert to plain text, may be <code>null</code>.
* @return A string with HTML tags converted into pure text, never <code>null</code>.
* @deprecated since 2.4.3, using {@link PluginUtils#toText(String)} instead of.
*/
protected static String toText( String html )
{
return PluginUtils.toText( html );
}
}

View File

@ -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" )
Iterator<MojoDescriptor> it = request.getPluginDescriptor().getMojos().iterator(); it.hasNext(); )
if ( request.getPluginDescriptor().getMojos() != null )
{
MojoDescriptor descriptor = it.next();
for ( @SuppressWarnings( "unchecked" ) Iterator<MojoDescriptor> it =
request.getPluginDescriptor().getMojos().iterator(); it.hasNext(); )
{
MojoDescriptor descriptor = it.next();
processMojoDescriptor( descriptor, destinationDirectory );
processMojoDescriptor( descriptor, destinationDirectory );
}
}
}
catch ( IOException e )
{
throw new GeneratorException( e.getMessage(), e );
}
}
/**
* @param mojoDescriptor not null
* @param mojoDescriptor not null
* @param destinationDirectory not null
* @throws IOException if any
*/
@ -147,7 +153,7 @@ public class PluginXdocGenerator
/**
* @param mojo not null
* @param ext not null
* @param ext not null
* @return the output file name
*/
private String getMojoFilename( MojoDescriptor mojo, String ext )
@ -157,7 +163,7 @@ public class PluginXdocGenerator
/**
* @param mojoDescriptor not null
* @param w not null
* @param w not null
*/
private void writeBody( MojoDescriptor mojoDescriptor, XMLWriter w )
{
@ -196,8 +202,8 @@ public class PluginXdocGenerator
w.endElement(); //p
w.startElement( "p" );
w.writeMarkup( mojoDescriptor.getPluginDescriptor().getGroupId() + ":"
+ mojoDescriptor.getPluginDescriptor().getArtifactId() + ":"
+ mojoDescriptor.getPluginDescriptor().getVersion() + ":" + mojoDescriptor.getGoal() );
+ mojoDescriptor.getPluginDescriptor().getArtifactId() + ":"
+ mojoDescriptor.getPluginDescriptor().getVersion() + ":" + mojoDescriptor.getGoal() );
w.endElement(); //p
if ( StringUtils.isNotEmpty( mojoDescriptor.getDeprecated() ) )
@ -237,7 +243,7 @@ public class PluginXdocGenerator
/**
* @param mojoDescriptor not null
* @param w not null
* @param w not null
*/
private void writeReportNotice( MojoDescriptor mojoDescriptor, XMLWriter w )
{
@ -252,7 +258,7 @@ public class PluginXdocGenerator
/**
* @param mojoDescriptor not null
* @param w not null
* @param w not null
*/
private void writeGoalAttributes( MojoDescriptor mojoDescriptor, XMLWriter w )
{
@ -273,12 +279,12 @@ public class PluginXdocGenerator
w.writeMarkup( getString( "pluginxdoc.mojodescriptor.projectRequired" ) );
w.endElement(); //li
}
if ( mojoDescriptor.isRequiresReports() )
{
if ( !addedUl )
{
w.startElement( "ul" );
w.startElement( "ul" );
addedUl = true;
}
w.startElement( "li" );
@ -451,12 +457,11 @@ public class PluginXdocGenerator
/**
* @param mojoDescriptor not null
* @param w not null
* @param w not null
*/
private void writeGoalParameterTable( MojoDescriptor mojoDescriptor, XMLWriter w )
{
@SuppressWarnings( "unchecked" )
List<Parameter> parameterList = mojoDescriptor.getParameters();
@SuppressWarnings( "unchecked" ) List<Parameter> parameterList = mojoDescriptor.getParameters();
//remove components and read-only parameters
List<Parameter> list = filterParameters( parameterList );
@ -490,7 +495,7 @@ public class PluginXdocGenerator
if ( parameterList != null )
{
for ( Parameter parameter : parameterList )
for ( Parameter parameter : parameterList )
{
if ( parameter.isEditable() )
{
@ -509,8 +514,8 @@ public class PluginXdocGenerator
/**
* @param mojoDescriptor not null
* @param parameterList not null
* @param w not null
* @param parameterList not null
* @param w not null
*/
private void writeParameterDetails( MojoDescriptor mojoDescriptor, List<Parameter> parameterList, XMLWriter w )
{
@ -570,8 +575,8 @@ public class PluginXdocGenerator
w.startElement( "ul" );
addedUl = true;
}
writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.since" ),
mojoDescriptor.getSince(), w );
writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.since" ), mojoDescriptor.getSince(),
w );
}
}
@ -582,8 +587,8 @@ public class PluginXdocGenerator
w.startElement( "ul" );
addedUl = true;
}
writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.required" ),
getString( "pluginxdoc.yes" ), w );
writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.required" ), getString( "pluginxdoc.yes" ),
w );
}
else
{
@ -592,8 +597,8 @@ public class PluginXdocGenerator
w.startElement( "ul" );
addedUl = true;
}
writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.required" ),
getString( "pluginxdoc.no" ), w );
writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.required" ), getString( "pluginxdoc.no" ),
w );
}
if ( !addedUl && StringUtils.isNotEmpty( parameter.getExpression() ) )
@ -628,7 +633,7 @@ public class PluginXdocGenerator
/**
* @param param not null
* @param value could be null
* @param w not null
* @param w not null
*/
private void writeDetail( String param, String value, XMLWriter w )
{
@ -642,8 +647,8 @@ public class PluginXdocGenerator
/**
* @param mojoDescriptor not null
* @param parameterList not null
* @param w not null
* @param parameterList not null
* @param w not null
*/
private void writeParameterSummary( MojoDescriptor mojoDescriptor, List<Parameter> parameterList, XMLWriter w )
{
@ -664,11 +669,12 @@ public class PluginXdocGenerator
/**
* @param mojoDescriptor not null
* @param title not null
* @param parameterList not null
* @param w not null
* @param title not null
* @param parameterList not null
* @param w not null
*/
private void writeParameterList( MojoDescriptor mojoDescriptor, String title, List<Parameter> parameterList, XMLWriter w )
private void writeParameterList( MojoDescriptor mojoDescriptor, String title, List<Parameter> parameterList,
XMLWriter w )
{
w.startElement( "subsection" );
w.addAttribute( "name", title );
@ -722,9 +728,8 @@ public class PluginXdocGenerator
String description;
if ( StringUtils.isNotEmpty( parameter.getDeprecated() ) )
{
description =
format( "pluginxdoc.mojodescriptor.parameter.deprecated",
PluginUtils.makeHtmlValid( parameter.getDeprecated() ) );
description = format( "pluginxdoc.mojodescriptor.parameter.deprecated",
PluginUtils.makeHtmlValid( parameter.getDeprecated() ) );
}
else if ( StringUtils.isNotEmpty( parameter.getDescription() ) )
{
@ -750,7 +755,7 @@ public class PluginXdocGenerator
}
/**
* @param required <code>true</code> for required parameters, <code>false</code> otherwise.
* @param required <code>true</code> for required parameters, <code>false</code> otherwise.
* @param parameterList not null
* @return list of parameters depending the value of <code>required</code>
*/
@ -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 <code>key</code>.
* @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 <code>key</code> in the <code>ResourceBundle</code>,
* then formats that value for the specified <code>Locale</code> using <code>args</code>.
*
* @param key not null
* @param key not null
* @param args not null
* @return Localized, formatted text identified by <code>key</code>.
*/

View File

@ -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." );
}
}

View File

@ -19,6 +19,8 @@ package org.apache.maven.tools.plugin.generator;
* under the License.
*/
import org.codehaus.plexus.velocity.VelocityComponent;
/**
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
* @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 ) );
}
}

18
pom.xml
View File

@ -233,6 +233,24 @@
<artifactId>plexus-archiver</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-velocity</artifactId>
<version>1.1.8</version>
<exclusions>
<exclusion>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- other -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.qdox</groupId>