mirror of https://github.com/apache/maven.git
MNG-2778 Code and documentation for accessing the plexus container.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@512896 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
548d57661b
commit
d9004ba0ef
|
@ -65,6 +65,7 @@ import org.apache.maven.settings.validation.SettingsValidator;
|
|||
import org.codehaus.plexus.DefaultPlexusContainer;
|
||||
import org.codehaus.plexus.MutablePlexusContainer;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.classworlds.ClassWorld;
|
||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
|
||||
|
@ -618,8 +619,6 @@ public class MavenEmbedder
|
|||
{
|
||||
settings = settingsBuilder.buildSettings( configuration.getUserSettingsFile(),
|
||||
configuration.getGlobalSettingsFile() );
|
||||
|
||||
System.out.println( "settings.getLocalRepository() = " + settings.getLocalRepository() );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
|
@ -905,4 +904,14 @@ public class MavenEmbedder
|
|||
loggerManager.setThresholds( oldThreshold );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the instance of the plexus container being used in the embedder.
|
||||
*
|
||||
* @return The plexus container used in the embedder.
|
||||
*/
|
||||
public PlexusContainer getPlexusContainer()
|
||||
{
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,5 +41,12 @@ A Note on Configuring Settings
|
|||
|
||||
Also note that the user and global settings are merged, and the user settings are dominant.
|
||||
|
||||
|
||||
Accessing the Underlying Plexus Container
|
||||
|
||||
Though it is not recommended for general use, it is possible to get at the underlying Plexus Container instance if you
|
||||
wish to lookup custom components. The Maven Embedder was specifically designed to be used for Maven and not a general
|
||||
purpose use of Plexus. So if you use this method then you use it at your peril. You can access the Plexus Container
|
||||
using the following:
|
||||
|
||||
%{snippet|id=plexus-container|url=http://svn.apache.org/repos/asf/maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderExampleTest.java}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.apache.maven.execution.MavenExecutionRequest;
|
|||
import org.apache.maven.execution.MavenExecutionResult;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
@ -97,4 +98,31 @@ public class MavenEmbedderExampleTest
|
|||
}
|
||||
// END SNIPPET: mimic-cli
|
||||
}
|
||||
|
||||
public void testEmbedderExampleThatShowsAccessingThePlexusContainer()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
// START SNIPPET: plexus-container
|
||||
Configuration configuration = new DefaultConfiguration()
|
||||
.setUserSettingsFile( MavenEmbedder.DEFAULT_USER_SETTINGS_FILE )
|
||||
.setGlobalSettingsFile( MavenEmbedder.DEFAULT_GLOBAL_SETTINGS_FILE )
|
||||
.setClassLoader( Thread.currentThread().getContextClassLoader() );
|
||||
|
||||
ConfigurationValidationResult validationResult = MavenEmbedder.validateConfiguration( configuration );
|
||||
|
||||
if ( validationResult.isValid() )
|
||||
{
|
||||
// If the configuration is valid then do your thang ...
|
||||
}
|
||||
|
||||
MavenEmbedder embedder = new MavenEmbedder( configuration );
|
||||
|
||||
PlexusContainer container = embedder.getPlexusContainer();
|
||||
|
||||
// Do what you like with the container ...
|
||||
|
||||
// END SNIPPET: plexus-container
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue