Skip to content

Commit

Permalink
[MPLUGIN-427] only emit simple parameter type for configuration (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwin authored Oct 26, 2022
1 parent 322a9bb commit 8a76400
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ else if ( type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable()

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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

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;
Expand Down Expand Up @@ -114,14 +115,19 @@ public String getOutputDirectory()
return basedir + "/target";
}
} );

extendPluginDescriptor( pluginDescriptor );
generator.execute( destinationDirectory, new DefaultPluginToolsRequest( mavenProject, pluginDescriptor ) );

validate( destinationDirectory );

FileUtils.deleteDirectory( destinationDirectory );
}

protected void extendPluginDescriptor( PluginDescriptor pluginDescriptor ) throws DuplicateParameterException
{
// may be overwritten
}

// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
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;
Expand All @@ -50,6 +52,17 @@
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
Expand Down Expand Up @@ -113,8 +126,21 @@ private void checkMojo( MojoDescriptor mojoDescriptor )

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 )
Expand Down

0 comments on commit 8a76400

Please sign in to comment.