This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git


The following commit(s) were added to refs/heads/master by this push:
     new 8a764005 [MPLUGIN-427] only emit simple parameter type for 
configuration (#163)
8a764005 is described below

commit 8a7640051ab2a4487e841fea6e21b95ac2d05ffe
Author: Konrad Windszus <[email protected]>
AuthorDate: Wed Oct 26 20:10:26 2022 +0200

    [MPLUGIN-427] only emit simple parameter type for configuration (#163)
---
 .../generator/PluginDescriptorFilesGenerator.java  |  3 ++-
 .../generator/AbstractGeneratorTestCase.java       |  8 ++++++-
 .../PluginDescriptorFilesGeneratorTest.java        | 28 +++++++++++++++++++++-
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git 
a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGenerator.java
 
b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGenerator.java
index a21a4e44..cce415f0 100644
--- 
a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGenerator.java
+++ 
b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGenerator.java
@@ -587,7 +587,8 @@ public class PluginDescriptorFilesGenerator
 
                 w.startElement( parameter.getName() );
 
-                String parameterType = parameter.getType();
+                // strip type by parameter type (generics) information
+                String parameterType = StringUtils.chomp( parameter.getType(), 
"<" );
                 if ( StringUtils.isNotEmpty( parameterType ) )
                 {
                     w.addAttribute( "implementation", parameterType );
diff --git 
a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
 
b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
index 1adcc5d0..c51406d1 100644
--- 
a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
+++ 
b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
@@ -20,6 +20,7 @@ package org.apache.maven.tools.plugin.generator;
  */
 
 import org.apache.maven.model.Build;
+import org.apache.maven.plugin.descriptor.DuplicateParameterException;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.Parameter;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
@@ -114,7 +115,7 @@ public abstract class AbstractGeneratorTestCase
                 return basedir + "/target";
             }
         } );
-
+        extendPluginDescriptor( pluginDescriptor );
         generator.execute( destinationDirectory, new 
DefaultPluginToolsRequest( mavenProject, pluginDescriptor ) );
 
         validate( destinationDirectory );
@@ -122,6 +123,11 @@ public abstract class AbstractGeneratorTestCase
         FileUtils.deleteDirectory( destinationDirectory );
     }
 
+    protected void extendPluginDescriptor( PluginDescriptor pluginDescriptor ) 
throws DuplicateParameterException
+    {
+        // may be overwritten
+    }
+
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------
diff --git 
a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGeneratorTest.java
 
b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGeneratorTest.java
index 3e8decd8..b2c3b3ec 100644
--- 
a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGeneratorTest.java
+++ 
b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGeneratorTest.java
@@ -29,12 +29,14 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.List;
 
+import org.apache.maven.plugin.descriptor.DuplicateParameterException;
 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.PluginDescriptorBuilder;
 import org.apache.maven.tools.plugin.javadoc.JavadocLinkGenerator;
 import org.codehaus.plexus.component.repository.ComponentDependency;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.testing.PlexusTest;
 import org.codehaus.plexus.util.ReaderFactory;
 import org.junit.jupiter.api.Test;
@@ -50,6 +52,17 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 public class PluginDescriptorFilesGeneratorTest
     extends AbstractGeneratorTestCase
 {
+    @Override
+    protected void extendPluginDescriptor( PluginDescriptor pluginDescriptor ) 
throws DuplicateParameterException
+    {
+        Parameter parameterWithGenerics = new Parameter();
+        parameterWithGenerics.setName( "parameterWithGenerics" );
+        
parameterWithGenerics.setType("java.util.Collection<java.lang.String>");
+        parameterWithGenerics.setExpression( "${customParam}" );
+        parameterWithGenerics.setDefaultValue( "a,b,c" );
+        pluginDescriptor.getMojos().get( 0 ).addParameter( 
parameterWithGenerics );
+    }
+
     @Override
     protected void validate( File destinationDirectory )
         throws Exception
@@ -113,8 +126,21 @@ public class PluginDescriptorFilesGeneratorTest
 
         assertNotNull( mojoDescriptor.isDependencyResolutionRequired() );
 
-        // check the parameter.
+        // check the default parameter
         checkParameter( mojoDescriptor.getParameters().get( 0 ) );
+
+        // check another parameter with generics type information
+        Parameter parameterWithGenerics = mojoDescriptor.getParameters().get( 
2 );
+        assertNotNull( parameterWithGenerics );
+        assertEquals( "parameterWithGenerics", parameterWithGenerics.getName() 
);
+        assertEquals( "java.util.Collection", parameterWithGenerics.getType() 
);
+
+        PlexusConfiguration configurations = 
mojoDescriptor.getMojoConfiguration();
+        assertNotNull( configurations );
+        PlexusConfiguration configuration = configurations.getChild( 
"parameterWithGenerics" );
+        assertEquals( "java.util.Collection", configuration.getAttribute( 
"implementation" ) );
+        assertEquals( "a,b,c", configuration.getAttribute( "default-value") );
+        assertEquals( "${customParam}", configuration.getValue() );
     }
 
     private void checkParameter( Parameter parameter )

Reply via email to