From d84b1eb2dc10f76e81a2c47399fd3192701408f9 Mon Sep 17 00:00:00 2001 From: Mark Donszelmann Date: Sat, 17 Oct 2009 23:22:39 +0200 Subject: More fix for NAR-25; System env passed when not given in NarUtil --- .../java/org/apache/maven/plugin/nar/NarUtil.java | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/org/apache/maven/plugin/nar/NarUtil.java b/src/main/java/org/apache/maven/plugin/nar/NarUtil.java index c65f3e6..4aad1fe 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarUtil.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarUtil.java @@ -28,6 +28,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Vector; import java.util.regex.Pattern; import org.apache.bcel.classfile.ClassFormatException; @@ -39,6 +40,7 @@ import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.PropertyUtils; import org.codehaus.plexus.util.cli.CommandLineException; +import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; /** @@ -461,10 +463,42 @@ public class NarUtil extends Commandline { // Override this method to prevent addition (and obstruction) of system env variables + // but (for now) add them when no envVars are given. + + // NOTE and FIXME: we need to properly put system variables in there + // mixed (overridden) by our own. public String[] getEnvironmentVariables() throws CommandLineException { - return (String[]) envVars.toArray( new String[envVars.size()] ); + if ( envVars.size() == 0 ) + { + try + { + Vector systemEnvVars = getSystemEnvironment(); + return (String[]) systemEnvVars.toArray( new String[systemEnvVars.size()] ); + } + catch ( IOException e ) + { + throw new CommandLineException( "Error setting up environmental variables", e ); + } + } + else + { + return (String[]) envVars.toArray( new String[envVars.size()] ); + } + } + + private Vector getSystemEnvironment() throws IOException { + Properties envVars = CommandLineUtils.getSystemEnvVars(); + Vector systemEnvVars = new Vector(envVars.size()); + + for ( Iterator i = envVars.keySet().iterator(); i.hasNext(); ) + { + String key = (String) i.next(); + systemEnvVars.add( key + "=" + envVars.getProperty( key ) ); + } + + return systemEnvVars; } } -- cgit v1.2.3