From c3ac93da0ffa924b76c01bd1119e9e5fdf538cb0 Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Mon, 16 Mar 2015 14:29:21 +0100 Subject: [PATCH 1/3] Avoid duplicate MOJO parameters --- .../JavaAnnotationsMojoDescriptorExtractor.java | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractor.java index 231f623..a034dc2 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractor.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractor.java @@ -29,6 +29,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -573,7 +574,7 @@ public class JavaAnnotationsMojoDescriptorExtractor parameter.setSince( parameterAnnotationContent.getSince() ); parameter.setRequired( parameterAnnotationContent.required() ); - mojoDescriptor.addParameter( parameter ); + addParameter( mojoDescriptor, parameter ); } // Component annotations @@ -614,7 +615,7 @@ public class JavaAnnotationsMojoDescriptorExtractor //parameter.setRequired( ... ); parameter.setEditable( false ); - mojoDescriptor.addParameter( parameter ); + addParameter( mojoDescriptor, parameter ); } mojoDescriptor.setPluginDescriptor( pluginDescriptor ); @@ -624,6 +625,25 @@ public class JavaAnnotationsMojoDescriptorExtractor return mojoDescriptors; } + private void addParameter( ExtendedMojoDescriptor mojoDescriptor, + org.apache.maven.plugin.descriptor.Parameter parameter ) + throws DuplicateParameterException + { + if ( mojoDescriptor.getParameters() != null ) + { + for ( Iterator it = mojoDescriptor.getParameters().iterator(); it.hasNext(); ) + { + if ( it.next().equals( parameter ) ) + { + getLogger().warn( "Duplicate parameter " + parameter.getName() + " field in MOJO descriptor" ); + it.remove(); + } + } + } + + mojoDescriptor.addParameter( parameter ); + } + protected ExecuteAnnotationContent findExecuteInParentHierarchy( MojoAnnotatedClass mojoAnnotatedClass, Map mojoAnnotatedClasses ) { -- 2.7.4