[MPLUGIN-176] helpmojo: Use Java 5 generics in generated help mojo

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1050558 13f79535-47bb-0310-9956-ffa450edef68
master
Benjamin Bentmann 2010-12-18 00:46:38 +00:00
parent 9ea26413d9
commit a30e8eabbd
2 changed files with 26 additions and 3 deletions

View File

@ -53,6 +53,14 @@ public class HelpGeneratorMojo
*/ */
private String helpPackageName; private String helpPackageName;
/**
* Generate Java 5 sources.
*
* @parameter expression="${useJava5}" default-value="false"
* @since 2.7
*/
private boolean useJava5;
/** {@inheritDoc} */ /** {@inheritDoc} */
protected File getOutputDirectory() protected File getOutputDirectory()
{ {
@ -62,7 +70,7 @@ public class HelpGeneratorMojo
/** {@inheritDoc} */ /** {@inheritDoc} */
protected Generator createGenerator() protected Generator createGenerator()
{ {
return new PluginHelpGenerator().setHelpPackageName( helpPackageName ); return new PluginHelpGenerator().setHelpPackageName( helpPackageName ).setUseJava5( useJava5 );
} }
/** {@inheritDoc} */ /** {@inheritDoc} */

View File

@ -66,6 +66,9 @@ public class PluginHelpGenerator
private static final String HELP_GOAL = "help"; private static final String HELP_GOAL = "help";
private String helpPackageName; private String helpPackageName;
/** Flag to indicate if the generated help mojo should use Java 5 features */
private boolean useJava5;
/** /**
* Default constructor * Default constructor
@ -127,7 +130,7 @@ public class PluginHelpGenerator
try try
{ {
writer = new OutputStreamWriter( new FileOutputStream( helpClass ), request.getEncoding() ); writer = new OutputStreamWriter( new FileOutputStream( helpClass ), request.getEncoding() );
writeClass( writer, pluginDescriptor, helpDescriptor ); writeClass( writer, pluginDescriptor, helpDescriptor, useJava5 );
writer.flush(); writer.flush();
} }
finally finally
@ -142,6 +145,12 @@ public class PluginHelpGenerator
return this; return this;
} }
public PluginHelpGenerator setUseJava5( boolean useJava5 )
{
this.useJava5 = useJava5;
return this;
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Private methods // Private methods
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -278,9 +287,10 @@ public class PluginHelpGenerator
* @param writer not null * @param writer not null
* @param pluginDescriptor not null * @param pluginDescriptor not null
* @param helpDescriptor not null * @param helpDescriptor not null
* @param useJava5 If the generated code should use Java5 features
* @throws IOException if any * @throws IOException if any
*/ */
private static void writeClass( Writer writer, PluginDescriptor pluginDescriptor, MojoDescriptor helpDescriptor ) private static void writeClass( Writer writer, PluginDescriptor pluginDescriptor, MojoDescriptor helpDescriptor, boolean useJava5 )
throws IOException throws IOException
{ {
String packageName = ""; String packageName = "";
@ -303,6 +313,11 @@ public class PluginHelpGenerator
writeMojoJavadoc( writer, pluginDescriptor, helpDescriptor ); writeMojoJavadoc( writer, pluginDescriptor, helpDescriptor );
if ( useJava5 )
{
writer.write( "@SuppressWarnings( \"all\" )" + LS );
}
writer.write( "public class " + simpleName + LS ); writer.write( "public class " + simpleName + LS );
writer.write( " extends AbstractMojo" + LS ); writer.write( " extends AbstractMojo" + LS );
writer.write( "{" + LS ); writer.write( "{" + LS );