diff --git a/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java b/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java index 67ce6746b3..fa2869bd56 100644 --- a/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java +++ b/maven-core-it-plugin/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java @@ -22,6 +22,7 @@ import org.apache.maven.plugin.MojoExecutionException; import java.io.IOException; import java.io.File; import java.io.FileWriter; +import java.util.List; /** * @goal touch @@ -39,6 +40,12 @@ public class CoreItMojo */ private String outputDirectory; + /** Test setting of plugin-artifacts on the PluginDescriptor instance. + * @parameter expression="${plugin.artifacts}" + * @required + */ + private List pluginArtifacts; + /** * @parameter expression="target/test-basedir-alignment" */ 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 dd283ff9a8..e088b31673 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 @@ -185,7 +185,6 @@ public class DefaultPluginManager // TODO: this should be possibly outside if ( version == null ) { - Plugin pluginConfig = null; for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext(); ) @@ -299,6 +298,12 @@ public class DefaultPluginManager } container.createChildContainer( pluginKey, files, Collections.EMPTY_MAP, Collections.singletonList( this ) ); + + // this plugin's descriptor should have been discovered by now, so we should be able to circle + // around and set the artifacts. + PluginDescriptor addedPlugin = (PluginDescriptor) pluginDescriptors.get( pluginKey ); + + addedPlugin.setArtifacts( new ArrayList( resolved.values() ) ); } finally { @@ -413,8 +418,11 @@ public class DefaultPluginManager // PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, // mojoDescriptor.getConfiguration() ); - ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator, + ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, + pluginDescriptor, + pathTranslator, getLogger() ); + checkRequiredParameters( mojoDescriptor, mergedConfiguration, expressionEvaluator, plugin ); populatePluginFields( plugin, mojoDescriptor, mergedConfiguration, pluginContainer, expressionEvaluator ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java index d39d13c773..000c569d04 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java @@ -17,6 +17,7 @@ package org.apache.maven.plugin; */ import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.path.PathTranslator; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; @@ -39,9 +40,12 @@ public class PluginParameterExpressionEvaluator private final Logger logger; - public PluginParameterExpressionEvaluator( MavenSession context, PathTranslator pathTranslator, Logger logger ) + private final PluginDescriptor pluginDescriptor; + + public PluginParameterExpressionEvaluator( MavenSession context, PluginDescriptor pluginDescriptor, PathTranslator pathTranslator, Logger logger ) { this.context = context; + this.pluginDescriptor = pluginDescriptor; this.pathTranslator = pathTranslator; this.logger = logger; } @@ -108,6 +112,30 @@ public class PluginParameterExpressionEvaluator e ); } } + else if ( expression.startsWith( "plugin" ) ) + { + try + { + int pathSeparator = expression.indexOf( "/" ); + + if ( pathSeparator > 0 ) + { + String pathExpression = expression.substring( 1, pathSeparator ); + value = ReflectionValueExtractor.evaluate( pathExpression, pluginDescriptor ); + value = value + expression.substring( pathSeparator ); + } + else + { + value = ReflectionValueExtractor.evaluate( expression.substring( 1 ), pluginDescriptor ); + } + } + catch ( Exception e ) + { + // TODO: don't catch exception + throw new ExpressionEvaluationException( "Error evaluating plugin parameter expression: " + expression, + e ); + } + } else if ( "settings".equals( expression ) ) { value = context.getSettings(); diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index 914caa1a4d..01c673dfc1 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -16,12 +16,15 @@ package org.apache.maven.plugin; * limitations under the License. */ +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.monitor.event.DefaultEventDispatcher; +import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; import org.codehaus.plexus.PlexusContainer; @@ -30,6 +33,7 @@ import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator import java.io.File; import java.util.Collections; +import java.util.List; /** * @author Jason van Zyl @@ -53,7 +57,7 @@ public class PluginParameterExpressionEvaluatorTest MavenProject project = new MavenProject( model ); project.setFile( new File( "pom.xml" ).getCanonicalFile() ); - ExpressionEvaluator expressionEvaluator = createExpressionEvaluator( project ); + ExpressionEvaluator expressionEvaluator = createExpressionEvaluator( project, null ); Object value = expressionEvaluator.evaluate( "${project.build.directory}/classes" ); String actual = new File( value.toString() ).getCanonicalPath(); @@ -61,8 +65,7 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( expected, actual ); } - private static MavenSession createSession( MavenProject project, PlexusContainer container, - ArtifactRepository repo ) + private static MavenSession createSession( MavenProject project, PlexusContainer container, ArtifactRepository repo ) { return new MavenSession( project, container, new Settings(), repo, new DefaultEventDispatcher(), Collections.EMPTY_LIST ); @@ -71,7 +74,7 @@ public class PluginParameterExpressionEvaluatorTest public void testLocalRepositoryExtraction() throws Exception { - ExpressionEvaluator expressionEvaluator = createExpressionEvaluator( createDefaultProject() ); + ExpressionEvaluator expressionEvaluator = createExpressionEvaluator( createDefaultProject(), null ); Object value = expressionEvaluator.evaluate( "${localRepository}" ); assertEquals( "local", ( (ArtifactRepository) value ).getId() ); @@ -87,19 +90,43 @@ public class PluginParameterExpressionEvaluatorTest Model model = new Model(); model.setBuild( build ); - ExpressionEvaluator expressionEvaluator = createExpressionEvaluator( new MavenProject( model ) ); + ExpressionEvaluator expressionEvaluator = createExpressionEvaluator( new MavenProject( model ), null ); Object value = expressionEvaluator.evaluate( "${project.build.directory}/${project.build.finalName}" ); assertEquals( "expected-directory/expected-finalName", value ); } + public void testShouldExtractPluginArtifacts() + throws Exception + { + PluginDescriptor pd = new PluginDescriptor(); + + Artifact artifact = new DefaultArtifact( "testGroup", "testArtifact", "1.0", Artifact.SCOPE_COMPILE, "jar" ); + + pd.setArtifacts( Collections.singletonList( artifact ) ); + + ExpressionEvaluator ee = createExpressionEvaluator( createDefaultProject(), pd ); + + Object value = ee.evaluate( "${plugin.artifacts}" ); + + assertTrue( value instanceof List ); + + List artifacts = (List) value; + + assertEquals( 1, artifacts.size() ); + + Artifact result = (Artifact) artifacts.get( 0 ); + + assertEquals( "testGroup", result.getGroupId() ); + } + private MavenProject createDefaultProject() { return new MavenProject( new Model() ); } - private ExpressionEvaluator createExpressionEvaluator( MavenProject project ) + private ExpressionEvaluator createExpressionEvaluator( MavenProject project, PluginDescriptor pluginDescriptor ) throws Exception { ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, @@ -110,8 +137,8 @@ public class PluginParameterExpressionEvaluatorTest PlexusContainer container = getContainer(); MavenSession session = createSession( project, container, repo ); - ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null, - container.getLogger() ); + ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pluginDescriptor, + null, container.getLogger() ); return expressionEvaluator; } } \ No newline at end of file diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java index e081947190..e1d85373c1 100644 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java @@ -40,6 +40,8 @@ public class PluginDescriptor private String source; private boolean inheritedByDefault = true; + + private List artifacts; // ---------------------------------------------------------------------- // @@ -189,6 +191,16 @@ public class PluginDescriptor { this.inheritedByDefault = inheritedByDefault; } + + public List getArtifacts() + { + return artifacts; + } + + public void setArtifacts( List artifacts ) + { + this.artifacts = artifacts; + } public boolean equals( Object object ) {