Author: jvanzyl
Date: Wed Jan 18 23:19:04 2006
New Revision: 370406
URL: http://svn.apache.org/viewcvs?rev=370406&view=rev
Log:
o creating a mode for aligning the the embedder with a user installation
Modified:
maven/components/trunk/maven-embedder/pom.xml
maven/components/trunk/maven-embedder/run.sh
maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
Modified: maven/components/trunk/maven-embedder/pom.xml
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-embedder/pom.xml?rev=370406&r1=370405&r2=370406&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/pom.xml (original)
+++ maven/components/trunk/maven-embedder/pom.xml Wed Jan 18 23:19:04 2006
@@ -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>
Modified: maven/components/trunk/maven-embedder/run.sh
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-embedder/run.sh?rev=370406&r1=370405&r2=370406&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/run.sh (original)
+++ maven/components/trunk/maven-embedder/run.sh Wed Jan 18 23:19:04 2006
@@ -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
Modified:
maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java?rev=370406&r1=370405&r2=370406&view=diff
==============================================================================
---
maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
(original)
+++
maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
Wed Jan 18 23:19:04 2006
@@ -138,44 +138,23 @@
// 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 @@
return interactiveMode;
}
- public void setUsePluginRegistry( boolean usePluginRegistry )
- {
- this.usePluginRegistry = usePluginRegistry;
- }
-
- public boolean isUsePluginRegistry()
- {
- return usePluginRegistry;
- }
-
public void setOffline( boolean offline )
{
this.offline = offline;
@@ -206,24 +175,24 @@
return offline;
}
- public void setUpdateSnapshots( boolean updateSnapshots )
+ public void setGlobalChecksumPolicy( String globalChecksumPolicy )
{
- this.updateSnapshots = updateSnapshots;
+ this.globalChecksumPolicy = globalChecksumPolicy;
}
- public boolean isUpdateSnapshots()
+ public String getGlobalChecksumPolicy()
{
- return updateSnapshots;
+ return globalChecksumPolicy;
}
- public void setGlobalChecksumPolicy( String globalChecksumPolicy )
+ public boolean isAlignWithUserInstallation()
{
- this.globalChecksumPolicy = globalChecksumPolicy;
+ return alignWithUserInstallation;
}
- public String getGlobalChecksumPolicy()
+ public void setAlignWithUserInstallation( boolean
alignWithUserInstallation )
{
- return globalChecksumPolicy;
+ this.alignWithUserInstallation = alignWithUserInstallation;
}
/**
@@ -399,7 +368,6 @@
// ----------------------------------------------------------------------
// 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 @@
{
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 void start()
throws MavenEmbedderException
{
+ detectUserInstallation();
+
//
----------------------------------------------------------------------
// Set the maven.home system property which is need by components like
// the plugin registry builder.
@@ -646,11 +609,11 @@
mavenProjectBuilder = (MavenProjectBuilder) embedder.lookup(
MavenProjectBuilder.ROLE );
- artifactRepositoryFactory = (ArtifactRepositoryFactory)
embedder.lookup( ArtifactRepositoryFactory.ROLE );
-
- lifecycleExecutor = (LifecycleExecutor) embedder.lookup(
LifecycleExecutor.ROLE );
+ //
----------------------------------------------------------------------
+ // Artifact related components
+ //
----------------------------------------------------------------------
- wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
+ artifactRepositoryFactory = (ArtifactRepositoryFactory)
embedder.lookup( ArtifactRepositoryFactory.ROLE );
artifactFactory = (ArtifactFactory) embedder.lookup(
ArtifactFactory.ROLE );
@@ -658,42 +621,11 @@
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.
- //
----------------------------------------------------------------------
-
- if ( localRepositoryDirectory == null )
- {
- 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
- {
- settings = new Settings();
-
- settings.setLocalRepository(
localRepositoryDirectory.getAbsolutePath() );
- }
-
- settings.setRuntimeInfo( createRuntimeInfo( settings ) );
-
- settings.setOffline( offline );
+ lifecycleExecutor = (LifecycleExecutor) embedder.lookup(
LifecycleExecutor.ROLE );
- settings.setUsePluginRegistry( usePluginRegistry );
+ wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
- settings.setInteractiveMode( interactiveMode );
+ createMavenSettings();
localRepository = createLocalRepository( settings );
}
@@ -710,6 +642,76 @@
throw new MavenEmbedderException( "Cannot lookup required
component.", e );
}
}
+
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
+ 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