mirror of https://github.com/apache/maven.git
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:
parent
78de8abc8a
commit
8e7e771f81
|
@ -163,7 +163,7 @@ public class MavenSession
|
||||||
return request.getSettings();
|
return request.getSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getSortedProjects()
|
public List<MavenProject> getSortedProjects()
|
||||||
{
|
{
|
||||||
return reactorManager.getSortedProjects();
|
return reactorManager.getSortedProjects();
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class ReactorManager
|
||||||
return sorter.hasMultipleProjects();
|
return sorter.hasMultipleProjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getSortedProjects()
|
public List<MavenProject> getSortedProjects()
|
||||||
{
|
{
|
||||||
return sorter.getSortedProjects();
|
return sorter.getSortedProjects();
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ public class ReactorManager
|
||||||
{
|
{
|
||||||
private final DAG dag;
|
private final DAG dag;
|
||||||
|
|
||||||
private final List sortedProjects;
|
private final List<MavenProject> sortedProjects;
|
||||||
|
|
||||||
private MavenProject topLevelProject;
|
private MavenProject topLevelProject;
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ public class ReactorManager
|
||||||
// In this case, both the verify and the report goals are called
|
// 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
|
// 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.
|
// 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
|
throws CycleDetectedException, DuplicateProjectException
|
||||||
{
|
{
|
||||||
dag = new DAG();
|
dag = new DAG();
|
||||||
|
@ -380,7 +380,7 @@ public class ReactorManager
|
||||||
return topLevelProject;
|
return topLevelProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getSortedProjects()
|
public List<MavenProject> getSortedProjects()
|
||||||
{
|
{
|
||||||
return sortedProjects;
|
return sortedProjects;
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,17 +408,11 @@ public class DefaultPluginManager
|
||||||
// followed by the plugin's default artifact set
|
// followed by the plugin's default artifact set
|
||||||
dependencies.addAll( resolutionGroup.getArtifacts() );
|
dependencies.addAll( resolutionGroup.getArtifacts() );
|
||||||
|
|
||||||
Set repositories = new LinkedHashSet();
|
|
||||||
|
|
||||||
repositories.addAll( resolutionGroup.getResolutionRepositories() );
|
|
||||||
|
|
||||||
repositories.addAll( project.getRemoteArtifactRepositories() );
|
|
||||||
|
|
||||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
|
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
|
||||||
.setArtifact( pluginArtifact )
|
.setArtifact( pluginArtifact )
|
||||||
.setArtifactDependencies( dependencies )
|
.setArtifactDependencies( dependencies )
|
||||||
.setLocalRepository( localRepository )
|
.setLocalRepository( localRepository )
|
||||||
.setRemoteRepostories( repositories.isEmpty() ? Collections.EMPTY_LIST : new ArrayList( repositories ) )
|
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
|
||||||
.setManagedVersionMap( pluginManagedDependencies )
|
.setManagedVersionMap( pluginManagedDependencies )
|
||||||
.setFilter( filter )
|
.setFilter( filter )
|
||||||
.setMetadataSource( repositorySystem );
|
.setMetadataSource( repositorySystem );
|
||||||
|
@ -449,12 +443,8 @@ public class DefaultPluginManager
|
||||||
// Mojo execution
|
// Mojo execution
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
public void executeMojo( MavenProject project,
|
public void executeMojo( MavenProject project, MojoExecution mojoExecution, MavenSession session )
|
||||||
MojoExecution mojoExecution,
|
throws ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException
|
||||||
MavenSession session )
|
|
||||||
throws ArtifactResolutionException, MojoFailureException,
|
|
||||||
ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException,
|
|
||||||
PluginConfigurationException
|
|
||||||
{
|
{
|
||||||
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
|
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
|
||||||
|
|
||||||
|
@ -462,19 +452,13 @@ public class DefaultPluginManager
|
||||||
// anything that wants to execute a mojo.
|
// anything that wants to execute a mojo.
|
||||||
if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() )
|
if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() )
|
||||||
{
|
{
|
||||||
throw new PluginExecutionException( mojoExecution, project,
|
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." );
|
||||||
"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() )
|
if ( mojoDescriptor.isOnlineRequired() && session.isOffline() )
|
||||||
{
|
{
|
||||||
// TODO: Should we error out, or simply warn and skip??
|
// TODO: Should we error out, or simply warn and skip??
|
||||||
throw new PluginExecutionException( mojoExecution, project,
|
throw new PluginExecutionException( mojoExecution, project, "Mojo: " + mojoDescriptor.getGoal() + " requires online mode for execution. Maven is currently offline." );
|
||||||
"Mojo: "
|
|
||||||
+ mojoDescriptor.getGoal()
|
|
||||||
+ " requires online mode for execution. Maven is currently offline." );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mojoDescriptor.getDeprecated() != null )
|
if ( mojoDescriptor.getDeprecated() != null )
|
||||||
|
@ -488,7 +472,7 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
if ( mojoDescriptor.isDependencyResolutionRequired() != null )
|
if ( mojoDescriptor.isDependencyResolutionRequired() != null )
|
||||||
{
|
{
|
||||||
Collection projects;
|
Collection<MavenProject> projects;
|
||||||
|
|
||||||
if ( mojoDescriptor.isAggregator() )
|
if ( mojoDescriptor.isAggregator() )
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.maven.plugin;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
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.component.annotations.Requirement;
|
||||||
import org.codehaus.plexus.context.Context;
|
import org.codehaus.plexus.context.Context;
|
||||||
import org.codehaus.plexus.context.ContextException;
|
import org.codehaus.plexus.context.ContextException;
|
||||||
import org.codehaus.plexus.logging.LogEnabled;
|
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||||
|
|
||||||
@Component(role = PluginManagerSupport.class)
|
@Component(role = PluginManagerSupport.class)
|
||||||
public class DefaultPluginManagerSupport
|
public class DefaultPluginManagerSupport
|
||||||
implements PluginManagerSupport, LogEnabled, Contextualizable
|
implements PluginManagerSupport, Contextualizable
|
||||||
{
|
{
|
||||||
@Requirement
|
@Requirement
|
||||||
private MavenRepositorySystem repositorySystem;
|
private MavenRepositorySystem repositorySystem;
|
||||||
|
@ -70,7 +68,7 @@ public class DefaultPluginManagerSupport
|
||||||
@Requirement
|
@Requirement
|
||||||
private PluginVersionManager pluginVersionManager;
|
private PluginVersionManager pluginVersionManager;
|
||||||
|
|
||||||
//@Requirement
|
@Requirement
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
private Context containerContext;
|
private Context containerContext;
|
||||||
|
@ -80,26 +78,9 @@ public class DefaultPluginManagerSupport
|
||||||
{
|
{
|
||||||
ArtifactRepository localRepository = session.getLocalRepository();
|
ArtifactRepository localRepository = session.getLocalRepository();
|
||||||
|
|
||||||
List remoteRepositories = new ArrayList();
|
MavenProject pluginProject = buildPluginProject( plugin, localRepository, project.getRemoteArtifactRepositories() );
|
||||||
|
|
||||||
remoteRepositories.addAll( project.getRemoteArtifactRepositories() );
|
checkRequiredMavenVersion( plugin, pluginProject, localRepository, 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 );
|
|
||||||
|
|
||||||
checkPluginDependencySpec( plugin, pluginProject );
|
checkPluginDependencySpec( plugin, pluginProject );
|
||||||
|
|
||||||
|
@ -107,8 +88,10 @@ public class DefaultPluginManagerSupport
|
||||||
|
|
||||||
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
|
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
|
||||||
|
|
||||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, remoteRepositories );
|
ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, project.getRemoteArtifactRepositories() );
|
||||||
|
|
||||||
ArtifactResolutionResult result = repositorySystem.resolve( request );
|
ArtifactResolutionResult result = repositorySystem.resolve( request );
|
||||||
|
|
||||||
resolutionErrorHandler.throwErrors( request, result );
|
resolutionErrorHandler.throwErrors( request, result );
|
||||||
|
|
||||||
return pluginArtifact;
|
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
|
* @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
|
* manager which executes before the plugin is instantiated
|
||||||
*/
|
*/
|
||||||
public void checkRequiredMavenVersion( Plugin plugin,
|
public void checkRequiredMavenVersion( Plugin plugin, MavenProject pluginProject, ArtifactRepository localRepository, List remoteRepositories )
|
||||||
MavenProject pluginProject,
|
|
||||||
ArtifactRepository localRepository,
|
|
||||||
List remoteRepositories )
|
|
||||||
throws PluginVersionResolutionException, InvalidPluginException
|
throws PluginVersionResolutionException, InvalidPluginException
|
||||||
{
|
{
|
||||||
// if we don't have the required Maven version, then ignore an update
|
// if we don't have the required Maven version, then ignore an update
|
||||||
if ( ( pluginProject.getPrerequisites() != null )
|
if ( ( pluginProject.getPrerequisites() != null ) && ( pluginProject.getPrerequisites().getMaven() != null ) )
|
||||||
&& ( pluginProject.getPrerequisites().getMaven() != null ) )
|
|
||||||
{
|
{
|
||||||
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion(
|
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion( pluginProject.getPrerequisites().getMaven() );
|
||||||
pluginProject.getPrerequisites()
|
|
||||||
.getMaven() );
|
|
||||||
|
|
||||||
if ( runtimeInformation.getApplicationInformation().getVersion().compareTo( requiredVersion ) < 0 )
|
if ( runtimeInformation.getApplicationInformation().getVersion().compareTo( requiredVersion ) < 0 )
|
||||||
{
|
{
|
||||||
throw new PluginVersionResolutionException( plugin.getGroupId(),
|
throw new PluginVersionResolutionException( plugin.getGroupId(), plugin.getArtifactId(), "Plugin requires Maven version " + requiredVersion );
|
||||||
plugin.getArtifactId(),
|
|
||||||
"Plugin requires Maven version "
|
|
||||||
+ requiredVersion );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,18 +145,13 @@ public class DefaultPluginManagerSupport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginDescriptor loadIsolatedPluginDescriptor( Plugin plugin,
|
public PluginDescriptor loadIsolatedPluginDescriptor( Plugin plugin, MavenProject project, MavenSession session )
|
||||||
MavenProject project,
|
|
||||||
MavenSession session )
|
|
||||||
{
|
{
|
||||||
if ( plugin.getVersion() == null )
|
if ( plugin.getVersion() == null )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plugin.setVersion( pluginVersionManager.resolvePluginVersion( plugin.getGroupId(),
|
plugin.setVersion( pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), project, session ) );
|
||||||
plugin.getArtifactId(),
|
|
||||||
project,
|
|
||||||
session ) );
|
|
||||||
}
|
}
|
||||||
catch ( PluginVersionResolutionException e )
|
catch ( PluginVersionResolutionException e )
|
||||||
{
|
{
|
||||||
|
@ -239,11 +208,7 @@ public class DefaultPluginManagerSupport
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List componentSetDescriptors = RealmScanningUtils.scanForComponentSetDescriptors( artifact,
|
List componentSetDescriptors = RealmScanningUtils.scanForComponentSetDescriptors( artifact, discoverer, containerContext, "Plugin: " + plugin.getKey() );
|
||||||
discoverer,
|
|
||||||
containerContext,
|
|
||||||
"Plugin: "
|
|
||||||
+ plugin.getKey() );
|
|
||||||
|
|
||||||
if ( !componentSetDescriptors.isEmpty() )
|
if ( !componentSetDescriptors.isEmpty() )
|
||||||
{
|
{
|
||||||
|
@ -259,11 +224,6 @@ public class DefaultPluginManagerSupport
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableLogging( Logger logger )
|
|
||||||
{
|
|
||||||
this.logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void contextualize( Context context )
|
public void contextualize( Context context )
|
||||||
throws ContextException
|
throws ContextException
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue