o another pass the the plugin manager

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@774487 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-05-13 18:42:56 +00:00
parent 73fc3f1b0c
commit a2ac490107
9 changed files with 51 additions and 66 deletions

View File

@ -127,10 +127,6 @@ public class ArtifactResolutionRequest
return this;
}
// ------------------------------------------------------------------------
//
// ------------------------------------------------------------------------
public ArtifactMetadataSource getMetadataSource()
{
return metadataSource;

View File

@ -41,6 +41,7 @@ import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.PluginExecutionException;
import org.apache.maven.plugin.PluginLoaderException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
@ -64,6 +65,12 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
//TODO: Inside an IDE we are replacing the notion of our reactor with a workspace. In both of these cases
// we need to layer these as local repositories.
//TODO: Cache the lookups of the PluginDescriptors
//TODO: check for online status in the build plan and die if necessary
//TODO if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() )
//{
// throw new PluginExecutionException( mojoExecution, project, "Cannot execute mojo: " + mojoDescriptor.getGoal()
// + ". It requires a project with an existing pom.xml, but the build is not using one." );
//}
/**
* @author Jason van Zyl

View File

@ -22,4 +22,8 @@ public class DefaultPluginClassLoaderCache
return pluginClassLoaders.get( key );
}
public int size()
{
return pluginClassLoaders.size();
}
}

View File

@ -148,10 +148,6 @@ public class DefaultPluginManager
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionResolutionException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginContainerException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
@ -168,7 +164,7 @@ public class DefaultPluginManager
}
protected PluginDescriptor addPlugin( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactNotFoundException, ArtifactResolutionException, PluginVersionResolutionException, PluginContainerException, PluginVersionNotFoundException
throws ArtifactNotFoundException, ArtifactResolutionException, PluginContainerException, PluginVersionNotFoundException
{
Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin );
@ -181,7 +177,14 @@ public class DefaultPluginManager
resolutionErrorHandler.throwErrors( request, result );
ClassRealm pluginRealm = container.createChildRealm( pluginKey( plugin ) );
ClassRealm pluginRealm = pluginClassLoaderCache.get( constructPluginKey( plugin ) );
if ( pluginRealm != null )
{
return getPluginDescriptor( plugin );
}
pluginRealm = container.createChildRealm( pluginKey( plugin ) );
Set<Artifact> pluginArtifacts = getPluginArtifacts( pluginArtifact, plugin, localRepository, remoteRepositories );
@ -196,13 +199,9 @@ public class DefaultPluginManager
// Not going to happen
}
}
//pluginRealm.display();
try
{
logger.debug( "Discovering components in realm: " + pluginRealm );
container.discoverComponents( pluginRealm );
}
catch ( PlexusConfigurationException e )
@ -215,21 +214,10 @@ public class DefaultPluginManager
}
pluginClassLoaderCache.put( constructPluginKey( plugin ), pluginRealm );
PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin );
// We just need to keep track of the realm, if we need to augment we will wrap the realm
pluginDescriptor.setPluginArtifact( pluginArtifact );
pluginDescriptor.setArtifacts( new ArrayList<Artifact>( pluginArtifacts ) );
pluginDescriptor.setClassRealm( pluginRealm );
return pluginDescriptor;
return getPluginDescriptor( plugin );
}
// plugin artifact
// its dependencies while filtering out what's in the core
// layering on the project level plugin dependencies
private Set<Artifact> getPluginArtifacts( Artifact pluginArtifact, Plugin pluginAsSpecifiedinPom, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactNotFoundException, ArtifactResolutionException
{
@ -283,23 +271,6 @@ public class DefaultPluginManager
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() )
{
throw new PluginExecutionException( mojoExecution, project, "Cannot execute mojo: " + mojoDescriptor.getGoal()
+ ". It requires a project with an existing pom.xml, but the build is not using one." );
}
if ( mojoDescriptor.isOnlineRequired() && session.isOffline() )
{
// TODO: Should we error out, or simply warn and skip??
throw new PluginExecutionException( mojoExecution, project, "Mojo: " + mojoDescriptor.getGoal() + " requires online mode for execution. Maven is currently offline." );
}
if ( mojoDescriptor.getDeprecated() != null )
{
logger.warn( "Mojo: " + mojoDescriptor.getGoal() + " is deprecated.\n" + mojoDescriptor.getDeprecated() );
}
String goalName = mojoDescriptor.getFullGoalName();
Mojo mojo = null;
@ -311,15 +282,13 @@ public class DefaultPluginManager
}
// by this time, the pluginDescriptor has had the correct realm setup from getConfiguredMojo(..)
ClassRealm pluginRealm;
ClassRealm pluginRealm = pluginClassLoaderCache.get( constructPluginKey( mojoDescriptor.getPluginDescriptor() ) );
ClassRealm oldLookupRealm = container.getLookupRealm();
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try
{
mojo = getConfiguredMojo( session, mojoExecution, project, false, mojoExecution );
pluginRealm = pluginClassLoaderCache.get( constructPluginKey( mojoDescriptor.getPluginDescriptor() ) );
{
mojo = getConfiguredMojo( session, project, mojoExecution, pluginRealm );
Thread.currentThread().setContextClassLoader( pluginRealm );
@ -371,15 +340,13 @@ public class DefaultPluginManager
}
}
private Mojo getConfiguredMojo( MavenSession session, MojoExecution MojoExecution, MavenProject project, boolean report, MojoExecution mojoExecution )
private Mojo getConfiguredMojo( MavenSession session, MavenProject project, MojoExecution mojoExecution, ClassRealm pluginRealm )
throws PluginConfigurationException, PluginManagerException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
ClassRealm pluginRealm = pluginDescriptor.getClassRealm();
// 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.
@ -388,8 +355,6 @@ public class DefaultPluginManager
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( pluginRealm );
logger.debug( "Looking up mojo " + mojoDescriptor.getRoleHint() + " in realm " + pluginRealm.getId() + " - descRealmId=" + mojoDescriptor.getRealm() );
Mojo mojo;
try
@ -434,7 +399,7 @@ public class DefaultPluginManager
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, mojoExecution );
populatePluginFields( mojo, mojoDescriptor, pomConfiguration, expressionEvaluator );
populatePluginFields( mojo, mojoDescriptor, pluginRealm, pomConfiguration, expressionEvaluator );
Thread.currentThread().setContextClassLoader( oldClassLoader );
@ -445,14 +410,11 @@ public class DefaultPluginManager
// Mojo Parameter Handling
// ----------------------------------------------------------------------
private void populatePluginFields( Mojo plugin, MojoDescriptor mojoDescriptor, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator )
private void populatePluginFields( Mojo mojo, MojoDescriptor mojoDescriptor, ClassRealm realm, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator )
throws PluginConfigurationException
{
ComponentConfigurator configurator = null;
// TODO: What is the point in using the plugin realm here instead of the core realm?
ClassRealm realm = mojoDescriptor.getPluginDescriptor().getClassRealm();
try
{
String configuratorId = mojoDescriptor.getComponentConfigurator();
@ -473,7 +435,7 @@ public class DefaultPluginManager
logger.debug( "Configuring mojo '" + mojoDescriptor.getId() + "' with " + ( configuratorId == null ? "basic" : configuratorId ) + " configurator -->" );
// This needs to be able to use methods
configurator.configureComponent( plugin, configuration, expressionEvaluator, realm, listener );
configurator.configureComponent( mojo, configuration, expressionEvaluator, realm, listener );
logger.debug( "-- end configuration --" );
}

View File

@ -16,4 +16,6 @@ public interface PluginClassLoaderCache
void put( String key, ClassRealm pluginClassLoader );
ClassRealm get( String key );
int size();
}

View File

@ -106,7 +106,7 @@ public class DefaultMavenProjectBuilder
public MavenProject build( File pomFile, ProjectBuilderConfiguration configuration )
throws ProjectBuildingException
{
{
MavenProject project = projectCache.get( pomFile.getAbsolutePath() );
if ( project != null )

View File

@ -20,4 +20,9 @@ public class DefaultMavenProjectCache
{
projectCache.put( key, project );
}
public int size()
{
return projectCache.size();
}
}

View File

@ -5,4 +5,6 @@ public interface MavenProjectCache
MavenProject get( String absolutePath );
void put( String absolutePath, MavenProject project );
int size();
}

View File

@ -112,10 +112,17 @@ public class DefaultMavenProjectBuilderTest
throws Exception
{
ArtifactRepositoryLayout repoLayout = lookup( ArtifactRepositoryLayout.class, "legacy" );
ArtifactRepository r = new DefaultArtifactRepository( "local", "file://" + localRepoDir.getAbsolutePath(),
repoLayout );
ArtifactRepository r = new DefaultArtifactRepository( "local", "file://" + localRepoDir.getAbsolutePath(), repoLayout );
return r;
}
public void xtestLoop() throws Exception
{
while( true )
{
File f1 = getTestFile( "src/test/resources/projects/duplicate-plugins-merged-pom.xml" );
getProject( f1 );
}
}
}