From 5c848ce17a0d02a0cb61b14e2739e14b6cf5f843 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Thu, 20 Aug 2009 18:17:26 +0000 Subject: [PATCH] [MNG-4312] Magic expressions injected by PluginParameterExpressionEvalutor conflict with expressions used by plugins to access system properties git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@806286 13f79535-47bb-0310-9956-ffa450edef68 --- .../PluginParameterExpressionEvaluator.java | 23 +++++++++++++++++-- pom.xml | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) 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 2acbf350c9..8739f9fd89 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 @@ -28,7 +28,7 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.path.PathTranslator; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; +import org.codehaus.plexus.component.configurator.expression.TypeAwareExpressionEvaluator; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.introspection.ReflectionValueExtractor; @@ -36,7 +36,7 @@ * @author Jason van Zyl */ public class PluginParameterExpressionEvaluator - implements ExpressionEvaluator + implements TypeAwareExpressionEvaluator { private MavenSession session; @@ -94,6 +94,12 @@ public PluginParameterExpressionEvaluator( MavenSession session, MojoExecution m public Object evaluate( String expr ) throws ExpressionEvaluationException + { + return evaluate( expr, null ); + } + + public Object evaluate( String expr, Class type ) + throws ExpressionEvaluationException { Object value = null; @@ -295,6 +301,19 @@ else if ( expression.startsWith( "basedir" ) ) } } + /* + * MNG-4312: We neither have reserved all of the above magic expressions nor is their set fixed/well-known (it + * gets occasionally extended by newer Maven versions). This imposes the risk for existing plugins to + * unintentionally use such a magic expression for an ordinary system property. So here we check whether we + * ended up with a magic value that is not compatible with the type of the configured mojo parameter (a string + * could still be converted by the configurator so we leave those alone). If so, back off to evaluating the + * expression from properties only. + */ + if ( value != null && type != null && !( value instanceof String ) && !type.isInstance( value ) ) + { + value = null; + } + if ( value == null ) { // The CLI should win for defining properties diff --git a/pom.xml b/pom.xml index 8fcec15816..2eff1cc2f9 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ 1.2 1.2_Java1.3 3.8.2 - 1.1.0 + 1.2.0 1.11 1.0-alpha-1 1.5.15