o creating a mode for aligning the the embedder with a user installation

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@370406 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2006-01-19 07:19:04 +00:00
parent f34721ad62
commit 2737100a43
3 changed files with 99 additions and 96 deletions

View File

@ -13,6 +13,7 @@
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.1-SNAPSHOT</version>
<configuration>
<descriptor>src/main/assembly/dep.xml</descriptor>
</configuration>

View File

@ -2,7 +2,7 @@
mvn clean:clean assembly:assembly
CLASSPATH=target/maven-embedder-2.0-dep.jar
CLASSPATH=target/maven-embedder-2.1-SNAPSHOT-dep.jar
javac -classpath $CLASSPATH Plugin.java

View File

@ -138,44 +138,23 @@ public class MavenEmbedder
// User options
// ----------------------------------------------------------------------
private boolean pluginUpdateOverride;
private boolean checkLatestPluginVersion;
// release plugin uses this but in IDE there will probably always be some form of interaction.
private boolean interactiveMode;
private boolean usePluginRegistry;
private boolean offline;
private boolean updateSnapshots;
private String globalChecksumPolicy;
/**
* This option determines whether the embedder is to be aligned to the user
* installation.
*/
private boolean alignWithUserInstallation;
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
public void setPluginUpdateOverride( boolean pluginUpdateOverride )
{
this.pluginUpdateOverride = pluginUpdateOverride;
}
public boolean isPluginUpdateOverride()
{
return pluginUpdateOverride;
}
public void setCheckLatestPluginVersion( boolean checkLatestPluginVersion )
{
this.checkLatestPluginVersion = checkLatestPluginVersion;
}
public boolean isCheckLatestPluginVersion()
{
return checkLatestPluginVersion;
}
public void setInteractiveMode( boolean interactiveMode )
{
this.interactiveMode = interactiveMode;
@ -186,16 +165,6 @@ public class MavenEmbedder
return interactiveMode;
}
public void setUsePluginRegistry( boolean usePluginRegistry )
{
this.usePluginRegistry = usePluginRegistry;
}
public boolean isUsePluginRegistry()
{
return usePluginRegistry;
}
public void setOffline( boolean offline )
{
this.offline = offline;
@ -206,16 +175,6 @@ public class MavenEmbedder
return offline;
}
public void setUpdateSnapshots( boolean updateSnapshots )
{
this.updateSnapshots = updateSnapshots;
}
public boolean isUpdateSnapshots()
{
return updateSnapshots;
}
public void setGlobalChecksumPolicy( String globalChecksumPolicy )
{
this.globalChecksumPolicy = globalChecksumPolicy;
@ -226,6 +185,16 @@ public class MavenEmbedder
return globalChecksumPolicy;
}
public boolean isAlignWithUserInstallation()
{
return alignWithUserInstallation;
}
public void setAlignWithUserInstallation( boolean alignWithUserInstallation )
{
this.alignWithUserInstallation = alignWithUserInstallation;
}
/**
* Set the classloader to use with the maven embedder.
*
@ -399,7 +368,6 @@ public class MavenEmbedder
// ----------------------------------------------------------------------
// TODO: should we allow the passing in of a settings object so that everything can be taken from the client env
// TODO: transfer listener
// TODO: logger
@ -565,14 +533,7 @@ public class MavenEmbedder
{
RuntimeInfo runtimeInfo = new RuntimeInfo( settings );
if ( pluginUpdateOverride )
{
runtimeInfo.setPluginUpdateOverride( Boolean.TRUE );
}
else
{
runtimeInfo.setPluginUpdateOverride( Boolean.FALSE );
}
runtimeInfo.setPluginUpdateOverride( Boolean.FALSE );
return runtimeInfo;
}
@ -606,6 +567,8 @@ public class MavenEmbedder
public void start()
throws MavenEmbedderException
{
detectUserInstallation();
// ----------------------------------------------------------------------
// Set the maven.home system property which is need by components like
// the plugin registry builder.
@ -646,54 +609,23 @@ public class MavenEmbedder
mavenProjectBuilder = (MavenProjectBuilder) embedder.lookup( MavenProjectBuilder.ROLE );
// ----------------------------------------------------------------------
// Artifact related components
// ----------------------------------------------------------------------
artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE );
lifecycleExecutor = (LifecycleExecutor) embedder.lookup( LifecycleExecutor.ROLE );
wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
artifactFactory = (ArtifactFactory) embedder.lookup( ArtifactFactory.ROLE );
artifactResolver = (ArtifactResolver) embedder.lookup( ArtifactResolver.ROLE );
defaultArtifactRepositoryLayout = (ArtifactRepositoryLayout) embedder.lookup( ArtifactRepositoryLayout.ROLE, DEFAULT_LAYOUT_ID );
// ----------------------------------------------------------------------
// If an explicit local repository has not been set then we will use the
// setting builder to use the maven defaults to help us find one.
// ----------------------------------------------------------------------
lifecycleExecutor = (LifecycleExecutor) embedder.lookup( LifecycleExecutor.ROLE );
if ( localRepositoryDirectory == null )
{
settingsBuilder = (MavenSettingsBuilder) embedder.lookup( MavenSettingsBuilder.ROLE );
wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
try
{
settings = settingsBuilder.buildSettings();
}
catch ( IOException e )
{
throw new MavenEmbedderException( "Error creating settings.", e );
}
catch ( XmlPullParserException e )
{
throw new MavenEmbedderException( "Error creating settings.", e );
}
}
else
{
settings = new Settings();
settings.setLocalRepository( localRepositoryDirectory.getAbsolutePath() );
}
settings.setRuntimeInfo( createRuntimeInfo( settings ) );
settings.setOffline( offline );
settings.setUsePluginRegistry( usePluginRegistry );
settings.setInteractiveMode( interactiveMode );
createMavenSettings();
localRepository = createLocalRepository( settings );
}
@ -711,6 +643,76 @@ public class MavenEmbedder
}
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
private void detectUserInstallation()
{
if ( new File( userHome, ".m2" ).exists() )
{
alignWithUserInstallation = true;
}
}
/**
* Create the Settings that will be used with the embedder. If we are aligning with the user
* installation then we lookup the standard settings builder and use that to create our
* settings. Otherwise we constructs a settings object and populate the information
* ourselves.
*
* @throws MavenEmbedderException
* @throws ComponentLookupException
*/
private void createMavenSettings()
throws MavenEmbedderException, ComponentLookupException
{
if ( alignWithUserInstallation )
{
// ----------------------------------------------------------------------
// We will use the standard method for creating the settings. This
// method reproduces the method of building the settings from the CLI
// mode of operation.
// ----------------------------------------------------------------------
settingsBuilder = (MavenSettingsBuilder) embedder.lookup( MavenSettingsBuilder.ROLE );
try
{
settings = settingsBuilder.buildSettings();
}
catch ( IOException e )
{
throw new MavenEmbedderException( "Error creating settings.", e );
}
catch ( XmlPullParserException e )
{
throw new MavenEmbedderException( "Error creating settings.", e );
}
}
else
{
if ( localRepository == null )
{
throw new IllegalArgumentException( "When not aligning with a user install you must specify a local repository location using the setLocalRepositoryDirectory( File ) method." );
}
settings = new Settings();
settings.setLocalRepository( localRepositoryDirectory.getAbsolutePath() );
settings.setRuntimeInfo( createRuntimeInfo( settings ) );
settings.setOffline( offline );
settings.setInteractiveMode( interactiveMode );
}
}
// ----------------------------------------------------------------------
// Lifecycle
// ----------------------------------------------------------------------
public void stop()
throws MavenEmbedderException
{