mirror of https://github.com/apache/maven.git
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:
parent
f34721ad62
commit
2737100a43
|
@ -13,6 +13,7 @@
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>2.1-SNAPSHOT</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<descriptor>src/main/assembly/dep.xml</descriptor>
|
<descriptor>src/main/assembly/dep.xml</descriptor>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
mvn clean:clean assembly:assembly
|
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
|
javac -classpath $CLASSPATH Plugin.java
|
||||||
|
|
||||||
|
|
|
@ -138,44 +138,23 @@ public class MavenEmbedder
|
||||||
// User options
|
// User options
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
private boolean pluginUpdateOverride;
|
// release plugin uses this but in IDE there will probably always be some form of interaction.
|
||||||
|
|
||||||
private boolean checkLatestPluginVersion;
|
|
||||||
|
|
||||||
private boolean interactiveMode;
|
private boolean interactiveMode;
|
||||||
|
|
||||||
private boolean usePluginRegistry;
|
|
||||||
|
|
||||||
private boolean offline;
|
private boolean offline;
|
||||||
|
|
||||||
private boolean updateSnapshots;
|
|
||||||
|
|
||||||
private String globalChecksumPolicy;
|
private String globalChecksumPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This option determines whether the embedder is to be aligned to the user
|
||||||
|
* installation.
|
||||||
|
*/
|
||||||
|
private boolean alignWithUserInstallation;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Accessors
|
// 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 )
|
public void setInteractiveMode( boolean interactiveMode )
|
||||||
{
|
{
|
||||||
this.interactiveMode = interactiveMode;
|
this.interactiveMode = interactiveMode;
|
||||||
|
@ -186,16 +165,6 @@ public class MavenEmbedder
|
||||||
return interactiveMode;
|
return interactiveMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsePluginRegistry( boolean usePluginRegistry )
|
|
||||||
{
|
|
||||||
this.usePluginRegistry = usePluginRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUsePluginRegistry()
|
|
||||||
{
|
|
||||||
return usePluginRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOffline( boolean offline )
|
public void setOffline( boolean offline )
|
||||||
{
|
{
|
||||||
this.offline = offline;
|
this.offline = offline;
|
||||||
|
@ -206,16 +175,6 @@ public class MavenEmbedder
|
||||||
return offline;
|
return offline;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUpdateSnapshots( boolean updateSnapshots )
|
|
||||||
{
|
|
||||||
this.updateSnapshots = updateSnapshots;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUpdateSnapshots()
|
|
||||||
{
|
|
||||||
return updateSnapshots;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGlobalChecksumPolicy( String globalChecksumPolicy )
|
public void setGlobalChecksumPolicy( String globalChecksumPolicy )
|
||||||
{
|
{
|
||||||
this.globalChecksumPolicy = globalChecksumPolicy;
|
this.globalChecksumPolicy = globalChecksumPolicy;
|
||||||
|
@ -226,6 +185,16 @@ public class MavenEmbedder
|
||||||
return globalChecksumPolicy;
|
return globalChecksumPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAlignWithUserInstallation()
|
||||||
|
{
|
||||||
|
return alignWithUserInstallation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlignWithUserInstallation( boolean alignWithUserInstallation )
|
||||||
|
{
|
||||||
|
this.alignWithUserInstallation = alignWithUserInstallation;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the classloader to use with the maven embedder.
|
* 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: should we allow the passing in of a settings object so that everything can be taken from the client env
|
||||||
|
|
||||||
// TODO: transfer listener
|
// TODO: transfer listener
|
||||||
// TODO: logger
|
// TODO: logger
|
||||||
|
|
||||||
|
@ -565,14 +533,7 @@ public class MavenEmbedder
|
||||||
{
|
{
|
||||||
RuntimeInfo runtimeInfo = new RuntimeInfo( settings );
|
RuntimeInfo runtimeInfo = new RuntimeInfo( settings );
|
||||||
|
|
||||||
if ( pluginUpdateOverride )
|
runtimeInfo.setPluginUpdateOverride( Boolean.FALSE );
|
||||||
{
|
|
||||||
runtimeInfo.setPluginUpdateOverride( Boolean.TRUE );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
runtimeInfo.setPluginUpdateOverride( Boolean.FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
return runtimeInfo;
|
return runtimeInfo;
|
||||||
}
|
}
|
||||||
|
@ -606,6 +567,8 @@ public class MavenEmbedder
|
||||||
public void start()
|
public void start()
|
||||||
throws MavenEmbedderException
|
throws MavenEmbedderException
|
||||||
{
|
{
|
||||||
|
detectUserInstallation();
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Set the maven.home system property which is need by components like
|
// Set the maven.home system property which is need by components like
|
||||||
// the plugin registry builder.
|
// the plugin registry builder.
|
||||||
|
@ -646,54 +609,23 @@ public class MavenEmbedder
|
||||||
|
|
||||||
mavenProjectBuilder = (MavenProjectBuilder) embedder.lookup( MavenProjectBuilder.ROLE );
|
mavenProjectBuilder = (MavenProjectBuilder) embedder.lookup( MavenProjectBuilder.ROLE );
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Artifact related components
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE );
|
artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE );
|
||||||
|
|
||||||
lifecycleExecutor = (LifecycleExecutor) embedder.lookup( LifecycleExecutor.ROLE );
|
|
||||||
|
|
||||||
wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
|
|
||||||
|
|
||||||
artifactFactory = (ArtifactFactory) embedder.lookup( ArtifactFactory.ROLE );
|
artifactFactory = (ArtifactFactory) embedder.lookup( ArtifactFactory.ROLE );
|
||||||
|
|
||||||
artifactResolver = (ArtifactResolver) embedder.lookup( ArtifactResolver.ROLE );
|
artifactResolver = (ArtifactResolver) embedder.lookup( ArtifactResolver.ROLE );
|
||||||
|
|
||||||
defaultArtifactRepositoryLayout = (ArtifactRepositoryLayout) embedder.lookup( ArtifactRepositoryLayout.ROLE, DEFAULT_LAYOUT_ID );
|
defaultArtifactRepositoryLayout = (ArtifactRepositoryLayout) embedder.lookup( ArtifactRepositoryLayout.ROLE, DEFAULT_LAYOUT_ID );
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
lifecycleExecutor = (LifecycleExecutor) embedder.lookup( LifecycleExecutor.ROLE );
|
||||||
// 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.
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
if ( localRepositoryDirectory == null )
|
wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
|
||||||
{
|
|
||||||
settingsBuilder = (MavenSettingsBuilder) embedder.lookup( MavenSettingsBuilder.ROLE );
|
|
||||||
|
|
||||||
try
|
createMavenSettings();
|
||||||
{
|
|
||||||
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 );
|
|
||||||
|
|
||||||
localRepository = createLocalRepository( settings );
|
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()
|
public void stop()
|
||||||
throws MavenEmbedderException
|
throws MavenEmbedderException
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue