diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index f2fc322b34..1750a7b15a 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -68,6 +68,7 @@ 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 @@ private Properties getSystemProperties() EnvironmentUtils.addEnvVars( props ); - props.putAll( System.getProperties() ); + SystemProperties.addSystemProperties( props ); return props; } diff --git a/maven-core/src/main/java/org/apache/maven/properties/internal/SystemProperties.java b/maven-core/src/main/java/org/apache/maven/properties/internal/SystemProperties.java new file mode 100644 index 0000000000..9cb07c4d12 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/properties/internal/SystemProperties.java @@ -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; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java b/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java index f11c4418fd..820d886e29 100644 --- a/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java @@ -23,6 +23,7 @@ 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 Settings buildSettings( File userSettingsFile ) SettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); request.setUserSettingsFile( userSettingsFile ); request.setGlobalSettingsFile( globalSettingsFile ); - request.setSystemProperties( System.getProperties() ); + request.setSystemProperties( SystemProperties.getSystemProperties() ); return build( request ); } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 123b01aa81..9e64dd1aa3 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -59,6 +59,7 @@ 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,8 +1164,8 @@ static void populateProperties( CommandLine commandLine, Properties systemProper } } - systemProperties.putAll( System.getProperties() ); - + SystemProperties.addSystemProperties( systemProperties ); + // ---------------------------------------------------------------------- // Properties containing info about the currently running version of Maven // These override any corresponding properties set on the command line diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuildingRequest.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuildingRequest.java index 6b7e2f4faf..08c93fce43 100644 --- a/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuildingRequest.java +++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuildingRequest.java @@ -106,7 +106,11 @@ public DefaultSettingsBuildingRequest setSystemProperties( Properties systemProp 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 {