o found another untested path way which i'll make another test for tomorrow. executing one mojos work, but when stringing

them together the optimization I'm trying to make for incremental support fails.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@753142 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-13 07:12:21 +00:00
parent 24139e8256
commit ecb1bfe2fd
18 changed files with 60 additions and 1130 deletions

View File

@ -215,7 +215,6 @@ public class DefaultArtifactFactory
ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( type );
return new DefaultArtifact( groupId, artifactId, versionRange, desiredScope, type, classifier, handler,
optional );
return new DefaultArtifact( groupId, artifactId, versionRange, desiredScope, type, classifier, handler, optional );
}
}

View File

@ -388,13 +388,12 @@ public class DefaultArtifactResolver
// This is often an artifact like a POM that is taken from disk and we already have hold of the
// file reference. But this may be a Maven Plugin that we need to resolve from a remote repository
// as well as its dependencies.
if ( request.isResolveRoot() && rootArtifact.getFile() == null )
{
{
try
{
resolve( rootArtifact, remoteRepositories, localRepository );
result.addArtifact( rootArtifact );
}
catch ( ArtifactResolutionException e )
{
@ -410,12 +409,16 @@ public class DefaultArtifactResolver
if ( artifacts == null || artifacts.size() == 0 )
{
result.addArtifact( rootArtifact );
return result;
}
// After the collection we will have the artifact object in the result but they will not be resolved yet.
result = artifactCollector.collect( artifacts, rootArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners );
// Add the root artifact
result.addArtifact( rootArtifact );
// We have metadata retrieval problems, or there are cycles that have been detected
// so we give this back to the calling code and let them deal with this information
// appropriately.
@ -449,7 +452,7 @@ public class DefaultArtifactResolver
}
}
}
return result;
}

View File

@ -27,7 +27,6 @@ import org.apache.maven.profiles.ProfileActivationContext;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.settings.Settings;
import org.apache.maven.wagon.events.TransferListener;
@ -118,8 +117,6 @@ public class DefaultMavenExecutionRequest
* @issue MNG-2681
*/
private boolean noSnapshotUpdates;
private MavenRealmManager realmManager;
public static MavenExecutionRequest copy( MavenExecutionRequest original )
{
@ -156,7 +153,6 @@ public class DefaultMavenExecutionRequest
copy.setProfileManager( original.getProfileManager() );
copy.setRemoteRepositories( original.getRemoteRepositories() );
copy.setNoSnapshotUpdates( original.isNoSnapshotUpdates() );
copy.setRealmManager( original.getRealmManager() );
return original;
}
@ -692,24 +688,6 @@ public class DefaultMavenExecutionRequest
return remoteRepositories;
}
public MavenExecutionRequest setRealmManager( MavenRealmManager realmManager )
{
this.realmManager = realmManager;
return this;
}
public MavenRealmManager getRealmManager()
{
return realmManager;
}
public MavenExecutionRequest clearAccumulatedBuildState()
{
realmManager.clear();
return this;
}
public ProfileActivationContext getProfileActivationContext()
{
return profileActivationContext;

View File

@ -30,7 +30,6 @@ import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.profiles.ProfileActivationContext;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.settings.Settings;
import org.apache.maven.wagon.events.TransferListener;
import org.codehaus.plexus.logging.Logger;
@ -221,10 +220,5 @@ public interface MavenExecutionRequest
MavenExecutionRequest setRemoteRepositories( List<ArtifactRepository> repositories );
List<ArtifactRepository> getRemoteRepositories();
MavenExecutionRequest setRealmManager( MavenRealmManager realmManager );
MavenRealmManager getRealmManager();
MavenExecutionRequest clearAccumulatedBuildState();
ProjectBuilderConfiguration getProjectBuildingConfiguration();
}

View File

