cleaning up NPE in the realm manager, and adding clear() method calls to the embedder to cleanup the realm manager after it's used, to try to keep the number of open realms to a minimum...

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@592222 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-11-06 01:34:38 +00:00
parent d206986023
commit a1f995029a
8 changed files with 392 additions and 252 deletions

View File

@ -37,7 +37,6 @@ import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.Collection;
import java.util.Set;
@ -129,6 +128,8 @@ public privileged aspect Maven20xCompatAspect
&& this( mgr )
&& notHere();
// We use the same hack here to make sure that plexus 1.1 is available for extensions that do
// not declare plexus-utils but need it. MNG-2900
Set around( DefaultExtensionManager mgr ): extDepArtifactsResolved( mgr )
{
Set result = proceed( mgr );

View File

@ -22,16 +22,18 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class DefaultMavenRealmManager
implements MavenRealmManager
{
private Map extensionComponents = new HashMap();
private Map pluginArtifacts = new HashMap();
private Set managedRealmIds = new HashSet();
private final ClassWorld world;
private final PlexusContainer container;
@ -47,8 +49,27 @@ public DefaultMavenRealmManager( PlexusContainer container,
public void clear()
{
extensionComponents.clear();
pluginArtifacts.clear();
Collection realms = new HashSet( world.getRealms() );
for ( Iterator it = realms.iterator(); it.hasNext(); )
{
ClassRealm realm = (ClassRealm) it.next();
String id = realm.getId();
if ( managedRealmIds.contains( id ) )
{
try
{
world.disposeRealm( id );
}
catch ( NoSuchRealmException e )
{
// cannot happen.
}
}
}
managedRealmIds.clear();
// pluginArtifacts.clear();
}
public boolean hasExtensionRealm( Artifact extensionArtifact )
@ -73,6 +94,7 @@ public ClassRealm createExtensionRealm( Artifact extensionArtifact,
try
{
realm = container.getContainerRealm().createChildRealm( id );
managedRealmIds.add( id );
}
catch ( DuplicateRealmException e )
{
@ -92,101 +114,112 @@ public void importExtensionsIntoProjectRealm( String projectGroupId,
throws RealmManagementException
{
String extensionRealmId = RealmUtils.createExtensionRealmId( extensionArtifact );
List componentSetDescriptors = (List) extensionComponents.get( extensionRealmId );
// don't re-discover components once this is done once.
if ( componentSetDescriptors == null )
if ( extensionArtifact.getFile() == null )
{
ClassWorld discoveryWorld = new ClassWorld();
throw new RealmManagementException( extensionRealmId, "Cannot import project extensions; extension artifact has no associated file that can be scanned for extension components (extension: " + extensionArtifact.getId() + ")" );
}
ClassWorld discoveryWorld = new ClassWorld();
List componentSetDescriptors;
try
{
// Create an entire new ClassWorld, ClassRealm for discovering
// the immediate components of the extension artifact, so we don't pollute the
// container with component descriptors or realms that don't have any meaning beyond discovery.
ClassRealm discoveryRealm;
try
{
// Create an entire new ClassWorld, ClassRealm for discovering
// the immediate components of the extension artifact, so we don't pollute the
// container with component descriptors or realms that don't have any meaning beyond discovery.
ClassRealm discoveryRealm = new ClassRealm( discoveryWorld, "discovery" );
try
{
discoveryRealm.addURL( extensionArtifact.getFile().toURL() );
}
catch ( MalformedURLException e )
{
throw new RealmManagementException( extensionRealmId, extensionArtifact, "Unable to generate URL from extension artifact file: " + extensionArtifact.getFile() + " for local-component discovery.", e );
}
ComponentDiscoverer discoverer = new DefaultComponentDiscoverer();
discoverer.setManager( new DummyDiscovererManager() );
try
{
// Find the extension component descriptors that exist ONLY in the immediate extension
// artifact...this prevents us from adding plexus-archiver components to the mix, for instance,
// when the extension uses that dependency.
componentSetDescriptors = discoverer.findComponents( container.getContext(), discoveryRealm );
extensionComponents.put( extensionRealmId, componentSetDescriptors );
}
catch ( PlexusConfigurationException e )
{
throw new RealmManagementException( extensionRealmId, "Unable to discover components in extension artifact: " + extensionArtifact.getId(), e );
}
discoveryRealm = discoveryWorld.newRealm( "discovery: " + extensionRealmId );
}
finally
catch ( DuplicateRealmException e )
{
Collection realms = discoveryWorld.getRealms();
for ( Iterator it = realms.iterator(); it.hasNext(); )
throw new RealmManagementException( extensionRealmId, "Unable to create temporary ClassRealm for local-component discovery.", e );
}
try
{
discoveryRealm.addURL( extensionArtifact.getFile().toURL() );
}
catch ( MalformedURLException e )
{
throw new RealmManagementException( extensionRealmId, extensionArtifact, "Unable to generate URL from extension artifact file: " + extensionArtifact.getFile() + " for local-component discovery.", e );
}
ComponentDiscoverer discoverer = new DefaultComponentDiscoverer();
discoverer.setManager( new DummyDiscovererManager() );
try
{
// Find the extension component descriptors that exist ONLY in the immediate extension
// artifact...this prevents us from adding plexus-archiver components to the mix, for instance,
// when the extension uses that dependency.
componentSetDescriptors = discoverer.findComponents( container.getContext(), discoveryRealm );
}
catch ( PlexusConfigurationException e )
{
throw new RealmManagementException( extensionRealmId, "Unable to discover components in extension artifact: " + extensionArtifact.getId(), e );
}
ClassRealm realm = getProjectRealm( projectGroupId, projectArtifactId, projectVersion, true );
for ( Iterator it = componentSetDescriptors.iterator(); it.hasNext(); )
{
ComponentSetDescriptor compSet = (ComponentSetDescriptor) it.next();
for ( Iterator compIt = compSet.getComponents().iterator(); compIt.hasNext(); )
{
ClassRealm realm = (ClassRealm) it.next();
// For each component in the extension artifact:
ComponentDescriptor comp = (ComponentDescriptor) compIt.next();
String implementation = comp.getImplementation();
try
{
discoveryWorld.disposeRealm( realm.getId() );
logger.debug( "Importing: " + implementation + "\nwith role: " + comp.getRole() + "\nand hint: " + comp.getRoleHint() + "\nfrom extension realm: " + extensionRealmId + "\nto project realm: " + realm.getId() );
// Import the extension component's implementation class into the project-level
// realm.
realm.importFrom( extensionRealmId, implementation );
// Set the realmId to be used in looking up this extension component to the
// project-level realm, since we now have a restricted import
// that allows most of the extension to stay hidden, and the
// specific local extension components are still accessible
// from the project-level realm.
comp.setRealmId( realm.getId() );
// Finally, add the extension component's descriptor (with projectRealm
// set as the lookup realm) to the container.
container.addComponentDescriptor( comp );
}
catch ( NoSuchRealmException e )
{
throw new RealmManagementException( extensionRealmId, "Failed to create import for component: " + implementation + " from extension realm: " + extensionRealmId + " to project realm: " + realm.getId(), e );
}
catch ( ComponentRepositoryException e )
{
String projectId = RealmUtils.createProjectId( projectGroupId, projectArtifactId, projectVersion );
throw new RealmManagementException( extensionRealmId, "Unable to discover components from imports to project: " + projectId + " from extension artifact: " + extensionArtifact.getId(), e );
}
}
}
}
ClassRealm realm = getProjectRealm( projectGroupId, projectArtifactId, projectVersion, true );
for ( Iterator it = componentSetDescriptors.iterator(); it.hasNext(); )
finally
{
ComponentSetDescriptor compSet = (ComponentSetDescriptor) it.next();
for ( Iterator compIt = compSet.getComponents().iterator(); compIt.hasNext(); )
Collection realms = discoveryWorld.getRealms();
for ( Iterator it = realms.iterator(); it.hasNext(); )
{
// For each component in the extension artifact:
ComponentDescriptor comp = (ComponentDescriptor) compIt.next();
String implementation = comp.getImplementation();
ClassRealm realm = (ClassRealm) it.next();
try
{
logger.debug( "Importing: " + implementation + "\nwith role: " + comp.getRole() + "\nand hint: " + comp.getRoleHint() + "\nfrom extension realm: " + extensionRealmId + "\nto project realm: " + realm.getId() );
// Import the extension component's implementation class into the project-level
// realm.
realm.importFrom( extensionRealmId, implementation );
// Set the realmId to be used in looking up this extension component to the
// project-level realm, since we now have a restricted import
// that allows most of the extension to stay hidden, and the
// specific local extension components are still accessible
// from the project-level realm.
comp.setRealmId( realm.getId() );
// Finally, add the extension component's descriptor (with projectRealm
// set as the lookup realm) to the container.
container.addComponentDescriptor( comp );
discoveryWorld.disposeRealm( realm.getId() );
}
catch ( NoSuchRealmException e )
{
throw new RealmManagementException( extensionRealmId, "Failed to create import for component: " + implementation + " from extension realm: " + extensionRealmId + " to project realm: " + realm.getId(), e );
}
catch ( ComponentRepositoryException e )
{
String projectId = RealmUtils.createProjectId( projectGroupId, projectArtifactId, projectVersion );
throw new RealmManagementException( extensionRealmId, "Unable to discover components from imports to project: " + projectId + " from extension artifact: " + extensionArtifact.getId(), e );
}
}
}
}
public ClassRealm getProjectRealm( String projectGroupId, String projectArtifactId, String projectVersion )
@ -210,6 +243,7 @@ private ClassRealm getProjectRealm( String projectGroupId, String projectArtifac
try
{
realm = container.getContainerRealm().createChildRealm( id );
managedRealmIds.add( id );
}
catch ( DuplicateRealmException duplicateError )
{
@ -286,6 +320,7 @@ public ClassRealm createPluginRealm( Plugin plugin,
try
{
realm = world.newRealm( id );
// managedRealmIds.add( id );
}
catch ( DuplicateRealmException e )
{

View File

@ -56,6 +56,12 @@ public RealmManagementException( String realmId,
this.realmId = realmId;
}
public RealmManagementException( String realmId, String message )
{
super( message );
this.realmId = realmId;
}
public String getRealmId()
{
return realmId;

View File

@ -194,47 +194,47 @@ public void addPluginAsExtension( Plugin plugin,
if ( ( pluginArtifact != null )
&& coreFilter.include( pluginArtifact ) )
{
MavenProject dummyProject = new MavenProject( originatingModel );
EventDispatcher dispatcher = new DefaultEventDispatcher( request.getEventMonitors() );
MavenSession session = new MavenSession( container, request, dispatcher, null );
PluginDescriptor pd;
try
{
pd = pluginManager.verifyPlugin( plugin, dummyProject, session );
pluginArtifact = pd.getPluginArtifact();
}
catch ( ArtifactResolutionException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( ArtifactNotFoundException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( PluginNotFoundException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( PluginVersionResolutionException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( InvalidPluginException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( PluginManagerException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( PluginVersionNotFoundException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
if ( !realmManager.hasExtensionRealm( pluginArtifact ) )
{
MavenProject dummyProject = new MavenProject( originatingModel );
EventDispatcher dispatcher = new DefaultEventDispatcher( request.getEventMonitors() );
MavenSession session = new MavenSession( container, request, dispatcher, null );
PluginDescriptor pd;
try
{
pd = pluginManager.verifyPlugin( plugin, dummyProject, session );
pluginArtifact = pd.getPluginArtifact();
}
catch ( ArtifactResolutionException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( ArtifactNotFoundException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( PluginNotFoundException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( PluginVersionResolutionException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( InvalidPluginException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( PluginManagerException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
catch ( PluginVersionNotFoundException e )
{
throw new ExtensionManagerException( "Failed to resolve extension plugin: " + pluginArtifact, pluginArtifact, groupId, artifactId, version, e );
}
try
{
realmManager.createExtensionRealm( pluginArtifact, pd.getArtifacts() );
@ -300,71 +300,67 @@ private void addExtension( Artifact extensionArtifact,
if ( ( extensionArtifact != null )
&& coreFilter.include( extensionArtifact ) )
{
ArtifactFilter filter =
new ProjectArtifactExceptionFilter( coreFilter, projectArtifact );
ResolutionGroup resolutionGroup;
ArtifactRepository localRepository = request.getLocalRepository();
try
{
resolutionGroup = artifactMetadataSource.retrieve( extensionArtifact, localRepository, remoteRepositories );
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new ExtensionManagerException( "Unable to download metadata from repository for extension artifact '" +
extensionArtifact.getId() + "': " + e.getMessage(), extensionArtifact, projectGroupId, projectArtifactId, projectVersion, e );
}
Set dependencies = new LinkedHashSet();
dependencies.add( extensionArtifact );
dependencies.addAll( resolutionGroup.getArtifacts() );
ArtifactResolutionRequest dependencyReq = new ArtifactResolutionRequest().setArtifact( projectArtifact )
.setArtifactDependencies( dependencies )
.setFilter( filter )
.setLocalRepository( localRepository )
.setRemoteRepostories( remoteRepositories )
.setMetadataSource( artifactMetadataSource );
// TODO: Make this work with managed dependencies, or an analogous management section in the POM.
ArtifactResolutionResult result = artifactResolver.resolve( dependencyReq );
if ( result.hasCircularDependencyExceptions() || result.hasErrorArtifactExceptions()
|| result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() )
{
throw new ExtensionManagerException( "Failed to resolve extension: " + extensionArtifact, extensionArtifact, projectGroupId, projectArtifactId, projectVersion, result );
}
Set resultArtifacts = new LinkedHashSet();
for ( Iterator iterator = result.getArtifacts().iterator(); iterator.hasNext(); )
{
Artifact a = (Artifact) iterator.next();
if ( activeArtifactResolver != null )
{
a = activeArtifactResolver.replaceWithActiveArtifact( a );
}
getLogger().debug( "Adding: " + a.getFile() + " to classpath for extension: " + extensionArtifact.getId() );
resultArtifacts.add( a );
}
// TODO: This shouldn't be required, now that we're checking the core filter before getting here.
if ( !extensionArtifact.isResolved() || ( extensionArtifact.getFile() == null ) )
{
throw new ExtensionManagerException( "Extension artifact was not resolved, or has no file associated with it.", extensionArtifact, projectGroupId, projectArtifactId, projectVersion );
}
if ( !realmManager.hasExtensionRealm( extensionArtifact ) )
{
ArtifactFilter filter =
new ProjectArtifactExceptionFilter( coreFilter, projectArtifact );
ResolutionGroup resolutionGroup;
ArtifactRepository localRepository = request.getLocalRepository();
try
{
resolutionGroup = artifactMetadataSource.retrieve( extensionArtifact, localRepository, remoteRepositories );
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new ExtensionManagerException( "Unable to download metadata from repository for extension artifact '" +
extensionArtifact.getId() + "': " + e.getMessage(), extensionArtifact, projectGroupId, projectArtifactId, projectVersion, e );
}
// We use the same hack here to make sure that plexus 1.1 is available for extensions that do
// not declare plexus-utils but need it. MNG-2900
// DefaultPluginManager.checkPlexusUtils( resolutionGroup, artifactFactory );
Set dependencies = new LinkedHashSet();
dependencies.add( extensionArtifact );
dependencies.addAll( resolutionGroup.getArtifacts() );
ArtifactResolutionRequest dependencyReq = new ArtifactResolutionRequest().setArtifact( projectArtifact )
.setArtifactDependencies( dependencies )
.setFilter( filter )
.setLocalRepository( localRepository )
.setRemoteRepostories( remoteRepositories )
.setMetadataSource( artifactMetadataSource );
// TODO: Make this work with managed dependencies, or an analogous management section in the POM.
ArtifactResolutionResult result = artifactResolver.resolve( dependencyReq );
if ( result.hasCircularDependencyExceptions() || result.hasErrorArtifactExceptions()
|| result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() )
{
throw new ExtensionManagerException( "Failed to resolve extension: " + extensionArtifact, extensionArtifact, projectGroupId, projectArtifactId, projectVersion, result );
}
Set resultArtifacts = new LinkedHashSet();
for ( Iterator iterator = result.getArtifacts().iterator(); iterator.hasNext(); )
{
Artifact a = (Artifact) iterator.next();
if ( activeArtifactResolver != null )
{
a = activeArtifactResolver.replaceWithActiveArtifact( a );
}
getLogger().debug( "Adding: " + a.getFile() + " to classpath for extension: " + extensionArtifact.getId() );
resultArtifacts.add( a );
}
// TODO: This shouldn't be required, now that we're checking the core filter before getting here.
if ( !extensionArtifact.isResolved() || ( extensionArtifact.getFile() == null ) )
{
throw new ExtensionManagerException( "Extension artifact was not resolved, or has no file associated with it.", extensionArtifact, projectGroupId, projectArtifactId, projectVersion );
}
try
{
realmManager.createExtensionRealm( extensionArtifact, resultArtifacts );

View File

@ -0,0 +1,81 @@
package org.apache.maven.execution;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import java.io.File;
import java.net.URL;
import java.util.Collections;
public class DefaultMavenRealmManagerTest
extends PlexusTestCase
{
private ArtifactFactory factory;
protected void setUp() throws Exception
{
super.setUp();
factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
}
public void test_ReuseSingleExtensionRealmFromMultipleProjectRealms_UsingTwoManagerInstances()
throws RealmManagementException, ComponentLookupException
{
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
URL jarResource = cloader.getResource( "org/apache/maven/execution/test-extension-1.jar" );
Artifact ext1 = factory.createBuildArtifact( "org.group", "artifact-ext", "1", "jar" );
Artifact ext2 = factory.createBuildArtifact( "org.group", "artifact-ext", "1", "jar" );
assertNotSame( ext1, ext2 );
ext1.setFile( new File( jarResource.getPath() ) );
ext1.setResolved( true );
ext2.setFile( new File( jarResource.getPath() ) );
ext2.setResolved( true );
Logger logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "test" );
DefaultMavenRealmManager mgr1 = new DefaultMavenRealmManager( getContainer(), logger );
assertFalse( mgr1.hasExtensionRealm( ext1 ) );
mgr1.createExtensionRealm( ext1, Collections.EMPTY_SET );
assertTrue( mgr1.hasExtensionRealm( ext1 ) );
String pAid1 = "artifact-project1";
String pAid2 = "artifact-project1";
assertNotNull( ext1.getFile() );
mgr1.importExtensionsIntoProjectRealm( "org.group", pAid1, "2", ext1 );
String targetClass = ArtifactFactory.ROLE;
Object result1 = getContainer().lookup( targetClass, "test", mgr1.getProjectRealm( "org.group", pAid1, "2" ) );
assertNotNull( result1 );
DefaultMavenRealmManager mgr2 = new DefaultMavenRealmManager( getContainer(), logger );
assertNotNull( ext2.getFile() );
assertTrue( mgr2.hasExtensionRealm( ext2 ) );
// ext2 doesn't have a file associated with it, but it SHOULD succeed anyway.
mgr2.importExtensionsIntoProjectRealm( "org.group", pAid2, "2", ext2 );
Object result2 = getContainer().lookup( targetClass, "test", mgr2.getProjectRealm( "org.group", pAid2, "2" ) );
assertNotNull( result2 );
assertEquals( result1.getClass().getName(), result2.getClass().getName() );
}
}

View File

@ -170,7 +170,7 @@ under the License.
-->
<id>tycho</id>
<properties>
<bundleVersion>2.1.0.v20070901-1427</bundleVersion>
<bundleVersion>2.1.0.v20071105-1933</bundleVersion>
</properties>
<build>
<resources>

View File

@ -328,6 +328,19 @@ protected void verifyPlugin( Plugin plugin,
// ----------------------------------------------------------------------
public MavenProject readProject( File mavenProject )
throws ProjectBuildingException, ExtensionScanningException
{
try
{
return readProject( mavenProject, request );
}
finally
{
request.getRealmManager().clear();
}
}
private MavenProject readProject( File mavenProject, MavenExecutionRequest request )
throws ProjectBuildingException, ExtensionScanningException
{
getLogger().info( "Scanning for extensions: " + mavenProject );
@ -350,89 +363,96 @@ public MavenExecutionResult readProjectWithDependencies( MavenExecutionRequest r
try
{
request = populator.populateDefaults( request, configuration );
try
{
request = populator.populateDefaults( request, configuration );
// This is necessary to make the MavenEmbedderProjectWithExtensionReadingTest work which uses
// a custom type for a dependency like this:
// This is necessary to make the MavenEmbedderProjectWithExtensionReadingTest work which uses
// a custom type for a dependency like this:
//
// <dependency>
// <groupId>junit</groupId>
// <artifactId>junit</artifactId>
// <version>3.8.1</version>
// <scope>test</scope>
// <type>mkleint</type>
// </dependency>
//
// If the artifact handlers are not loaded up-front then this dependency element is not
// registered as an artifact and is not added to the classpath elements.
MavenProject project = readProject( request.getPom(), request );
// Map handlers = findArtifactTypeHandlers( project );
//TODO: ok this is crappy, now there are active collections so when new artifact handlers
// enter the system they should be available.
// artifactHandlerManager.addHandlers( handlers );
}
catch ( MavenEmbedderException e )
{
return result.addUnknownException( e );
}
catch ( ProjectBuildingException e )
{
return result.addProjectBuildingException( e );
}
catch ( ExtensionScanningException e )
{
return result.addExtensionScanningException( e );
}
ReactorManager reactorManager = maven.createReactorManager( request, result );
if ( result.hasExceptions() )
{
return result;
}
MavenProjectBuildingResult projectBuildingResult;
try
{
projectBuildingResult = mavenProjectBuilder.buildWithDependencies(
request.getPom(),
request.getLocalRepository(),
request.getProfileManager() );
}
catch ( ProjectBuildingException e )
{
return result.addProjectBuildingException( e );
}
if ( reactorManager.hasMultipleProjects() )
{
result.setProject( projectBuildingResult.getProject() );
result.setTopologicallySortedProjects( reactorManager.getSortedProjects() );
}
else
{
result.setProject( projectBuildingResult.getProject() );
result.setTopologicallySortedProjects( Arrays.asList( new MavenProject[]{ projectBuildingResult.getProject()} ) );
}
result.setArtifactResolutionResult( projectBuildingResult.getArtifactResolutionResult() );
// From this I could produce something that would help IDE integrators create importers:
// - topo sorted list of projects
// - binary dependencies
// - source dependencies (projects in the reactor)
//
// <dependency>
// <groupId>junit</groupId>
// <artifactId>junit</artifactId>
// <version>3.8.1</version>
// <scope>test</scope>
// <type>mkleint</type>
// </dependency>
//
// If the artifact handlers are not loaded up-front then this dependency element is not
// registered as an artifact and is not added to the classpath elements.
// We could create a layer approach here. As to do anything you must resolve a projects artifacts,
// and with that set you could then subsequently execute goals for each of those project.
MavenProject project = readProject( request.getPom() );
// Map handlers = findArtifactTypeHandlers( project );
//TODO: ok this is crappy, now there are active collections so when new artifact handlers
// enter the system they should be available.
// artifactHandlerManager.addHandlers( handlers );
}
catch ( MavenEmbedderException e )
{
return result.addUnknownException( e );
}
catch ( ProjectBuildingException e )
{
return result.addProjectBuildingException( e );
}
catch ( ExtensionScanningException e )
{
return result.addExtensionScanningException( e );
}
ReactorManager reactorManager = maven.createReactorManager( request, result );
if ( result.hasExceptions() )
{
return result;
}
MavenProjectBuildingResult projectBuildingResult;
try
finally
{
projectBuildingResult = mavenProjectBuilder.buildWithDependencies(
request.getPom(),
request.getLocalRepository(),
request.getProfileManager() );
request.getRealmManager().clear();
}
catch ( ProjectBuildingException e )
{
return result.addProjectBuildingException( e );
}
if ( reactorManager.hasMultipleProjects() )
{
result.setProject( projectBuildingResult.getProject() );
result.setTopologicallySortedProjects( reactorManager.getSortedProjects() );
}
else
{
result.setProject( projectBuildingResult.getProject() );
result.setTopologicallySortedProjects( Arrays.asList( new MavenProject[]{ projectBuildingResult.getProject()} ) );
}
result.setArtifactResolutionResult( projectBuildingResult.getArtifactResolutionResult() );
// From this I could produce something that would help IDE integrators create importers:
// - topo sorted list of projects
// - binary dependencies
// - source dependencies (projects in the reactor)
//
// We could create a layer approach here. As to do anything you must resolve a projects artifacts,
// and with that set you could then subsequently execute goals for each of those project.
return result;
}
// ----------------------------------------------------------------------
@ -786,6 +806,7 @@ public MavenExecutionResult execute( MavenExecutionRequest request )
finally
{
loggerManager.setThresholds( oldThreshold );
request.getRealmManager().clear();
}
}