mirror of https://github.com/apache/maven.git
o another pass at the plugin manager
git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@760747 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1ce1debe96
commit
1480e5cba4
|
@ -144,7 +144,7 @@ public class DefaultMaven
|
|||
|
||||
try
|
||||
{
|
||||
session = new MavenSession( request, projects );
|
||||
session = new MavenSession( container, request, projects );
|
||||
|
||||
result.setReactorManager( session.getReactorManager() );
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
|||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||
|
||||
/**
|
||||
|
@ -37,6 +38,8 @@ import org.codehaus.plexus.util.dag.CycleDetectedException;
|
|||
*/
|
||||
public class MavenSession
|
||||
{
|
||||
private PlexusContainer container;
|
||||
|
||||
private ReactorManager reactorManager;
|
||||
|
||||
private MavenExecutionRequest request;
|
||||
|
@ -49,15 +52,16 @@ public class MavenSession
|
|||
this.request = request;
|
||||
}
|
||||
|
||||
public MavenSession( MavenExecutionRequest request, MavenProject project )
|
||||
public MavenSession( PlexusContainer container, MavenExecutionRequest request, MavenProject project )
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
this( request, Arrays.asList( new MavenProject[]{ project } ) );
|
||||
this( container, request, Arrays.asList( new MavenProject[]{ project } ) );
|
||||
}
|
||||
|
||||
public MavenSession( MavenExecutionRequest request, List<MavenProject> projects )
|
||||
public MavenSession( PlexusContainer container, MavenExecutionRequest request, List<MavenProject> projects )
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
this.container = container;
|
||||
this.request = request;
|
||||
this.reactorManager = new ReactorManager( projects, request.getReactorFailureBehavior() );
|
||||
this.currentProject = projects.get( 0 );
|
||||
|
@ -73,6 +77,11 @@ public class MavenSession
|
|||
return reactorManager.getPluginContext( pluginDescriptor, project );
|
||||
}
|
||||
|
||||
public PlexusContainer getContainer()
|
||||
{
|
||||
return container;
|
||||
}
|
||||
|
||||
public ArtifactRepository getLocalRepository()
|
||||
{
|
||||
return request.getLocalRepository();
|
||||
|
|
|
@ -403,11 +403,7 @@ public class DefaultLifecycleExecutor
|
|||
{
|
||||
throw new LifecycleExecutionException( "Error loading MojoDescriptor.", e );
|
||||
}
|
||||
|
||||
// this has been simplified from the old code that injected the plugin management stuff, since
|
||||
// pluginManagement injection is now handled by the project method.
|
||||
project.addPlugin( plugin );
|
||||
|
||||
|
||||
return mojoDescriptor;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ import java.util.Set;
|
|||
|
||||
import org.apache.maven.ArtifactFilterManager;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
|
||||
import org.apache.maven.artifact.repository.metadata.Metadata;
|
||||
|
@ -152,13 +151,7 @@ public class DefaultPluginManager
|
|||
{
|
||||
resolvePluginVersion( plugin, project, session );
|
||||
|
||||
addPlugin( plugin, project, session );
|
||||
|
||||
pluginDescriptor = pluginCollector.getPluginDescriptor( plugin );
|
||||
|
||||
project.addPlugin( plugin );
|
||||
|
||||
return pluginDescriptor;
|
||||
return addPlugin( plugin, project, session );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
|
@ -191,7 +184,7 @@ public class DefaultPluginManager
|
|||
return plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion();
|
||||
}
|
||||
|
||||
protected void addPlugin( Plugin plugin, MavenProject project, MavenSession session )
|
||||
protected PluginDescriptor addPlugin( Plugin plugin, MavenProject project, MavenSession session )
|
||||
throws ArtifactNotFoundException, ArtifactResolutionException, PluginManagerException, InvalidPluginException, PluginVersionResolutionException
|
||||
{
|
||||
ArtifactRepository localRepository = session.getLocalRepository();
|
||||
|
@ -247,6 +240,8 @@ public class DefaultPluginManager
|
|||
pluginDescriptor.setPluginArtifact( pluginArtifact );
|
||||
pluginDescriptor.setArtifacts( new ArrayList<Artifact>( pluginArtifacts ) );
|
||||
pluginDescriptor.setClassRealm( pluginRealm );
|
||||
|
||||
return pluginDescriptor;
|
||||
}
|
||||
|
||||
// plugin artifact
|
||||
|
@ -1224,9 +1219,30 @@ public class DefaultPluginManager
|
|||
// in settings.xml.
|
||||
if ( StringUtils.isEmpty( version ) || Artifact.RELEASE_VERSION.equals( version ) )
|
||||
{
|
||||
// 1. resolve the version to be used
|
||||
version = resolveMetaVersion( groupId, artifactId, project, session.getLocalRepository(), Artifact.RELEASE_VERSION );
|
||||
logger.debug( "Version from RELEASE metadata: " + version );
|
||||
// 1. resolve the version to be used
|
||||
Artifact artifact = repositorySystem.createProjectArtifact( groupId, artifactId, Artifact.RELEASE_VERSION );
|
||||
|
||||
String artifactVersion = artifact.getVersion();
|
||||
|
||||
// make sure this artifact was transformed to a real version, and actually resolved to a file in the repo...
|
||||
if ( !Artifact.RELEASE_VERSION.equals( artifactVersion ) && ( artifact.getFile() != null ) )
|
||||
{
|
||||
boolean pluginValid = false;
|
||||
|
||||
while ( !pluginValid && ( artifactVersion != null ) )
|
||||
{
|
||||
pluginValid = true;
|
||||
|
||||
artifact = repositorySystem.createProjectArtifact( groupId, artifactId, artifactVersion );
|
||||
}
|
||||
|
||||
version = artifactVersion;
|
||||
}
|
||||
|
||||
if ( version == null )
|
||||
{
|
||||
version = artifactVersion;
|
||||
}
|
||||
}
|
||||
|
||||
// if we still haven't found a version, then fail early before we get into the update goop.
|
||||
|
@ -1238,53 +1254,6 @@ public class DefaultPluginManager
|
|||
plugin.setVersion( version );
|
||||
}
|
||||
|
||||
private String resolveMetaVersion( String groupId, String artifactId, MavenProject project, ArtifactRepository localRepository, String metaVersionId )
|
||||
throws PluginVersionResolutionException, InvalidPluginException
|
||||
{
|
||||
logger.info( "Attempting to resolve a version for plugin: " + groupId + ":" + artifactId + " using meta-version: " + metaVersionId );
|
||||
|
||||
Artifact artifact = repositorySystem.createProjectArtifact( groupId, artifactId, metaVersionId );
|
||||
|
||||
String version = null;
|
||||
|
||||
String artifactVersion = artifact.getVersion();
|
||||
|
||||
// make sure this artifact was transformed to a real version, and actually resolved to a file in the repo...
|
||||
if ( !metaVersionId.equals( artifactVersion ) && ( artifact.getFile() != null ) )
|
||||
{
|
||||
boolean pluginValid = false;
|
||||
|
||||
while ( !pluginValid && ( artifactVersion != null ) )
|
||||
{
|
||||
pluginValid = true;
|
||||
|
||||
MavenProject pluginProject;
|
||||
|
||||
try
|
||||
{
|
||||
artifact = repositorySystem.createProjectArtifact( groupId, artifactId, artifactVersion );
|
||||
|
||||
pluginProject = mavenProjectBuilder.buildFromRepository( artifact, project.getRemoteArtifactRepositories(), localRepository );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
throw new InvalidPluginException( "Unable to build project information for plugin '" + ArtifactUtils.versionlessKey( groupId, artifactId ) + "': " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
version = artifactVersion;
|
||||
}
|
||||
|
||||
if ( version == null )
|
||||
{
|
||||
version = artifactVersion;
|
||||
}
|
||||
|
||||
logger.info( "Using version: " + version + " of plugin: " + groupId + ":" + artifactId );
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
// 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
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent;
|
|||
import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
|
||||
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
|
||||
|
||||
//TODO: collapse this into the plugin manager
|
||||
public class MavenPluginCollector
|
||||
implements ComponentDiscoveryListener
|
||||
{
|
||||
|
|
|
@ -99,7 +99,7 @@ public abstract class AbstractCoreMavenComponentTest
|
|||
// We just need to use the configuration, and get the POM from that.
|
||||
MavenProject project = projectBuilder.build( pom, configuration );
|
||||
|
||||
MavenSession session = new MavenSession( request, project );
|
||||
MavenSession session = new MavenSession( getContainer(), request, project );
|
||||
|
||||
return session;
|
||||
}
|
||||
|
|
|
@ -1301,20 +1301,6 @@ public class MavenProject
|
|||
return build;
|
||||
}
|
||||
|
||||
public void addPlugin( Plugin plugin )
|
||||
{
|
||||
Build build = getModelBuild();
|
||||
|
||||
if ( !build.getPluginsAsMap().containsKey( plugin.getKey() ) )
|
||||
{
|
||||
injectPluginManagementInfo( plugin );
|
||||
|
||||
build.addPlugin( plugin );
|
||||
|
||||
build.flushPluginMap();
|
||||
}
|
||||
}
|
||||
|
||||
//!!jvz remove ModelUtils
|
||||
public void injectPluginManagementInfo( Plugin plugin )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue