From ed14ff454d8956206222cbccccfc7e5262a435d4 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 27 Apr 2005 15:11:28 +0000 Subject: [PATCH] Modifying the mojo generators to handle alias, and other missing elements where appropriate. Changed the resources mojos to be as trim as I can, and added @required to the field-level annotations (this might be a good thing to do for all plexus components, dunno if it's there already)...finally, trimmed up the annotation handling in the JavaMojoDescriptorExtractor to push as many annotation fields as possible into the endangered area, and started pulling as much info from the field, other companion annotations on the field, etc. as I can...I think the annotations are there, now. They need to be cleaned up after converting all the core plugins to use field-level annotations, then we're set. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@164990 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/plugin/generator/BeanGenerator.java | 3 + .../generator/PluginDescriptorGenerator.java | 5 ++ .../plugin/generator/PluginXdocGenerator.java | 72 +++++++++++++++++-- .../jelly/JellyHarnessGenerator.java | 10 ++- .../java/JavaMojoDescriptorExtractor.java | 24 +++++-- .../maven/plugin/resources/ResourcesMojo.java | 10 ++- .../plugin/resources/TestResourcesMojo.java | 10 ++- 7 files changed, 110 insertions(+), 24 deletions(-) diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/BeanGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/BeanGenerator.java index 3e3408f3d6..a736a40410 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/BeanGenerator.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/BeanGenerator.java @@ -33,6 +33,9 @@ import java.util.List; import java.util.Set; /** + * [JC] Is this class defunct now? I can't find o.a.m.plugin.BeanPluginAdapter in the codebase... + * I'm not going to edit this class to account for aliases, deprecation, etc. until I know. + * * @todo use the descriptions in the descriptor for the javadoc pushed into the * source code. */ diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java index 719f92b85d..40e51103c8 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java @@ -181,6 +181,11 @@ public class PluginDescriptorGenerator w.startElement( "parameter" ); element( w, "name", parameter.getName() ); + + if( parameter.getAlias() != null ) + { + element( w, "alias", parameter.getAlias() ); + } element( w, "type", parameter.getType() ); diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java index ce44373f4d..dffb0ee32a 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java @@ -19,6 +19,7 @@ package org.apache.maven.tools.plugin.generator; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; @@ -37,7 +38,8 @@ import java.util.Set; public class PluginXdocGenerator implements Generator { - public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project ) throws Exception + public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project ) + throws Exception { for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); ) { @@ -137,7 +139,8 @@ public class PluginXdocGenerator writer.close(); } - private void writeGoalParameterTable( MojoDescriptor mojoDescriptor, XMLWriter w ) throws Exception + private void writeGoalParameterTable( MojoDescriptor mojoDescriptor, XMLWriter w ) + throws Exception { w.startElement( "p" ); @@ -153,6 +156,12 @@ public class PluginXdocGenerator w.startElement( "th" ); + w.writeText( "Type" ); + + w.endElement(); + + w.startElement( "th" ); + w.writeText( "Expression" ); w.endElement(); @@ -163,6 +172,18 @@ public class PluginXdocGenerator w.endElement(); + w.startElement( "th" ); + + w.writeText( "Required?" ); + + w.endElement(); + + w.startElement( "th" ); + + w.writeText( "Deprecated?" ); + + w.endElement(); + w.endElement(); List parameters = mojoDescriptor.getParameters(); @@ -181,7 +202,24 @@ public class PluginXdocGenerator w.startElement( "td" ); - w.writeText( parameter.getName() ); + String paramName = parameter.getAlias(); + + if ( StringUtils.isEmpty( paramName ) ) + { + paramName = parameter.getName(); + } + + w.writeText( paramName ); + + w.endElement(); + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + w.startElement( "td" ); + + w.writeText( parameter.getType() ); w.endElement(); @@ -201,12 +239,34 @@ public class PluginXdocGenerator w.startElement( "td" ); - Parameter p = (Parameter) parameterMap.get( parameter.getName() ); - - w.writeText( p.getDescription() ); + w.writeText( parameter.getDescription() ); w.endElement(); + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + w.startElement( "td" ); + + w.writeText( Boolean.toString( parameter.isRequired() ) ); + + w.endElement(); + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + String deprecationWarning = parameter.getDeprecated(); + if ( StringUtils.isNotEmpty( deprecationWarning ) ) + { + w.startElement( "td" ); + + w.writeText( deprecationWarning ); + + w.endElement(); + } + w.endElement(); } diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/jelly/JellyHarnessGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/jelly/JellyHarnessGenerator.java index 134538b1bb..b8bb6e0f89 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/jelly/JellyHarnessGenerator.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/jelly/JellyHarnessGenerator.java @@ -22,6 +22,7 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.generator.Generator; import org.apache.maven.tools.plugin.util.PluginUtils; +import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; @@ -194,7 +195,14 @@ public class JellyHarnessGenerator { Parameter parameter = (Parameter) parameters.get( i ); - w.addAttribute( parameter.getName(), "${" + parameter.getName() + "}" ); + String paramName = parameter.getAlias(); + + if( StringUtils.isEmpty( paramName ) ) + { + paramName = parameter.getName(); + } + + w.addAttribute( paramName, "${" + paramName + "}" ); } w.endElement(); diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java index 8810148759..fa38274d54 100644 --- a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java +++ b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java @@ -60,6 +60,12 @@ public class JavaMojoDescriptorExtractor public static final String MAVEN_PLUGIN_MODE = "maven.plugin.mode"; public static final String PARAMETER = "parameter"; + + public static final String PARAMETER_EXPRESSION = "expression"; + + public static final String REQUIRED = "required"; + + public static final String DEPRECATED = "deprecated"; public static final String GOAL = "goal"; @@ -298,6 +304,10 @@ public class JavaMojoDescriptorExtractor pd.setDefaultValue( parameter.getNamedParameter( "default" ) ); pd.setDescription( parameter.getNamedParameter( "description" ) ); + + pd.setRequired( parameter.getNamedParameter( "required" ).equals( "true" ) ? true : false ); + + pd.setDeprecated( parameter.getNamedParameter( "deprecated" ) ); } else { @@ -306,6 +316,14 @@ public class JavaMojoDescriptorExtractor pd.setType( field.getType().getValue() ); pd.setDescription( field.getComment() ); + + pd.setRequired( field.getTagByName(REQUIRED) != null ); + + DocletTag deprecationTag = field.getTagByName( DEPRECATED ); + if( deprecationTag != null) + { + pd.setDeprecated( deprecationTag.getValue() ); + } } String alias = parameter.getNamedParameter( "alias" ); @@ -315,11 +333,7 @@ public class JavaMojoDescriptorExtractor pd.setAlias( alias ); } - pd.setRequired( parameter.getNamedParameter( "required" ).equals( "true" ) ? true : false ); - - pd.setExpression( parameter.getNamedParameter( "expression" ) ); - - pd.setDeprecated( parameter.getNamedParameter( "deprecated" ) ); + pd.setExpression( parameter.getNamedParameter( PARAMETER_EXPRESSION ) ); parameters.add( pd ); } diff --git a/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java b/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java index ecc8e90d3c..466d81342a 100644 --- a/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java +++ b/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java @@ -46,18 +46,16 @@ public class ResourcesMojo /** * The output directory into which to copy the resources. * - * @parameter name="outputDirectory" - * required="true" - * expression="${project.build.outputDirectory}" + * @parameter expression="${project.build.outputDirectory}" + * @required */ private String outputDirectory; /** * The list of resources we want to transfer. * - * @parameter name="resources" - * required="true" - * expression="${project.build.resources}" + * @parameter expression="${project.build.resources}" + * @required */ private List resources; diff --git a/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java b/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java index eecaaab8c3..95ec46cf17 100644 --- a/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java +++ b/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java @@ -33,18 +33,16 @@ public class TestResourcesMojo /** * The output directory into which to copy the resources. * - * @parameter name="outputDirectory" - * required="true" - * expression="${project.build.testOutputDirectory}" + * @parameter expression="${project.build.testOutputDirectory}" + * @required */ private String outputDirectory; /** * The list of resources we want to transfer. * - * @parameter name="resources" - * required="true" - * expression="${project.build.testResources}" + * @parameter expression="${project.build.testResources}" + * @required */ private List resources;