@ -35,7 +35,6 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusContainer;
@ -65,16 +64,13 @@ public class MavenSession
//For testing
private ArtifactRepository localRepository;
private MavenRealmManager realmManager;
private List<String> pluginGroups;
public MavenSession( ArtifactRepository localRepository, List<String> pluginGroups, MavenRealmManager realmManager )
public MavenSession( ArtifactRepository localRepository, List<String> pluginGroups )
{
this.localRepository = localRepository;
this.pluginGroups = pluginGroups;
this.realmManager = realmManager;
}
public MavenSession( PlexusContainer container, MavenExecutionRequest request, EventDispatcher eventDispatcher, ReactorManager reactorManager )
@ -85,16 +81,6 @@ public class MavenSession
this.reactorManager = reactorManager;
}
public MavenRealmManager getRealmManager()
{
if ( realmManager != null )
{
return realmManager;
}
return request.getRealmManager();
}
public Map getPluginContext( PluginDescriptor pluginDescriptor, MavenProject project )
{
if ( reactorManager == null )

View File

@ -18,6 +18,7 @@ package org.apache.maven.plugin;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -73,9 +74,6 @@ import org.apache.maven.project.builder.PomInterpolatorTag;
import org.apache.maven.project.builder.PomTransformer;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.realm.RealmManagementException;
import org.apache.maven.realm.RealmScanningUtils;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.VersionNotFoundException;
@ -160,8 +158,7 @@ public class DefaultPluginManager
}
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, InvalidPluginException, PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException
{
String pluginVersion = plugin.getVersion();
@ -192,7 +189,7 @@ public class DefaultPluginManager
try
{
Artifact pluginArtifact = resolvePluginArtifact( plugin, project, session );
addPlugin( plugin, pluginArtifact, project, session );
project.addPlugin( plugin );
@ -221,11 +218,17 @@ public class DefaultPluginManager
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( plugin );
setDescriptorClassAndArtifactInfo( pluginDescriptor, project, session, new ArrayList() );
return pluginDescriptor;
}
// We need to load different
private Map<String,ClassRealm> pluginRealms = new HashMap<String,ClassRealm>();
private String pluginKey( Plugin plugin )
{
return plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion();
}
protected void addPlugin( Plugin plugin, Artifact pluginArtifact, MavenProject project, MavenSession session )
throws ArtifactNotFoundException, ArtifactResolutionException, PluginManagerException, InvalidPluginException
{
@ -242,37 +245,38 @@ public class DefaultPluginManager
{
projectPlugin = plugin;
}
else if ( projectPlugin.getVersion() == null || Artifact.RELEASE_VERSION.equals( projectPlugin.getVersion() ) || Artifact.LATEST_VERSION.equals( projectPlugin.getVersion() ) )
else if ( projectPlugin.getVersion() == null || Artifact.RELEASE_VERSION.equals( projectPlugin.getVersion() ) )
{
projectPlugin.setVersion( plugin.getVersion() );
}
Set<Artifact> artifactSet = getPluginArtifacts( pluginArtifact, projectPlugin, project, session.getLocalRepository() );
List<Artifact> artifacts = ( artifactSet == null || artifactSet.isEmpty() ) ? new ArrayList<Artifact>() : new ArrayList<Artifact>( artifactSet );
logger.debug( "Got plugin artifacts:\n\n" + artifacts );
MavenRealmManager realmManager = session.getRealmManager();
ClassRealm pluginRealm = realmManager.getPluginRealm( projectPlugin );
if ( pluginRealm == null )
{
try
{
pluginRealm = realmManager.createPluginRealm( projectPlugin, pluginArtifact, artifacts, coreArtifactFilterManager.getArtifactFilter() );
logger.debug( "Created realm: " + pluginRealm + " for plugin: " + projectPlugin.getKey() );
}
catch ( RealmManagementException e )
{
throw new PluginContainerException( plugin, "Failed to create realm for plugin '" + projectPlugin, e );
}
// associate the realm with the descriptor
ClassRealm pluginRealm = pluginRealms.get( pluginKey( plugin ) );
if ( pluginRealm == null )
{
pluginRealm = container.createChildRealm( pluginKey( plugin ) );
Set<Artifact> pluginArtifacts = getPluginArtifacts( pluginArtifact, projectPlugin, project, session.getLocalRepository() );
for( Artifact a : pluginArtifacts )
{
try
{
pluginRealm.addURL( a.getFile().toURI().toURL() );
}
catch ( MalformedURLException e )
{
// Not going to happen
}
}
try
{
logger.debug( "Discovering components in realm: " + pluginRealm );
container.discoverComponents( pluginRealm );
container.discoverComponents( pluginRealm );
}
catch ( PlexusConfigurationException e )
{
@ -300,24 +304,16 @@ public class DefaultPluginManager
}
logger.debug( "Removing invalid plugin realm." );
realmManager.disposePluginRealm( projectPlugin );
throw new PluginManagerException( projectPlugin, "The plugin descriptor for the plugin " + projectPlugin.getKey() + " was not found. Should have been in realm: " + pluginRealm
+ " Please verify that the plugin JAR " + pluginArtifact.getFile() + " is intact.", project );
}
pluginDescriptor.setPluginArtifact( pluginArtifact );
logger.debug( "Realm for plugin: " + plugin.getKey() + ":\n" + pluginRealm );
}
else
{
List<Artifact> managedPluginArtifacts = realmManager.getPluginArtifacts( projectPlugin );
if ( ( managedPluginArtifacts == null ) || ( managedPluginArtifacts.isEmpty() && !artifacts.isEmpty() ) )
{
realmManager.setPluginArtifacts( projectPlugin, artifacts );
}
pluginDescriptor.setPluginArtifact( pluginArtifact );
pluginDescriptor.setClassRealm( pluginRealm );
pluginRealms.put( pluginKey( plugin ), pluginRealm );
}
}
@ -387,7 +383,8 @@ public class DefaultPluginManager
.setLocalRepository( localRepository )
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
.setManagedVersionMap( pluginManagedDependencies )
.setFilter( filter );
.setFilter( filter )
.setResolveRoot( false ); // We are setting this to false because the artifact itself has been resolved.
ArtifactResolutionResult result = repositorySystem.resolve( request );
resolutionErrorHandler.throwErrors( request, result );
@ -414,11 +411,8 @@ public class DefaultPluginManager
// ----------------------------------------------------------------------
// Mojo execution
// ----------------------------------------------------------------------
public void executeMojo( MavenProject project, MojoExecution mojoExecution )
throws MojoFailureException, PluginExecutionException, PluginConfigurationException
{
}
// We should assume that We've already loaded the plugin in question.
public void executeMojo( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws MojoFailureException, PluginExecutionException, PluginConfigurationException
@ -574,8 +568,8 @@ public class DefaultPluginManager
//dispatcher.dispatchStart( event, goalExecId );
pluginRealm = pluginDescriptor.getClassRealm();
pluginRealm = pluginDescriptor.getClassRealm();
logger.debug( "Setting context classloader for plugin to: " + pluginRealm.getId() + " (instance is: " + pluginRealm + ")" );
Thread.currentThread().setContextClassLoader( pluginRealm );
@ -655,16 +649,6 @@ public class DefaultPluginManager
}
}
private Plugin createDummyPlugin( PluginDescriptor pluginDescriptor )
{
Plugin plugin = new Plugin();
plugin.setGroupId( pluginDescriptor.getGroupId() );
plugin.setArtifactId( pluginDescriptor.getArtifactId() );
plugin.setVersion( pluginDescriptor.getVersion() );
return plugin;
}
public MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException, ArtifactResolutionException
{
@ -708,24 +692,8 @@ public class DefaultPluginManager
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
setDescriptorClassAndArtifactInfo( pluginDescriptor, project, session, realmActions );
ClassRealm pluginRealm = pluginDescriptor.getClassRealm();
if ( mojoDescriptor.isRequiresReports() )
{
Set reportDescriptors = session.getReportMojoDescriptors();
if ( ( reportDescriptors != null ) && !reportDescriptors.isEmpty() )
{
for ( Iterator it = reportDescriptors.iterator(); it.hasNext(); )
{
MojoDescriptor reportDescriptor = (MojoDescriptor) it.next();
setDescriptorClassAndArtifactInfo( reportDescriptor.getPluginDescriptor(), project, session, realmActions );
}
}
}
// We are forcing the use of the plugin realm for all lookups that might occur during
// the lifecycle that is part of the lookup. Here we are specifically trying to keep
// lookups that occur in contextualize calls in line with the right realm.
@ -735,10 +703,11 @@ public class DefaultPluginManager
Thread.currentThread().setContextClassLoader( pluginRealm );
try
{
System.out.println( pluginDescriptor );
logger.debug( "Looking up mojo " + mojoDescriptor.getRoleHint() + " in realm " + pluginRealm.getId() + " - descRealmId=" + mojoDescriptor.getRealm() );
Mojo mojo;
try
{
mojo = container.lookup( Mojo.class, mojoDescriptor.getRoleHint() );
@ -877,44 +846,6 @@ public class DefaultPluginManager
}
}
private void setDescriptorClassAndArtifactInfo( PluginDescriptor pluginDescriptor, MavenProject project, MavenSession session, List realmActions )
{
MavenRealmManager realmManager = session.getRealmManager();
ClassRealm projectRealm = realmManager.getProjectRealm( project.getGroupId(), project.getArtifactId(), project.getVersion() );
if ( projectRealm == null )
{
logger.debug( "Realm for project: " + project.getId() + " not found. Using container realm instead." );
projectRealm = container.getContainerRealm();
}
Plugin plugin = project.getPlugin( pluginDescriptor.getPluginLookupKey() );
if ( plugin == null )
{
plugin = createDummyPlugin( pluginDescriptor );
}
ClassRealm pluginRealm = realmManager.getPluginRealm( plugin );
if ( pluginRealm == null )
{
logger.debug( "Realm for plugin: " + pluginDescriptor.getId() + " not found. Using project realm instead." );
pluginRealm = projectRealm;
realmActions.add( new PluginRealmAction( pluginDescriptor ) );
}
else
{
pluginRealm.setParentRealm( projectRealm );
realmActions.add( new PluginRealmAction( pluginDescriptor, pluginRealm ) );
}
logger.debug( "Setting realm for plugin descriptor: " + pluginDescriptor.getId() + " to: " + pluginRealm );
pluginDescriptor.setClassRealm( pluginRealm );
pluginDescriptor.setArtifacts( realmManager.getPluginArtifacts( plugin ) );
}
private PlexusConfiguration extractMojoConfiguration( PlexusConfiguration mergedConfiguration, MojoDescriptor mojoDescriptor )
{
Map parameterMap = mojoDescriptor.getParameterMap();
@ -1672,8 +1603,7 @@ public class DefaultPluginManager
return version;
}
// Plugin Manager Support
// We need to strip out the methods in here for a validation method.
public Artifact resolvePluginArtifact( Plugin plugin, MavenProject project, MavenSession session )
throws PluginManagerException, InvalidPluginException, PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException
{
@ -1749,86 +1679,6 @@ public class DefaultPluginManager
throw new InvalidPluginException( "Plugin: " + plugin.getKey() + " has a dependency with an invalid version." );
}
}
public PluginDescriptor loadIsolatedPluginDescriptor( Plugin plugin, MavenProject project, MavenSession session )
{
if ( plugin.getVersion() == null )
{
try
{
plugin.setVersion( resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), project, session ) );
}
catch ( PluginVersionResolutionException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( InvalidPluginException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( PluginVersionNotFoundException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
}
if ( plugin.getVersion() == null )
{
return null;
}
Artifact artifact = null;
try
{
artifact = resolvePluginArtifact( plugin, project, session );
}
catch ( ArtifactResolutionException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( ArtifactNotFoundException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( PluginManagerException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( InvalidPluginException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( PluginVersionResolutionException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
if ( artifact == null )
{
return null;
}
MavenPluginDiscoverer discoverer = new MavenPluginDiscoverer();
discoverer.setManager( RealmScanningUtils.getDummyComponentDiscovererManager() );
try
{
List componentSetDescriptors =
RealmScanningUtils.scanForComponentSetDescriptors( artifact, discoverer, container.getContext(),
"Plugin: " + plugin.getKey() );
if ( !componentSetDescriptors.isEmpty() )
{
return (PluginDescriptor) componentSetDescriptors.get( 0 );
}
}
catch ( RealmManagementException e )
{
logger.debug( "Failed to scan plugin artifact: " + artifact.getId() + " for descriptors.", e );
}
return null;
}
// Plugin Mapping Manager

View File

@ -2,7 +2,6 @@ package org.apache.maven.plugin;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.realm.RealmManagementException;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
@ -45,11 +44,6 @@ public class PluginContainerException
this.pluginRealm = pluginRealm;
}
public PluginContainerException( Plugin plugin, String message, RealmManagementException e )
{
super( plugin, message, e );
}
public ClassRealm getPluginRealm()
{
return pluginRealm;

View File

@ -5,7 +5,6 @@ import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.realm.RealmManagementException;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
@ -159,15 +158,6 @@ public class PluginManagerException
pluginVersion = plugin.getVersion();
}
public PluginManagerException( Plugin plugin, String message, RealmManagementException cause )
{
super( message, cause );
pluginGroupId = plugin.getGroupId();
pluginArtifactId = plugin.getArtifactId();
pluginVersion = plugin.getVersion();
}
public PluginManagerException( Plugin plugin, String message, MavenProject project )
{
super( message );

View File

@ -1,390 +0,0 @@
package org.apache.maven.realm;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.model.Plugin;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
import org.codehaus.plexus.component.discovery.ComponentDiscoverer;
import org.codehaus.plexus.component.discovery.DefaultComponentDiscoverer;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
import org.codehaus.plexus.logging.Logger;
import java.net.MalformedURLException;
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 pluginArtifacts = new HashMap();
private Set managedRealmIds = new HashSet();
private final ClassWorld world;
private final PlexusContainer container;
private final Logger logger;
public DefaultMavenRealmManager( PlexusContainer container, Logger logger )
{
world = container.getContainerRealm().getWorld();
this.container = container;
this.logger = logger;
}
//mkleint: the clearing is fine for sequenced operations. Even though the
// MavenRealmManager is associated with request, the paralel execution will
// eventualy fail as the ClassWorld and PlexusContainer are not meant for
// multithreaded environment.
public void 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
{
logger.debug( "disposing managed ClassRealm with id: " + id );
world.disposeRealm( id );
logger.debug( "dissociating all components from managed ClassRealm with id: " + id );
container.removeComponentRealm( realm );
}
catch ( NoSuchRealmException e )
{
// cannot happen.
}
catch ( PlexusContainerException e )
{
logger.debug( "Error while dissociating: " + e.getMessage(), e );
}
}
}
managedRealmIds.clear();
pluginArtifacts.clear();
}
public boolean hasExtensionRealm( Artifact extensionArtifact )
{
String id = RealmUtils.createExtensionRealmId( extensionArtifact );
try
{
return world.getRealm( id ) != null;
}
catch ( NoSuchRealmException e )
{
return false;
}
}
public ClassRealm createExtensionRealm( Artifact extensionArtifact, List artifacts )
throws RealmManagementException
{
String id = RealmUtils.createExtensionRealmId( extensionArtifact );
ClassRealm realm;
try
{
realm = container.getContainerRealm().createChildRealm( id );
managedRealmIds.add( id );
}
catch ( DuplicateRealmException e )
{
throw new RealmManagementException( id, "Extension realm: " + id + " already exists.", e );
}
populateRealm( id, realm, extensionArtifact, artifacts, null );
return realm;
}
public void importExtensionsIntoProjectRealm( String projectGroupId, String projectArtifactId,
String projectVersion, Artifact extensionArtifact )
throws RealmManagementException
{
String extensionRealmId = RealmUtils.createExtensionRealmId( extensionArtifact );
if ( extensionArtifact.getFile() == null )
{
throw new RealmManagementException( extensionRealmId,
"Cannot import project extensions; extension artifact has no associated file that can be scanned for extension components (extension: " +
extensionArtifact.getId() + ")" );
}
ComponentDiscoverer discoverer = new DefaultComponentDiscoverer();
discoverer.setManager( RealmScanningUtils.getDummyComponentDiscovererManager() );
List componentSetDescriptors = RealmScanningUtils.scanForComponentSetDescriptors( extensionArtifact, discoverer,
container.getContext(),
extensionRealmId );
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(); )
{
// For each component in the extension artifact:
ComponentDescriptor comp = (ComponentDescriptor) compIt.next();
String implementation = comp.getImplementation();
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.setRealm( realm );
// 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 );
}
}
}
}
public ClassRealm getProjectRealm( String projectGroupId, String projectArtifactId, String projectVersion )
{
return getProjectRealm( projectGroupId, projectArtifactId, projectVersion, false );
}
private ClassRealm getProjectRealm( String projectGroupId, String projectArtifactId, String projectVersion,
boolean create )
{
String id = RealmUtils.createProjectId( projectGroupId, projectArtifactId, projectVersion );
ClassRealm realm = null;
try
{
realm = world.getRealm( id );
}
catch ( NoSuchRealmException e )
{
if ( create )
{
try
{
realm = container.getContainerRealm().createChildRealm( id );
managedRealmIds.add( id );
}
catch ( DuplicateRealmException duplicateError )
{
// won't happen.
}
}
}
return realm;
}
public ClassRealm getPluginRealm( Plugin plugin )
{
String id = RealmUtils.createPluginRealmId( plugin );
logger.debug( "Retrieving realm for plugin with id: " + id );
ClassRealm pluginRealm = null;
try
{
pluginRealm = world.getRealm( id );
//MNG-3012
String parentRealmId = container.getContainerRealm().getId();
pluginRealm.importFrom( parentRealmId, Xpp3Dom.class.getName() );
pluginRealm.importFrom( parentRealmId, XmlPullParser.class.getName() );
pluginRealm.importFrom( parentRealmId, XmlPullParserException.class.getName() );
pluginRealm.importFrom( parentRealmId, XmlSerializer.class.getName() );
}
catch ( NoSuchRealmException e )
{
}
finally
{
return pluginRealm;
}
}
public void disposePluginRealm( Plugin plugin )
{
String id = RealmUtils.createPluginRealmId( plugin );
logger.debug( "Disposing realm for plugin with id: " + id );
try
{
world.disposeRealm( id );
}
catch ( NoSuchRealmException e )
{
logger.debug( "Plugin realm: " + id + " didn't exist in ClassWorld instance." );
}
managedRealmIds.remove( id );
pluginArtifacts.remove( id );
}
public ClassRealm createPluginRealm( Plugin plugin, Artifact pluginArtifact, List artifacts,
ArtifactFilter coreArtifactFilter )
throws RealmManagementException
{
String id = RealmUtils.createPluginRealmId( plugin );
logger.debug( "Creating realm for plugin with id: " + id );
ClassRealm realm;
try
{
realm = world.newRealm( id );
managedRealmIds.add( id );
}
catch ( DuplicateRealmException e )
{
throw new RealmManagementException( id, "Plugin realm: " + id + " already exists.", e );
}
populateRealm( id, realm, pluginArtifact, artifacts, coreArtifactFilter );
logger.debug( "Saving artifacts:\n\n" + artifacts + "\n\nfor plugin: " + id );
pluginArtifacts.put( id, artifacts );
return realm;
}
private void populateRealm( String id, ClassRealm realm, Artifact mainArtifact, List artifacts,
ArtifactFilter coreArtifactFilter )
throws RealmManagementException
{
if ( !artifacts.contains( mainArtifact ) )
{
try
{
realm.addURL( mainArtifact.getFile().toURI().toURL() );
}
catch ( MalformedURLException e )
{
throw new RealmManagementException( id, mainArtifact, "Invalid URL for artifact file: " +
mainArtifact.getFile() + " to be used in realm: " + id + ".", e );
}
}
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
{
Artifact artifact = (Artifact) it.next();
if ( ( coreArtifactFilter == null ) || coreArtifactFilter.include( artifact ) )
{
try
{
realm.addURL( artifact.getFile().toURI().toURL() );
}
catch ( MalformedURLException e )
{
throw new RealmManagementException( id, artifact, "Invalid URL for artifact file: " +
artifact.getFile() + " to be used in realm: " + id + ".", e );
}
}
else
{
logger.debug( "Excluding artifact: " + artifact.getArtifactId() +
" from plugin realm; it's already included in Maven's core." );
}
}
}
public List getPluginArtifacts( Plugin plugin )
{
String id = RealmUtils.createPluginRealmId( plugin );
logger.debug( "Getting artifacts used in realm for plugin with id: " + id );
Collection artifacts = (Collection) pluginArtifacts.get( id );
if ( artifacts != null )
{
logger.debug( "Returning artifacts:\n\n" + artifacts + "\n\nfor plugin: " + id );
return new ArrayList( artifacts );
}
logger.debug( "Found no artifacts for plugin: " + id );
return null;
}
public void setPluginArtifacts( Plugin plugin, List artifacts )
{
String id = RealmUtils.createPluginRealmId( plugin );
logger.debug( "Setting artifact collection for plugin with id: " + id + " to:\n\n" + artifacts );
pluginArtifacts.put( id, artifacts );
}
}

