diff --git a/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/Bla.java b/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/Bla.java new file mode 100644 index 0000000000..98f472755e --- /dev/null +++ b/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/Bla.java @@ -0,0 +1,7 @@ +package org.apache.maven.plugin.coreit; + +/** + */ +public interface Bla +{ +} diff --git a/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/ParameterImplementationMojo.java b/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/ParameterImplementationMojo.java new file mode 100644 index 0000000000..40cfad5901 --- /dev/null +++ b/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/ParameterImplementationMojo.java @@ -0,0 +1,42 @@ +package org.apache.maven.plugin.coreit; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; + +/** + * Check that we correctly use the implementation parameter. See MNG-2293 + * + * @goal param-implementation + * @description Prints out the name of the implementation of the bla field. + */ +public class ParameterImplementationMojo + extends AbstractMojo +{ + + /** + * @parameter implementation="org.apache.maven.plugin.coreit.sub.MyBla" + * @required + */ + private Bla bla; + + /** + * The expected value of bla.toString(). + * + * @parameter + * @required + */ + private String expected; + + public void execute() + throws MojoExecutionException + { + + getLog().info( "bla: " + bla ); + + if ( ! expected.equals( bla.toString() ) ) + { + throw new MojoExecutionException( "Expected '" + expected + "'; found '" + bla + "'" ); + } + } + +} diff --git a/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/sub/MyBla.java b/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/sub/MyBla.java new file mode 100644 index 0000000000..b4328404df --- /dev/null +++ b/integration-tests/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/sub/MyBla.java @@ -0,0 +1,26 @@ +package org.apache.maven.plugin.coreit.sub; + +import org.apache.maven.plugin.coreit.Bla; + +/** + */ +public class MyBla + implements Bla +{ + private String field; + + public String getField() + { + return field; + } + + public void setField( String field ) + { + this.field = field; + } + + public String toString() + { + return getClass() + "-" + field; + } +} diff --git a/maven-core-it/README.txt b/maven-core-it/README.txt index 53679a25bf..0bf975244f 100644 --- a/maven-core-it/README.txt +++ b/maven-core-it/README.txt @@ -1,3 +1,11 @@ +Notes: +- today, 3 sets of integration tests, categorized by their ids (it0xxx, it1xxx, it2xxx). + see below for what these groups represent +- creating a new test: + - you can add mojos to the integration-tests plugins/maven-core-it-plugin + - add log.txt and target to your it test svn ignore list + +Details: ------------------------------------------------------------------------------- it0000: The simplest of builds. We have one application class and one test class. There are no resources, no source generation, no resource @@ -285,6 +293,8 @@ it0104: Verify that plugin configurations are resolved correctly, particularly when they contain ${project.build.directory} in the string value of a Map.Entry. +it0107: Verify that default implementation of an implementation for a complex object works as + expected [MNG-2293] ------------------------------------------------------------------------------- - generated sources diff --git a/maven-core-it/integration-tests.txt b/maven-core-it/integration-tests.txt index dfdb990550..8a200a31bf 100644 --- a/maven-core-it/integration-tests.txt +++ b/maven-core-it/integration-tests.txt @@ -1,3 +1,4 @@ +it0107 #it0104 Commenting out, not fixed until post-2.0.4, due to dependency on new plexus-container-default version. it0103 it0102 diff --git a/maven-core-it/it0107/cli-options.txt b/maven-core-it/it0107/cli-options.txt new file mode 100644 index 0000000000..653774072c --- /dev/null +++ b/maven-core-it/it0107/cli-options.txt @@ -0,0 +1 @@ +-X diff --git a/maven-core-it/it0107/goals.txt b/maven-core-it/it0107/goals.txt new file mode 100644 index 0000000000..1de2cfeb84 --- /dev/null +++ b/maven-core-it/it0107/goals.txt @@ -0,0 +1 @@ +core-it:param-implementation diff --git a/maven-core-it/it0107/pom.xml b/maven-core-it/it0107/pom.xml new file mode 100644 index 0000000000..cc41c3cfdf --- /dev/null +++ b/maven-core-it/it0107/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + org.apache.maven + maven-core-it0107 + pom + 3.8.1 + + + + maven-core-it-plugin + 1.1-SNAPSHOT + + param-implementation + + + foobar + class org.apache.maven.plugin.coreit.sub.MyBla-foobar + + + + + diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index a756d6b730..417c7b8784 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -872,6 +872,7 @@ public class DefaultPluginManager String paramName = parameter.getName(); String alias = parameter.getAlias(); + String implementation = parameter.getImplementation(); PlexusConfiguration pomConfig = fromPom.getChild( paramName ); PlexusConfiguration aliased = null; @@ -895,7 +896,7 @@ public class DefaultPluginManager pomConfig = buildTopDownMergedConfiguration( pomConfig, aliased ); } - boolean addedPomConfig = false; + PlexusConfiguration toAdd = null; if ( pomConfig != null ) { @@ -903,15 +904,29 @@ public class DefaultPluginManager if ( StringUtils.isNotEmpty( pomConfig.getValue( null ) ) || pomConfig.getChildCount() > 0 ) { - result.addChild( pomConfig ); - - addedPomConfig = true; + toAdd = pomConfig; } } - if ( !addedPomConfig && mojoConfig != null ) + if ( toAdd == null && mojoConfig != null ) { - result.addChild( copyConfiguration( mojoConfig ) ); + toAdd = copyConfiguration( mojoConfig ); + } + + if ( toAdd != null ) + { + if ( implementation != null + && toAdd.getAttribute( "implementation", null ) == null ) + { + + XmlPlexusConfiguration implementationConf = new XmlPlexusConfiguration( paramName ); + + implementationConf.setAttribute( "implementation", parameter.getImplementation() ); + + toAdd = buildTopDownMergedConfiguration( toAdd, implementationConf ); + } + + result.addChild( toAdd ); } } } diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java index 9ae716673f..03bbbc4e12 100644 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/Parameter.java @@ -40,6 +40,8 @@ public class Parameter private String defaultValue; + private String implementation; + private Requirement requirement; // ---------------------------------------------------------------------- @@ -160,4 +162,14 @@ public class Parameter { this.requirement = requirement; } + + public String getImplementation() + { + return implementation; + } + + public void setImplementation( String implementation ) + { + this.implementation = implementation; + } } diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java index ee3bdf0f00..d8a0539a0e 100755 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java @@ -250,6 +250,8 @@ public class PluginDescriptorBuilder parameter.setDeprecated( d.getChild( "deprecated" ).getValue() ); + parameter.setImplementation( d.getChild( "implementation" ).getValue() ); + parameters.add( parameter ); } 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 61f3383584..ce6c6c6d2e 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 @@ -335,6 +335,11 @@ public class PluginDescriptorGenerator element( w, "deprecated", parameter.getDeprecated() ); } + if ( parameter.getImplementation() != null ) + { + element( w, "implementation", parameter.getImplementation() ); + } + element( w, "required", Boolean.toString( parameter.isRequired() ) ); element( w, "editable", Boolean.toString( parameter.isEditable() ) ); 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 f72ef23cfa..4c074a2f3c 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 @@ -59,6 +59,11 @@ public class JavaMojoDescriptorExtractor public static final String PARAMETER_DEFAULT_VALUE = "default-value"; + /** + * This defines the default implementation in the case the parameter type is an interface. + */ + public static final String PARAMETER_IMPLEMENTATION = "implementation"; + /** * This indicates the base name of the bean properties used to read/write this parameter's value. * So: @@ -422,6 +427,9 @@ public class JavaMojoDescriptorExtractor } pd.setDefaultValue( parameter.getNamedParameter( PARAMETER_DEFAULT_VALUE ) ); + + pd.setImplementation( parameter.getNamedParameter( PARAMETER_IMPLEMENTATION ) ); + } mojoDescriptor.addParameter( pd ); diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java b/maven-plugin-tools/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java index 6a2f4b405e..dbcbb63788 100644 --- a/maven-plugin-tools/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java +++ b/maven-plugin-tools/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java @@ -19,12 +19,16 @@ package org.apache.maven.tools.plugin.extractor.java; import junit.framework.TestCase; import org.apache.maven.model.Model; import org.apache.maven.project.MavenProject; +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.PluginDescriptor; import java.io.File; import java.net.URL; import java.util.List; +import source2.sub.MyBla; + /** * @author jdcasey */ @@ -56,6 +60,40 @@ public class JavaMojoDescriptorExtractorTest assertEquals( 2, results.size() ); } + public void testShouldPropagateImplementationParameter() + throws Exception + { + JavaMojoDescriptorExtractor extractor = new JavaMojoDescriptorExtractor(); + + File sourceFile = fileOf( "dir-flag.txt" ); + System.out.println( "found source file: " + sourceFile ); + + File dir = sourceFile.getParentFile(); + + Model model = new Model(); + model.setArtifactId( "maven-unitTesting-plugin" ); + + MavenProject project = new MavenProject( model ); + + project.setFile( new File( dir, "pom.xml" ) ); + project.addCompileSourceRoot( new File( dir, "source2" ).getPath() ); + + PluginDescriptor pluginDescriptor = new PluginDescriptor(); + pluginDescriptor.setGoalPrefix( "test" ); + List results = extractor.execute( project, pluginDescriptor ); + assertEquals( 1, results.size() ); + + MojoDescriptor mojoDescriptor = (MojoDescriptor) results.get( 0 ); + + List parameters = mojoDescriptor.getParameters(); + + assertEquals( 1, parameters.size() ); + + Parameter parameter = (Parameter) parameters.get( 0 ); + + assertEquals( MyBla.class.getName(), parameter.getImplementation() ); + } + private File fileOf( String classpathResource ) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); @@ -70,4 +108,4 @@ public class JavaMojoDescriptorExtractorTest return result; } -} \ No newline at end of file +} diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/test/resources/source2/Bla.java b/maven-plugin-tools/maven-plugin-tools-java/src/test/resources/source2/Bla.java new file mode 100644 index 0000000000..c8b7b07eba --- /dev/null +++ b/maven-plugin-tools/maven-plugin-tools-java/src/test/resources/source2/Bla.java @@ -0,0 +1,5 @@ +package source2; + +public interface Bla +{ +} diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/test/resources/source2/JavaExtractorTestThree.java b/maven-plugin-tools/maven-plugin-tools-java/src/test/resources/source2/JavaExtractorTestThree.java new file mode 100644 index 0000000000..2a9b6ae1cc --- /dev/null +++ b/maven-plugin-tools/maven-plugin-tools-java/src/test/resources/source2/JavaExtractorTestThree.java @@ -0,0 +1,31 @@ +package source2; + +import org.apache.maven.plugin.AbstractMojo; + +/** + * Tests the implementation argument of the parameter annotation. + * + * @goal ideaThree + * @requiresDependencyResolution compile + */ +public class JavaExtractorTestThree + extends AbstractMojo +{ + /** + * @parameter implementation=source2.sub.MyBla + * @required + */ + private Bla bla; + + public JavaExtractorTestThree() + { + } + + public void execute() + { + if ( getLog() != null ) + { + getLog().info( "bla: " + bla ); + } + } +} diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/test/resources/source2/sub/MyBla.java b/maven-plugin-tools/maven-plugin-tools-java/src/test/resources/source2/sub/MyBla.java new file mode 100644 index 0000000000..45b05bc08b --- /dev/null +++ b/maven-plugin-tools/maven-plugin-tools-java/src/test/resources/source2/sub/MyBla.java @@ -0,0 +1,8 @@ +package source2.sub; + +import source2.Bla; + +public class MyBla + implements Bla +{ +} diff --git a/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java b/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java index 87de0ff8e2..e79b29f8e4 100644 --- a/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java @@ -216,7 +216,7 @@ public class DefaultModelValidatorTest private ModelValidationResult validate( String testName ) throws Exception { - Reader input = new FileReader( getFileForClasspathResource( "/validation/" + testName ) ); + Reader input = new FileReader( getFileForClasspathResource( "validation/" + testName ) ); MavenXpp3Reader reader = new MavenXpp3Reader();