mirror of https://github.com/apache/maven.git
o merged from r609944 (MNG-2848: Environment variables in profile activation not working)
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@609945 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ff35d87011
commit
e75b388cb0
|
@ -4,12 +4,16 @@ import org.apache.commons.cli.CommandLine;
|
|||
import org.apache.maven.MavenTransferListener;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.codehaus.plexus.util.cli.CommandLineUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public final class CLIRequestUtils
|
||||
{
|
||||
|
@ -225,10 +229,27 @@ public final class CLIRequestUtils
|
|||
// System properties handling
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private static Properties getExecutionProperties( CommandLine commandLine )
|
||||
static Properties getExecutionProperties( CommandLine commandLine )
|
||||
{
|
||||
Properties executionProperties = new Properties();
|
||||
|
||||
// add the env vars to the property set, with the "env." prefix
|
||||
// XXX support for env vars should probably be removed from the ModelInterpolator
|
||||
try
|
||||
{
|
||||
Properties envVars = CommandLineUtils.getSystemEnvVars();
|
||||
Iterator i = envVars.entrySet().iterator();
|
||||
while ( i.hasNext() )
|
||||
{
|
||||
Entry e = (Entry) i.next();
|
||||
executionProperties.setProperty( "env." + e.getKey().toString(), e.getValue().toString() );
|
||||
}
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
System.err.println( "Error getting environment vars for profile activation: " + e );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Options that are set on the command line become system properties
|
||||
// and therefore are set in the session properties. System properties
|
||||
|
@ -276,13 +297,5 @@ public final class CLIRequestUtils
|
|||
}
|
||||
|
||||
executionProperties.setProperty( name, value );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// I'm leaving the setting of system properties here as not to break
|
||||
// the SystemPropertyProfileActivator. This won't harm embedding. jvz.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
System.setProperty( name, value );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,4 +44,27 @@ public class CLIRequestUtilsTest
|
|||
assertTrue( ( goals == null ) || goals.isEmpty() );
|
||||
}
|
||||
|
||||
public void testGetExecutionProperties()
|
||||
throws Exception
|
||||
{
|
||||
System.setProperty( "test.property.1", "1.0" );
|
||||
System.setProperty( "test.property.2", "2.0" );
|
||||
Properties p = CLIRequestUtils.getExecutionProperties( new CLIManager().parse( new String[] {
|
||||
"-Dtest.property.2=2.1",
|
||||
"-Dtest.property.3=3.0" } ) );
|
||||
|
||||
// assume that everybody has a PATH env var
|
||||
String envPath = p.getProperty( "env.PATH" );
|
||||
if ( envPath == null )
|
||||
{
|
||||
envPath = p.getProperty( "env.Path" );
|
||||
}
|
||||
assertNotNull( envPath );
|
||||
|
||||
assertEquals( "1.0", p.getProperty( "test.property.1" ) );
|
||||
assertEquals( "3.0", p.getProperty( "test.property.3" ) );
|
||||
|
||||
// sys props should override cmdline props
|
||||
assertEquals( "2.0", p.getProperty( "test.property.2" ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue