From 0a36e611f24ca05f72d4547e2d6ab9364ac63ebd Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Sun, 2 Sep 2007 23:21:23 +0000 Subject: [PATCH] o turn on envar support in 2.1, we just can't turn it off now at this point. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@572190 13f79535-47bb-0310-9956-ffa450edef68 --- .../interpolation/RegexBasedModelInterpolator.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java b/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java index b3ad3175b5..a93b7e623e 100644 --- a/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java +++ b/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java @@ -25,15 +25,15 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.introspection.ReflectionValueExtractor; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; -import java.util.HashSet; import java.util.Map; -import java.util.Set; +import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -50,9 +50,12 @@ public class RegexBasedModelInterpolator { private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{(pom\\.|project\\.|env\\.)?([^}]+)\\}" ); + private Properties envars; + public RegexBasedModelInterpolator() throws IOException { + envars = CommandLineUtils.getSystemEnvVars(); } public Model interpolate( Model model, Map context ) @@ -181,6 +184,11 @@ public class RegexBasedModelInterpolator value = model.getProperties().getProperty( realExpr ); } + if ( value == null ) + { + value = envars.getProperty( realExpr ); + } + // Any expression, not just artifactId, version etc., but also scm.repository // were evaluated against the model, even if there is no prefix. // If the 2.1 strategy fails, try the legacy approach. If it yields a result, warn for it. @@ -213,6 +221,8 @@ public class RegexBasedModelInterpolator // but this could result in multiple lookups of stringValue, and replaceAll is not correct behaviour matcher.reset( result ); } + + /* // This is the desired behaviour, however there are too many crappy poms in the repo and an issue with the // timing of executing the interpolation