MNG-2724: Create a component in the embedder who's responsibility is to configure an execution request

http://jira.codehaus.org/browse/MNG-2724

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@491490 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2006-12-31 21:07:01 +00:00
parent b234e48cf5
commit 54ee18c115
3 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,87 @@
package org.apache.maven.embedder.execution;
import java.io.File;
import org.apache.maven.MavenTools;
import org.apache.maven.SettingsConfigurationException;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.codehaus.plexus.logging.AbstractLogEnabled;
public class DefaultMavenExecutionRequestDefaultsPopulator
extends AbstractLogEnabled
implements MavenExecutionRequestDefaultsPopulator
{
private MavenTools mavenTools;
private ArtifactRepositoryFactory artifactRepositoryFactory;
public MavenExecutionRequest populateDefaults(MavenExecutionRequest request)
throws MavenEmbedderException
{
// Settings
// Local repository
// TransferListener
// EventMonitor
// Proxy
// Settings
if ( request.getSettings() == null )
{
File userSettingsPath = mavenTools.getUserSettingsPath( request.getSettingsFile() );
File globalSettingsFile = mavenTools.getGlobalSettingsPath();
try
{
request.setSettings( mavenTools.buildSettings( userSettingsPath, globalSettingsFile, request.isInteractiveMode(),
request.isOffline(), request.isUsePluginRegistry(),
request.isUsePluginUpdateOverride() ) );
}
catch ( SettingsConfigurationException e )
{
throw new MavenEmbedderException( "Error processing settings.xml.", e );
}
}
// Local repository
if ( request.getLocalRepository() == null )
{
String localRepositoryPath = mavenTools.getLocalRepositoryPath( request.getSettings() );
if ( request.getLocalRepository() == null )
{
request.setLocalRepository( mavenTools.createLocalRepository( new File( localRepositoryPath ) ) );
}
}
// Repository update policies
boolean snapshotPolicySet = false;
if ( request.isOffline() )
{
snapshotPolicySet = true;
}
if ( !snapshotPolicySet ) {
if ( request.isUpdateSnapshots() )
{
artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
}
else if ( request.isNoSnapshotUpdates() )
{
getLogger().info( "+ Supressing SNAPSHOT updates.");
artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
}
}
artifactRepositoryFactory.setGlobalChecksumPolicy( request.getGlobalChecksumPolicy() );
return request;
}
}

View File

@ -0,0 +1,12 @@
package org.apache.maven.embedder.execution;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
public interface MavenExecutionRequestDefaultsPopulator
{
String ROLE = MavenExecutionRequestDefaultsPopulator.class.getName();
MavenExecutionRequest populateDefaults( MavenExecutionRequest request )
throws MavenEmbedderException;
}

View File

@ -0,0 +1,16 @@
<component-set>
<components>
<component>
<role>org.apache.maven.embedder.execution.MavenExecutionRequestDefaultsPopulator</role>
<implementation>org.apache.maven.embedder.execution.DefaultMavenExecutionRequestDefaultsPopulator</implementation>
<requirements>
<requirement>
<role>org.apache.maven.MavenTools</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
</requirements>
</component>
</components>
</component-set>