mirror of https://github.com/apache/maven.git
o Refactored code
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@901701 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2b1d264d31
commit
04983c0111
|
@ -24,7 +24,6 @@ import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -62,6 +61,7 @@ import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.project.ProjectBuilder;
|
import org.apache.maven.project.ProjectBuilder;
|
||||||
import org.apache.maven.project.ProjectBuildingException;
|
import org.apache.maven.project.ProjectBuildingException;
|
||||||
import org.apache.maven.project.ProjectBuildingRequest;
|
import org.apache.maven.project.ProjectBuildingRequest;
|
||||||
|
import org.apache.maven.properties.internal.EnvironmentUtils;
|
||||||
import org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest;
|
import org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest;
|
||||||
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
|
@ -69,7 +69,6 @@ import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
import org.codehaus.plexus.util.Os;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jason van Zyl
|
* @author Jason van Zyl
|
||||||
|
@ -100,8 +99,6 @@ public class MavenMetadataSource
|
||||||
@Requirement
|
@Requirement
|
||||||
private LegacySupport legacySupport;
|
private LegacySupport legacySupport;
|
||||||
|
|
||||||
private static Properties envVars;
|
|
||||||
|
|
||||||
private void injectSession( MetadataResolutionRequest request )
|
private void injectSession( MetadataResolutionRequest request )
|
||||||
{
|
{
|
||||||
MavenSession session = legacySupport.getSession();
|
MavenSession session = legacySupport.getSession();
|
||||||
|
@ -700,19 +697,7 @@ public class MavenMetadataSource
|
||||||
{
|
{
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
|
|
||||||
if ( envVars == null )
|
EnvironmentUtils.addEnvVars( props );
|
||||||
{
|
|
||||||
Properties tmp = new Properties();
|
|
||||||
boolean caseSensitive = !Os.isFamily( Os.FAMILY_WINDOWS );
|
|
||||||
for ( Map.Entry<String, String> entry : System.getenv().entrySet() )
|
|
||||||
{
|
|
||||||
String key = "env." + ( caseSensitive ? entry.getKey() : entry.getKey().toUpperCase( Locale.ENGLISH ) );
|
|
||||||
tmp.setProperty( key, entry.getValue() );
|
|
||||||
}
|
|
||||||
envVars = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
props.putAll( envVars );
|
|
||||||
|
|
||||||
props.putAll( System.getProperties() );
|
props.putAll( System.getProperties() );
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
package org.apache.maven.properties.internal;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.codehaus.plexus.util.Os;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assists the project builder. <strong>Warning:</strong> This is an internal utility class that is only public for
|
||||||
|
* technical reasons, it is not part of the public API. In particular, this class can be changed or deleted without
|
||||||
|
* prior notice.
|
||||||
|
*
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
public class EnvironmentUtils
|
||||||
|
{
|
||||||
|
|
||||||
|
private static Properties envVars;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the environment variables in the form of properties whose keys are prefixed with {@code env.}, e.g. {@code
|
||||||
|
* env.PATH}. Unlike native environment variables, properties are always case-sensitive. For the sake of
|
||||||
|
* determinism, the environment variable names will be normalized to upper case on platforms with case-insensitive
|
||||||
|
* variable lookup.
|
||||||
|
*
|
||||||
|
* @param props The properties to add the environment variables to, may be {@code null}.
|
||||||
|
*/
|
||||||
|
public static void addEnvVars( Properties props )
|
||||||
|
{
|
||||||
|
if ( props != null )
|
||||||
|
{
|
||||||
|
if ( envVars == null )
|
||||||
|
{
|
||||||
|
Properties tmp = new Properties();
|
||||||
|
boolean caseSensitive = !Os.isFamily( Os.FAMILY_WINDOWS );
|
||||||
|
for ( Map.Entry<String, String> entry : System.getenv().entrySet() )
|
||||||
|
{
|
||||||
|
String key =
|
||||||
|
"env." + ( caseSensitive ? entry.getKey() : entry.getKey().toUpperCase( Locale.ENGLISH ) );
|
||||||
|
tmp.setProperty( key, entry.getValue() );
|
||||||
|
}
|
||||||
|
envVars = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
props.putAll( envVars );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -22,7 +22,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
@ -40,6 +39,7 @@ import org.apache.maven.execution.MavenExecutionResult;
|
||||||
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||||
import org.apache.maven.model.building.ModelProcessor;
|
import org.apache.maven.model.building.ModelProcessor;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.apache.maven.properties.internal.EnvironmentUtils;
|
||||||
import org.apache.maven.repository.ArtifactTransferListener;
|
import org.apache.maven.repository.ArtifactTransferListener;
|
||||||
import org.apache.maven.settings.building.DefaultSettingsBuildingRequest;
|
import org.apache.maven.settings.building.DefaultSettingsBuildingRequest;
|
||||||
import org.apache.maven.settings.building.SettingsBuilder;
|
import org.apache.maven.settings.building.SettingsBuilder;
|
||||||
|
@ -52,7 +52,6 @@ import org.codehaus.plexus.DefaultPlexusContainer;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.classworlds.ClassWorld;
|
import org.codehaus.plexus.classworlds.ClassWorld;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
import org.codehaus.plexus.util.Os;
|
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
import org.sonatype.plexus.components.cipher.DefaultPlexusCipher;
|
import org.sonatype.plexus.components.cipher.DefaultPlexusCipher;
|
||||||
import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;
|
import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;
|
||||||
|
@ -898,14 +897,7 @@ public class MavenCli
|
||||||
|
|
||||||
static void populateProperties( CommandLine commandLine, Properties systemProperties, Properties userProperties )
|
static void populateProperties( CommandLine commandLine, Properties systemProperties, Properties userProperties )
|
||||||
{
|
{
|
||||||
// add the env vars to the property set, with the "env." prefix
|
EnvironmentUtils.addEnvVars( systemProperties );
|
||||||
// XXX support for env vars should probably be removed from the ModelInterpolator
|
|
||||||
boolean caseSensitive = !Os.isFamily( Os.FAMILY_WINDOWS );
|
|
||||||
for ( Map.Entry<String, String> entry : System.getenv().entrySet() )
|
|
||||||
{
|
|
||||||
String key = "env." + ( caseSensitive ? entry.getKey() : entry.getKey().toUpperCase( Locale.ENGLISH ) );
|
|
||||||
systemProperties.setProperty( key, entry.getValue() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Options that are set on the command line become system properties
|
// Options that are set on the command line become system properties
|
||||||
|
|
Loading…
Reference in New Issue