mirror of https://github.com/apache/maven.git
MNG-5670 guard against ConcurrentModificationException iterating over System properties
Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>
This commit is contained in:
parent
e3000a09c9
commit
8980f67b9b
|
@ -68,6 +68,7 @@ import org.apache.maven.project.ProjectBuilder;
|
|||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.ProjectBuildingRequest;
|
||||
import org.apache.maven.properties.internal.EnvironmentUtils;
|
||||
import org.apache.maven.properties.internal.SystemProperties;
|
||||
import org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest;
|
||||
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
|
@ -752,7 +753,7 @@ public class MavenMetadataSource
|
|||
|
||||
EnvironmentUtils.addEnvVars( props );
|
||||
|
||||
props.putAll( System.getProperties() );
|
||||
SystemProperties.addSystemProperties( props );
|
||||
|
||||
return props;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package org.apache.maven.properties.internal;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @since 3.2.3
|
||||
*/
|
||||
public class SystemProperties
|
||||
{
|
||||
/**
|
||||
* Thread-safe System.properties copy implementation.
|
||||
*
|
||||
* @see http://jira.codehaus.org/browse/MNG-5670
|
||||
*/
|
||||
public static void addSystemProperties( Properties props )
|
||||
{
|
||||
for ( String key : System.getProperties().stringPropertyNames() )
|
||||
{
|
||||
props.put( key, System.getProperty( key ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns System.properties copy.
|
||||
*/
|
||||
public static Properties getSystemProperties()
|
||||
{
|
||||
Properties systemProperties = new Properties();
|
||||
addSystemProperties( systemProperties );
|
||||
return systemProperties;
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.properties.internal.SystemProperties;
|
||||
import org.apache.maven.settings.building.DefaultSettingsBuildingRequest;
|
||||
import org.apache.maven.settings.building.SettingsBuilder;
|
||||
import org.apache.maven.settings.building.SettingsBuildingException;
|
||||
|
@ -71,7 +72,7 @@ public class DefaultMavenSettingsBuilder
|
|||
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
|
||||
request.setUserSettingsFile( userSettingsFile );
|
||||
request.setGlobalSettingsFile( globalSettingsFile );
|
||||
request.setSystemProperties( System.getProperties() );
|
||||
request.setSystemProperties( SystemProperties.getSystemProperties() );
|
||||
return build( request );
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ import org.apache.maven.lifecycle.LifecycleExecutionException;
|
|||
import org.apache.maven.model.building.ModelProcessor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.properties.internal.EnvironmentUtils;
|
||||
import org.apache.maven.properties.internal.SystemProperties;
|
||||
import org.apache.maven.settings.building.DefaultSettingsBuildingRequest;
|
||||
import org.apache.maven.settings.building.SettingsBuilder;
|
||||
import org.apache.maven.settings.building.SettingsBuildingRequest;
|
||||
|
@ -1163,7 +1164,7 @@ public class MavenCli
|
|||
}
|
||||
}
|
||||
|
||||
systemProperties.putAll( System.getProperties() );
|
||||
SystemProperties.addSystemProperties( systemProperties );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Properties containing info about the currently running version of Maven
|
||||
|
|
|
@ -106,7 +106,11 @@ public class DefaultSettingsBuildingRequest
|
|||
if ( systemProperties != null )
|
||||
{
|
||||
this.systemProperties = new Properties();
|
||||
this.systemProperties.putAll( systemProperties );
|
||||
// MNG-5670 guard against ConcurrentModificationException
|
||||
for ( String key : System.getProperties().stringPropertyNames() )
|
||||
{
|
||||
this.systemProperties.put( key, System.getProperty( key ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue