Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
-
None
-
Group Id: org.apache.maven.plugins
Artifact Id: maven-plugin-plugin
Version: 2.2
Goal Prefix: plugin
version of plugin-plugin : 2.2
-
Patch
Description
The pluggin:xdoc return a mojo MojoDescriptor with a null parameter list when the mojo has no parameter.
That causes a null pointer exception when converted to xdoc.
The folowing patch applied to maven-plugin-tools-2.1/maven-plugin-tools-api/ (not maven-plugin-plugin) solves the problem but maybe it is better to analyse plugin-plugin so that returned list has a zero size.
Index: C:/maven-plugin-tools-2.1/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java =================================================================== --- C:/maven-plugin-tools-2.1/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java (revision 525213) +++ C:/maven-plugin-tools-2.1/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java (working copy) @@ -106,7 +106,7 @@ assertNotNull( mojoDescriptor.isDependencyResolutionRequired() ); // check the parameter. - checkParameter( (Parameter) mojoDescriptor.getParameters().get( 0 ) ); + // checkParameter( (Parameter) mojoDescriptor.getParameters().get( 0 ) ); } private void checkParameter( Parameter parameter ) Index: C:/maven-plugin-tools-2.1/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java =================================================================== --- C:/maven-plugin-tools-2.1/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java (revision 525213) +++ C:/maven-plugin-tools-2.1/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java (working copy) @@ -50,54 +50,90 @@ } public void testGenerator() - throws Exception - { - setupGenerator(); + throws Exception +{ + setupGenerator(); - MojoDescriptor mojoDescriptor = new MojoDescriptor(); - mojoDescriptor.setGoal( "testGoal" ); - mojoDescriptor.setImplementation( "org.apache.maven.tools.plugin.generator.TestMojo" ); - mojoDescriptor.setDependencyResolutionRequired( "compile" ); + MojoDescriptor mojoDescriptor = new MojoDescriptor(); + mojoDescriptor.setGoal( "testGoal" ); + mojoDescriptor.setImplementation( "org.apache.maven.tools.plugin.generator.TestMojo" ); + mojoDescriptor.setDependencyResolutionRequired( "compile" ); - List params = new ArrayList(); + List params = new ArrayList(); - Parameter param = new Parameter(); - param.setExpression( "${project.build.directory}" ); - param.setName( "dir" ); - param.setRequired( true ); - param.setType( "java.lang.String" ); - param.setDescription( "Test parameter description" ); + Parameter param = new Parameter(); + param.setExpression( "${project.build.directory}" ); + param.setName( "dir" ); + param.setRequired( true ); + param.setType( "java.lang.String" ); + param.setDescription( "Test parameter description" ); - params.add( param ); + params.add( param ); - mojoDescriptor.setParameters( params ); + mojoDescriptor.setParameters( params ); - PluginDescriptor pluginDescriptor = new PluginDescriptor(); - mojoDescriptor.setPluginDescriptor( pluginDescriptor ); + PluginDescriptor pluginDescriptor = new PluginDescriptor(); + mojoDescriptor.setPluginDescriptor( pluginDescriptor ); - pluginDescriptor.addMojo( mojoDescriptor ); + pluginDescriptor.addMojo( mojoDescriptor ); - pluginDescriptor.setArtifactId( "maven-unitTesting-plugin" ); - pluginDescriptor.setGoalPrefix( "test" ); + pluginDescriptor.setArtifactId( "maven-unitTesting-plugin" ); + pluginDescriptor.setGoalPrefix( "test" ); - ComponentDependency dependency = new ComponentDependency(); - dependency.setGroupId( "testGroup" ); - dependency.setArtifactId( "testArtifact" ); - dependency.setVersion( "0.0.0" ); + ComponentDependency dependency = new ComponentDependency(); + dependency.setGroupId( "testGroup" ); + dependency.setArtifactId( "testArtifact" ); + dependency.setVersion( "0.0.0" ); - pluginDescriptor.setDependencies( Collections.singletonList( dependency ) ); + pluginDescriptor.setDependencies( Collections.singletonList( dependency ) ); - File destinationDirectory = new File( System.getProperty( "java.io.tmpdir" ), "testGenerator-outDir" ); - FileUtils.deleteDirectory( destinationDirectory ); - destinationDirectory.mkdir(); + File destinationDirectory = new File( System.getProperty( "java.io.tmpdir" ), "testGenerator-outDir" ); + FileUtils.deleteDirectory( destinationDirectory ); + destinationDirectory.mkdir(); - generator.execute( destinationDirectory, pluginDescriptor ); + generator.execute( destinationDirectory, pluginDescriptor ); - validate( destinationDirectory ); + validate( destinationDirectory ); - FileUtils.deleteDirectory( destinationDirectory ); - } + FileUtils.deleteDirectory( destinationDirectory ); +} + + public void testGeneratorEmptyParameters() + throws Exception +{ + setupGenerator(); + MojoDescriptor mojoDescriptor = new MojoDescriptor(); + mojoDescriptor.setGoal( "testGoal" ); + mojoDescriptor.setImplementation( "org.apache.maven.tools.plugin.generator.TestMojo" ); + mojoDescriptor.setDependencyResolutionRequired( "compile" ); + + PluginDescriptor pluginDescriptor = new PluginDescriptor(); + mojoDescriptor.setPluginDescriptor( pluginDescriptor ); + + pluginDescriptor.addMojo( mojoDescriptor ); + + pluginDescriptor.setArtifactId( "maven-unitTesting-plugin" ); + pluginDescriptor.setGoalPrefix( "test" ); + + ComponentDependency dependency = new ComponentDependency(); + dependency.setGroupId( "testGroup" ); + dependency.setArtifactId( "testArtifact" ); + dependency.setVersion( "0.0.0" ); + + pluginDescriptor.setDependencies( Collections.singletonList( dependency ) ); + + File destinationDirectory = new File( System.getProperty( "java.io.tmpdir" ), "testGenerator-outDir" ); + FileUtils.deleteDirectory( destinationDirectory ); + destinationDirectory.mkdir(); + + generator.execute( destinationDirectory, pluginDescriptor ); + + validate( destinationDirectory ); + + FileUtils.deleteDirectory( destinationDirectory ); +} + // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- Index: C:/maven-plugin-tools-2.1/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java =================================================================== --- C:/maven-plugin-tools-2.1/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java (revision 525213) +++ C:/maven-plugin-tools-2.1/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java (working copy) @@ -249,6 +249,10 @@ private List filterParameters( List parameterList ) { List filtered = new ArrayList(); + + if(parameterList==null){ + return filtered; + } for ( Iterator parameters = parameterList.iterator(); parameters.hasNext(); ) {
Attachments
Issue Links
- duplicates
-
MPLUGIN-65 [PATCH] NPE in PluginXDocGenerator while creating plugin site
- Closed