o scrub of the settings building, was able to reduce to the need of the build context and use the execution request

directly. eventually i will get it to be the session, along with the profile tools, then all the tools can also 
  share a common interpolator, which can then be shared by other components instead of having 5 interpolators lying
  around causing a great deal of inconsistency.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@573494 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-09-07 07:54:11 +00:00
parent 28ac7d65cb
commit e9b6657f4c
13 changed files with 272 additions and 413 deletions

View File

@ -32,7 +32,7 @@ import java.util.List;
import java.util.Properties;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @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;
}
}

View File

@ -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 );
}

View File

@ -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,14 +48,14 @@ 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(
@ -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,16 +135,14 @@ public class DefaultMavenSettingsBuilder
if ( settingsFile == null )
{
getLogger().debug( "Settings file is null. Returning." );
return null;
}
Settings settings = null;
if ( settingsFile.exists() && settingsFile.isFile() )
{
getLogger().debug( "Settings file is a proper file. Reading." );
FileReader reader = null;
try
{
reader = new FileReader( settingsFile );
@ -144,12 +150,6 @@ public class DefaultMavenSettingsBuilder
SettingsXpp3Reader modelReader = new SettingsXpp3Reader();
settings = modelReader.read( reader );
RuntimeInfo rtInfo = new RuntimeInfo( settings );
rtInfo.addLocation( settingsFile.getAbsolutePath() );
settings.setRuntimeInfo( rtInfo );
}
catch ( XmlPullParserException e )
{
@ -167,12 +167,12 @@ public class DefaultMavenSettingsBuilder
{
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 );

View File

@ -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:
* <ul>
* <li>user settings: ${user.home}/settings.xml</li>
* <li>global settings: ${maven.home}/conf/settings.xml</li>
* </ul>
*
* @author jdcasey
* @author Jason van Zyl
* @version $Id$
*/
public interface MavenSettingsBuilder
{
String ROLE = MavenSettingsBuilder.class.getName();
/**
*
* @param userSettingsFile
* @param globalSettingsFile
* @return a <code>Settings</code> 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;
}

View File

@ -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;
}
}

View File

@ -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 );

View File

@ -392,18 +392,6 @@
return profileMap;
}
private RuntimeInfo runtimeInfo;
public void setRuntimeInfo( RuntimeInfo runtimeInfo )
{
this.runtimeInfo = runtimeInfo;
}
public RuntimeInfo getRuntimeInfo()
{
return runtimeInfo;
}
]]>
</code>
</codeSegment>

View File

@ -33,13 +33,9 @@ public class SettingsUtilsTest
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();

View File

@ -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://<path>
// We want to eliminate any relative path nonsense and lock down the path so we
// need to fully resolve it before any sub-modules use the path. This can happen
// when you are using a custom settings.xml that contains a relative path entry
// for the local repository setting.
File localRepository = new File( url.substring( "file://".length() ) );
if ( !localRepository.isAbsolute() )
{
url = "file://" + localRepository.getCanonicalPath();
}
return url;
}
public ArtifactRepository createRepository( String url,
String repositoryId )
{
// snapshots vs releases
// offline = to turning the update policy off
//TODO: we'll need to allow finer grained creation of repositories but this will do for now
String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS;
String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN;
ArtifactRepositoryPolicy snapshotsPolicy =
new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag );
ArtifactRepositoryPolicy releasesPolicy =
new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag );
return artifactRepositoryFactory.createArtifactRepository( repositoryId, url, defaultArtifactRepositoryLayout,
snapshotsPolicy, releasesPolicy );
}
// ----------------------------------------------------------------------------
// Configuration
// ----------------------------------------------------------------------------
@ -902,7 +808,7 @@ public class MavenEmbedder
try
{
request = populator.populateDefaults( request, this );
request = populator.populateDefaults( request, configuration );
}
catch ( MavenEmbedderException e )
{

View File

@ -20,11 +20,12 @@ package org.apache.maven.embedder.execution;
*/
import org.apache.maven.Maven;
import org.apache.maven.settings.SettingsConfigurationException;
import org.apache.maven.artifact.manager.WagonManager;
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.embedder.Configuration;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
@ -38,6 +39,7 @@ import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.SettingsConfigurationException;
import org.apache.maven.settings.SettingsUtils;
import org.apache.maven.wagon.repository.RepositoryPermissions;
import org.codehaus.plexus.PlexusConstants;
@ -49,9 +51,11 @@ import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
@ -62,7 +66,8 @@ import java.util.List;
*/
public class DefaultMavenExecutionRequestPopulator
extends AbstractLogEnabled
implements MavenExecutionRequestPopulator, Contextualizable
implements MavenExecutionRequestPopulator,
Contextualizable
{
private ArtifactRepositoryFactory artifactRepositoryFactory;
@ -75,31 +80,39 @@ public class DefaultMavenExecutionRequestPopulator
private MavenSettingsBuilder settingsBuilder;
public MavenExecutionRequest populateDefaults( MavenExecutionRequest request,
MavenEmbedder embedder )
Configuration configuration )
throws MavenEmbedderException
{
// Actual POM File
if ( request.getPomFile() == null && request.getBaseDirectory() != null )
{
File pom = new File( request.getBaseDirectory(), Maven.RELEASE_POMv4 );
File pom = new File(
request.getBaseDirectory(),
Maven.RELEASE_POMv4 );
if ( !pom.exists() )
{
pom = new File( request.getBaseDirectory(), Maven.POMv4 );
pom = new File(
request.getBaseDirectory(),
Maven.POMv4 );
}
request.setPomFile( pom.getAbsolutePath() );
}
request.setGlobalSettingsFile( configuration.getGlobalSettingsFile() );
request.setUserSettingsFile( configuration.getUserSettingsFile() );
if ( request.getSettings() == null )
{
try
{
request.setSettings(
settingsBuilder.buildSettings(
embedder.getConfiguration().getUserSettingsFile(),
embedder.getConfiguration().getGlobalSettingsFile() ) );
configuration.getUserSettingsFile(),
configuration.getGlobalSettingsFile() ) );
}
catch ( Exception e )
{
@ -109,7 +122,7 @@ public class DefaultMavenExecutionRequestPopulator
if ( request.getLocalRepository() == null )
{
request.setLocalRepository( embedder.createLocalRepository( request.getSettings() ) );
request.setLocalRepository( createLocalRepository( request.getSettings(), configuration ) );
}
// Repository update policies
@ -161,7 +174,9 @@ public class DefaultMavenExecutionRequestPopulator
}
catch ( Exception e )
{
throw new MavenEmbedderException( "Unable to configure Maven for execution", e );
throw new MavenEmbedderException(
"Unable to configure Maven for execution",
e );
}
// BaseDirectory in MavenExecutionRequest
@ -186,7 +201,9 @@ public class DefaultMavenExecutionRequestPopulator
ProfileManager globalProfileManager = new DefaultProfileManager( container );
loadSettingsProfiles( globalProfileManager, request.getSettings() );
loadSettingsProfiles(
globalProfileManager,
request.getSettings() );
globalProfileManager.explicitlyActivate( request.getActiveProfiles() );
@ -213,22 +230,36 @@ public class DefaultMavenExecutionRequestPopulator
throw new SettingsConfigurationException( "Proxy in settings.xml has no host" );
}
wagonManager.addProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(),
proxy.getPassword(), proxy.getNonProxyHosts() );
wagonManager.addProxy(
proxy.getProtocol(),
proxy.getHost(),
proxy.getPort(),
proxy.getUsername(),
proxy.getPassword(),
proxy.getNonProxyHosts() );
}
for ( Iterator i = settings.getServers().iterator(); i.hasNext(); )
{
Server server = (Server) i.next();
wagonManager.addAuthenticationInfo( server.getId(), server.getUsername(), server.getPassword(),
server.getPrivateKey(), server.getPassphrase() );
wagonManager.addAuthenticationInfo(
server.getId(),
server.getUsername(),
server.getPassword(),
server.getPrivateKey(),
server.getPassphrase() );
wagonManager.addPermissionInfo( server.getId(), server.getFilePermissions(), server.getDirectoryPermissions() );
wagonManager.addPermissionInfo(
server.getId(),
server.getFilePermissions(),
server.getDirectoryPermissions() );
if ( server.getConfiguration() != null )
{
wagonManager.addConfiguration( server.getId(), (Xpp3Dom) server.getConfiguration() );
wagonManager.addConfiguration(
server.getId(),
(Xpp3Dom) server.getConfiguration() );
}
}
@ -244,7 +275,10 @@ public class DefaultMavenExecutionRequestPopulator
{
Mirror mirror = (Mirror) i.next();
wagonManager.addMirror( mirror.getId(), mirror.getMirrorOf(), mirror.getUrl() );
wagonManager.addMirror(
mirror.getId(),
mirror.getMirrorOf(),
mirror.getUrl() );
}
}
finally
@ -263,7 +297,8 @@ public class DefaultMavenExecutionRequestPopulator
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
public void loadSettingsProfiles( ProfileManager profileManager, Settings settings )
public void loadSettingsProfiles( ProfileManager profileManager,
Settings settings )
{
List settingsProfiles = settings.getProfiles();
@ -284,4 +319,111 @@ public class DefaultMavenExecutionRequestPopulator
}
}
// ----------------------------------------------------------------------
// Local Repository
// ----------------------------------------------------------------------
public ArtifactRepository createLocalRepository( Settings settings, Configuration configuration )
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://<path>
// We want to eliminate any relative path nonsense and lock down the path so we
// need to fully resolve it before any sub-modules use the path. This can happen
// when you are using a custom settings.xml that contains a relative path entry
// for the local repository setting.
File localRepository = new File( url.substring( "file://".length() ) );
if ( !localRepository.isAbsolute() )
{
url = "file://" + localRepository.getCanonicalPath();
}
return url;
}
public ArtifactRepository createRepository( String url,
String repositoryId )
{
// snapshots vs releases
// offline = to turning the update policy off
//TODO: we'll need to allow finer grained creation of repositories but this will do for now
String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS;
String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN;
ArtifactRepositoryPolicy snapshotsPolicy =
new ArtifactRepositoryPolicy(
true,
updatePolicyFlag,
checksumPolicyFlag );
ArtifactRepositoryPolicy releasesPolicy =
new ArtifactRepositoryPolicy(
true,
updatePolicyFlag,
checksumPolicyFlag );
return artifactRepositoryFactory.createArtifactRepository(
repositoryId,
url,
defaultArtifactRepositoryLayout,
snapshotsPolicy,
releasesPolicy );
}
}

View File

@ -19,7 +19,7 @@ package org.apache.maven.embedder.execution;
* under the License.
*/
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
@ -27,6 +27,6 @@ public interface MavenExecutionRequestPopulator
{
String ROLE = MavenExecutionRequestPopulator.class.getName();
MavenExecutionRequest populateDefaults( MavenExecutionRequest request, MavenEmbedder embedder )
MavenExecutionRequest populateDefaults( MavenExecutionRequest request, Configuration configuration )
throws MavenEmbedderException;
}

View File

@ -27,11 +27,15 @@ under the License.
<role>org.apache.maven.artifact.manager.WagonManager</role>
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.settings.MavenSettingsBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.settings.MavenSettingsBuilder</role>
<role>org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout</role>
<role-hint>default</role-hint>
</requirement>
</requirements>
</component>

View File

@ -59,7 +59,7 @@ public class MavenEmbedderExampleTest
if ( result.hasExceptions() )
{
// Notify user that exceptions have occured.
fail( ((Exception)result.getExceptions().get( 0 )).getMessage() );
}
// ----------------------------------------------------------------------------