View File

@ -1,37 +0,0 @@
package org.apache.maven.realm;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.model.Plugin;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import java.util.List;
public interface MavenRealmManager
{
void clear();
boolean hasExtensionRealm( Artifact extensionArtifact );
ClassRealm createExtensionRealm( Artifact extensionArtifact, List artifacts )
throws RealmManagementException;
void importExtensionsIntoProjectRealm( String projectGroupId, String projectArtifactId, String projectVersion,
Artifact extensionArtifact )
throws RealmManagementException;
ClassRealm getProjectRealm( String groupId, String artifactId, String version );
ClassRealm getPluginRealm( Plugin plugin );
List getPluginArtifacts( Plugin plugin );
ClassRealm createPluginRealm( Plugin plugin, Artifact pluginArtifact, List artifacts,
ArtifactFilter coreArtifactFilter )
throws RealmManagementException;
void disposePluginRealm( Plugin plugin );
void setPluginArtifacts( Plugin plugin, List artifacts );
}

View File

@ -1,83 +0,0 @@
package org.apache.maven.realm;
import org.apache.maven.artifact.Artifact;
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import java.net.MalformedURLException;
public class RealmManagementException
extends Exception
{
private final String realmId;
private String offendingGroupId;
private String offendingArtifactId;
private String offendingVersion;
public RealmManagementException( String realmId, String message, DuplicateRealmException cause )
{
super( message, cause );
this.realmId = realmId;
}
public RealmManagementException( String realmId, Artifact offendingArtifact, String message,
MalformedURLException cause )
{
super( message, cause );
this.realmId = realmId;
offendingGroupId = offendingArtifact.getGroupId();
offendingArtifactId = offendingArtifact.getArtifactId();
offendingVersion = offendingArtifact.getVersion();
}
public RealmManagementException( String realmId, String message, NoSuchRealmException cause )
{
super( message, cause );
this.realmId = realmId;
}
public RealmManagementException( String realmId, String message, ComponentRepositoryException cause )
{
super( message, cause );
this.realmId = realmId;
}
public RealmManagementException( String realmId, String message, PlexusConfigurationException cause )
{
super( message, cause );
this.realmId = realmId;
}
public RealmManagementException( String realmId, String message )
{
super( message );
this.realmId = realmId;
}
public String getRealmId()
{
return realmId;
}
public String getOffendingGroupId()
{
return offendingGroupId;
}
public String getOffendingArtifactId()
{
return offendingArtifactId;
}
public String getOffendingVersion()
{
return offendingVersion;
}
}

View File

@ -1,135 +0,0 @@
package org.apache.maven.realm;
import org.apache.maven.artifact.Artifact;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
import org.codehaus.plexus.component.discovery.ComponentDiscoverer;
import org.codehaus.plexus.component.discovery.ComponentDiscovererManager;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.context.Context;
import java.net.MalformedURLException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class RealmScanningUtils
{
private static final String DISCOVERY_REALM_ID = "discovery realm";
public static List scanForComponentSetDescriptors( Artifact artifact, ComponentDiscoverer discoverer,
Context context, String discoveryContextId )
throws RealmManagementException
{
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
{
discoveryRealm = discoveryWorld.newRealm( DISCOVERY_REALM_ID );
}
catch ( DuplicateRealmException e )
{
throw new RealmManagementException( discoveryContextId,
"Unable to create temporary ClassRealm for local-component discovery.",
e );
}
try
{
discoveryRealm.addURL( artifact.getFile().toURL() );
}
catch ( MalformedURLException e )
{
throw new RealmManagementException( discoveryContextId, artifact,
"Unable to generate URL from artifact file: " + artifact.getFile() +
" for local-component discovery.", e );
}
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( context, discoveryRealm );
}
catch ( PlexusConfigurationException e )
{
throw new RealmManagementException( discoveryContextId,
"Unable to discover components in artifact: " + artifact.getId(),
e );
}
}
finally
{
Collection realms = discoveryWorld.getRealms();
for ( Iterator it = realms.iterator(); it.hasNext(); )
{
ClassRealm realm = (ClassRealm) it.next();
try
{
discoveryWorld.disposeRealm( realm.getId() );
}
catch ( NoSuchRealmException e )
{
}
}
}
return componentSetDescriptors;
}
public static ComponentDiscovererManager getDummyComponentDiscovererManager()
{
return new DummyDiscovererManager();
}
private static final class DummyDiscovererManager
implements ComponentDiscovererManager
{
public void fireComponentDiscoveryEvent( ComponentDiscoveryEvent arg0 )
{
}
public List getComponentDiscoverers()
{
return null;
}
public Map getComponentDiscoveryListeners()
{
return null;
}
public List getListeners()
{
return null;
}
public void initialize()
{
}
public void registerComponentDiscoveryListener( ComponentDiscoveryListener l )
{
}
public void removeComponentDiscoveryListener( ComponentDiscoveryListener l )
{
}
}
}

View File

@ -1,94 +0,0 @@
package org.apache.maven.realm;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
public final class RealmUtils
{
private RealmUtils()
{
}
public static String createExtensionRealmId( Artifact extensionArtifact )
{
return "/extensions/" + extensionArtifact.getGroupId() + ":" + extensionArtifact.getArtifactId() + ":" +
extensionArtifact.getVersion() + "/thread:" +
Thread.currentThread().getId(); //add thread to the mix to prevent clashes in parallel execution
}
public static String createProjectId( String projectGroupId, String projectArtifactId, String projectVersion )
{
return "/projects/" + projectGroupId + ":" + projectArtifactId + ":" + projectVersion + "/thread:" +
Thread.currentThread().getId(); //add thread to the mix to prevent clashes in parallel execution
}
public static String createPluginRealmId( Plugin plugin )
{
StringBuffer id = new StringBuffer().append( "/plugins/" )
.append( plugin.getGroupId() )
.append( ':' )
.append( plugin.getArtifactId() )
.append( ':' )
.append( plugin.getVersion() );
StringBuffer depId = new StringBuffer();
Collection dependencies = plugin.getDependencies();
if ( ( dependencies != null ) && !dependencies.isEmpty() )
{
dependencies = new LinkedHashSet( dependencies );
for ( Iterator it = dependencies.iterator(); it.hasNext(); )
{
Dependency dep = (Dependency) it.next();
depId.append( dep.getGroupId() )
.append( ':' )
.append( dep.getArtifactId() )
.append( ';' )
.append( dep.getVersion() );
if ( it.hasNext() )
{
depId.append( ',' );
}
}
}
else
{
depId.append( '0' );
}
id.append( '@' ).append( depId.toString().hashCode() )
.append( "/thread:" ).append(
Thread.currentThread().getId() ); //add thread to the mix to prevent clashes in parallel execution
return id.toString();
}
}

View File

@ -1,80 +0,0 @@
package org.apache.maven.execution;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.realm.DefaultMavenRealmManager;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.FileUtils;
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 = lookup( ArtifactFactory.class );
}
public void test_ReuseSingleExtensionRealmFromMultipleProjectRealms_UsingTwoManagerInstances()
throws Exception
{
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( FileUtils.toFile( jarResource ) );
ext1.setResolved( true );
ext2.setFile( FileUtils.toFile( jarResource ) );
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_LIST );
assertTrue( mgr1.hasExtensionRealm( ext1 ) );
String pAid1 = "artifact-project1";
String pAid2 = "artifact-project1";
assertNotNull( ext1.getFile() );
mgr1.importExtensionsIntoProjectRealm( "org.group", pAid1, "2", ext1 );
ArtifactFactory result1 = getContainer().lookup( ArtifactFactory.class, "test" );
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 );
ArtifactFactory result2 = getContainer().lookup( ArtifactFactory.class, "test" );
assertNotNull( result2 );
assertEquals( result1.getClass().getName(), result2.getClass().getName() );
}
}

View File

@ -19,13 +19,10 @@ import org.apache.maven.project.DefaultProjectBuilderConfiguration;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.realm.DefaultMavenRealmManager;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.FileUtils;
public class LifecycleExecutorTest
@ -87,17 +84,12 @@ public class LifecycleExecutorTest
MavenProject project = projectBuilder.build( targetPom, configuration );
assertEquals( "maven", project.getArtifactId() );
assertEquals( "3.0-SNAPSHOT", project.getVersion() );
// We need a local repository and realm manager in the session in order to execute a mojo. This
// is not really a good situation.
MavenRealmManager realmManager = new DefaultMavenRealmManager( getContainer(), new ConsoleLogger( 0, "logger" ) );
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setProjectPresent( true )
.setPluginGroups( Arrays.asList( new String[]{ "org.apache.maven.plugins"} ) )
.setLocalRepository( localRepository )
.setRemoteRepositories( Arrays.asList( repositorySystem.buildArtifactRepository( repository ) ) )
.setRealmManager( realmManager )
.setProperties( new Properties() );
MavenSession session = new MavenSession( getContainer(), request, null, null );

