From ea1009973e45c65c4e814f4d73c890f83202f746 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Mon, 9 Aug 2004 18:40:50 +0000 Subject: [PATCH] o interpolate System properties into the maven.properties values git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@162917 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/maven/it/Verifier.java | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java b/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java index e9fc79fc7d..b751330cb9 100644 --- a/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java +++ b/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java @@ -8,6 +8,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.net.URL; import java.util.Properties; +import java.util.Iterator; +import java.util.Map; /** * @author Jason van Zyl @@ -28,21 +30,51 @@ public class Verifier // // ---------------------------------------------------------------------- + public static String interpolate( String text, Map namespace ) + { + Iterator keys = namespace.keySet().iterator(); + + while ( keys.hasNext() ) + { + String key = keys.next().toString(); + + Object obj = namespace.get( key ); + + String value = obj.toString(); + + text = replace( text, "${" + key + "}", value ); + + if ( key.indexOf( " " ) == -1 ) + { + text = replace( text, "$" + key, value ); + } + } + return text; + } + public void verify() throws VerificationException { - Properties mavenProperties = new Properties(); + Properties properties = new Properties(); try { - mavenProperties.load( new FileInputStream( new File( System.getProperty( "user.home" ), "maven.properties" ) ) ); + properties.load( new FileInputStream( new File( System.getProperty( "user.home" ), "maven.properties" ) ) ); + + for ( Iterator i = properties.keySet().iterator(); i.hasNext(); ) + { + String key = (String) i.next(); + + properties.setProperty( key, interpolate( properties.getProperty( key ), System.getProperties() ) ); + } + } catch ( IOException e ) { throw new VerificationException( "Can't find the maven.properties file! Verification can't proceed!" ); } - mavenRepoLocal = mavenProperties.getProperty( "maven.repo.local" ); + mavenRepoLocal = properties.getProperty( "maven.repo.local" ); try {