Author: gboue Date: Sat Nov 5 15:49:26 2016 New Revision: 1768231 URL: http://svn.apache.org/viewvc?rev=1768231&view=rev Log: [MPH-119] The "artifact" parameter is not taken into account with Maven 3
Starting with Maven 3, PluginParameterExpressionEvaluator ignores the project given as parameter in its 6-args constructor, and fetches instead the current project from the Maven session. As such, the plugin needs to set the fake project created through the "artifact" parameter as the session current project, and put back the real one after construction of the evaluator. Added: maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/ maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/pom.xml (with props) maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/test.properties (with props) maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/verify.groovy (with props) Modified: maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java Added: maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/pom.xml?rev=1768231&view=auto ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/pom.xml (added) +++ maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/pom.xml Sat Nov 5 15:49:26 2016 @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<project> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.its.help</groupId> + <artifactId>test</artifactId> + <version>1.0</version> + <name>Maven Foo Bar</name> + <description>https://issues.apache.org/jira/browse/MPH-114</description> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-help-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <id>its</id> + <goals> + <goal>evaluate</goal> + </goals> + <phase>package</phase> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <version>1.4.1</version> + <executions> + <execution> + <id>enforce-currentproject</id> + <goals> + <goal>enforce</goal> + </goals> + <phase>package</phase> + <configuration> + <rules> + <evaluateBeanshell> + <!-- + Makes sure that the session contains the right currentProject (i.e. the Maven project being built), + and not the fake Maven project created with the "artifact" parameter. + --> + <condition>${session.currentProject.artifactId} == test</condition> + </evaluateBeanshell> + </rules> + <fail>true</fail> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/test.properties URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/test.properties?rev=1768231&view=auto ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/test.properties (added) +++ maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/test.properties Sat Nov 5 15:49:26 2016 @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +expression = project.name +output = result.txt +artifact = org.apache.maven.plugins:maven-help-plugin Propchange: maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/test.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/test.properties ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/verify.groovy URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/verify.groovy?rev=1768231&view=auto ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/verify.groovy (added) +++ maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/verify.groovy Sat Nov 5 15:49:26 2016 @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def result = new File(basedir, 'result.txt').text; +assert result == 'Apache Maven Help Plugin' + +return true; Propchange: maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/verify.groovy ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-help-plugin/src/it/evaluate-artifact-with-expression-with-output/verify.groovy ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java?rev=1768231&r1=1768230&r2=1768231&view=diff ============================================================================== --- maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java (original) +++ maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java Sat Nov 5 15:49:26 2016 @@ -154,7 +154,7 @@ public class EvaluateMojo protected ArtifactRepository localRepository; /** - * The current Maven project or the super pom. + * Maven project built from the given {@link #artifact}. Otherwise, the current Maven project or the super pom. */ @Parameter( defaultValue = "${project}", readonly = true, required = true ) protected MavenProject project; @@ -359,10 +359,18 @@ public class EvaluateMojo MojoDescriptor mojoDescriptor = HelpUtil.getMojoDescriptor( "help:evaluate", session, project, "help:evaluate", true, false ); MojoExecution mojoExecution = new MojoExecution( mojoDescriptor ); - evaluator = - new PluginParameterExpressionEvaluator( session, mojoExecution, pathTranslator, - loggerRetriever.getLogger(), project, - session.getExecutionProperties() ); + + MavenProject currentProject = session.getCurrentProject(); + // Maven3: PluginParameterExpressionEvaluator ignores the project parameter and gets the current project + // from the session: synchronize in case another thread wants to fetch the real current project in between + synchronized ( session ) + { + session.setCurrentProject( project ); + evaluator = new PluginParameterExpressionEvaluator( session, mojoExecution, pathTranslator, + loggerRetriever.getLogger(), project, + session.getExecutionProperties() ); + session.setCurrentProject( currentProject ); + } } return evaluator;