View File

@ -24,7 +24,6 @@ import java.util.List;
import java.util.Properties;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.realm.MavenRealmManager;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;
@ -129,10 +128,6 @@ public interface Configuration
List<URL> getExtensions();
Configuration setRealmManager( MavenRealmManager realmManager );
MavenRealmManager getRealmManager();
// ----------------------------------------------------------------------------
// Event Monitors
// ----------------------------------------------------------------------------

View File

@ -25,7 +25,6 @@ import java.util.List;
import java.util.Properties;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.realm.MavenRealmManager;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;
@ -59,8 +58,6 @@ public class DefaultConfiguration
private File localRepository;
private MavenRealmManager realmManager;
private List<EventMonitor> eventMonitors;
/** Creates a new instance of DefaultConfiguration */
@ -224,17 +221,6 @@ public class DefaultConfiguration
return localRepository;
}
public MavenRealmManager getRealmManager()
{
return realmManager;
}
public Configuration setRealmManager( MavenRealmManager realmManager )
{
this.realmManager = realmManager;
return this;
}
public Configuration addEventMonitor( EventMonitor eventMonitor )
{
if ( eventMonitors == null )

View File

@ -38,7 +38,6 @@ import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileActivationContext;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.realm.DefaultMavenRealmManager;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.apache.maven.settings.Mirror;
@ -95,8 +94,6 @@ public class DefaultMavenExecutionRequestPopulator
artifactTransferMechanism( request, configuration );
realmManager( request, configuration );
profileManager( request, configuration );
processSettings( request, configuration );
@ -133,21 +130,6 @@ public class DefaultMavenExecutionRequestPopulator
}
}
private void realmManager( MavenExecutionRequest request, Configuration configuration )
{
if ( request.getRealmManager() == null )
{
if ( configuration.getRealmManager() == null )
{
request.setRealmManager( new DefaultMavenRealmManager( container, getLogger() ) );
}
else
{
request.setRealmManager( configuration.getRealmManager() );
}
}
}
private void processSettings( MavenExecutionRequest request, Configuration configuration )
throws MavenEmbedderException
{