diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index 8d25fc07f5..09856cc3ee 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -32,7 +32,7 @@ import java.util.List; import java.util.Properties; /** - * @author Jason van Zyl + * @author Jason van Zyl * @version $Id$ */ public class DefaultMavenExecutionRequest @@ -60,6 +60,16 @@ public class DefaultMavenExecutionRequest private boolean isProjectPresent = true; + // ---------------------------------------------------------------------------- + // We need to allow per execution user and global settings as the embedder + // might be running in a mode where its executing many threads with totally + // different settings. + // ---------------------------------------------------------------------------- + + private File userSettingsFile; + + private File globalSettingsFile; + // ---------------------------------------------------------------------------- // Request // ---------------------------------------------------------------------------- @@ -531,4 +541,30 @@ public class DefaultMavenExecutionRequest return this; } + + // Settings files + + public File getUserSettingsFile() + { + return userSettingsFile; + } + + public MavenExecutionRequest setUserSettingsFile( File userSettingsFile ) + { + this.userSettingsFile = userSettingsFile; + + return this; + } + + public File getGlobalSettingsFile() + { + return globalSettingsFile; + } + + public MavenExecutionRequest setGlobalSettingsFile( File globalSettingsFile ) + { + this.globalSettingsFile = globalSettingsFile; + + return this; + } } diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java index 78153652ea..28bb52d4b2 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java @@ -189,4 +189,10 @@ public interface MavenExecutionRequest boolean isProjectPresent(); MavenExecutionRequest setProjectPresent( boolean isProjectPresent ); + + File getUserSettingsFile(); + MavenExecutionRequest setUserSettingsFile( File userSettingsFile ); + + File getGlobalSettingsFile(); + MavenExecutionRequest setGlobalSettingsFile( File globalSettingsFile ); } 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 2586b8f446..154466c3f4 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 @@ -19,8 +19,7 @@ package org.apache.maven.settings; * under the License. */ -import org.apache.maven.context.BuildContextManager; -import org.apache.maven.context.SystemBuildContext; +import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer; import org.apache.maven.settings.validation.SettingsValidationResult; @@ -49,18 +48,18 @@ public class DefaultMavenSettingsBuilder { private SettingsValidator validator; - private BuildContextManager manager; - - /** - * @since 2.1 - */ - public Settings buildSettings( File userSettingsFile, File globalSettingsFile ) + /** @since 2.1 */ + public Settings buildSettings( MavenExecutionRequest request ) throws IOException, XmlPullParserException { + File userSettingsFile = request.getUserSettingsFile(); + + File globalSettingsFile = request.getGlobalSettingsFile(); + if ( ( globalSettingsFile == null ) && ( userSettingsFile == null ) ) { getLogger().debug( - "No settings files provided, and default locations are disabled for this request. Returning empty Settings instance." ); + "No settings files provided, and default locations are disabled for this request. Returning empty Settings instance." ); return new Settings(); } @@ -82,37 +81,46 @@ public class DefaultMavenSettingsBuilder userSettings = new Settings(); } - validateSettings( globalSettings, globalSettingsFile ); + validateSettings( + globalSettings, + globalSettingsFile ); - validateSettings( userSettings, userSettingsFile ); + validateSettings( + userSettings, + userSettingsFile ); - SettingsUtils.merge( userSettings, globalSettings, TrackableBase.GLOBAL_LEVEL ); + SettingsUtils.merge( + userSettings, + globalSettings, + TrackableBase.GLOBAL_LEVEL ); - userSettings = interpolate( userSettings ); + userSettings = interpolate( userSettings, request ); return userSettings; } - private Settings interpolate( Settings settings ) + private Settings interpolate( Settings settings, MavenExecutionRequest request ) throws IOException, XmlPullParserException { List activeProfiles = settings.getActiveProfiles(); StringWriter writer = new StringWriter(); - - new SettingsXpp3Writer().write( writer, settings ); + + new SettingsXpp3Writer().write( + writer, + settings ); String serializedSettings = writer.toString(); - SystemBuildContext sysContext = SystemBuildContext.getSystemBuildContext( manager, true ); - RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); - interpolator.addValueSource( new PropertiesBasedValueSource( sysContext.getSystemProperties() ) ); + interpolator.addValueSource( new PropertiesBasedValueSource( request.getProperties() ) ); interpolator.addValueSource( new EnvarBasedValueSource() ); - serializedSettings = interpolator.interpolate( serializedSettings, "settings" ); + serializedSettings = interpolator.interpolate( + serializedSettings, + "settings" ); Settings result = new SettingsXpp3Reader().read( new StringReader( serializedSettings ) ); @@ -127,52 +135,44 @@ public class DefaultMavenSettingsBuilder if ( settingsFile == null ) { getLogger().debug( "Settings file is null. Returning." ); + return null; } Settings settings = null; - if ( settingsFile.exists() && settingsFile.isFile() ) + FileReader reader = null; + + try { - getLogger().debug( "Settings file is a proper file. Reading." ); + reader = new FileReader( settingsFile ); - FileReader reader = null; - try - { - reader = new FileReader( settingsFile ); + SettingsXpp3Reader modelReader = new SettingsXpp3Reader(); - SettingsXpp3Reader modelReader = new SettingsXpp3Reader(); + settings = modelReader.read( reader ); + } + catch ( XmlPullParserException e ) + { + getLogger().error( "Failed to read settings from: " + settingsFile + ". Throwing XmlPullParserException..." ); - settings = modelReader.read( reader ); + throw e; + } + catch ( IOException e ) + { + getLogger().error( "Failed to read settings from: " + settingsFile + ". Throwing IOException..." ); - RuntimeInfo rtInfo = new RuntimeInfo( settings ); - - rtInfo.addLocation( settingsFile.getAbsolutePath() ); - - settings.setRuntimeInfo( rtInfo ); - } - catch ( XmlPullParserException e ) - { - getLogger().error( "Failed to read settings from: " + settingsFile + ". Throwing XmlPullParserException..." ); - - throw e; - } - catch ( IOException e ) - { - getLogger().error( "Failed to read settings from: " + settingsFile + ". Throwing IOException..." ); - - throw e; - } - finally - { - IOUtil.close( reader ); - } + throw e; + } + finally + { + IOUtil.close( reader ); } return settings; } - private void validateSettings( Settings settings, File location ) + private void validateSettings( Settings settings, + File location ) throws IOException { SettingsValidationResult validationResult = validator.validate( settings ); diff --git a/maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java b/maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java index 7ac7045777..0bdeda0fff 100644 --- a/maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java @@ -19,34 +19,20 @@ package org.apache.maven.settings; * under the License. */ +import org.apache.maven.execution.MavenExecutionRequest; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import java.io.File; import java.io.IOException; /** - * Builder for the user or global settings. By default, the settings files are located: - *
Settings
object from the user and global settings file.
- * @throws IOException if any
- * @throws XmlPullParserException if any
- * @since 2.1
- */
- Settings buildSettings( File userSettingsFile, File globalSettingsFile )
+ Settings buildSettings( MavenExecutionRequest request )
throws IOException, XmlPullParserException;
}
diff --git a/maven-core/src/main/java/org/apache/maven/settings/RuntimeInfo.java b/maven-core/src/main/java/org/apache/maven/settings/RuntimeInfo.java
deleted file mode 100644
index b8116a7dfc..0000000000
--- a/maven-core/src/main/java/org/apache/maven/settings/RuntimeInfo.java
+++ /dev/null
@@ -1,180 +0,0 @@
-package org.apache.maven.settings;
-
-/*
- * 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.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * To handle runtime informations like local repository or profiles.
- *
- * @version $Id$
- */
-public class RuntimeInfo
-{
- private List locations = new ArrayList();
-
- // using Boolean for 3VL (null for not-set, otherwise override with value)
- private Boolean pluginUpdateForced;
-
- // using Boolean for 3VL (null, true-to-all, false-to-all)
- private Boolean applyToAllPluginUpdates;
-
-// private boolean pluginRegistryActive = true;
-
- // using Boolean for 3VL (null for not-set, otherwise override with value)
-// private Boolean checkLatest;
-
- private Map activeProfileToSourceLevel = new HashMap();
-
- private String localRepositorySourceLevel = TrackableBase.USER_LEVEL;
-
- private Map pluginGroupIdSourceLevels = new HashMap();
-
- private final Settings settings;
-
- /**
- * @param settings
- */
- public RuntimeInfo( Settings settings )
- {
- this.settings = settings;
- }
-
- /**
- * @param path
- */
- public void addLocation( String path )
- {
- this.locations.add( path );
- }
-
- /**
- * @return
- */
- public List getLocations()
- {
- return locations;
- }
-
- /**
- * @param pluginUpdateForced
- */
- public void setPluginUpdateOverride( Boolean pluginUpdateForced )
- {
- this.pluginUpdateForced = pluginUpdateForced;
- }
-
- /**
- * @return
- */
- public Boolean getPluginUpdateOverride()
- {
- return pluginUpdateForced;
- }
-
- /**
- * @return
- */
- public Boolean getApplyToAllPluginUpdates()
- {
- return applyToAllPluginUpdates;
- }
-
- /**
- * @param applyToAll
- */
- public void setApplyToAllPluginUpdates( Boolean applyToAll )
- {
- this.applyToAllPluginUpdates = applyToAll;
- }
-
- /**
- * @param activeProfile
- * @param sourceLevel
- */
- public void setActiveProfileSourceLevel( String activeProfile, String sourceLevel )
- {
- activeProfileToSourceLevel.put( activeProfile, sourceLevel );
- }
-
- /**
- * @param activeProfile
- * @return
- */
- public String getSourceLevelForActiveProfile( String activeProfile )
- {
- String sourceLevel = (String) activeProfileToSourceLevel.get( activeProfile );
-
- if ( sourceLevel != null )
- {
- return sourceLevel;
- }
- else
- {
- return settings.getSourceLevel();
- }
- }
-
- /**
- * @param pluginGroupId
- * @param sourceLevel
- */
- public void setPluginGroupIdSourceLevel( String pluginGroupId, String sourceLevel )
- {
- pluginGroupIdSourceLevels.put( pluginGroupId, sourceLevel );
- }
-
- /**
- * @param pluginGroupId
- * @return
- */
- public String getSourceLevelForPluginGroupId( String pluginGroupId )
- {
- String sourceLevel = (String) pluginGroupIdSourceLevels.get( pluginGroupId );
-
- if ( sourceLevel != null )
- {
- return sourceLevel;
- }
- else
- {
- return settings.getSourceLevel();
- }
- }
-
- /**
- * @param localRepoSourceLevel
- */
- public void setLocalRepositorySourceLevel( String localRepoSourceLevel )
- {
- this.localRepositorySourceLevel = localRepoSourceLevel;
- }
-
- /**
- * @return
- */
- public String getLocalRepositorySourceLevel()
- {
- return localRepositorySourceLevel;
- }
-}
diff --git a/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java b/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java
index 3971460ab2..519c3dec98 100644
--- a/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java
+++ b/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java
@@ -73,27 +73,12 @@ public final class SettingsUtils
if ( !dominantActiveProfiles.contains( profileId ) )
{
dominantActiveProfiles.add( profileId );
-
- if ( dominant.getRuntimeInfo() != null )
- {
- dominant.getRuntimeInfo().setActiveProfileSourceLevel( profileId, recessiveSourceLevel );
- }
}
}
}
- if ( dominant.getRuntimeInfo() != null && recessive.getRuntimeInfo() != null )
- {
- List recessiveLocations = recessive.getRuntimeInfo().getLocations();
- for ( Iterator it = recessiveLocations.iterator(); it.hasNext(); )
- {
- String path = (String) it.next();
-
- dominant.getRuntimeInfo().addLocation( path );
- }
- }
-
List dominantPluginGroupIds = dominant.getPluginGroups();
+
List recessivePluginGroupIds = recessive.getPluginGroups();
if ( recessivePluginGroupIds != null )
@@ -111,11 +96,6 @@ public final class SettingsUtils
if ( !dominantPluginGroupIds.contains( pluginGroupId ) )
{
dominantPluginGroupIds.add( pluginGroupId );
-
- if ( dominant.getRuntimeInfo() != null )
- {
- dominant.getRuntimeInfo().setPluginGroupIdSourceLevel( pluginGroupId, recessiveSourceLevel );
- }
}
}
}
@@ -123,11 +103,6 @@ public final class SettingsUtils
if ( StringUtils.isEmpty( dominant.getLocalRepository() ) )
{
dominant.setLocalRepository( recessive.getLocalRepository() );
-
- if ( dominant.getRuntimeInfo() != null )
- {
- dominant.getRuntimeInfo().setLocalRepositorySourceLevel( recessiveSourceLevel );
- }
}
shallowMergeById( dominant.getMirrors(), recessive.getMirrors(), recessiveSourceLevel );
diff --git a/maven-core/src/main/mdo/settings.mdo b/maven-core/src/main/mdo/settings.mdo
index 3c5293cda3..45895800d7 100644
--- a/maven-core/src/main/mdo/settings.mdo
+++ b/maven-core/src/main/mdo/settings.mdo
@@ -392,18 +392,6 @@
return profileMap;
}
-
- private RuntimeInfo runtimeInfo;
-
- public void setRuntimeInfo( RuntimeInfo runtimeInfo )
- {
- this.runtimeInfo = runtimeInfo;
- }
-
- public RuntimeInfo getRuntimeInfo()
- {
- return runtimeInfo;
- }
]]>
diff --git a/maven-core/src/test/java/org/apache/maven/settings/SettingsUtilsTest.java b/maven-core/src/test/java/org/apache/maven/settings/SettingsUtilsTest.java
index 763a7a9800..4c93c5374d 100644
--- a/maven-core/src/test/java/org/apache/maven/settings/SettingsUtilsTest.java
+++ b/maven-core/src/test/java/org/apache/maven/settings/SettingsUtilsTest.java
@@ -32,14 +32,10 @@ public class SettingsUtilsTest
Settings dominant = new Settings();
dominant.addPluginGroup( "org.apache.maven.plugins" );
dominant.addPluginGroup( "org.codehaus.modello" );
-
- dominant.setRuntimeInfo(new RuntimeInfo(dominant));
Settings recessive = new Settings();
recessive.addPluginGroup( "org.codehaus.plexus" );
- recessive.setRuntimeInfo(new RuntimeInfo(recessive));
-
SettingsUtils.merge( dominant, recessive, Settings.GLOBAL_LEVEL );
List pluginGroups = dominant.getPluginGroups();
diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
index f77791a83e..fcf4c239e6 100644
--- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
+++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
@@ -20,14 +20,12 @@ package org.apache.maven.embedder;
*/
import org.apache.maven.Maven;
-import org.apache.maven.settings.SettingsConfigurationException;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
@@ -58,6 +56,7 @@ import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.MavenProjectBuildingResult;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.SettingsConfigurationException;
import org.apache.maven.settings.io.jdom.SettingsJDOMWriter;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.apache.maven.settings.validation.DefaultSettingsValidator;
@@ -78,7 +77,6 @@ import org.codehaus.plexus.component.repository.exception.ComponentRepositoryExc
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.jdom.Document;
import org.jdom.Element;
@@ -406,7 +404,7 @@ public class MavenEmbedder
try
{
- request = populator.populateDefaults( request, this );
+ request = populator.populateDefaults( request, configuration );
// This is necessary to make the MavenEmbedderProjectWithExtensionReadingTest work which uses
// a custom type for a dependency like this:
@@ -654,7 +652,7 @@ public class MavenEmbedder
// simply cascade values in from requests used for individual executions.
request = new DefaultMavenExecutionRequest();
- populator.populateDefaults( request, this );
+ populator.populateDefaults( request, configuration );
}
catch ( ComponentLookupException e )
{
@@ -785,98 +783,6 @@ public class MavenEmbedder
return result;
}
- // ----------------------------------------------------------------------
- // Local Repository
- // ----------------------------------------------------------------------
-
- public ArtifactRepository createLocalRepository( Settings settings )
- throws MavenEmbedderException
- {
- String localRepositoryPath = null;
-
- if ( configuration.getLocalRepository() != null )
- {
- localRepositoryPath = configuration.getLocalRepository().getAbsolutePath();
- }
-
- if ( StringUtils.isEmpty( localRepositoryPath ) )
- {
- localRepositoryPath = settings.getLocalRepository();
- }
-
- if ( StringUtils.isEmpty( localRepositoryPath ) )
- {
- localRepositoryPath = MavenEmbedder.defaultUserLocalRepository.getAbsolutePath();
- }
-
- return createLocalRepository( localRepositoryPath, MavenEmbedder.DEFAULT_LOCAL_REPO_ID );
- }
-
- public ArtifactRepository createLocalRepository( String url,
- String repositoryId )
- throws MavenEmbedderException
- {
- try
- {
- return createRepository( canonicalFileUrl( url ), repositoryId );
- }
- catch ( IOException e )
- {
- throw new MavenEmbedderException( "Unable to resolve canonical path for local repository " + url, e );
- }
- }
-
- private String canonicalFileUrl( String url )
- throws IOException
- {
- if ( !url.startsWith( "file:" ) )
- {
- url = "file://" + url;
- }
- else if ( url.startsWith( "file:" ) && !url.startsWith( "file://" ) )
- {
- url = "file://" + url.substring( "file:".length() );
- }
-
- // So now we have an url of the form file://