o more plugin manager refactoring

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@750343 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-05 06:56:41 +00:00
parent 78de8abc8a
commit 8e7e771f81
4 changed files with 26 additions and 82 deletions

View File

@ -163,7 +163,7 @@ public class MavenSession
return request.getSettings();
}
public List getSortedProjects()
public List<MavenProject> getSortedProjects()
{
return reactorManager.getSortedProjects();
}

View File

@ -155,7 +155,7 @@ public class ReactorManager
return sorter.hasMultipleProjects();
}
public List getSortedProjects()
public List<MavenProject> getSortedProjects()
{
return sorter.getSortedProjects();
}
@ -194,7 +194,7 @@ public class ReactorManager
{
private final DAG dag;
private final List sortedProjects;
private final List<MavenProject> sortedProjects;
private MavenProject topLevelProject;
@ -221,7 +221,7 @@ public class ReactorManager
// In this case, both the verify and the report goals are called
// in a different lifecycle. Though the compiler-plugin has a valid usecase, although
// that seems to work fine. We need to take versions and lifecycle into account.
public ProjectSorter( List projects )
public ProjectSorter( List<MavenProject> projects )
throws CycleDetectedException, DuplicateProjectException
{
dag = new DAG();
@ -380,7 +380,7 @@ public class ReactorManager
return topLevelProject;
}
public List getSortedProjects()
public List<MavenProject> getSortedProjects()
{
return sortedProjects;
}

View File

@ -408,17 +408,11 @@ public class DefaultPluginManager
// followed by the plugin's default artifact set
dependencies.addAll( resolutionGroup.getArtifacts() );
Set repositories = new LinkedHashSet();
repositories.addAll( resolutionGroup.getResolutionRepositories() );
repositories.addAll( project.getRemoteArtifactRepositories() );
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
.setArtifact( pluginArtifact )
.setArtifactDependencies( dependencies )
.setLocalRepository( localRepository )
.setRemoteRepostories( repositories.isEmpty() ? Collections.EMPTY_LIST : new ArrayList( repositories ) )
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
.setManagedVersionMap( pluginManagedDependencies )
.setFilter( filter )
.setMetadataSource( repositorySystem );
@ -449,12 +443,8 @@ public class DefaultPluginManager
// Mojo execution
// ----------------------------------------------------------------------
public void executeMojo( MavenProject project,
MojoExecution mojoExecution,
MavenSession session )
throws ArtifactResolutionException, MojoFailureException,
ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException,
PluginConfigurationException
public void executeMojo( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
@ -462,19 +452,13 @@ public class DefaultPluginManager
// anything that wants to execute a mojo.
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." );
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." );
throw new PluginExecutionException( mojoExecution, project, "Mojo: " + mojoDescriptor.getGoal() + " requires online mode for execution. Maven is currently offline." );
}
if ( mojoDescriptor.getDeprecated() != null )
@ -488,7 +472,7 @@ public class DefaultPluginManager
if ( mojoDescriptor.isDependencyResolutionRequired() != null )
{
Collection projects;
Collection<MavenProject> projects;
if ( mojoDescriptor.isAggregator() )
{

View File

@ -19,7 +19,6 @@ package org.apache.maven.plugin;
* under the License.
*/
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.artifact.Artifact;
@ -47,13 +46,12 @@ import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
@Component(role = PluginManagerSupport.class)
public class DefaultPluginManagerSupport
implements PluginManagerSupport, LogEnabled, Contextualizable
implements PluginManagerSupport, Contextualizable
{
@Requirement
private MavenRepositorySystem repositorySystem;
@ -70,7 +68,7 @@ public class DefaultPluginManagerSupport
@Requirement
private PluginVersionManager pluginVersionManager;
//@Requirement
@Requirement
private Logger logger;
private Context containerContext;
@ -80,26 +78,9 @@ public class DefaultPluginManagerSupport
{
ArtifactRepository localRepository = session.getLocalRepository();
List remoteRepositories = new ArrayList();
MavenProject pluginProject = buildPluginProject( plugin, localRepository, project.getRemoteArtifactRepositories() );
remoteRepositories.addAll( project.getRemoteArtifactRepositories() );
MavenProject pluginProject = null;
for(MavenProject mp : (List<MavenProject>) session.getSortedProjects())
{
if(mp.getId().equals(project.getId()))
{
pluginProject = mp;
break;
}
}
if(pluginProject == null)
{
pluginProject = buildPluginProject( plugin, localRepository, remoteRepositories );
}
checkRequiredMavenVersion( plugin, pluginProject, localRepository, remoteRepositories );
checkRequiredMavenVersion( plugin, pluginProject, localRepository, project.getRemoteArtifactRepositories() );
checkPluginDependencySpec( plugin, pluginProject );
@ -107,8 +88,10 @@ public class DefaultPluginManagerSupport
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, remoteRepositories );
ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, project.getRemoteArtifactRepositories() );
ArtifactResolutionResult result = repositorySystem.resolve( request );
resolutionErrorHandler.throwErrors( request, result );
return pluginArtifact;
@ -133,26 +116,17 @@ public class DefaultPluginManagerSupport
* @todo would be better to store this in the plugin descriptor, but then it won't be available to the version
* manager which executes before the plugin is instantiated
*/
public void checkRequiredMavenVersion( Plugin plugin,
MavenProject pluginProject,
ArtifactRepository localRepository,
List remoteRepositories )
public void checkRequiredMavenVersion( Plugin plugin, MavenProject pluginProject, ArtifactRepository localRepository, List remoteRepositories )
throws PluginVersionResolutionException, InvalidPluginException
{
// if we don't have the required Maven version, then ignore an update
if ( ( pluginProject.getPrerequisites() != null )
&& ( pluginProject.getPrerequisites().getMaven() != null ) )
if ( ( pluginProject.getPrerequisites() != null ) && ( pluginProject.getPrerequisites().getMaven() != null ) )
{
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion(
pluginProject.getPrerequisites()
.getMaven() );
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion( pluginProject.getPrerequisites().getMaven() );
if ( runtimeInformation.getApplicationInformation().getVersion().compareTo( requiredVersion ) < 0 )
{
throw new PluginVersionResolutionException( plugin.getGroupId(),
plugin.getArtifactId(),
"Plugin requires Maven version "
+ requiredVersion );
throw new PluginVersionResolutionException( plugin.getGroupId(), plugin.getArtifactId(), "Plugin requires Maven version " + requiredVersion );
}
}
}
@ -171,18 +145,13 @@ public class DefaultPluginManagerSupport
}
}
public PluginDescriptor loadIsolatedPluginDescriptor( Plugin plugin,
MavenProject project,
MavenSession session )
public PluginDescriptor loadIsolatedPluginDescriptor( Plugin plugin, MavenProject project, MavenSession session )
{
if ( plugin.getVersion() == null )
{
try
{
plugin.setVersion( pluginVersionManager.resolvePluginVersion( plugin.getGroupId(),
plugin.getArtifactId(),
project,
session ) );
plugin.setVersion( pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), project, session ) );
}
catch ( PluginVersionResolutionException e )
{
@ -239,11 +208,7 @@ public class DefaultPluginManagerSupport
try
{
List componentSetDescriptors = RealmScanningUtils.scanForComponentSetDescriptors( artifact,
discoverer,
containerContext,
"Plugin: "
+ plugin.getKey() );
List componentSetDescriptors = RealmScanningUtils.scanForComponentSetDescriptors( artifact, discoverer, containerContext, "Plugin: " + plugin.getKey() );
if ( !componentSetDescriptors.isEmpty() )
{
@ -259,11 +224,6 @@ public class DefaultPluginManagerSupport
return null;
}
public void enableLogging( Logger logger )
{
this.logger = logger;
}
public void contextualize( Context context )
throws ContextException
{