o Fixed handling of missing plugin version during calculation of execution plan

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@821170 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-10-02 21:18:11 +00:00
parent f5b47d1a8a
commit bafa946f3c
2 changed files with 47 additions and 17 deletions

View File

@ -253,8 +253,6 @@ public class DefaultLifecycleExecutor
ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
RepositoryRequest repositoryRequest = getRepositoryRequest( session, null );
for ( ProjectBuild projectBuild : projectBuilds )
{
MavenProject currentProject = projectBuild.project;
@ -274,9 +272,6 @@ public class DefaultLifecycleExecutor
fireEvent( session, null, LifecycleEventCatapult.PROJECT_STARTED );
repositoryRequest.setRemoteRepositories( currentProject.getPluginArtifactRepositories() );
resolveMissingPluginVersions( currentProject.getBuildPlugins(), repositoryRequest );
ClassRealm projectRealm = currentProject.getClassRealm();
if ( projectRealm != null )
{
@ -750,6 +745,8 @@ public class DefaultLifecycleExecutor
PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException
{
resolveMissingPluginVersions( project, session );
List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
Set<String> requiredDependencyResolutionScopes = new TreeSet<String>();
@ -1705,22 +1702,15 @@ public class DefaultLifecycleExecutor
}
}
private void resolveMissingPluginVersions( Collection<Plugin> plugins, RepositoryRequest repositoryRequest )
throws LifecycleExecutionException
private void resolveMissingPluginVersions( MavenProject project, MavenSession session )
throws PluginVersionResolutionException
{
for ( Plugin plugin : plugins )
for ( Plugin plugin : project.getBuildPlugins() )
{
if ( plugin.getVersion() == null )
{
try
{
resolvePluginVersion( plugin, repositoryRequest );
}
catch ( PluginVersionResolutionException e )
{
throw new LifecycleExecutionException( "Error resolving version for plugin " + plugin.getKey()
+ ": " + e.getMessage(), e );
}
PluginVersionRequest request = new DefaultPluginVersionRequest( plugin, session );
plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() );
}
}
}

View File

@ -25,7 +25,9 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.artifact.repository.RepositoryRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
/**
* Collects settings required to resolve the version for a plugin.
@ -42,16 +44,30 @@ public class DefaultPluginVersionRequest
private RepositoryRequest repositoryRequest;
/**
* Creates an empty request.
*/
public DefaultPluginVersionRequest()
{
repositoryRequest = new DefaultRepositoryRequest();
}
/**
* Creates a request by copying settings from the specified repository request.
*
* @param repositoryRequest The repository request to copy from, must not be {@code null}.
*/
public DefaultPluginVersionRequest( RepositoryRequest repositoryRequest )
{
this.repositoryRequest = new DefaultRepositoryRequest( repositoryRequest );
}
/**
* Creates a request for the specified plugin by copying settings from the specified repository request.
*
* @param The plugin for which to resolve a version, must not be {@code null}.
* @param repositoryRequest The repository request to copy from, must not be {@code null}.
*/
public DefaultPluginVersionRequest( Plugin plugin, RepositoryRequest repositoryRequest )
{
this.groupId = plugin.getGroupId();
@ -59,6 +75,30 @@ public class DefaultPluginVersionRequest
this.repositoryRequest = new DefaultRepositoryRequest( repositoryRequest );
}
/**
* Creates a request for the specified plugin by copying settings from the specified build session. If the session
* has a current project, its plugin artifact repositories will be used as well.
*
* @param The plugin for which to resolve a version, must not be {@code null}.
* @param repositoryRequest The repository request to copy from, must not be {@code null}.
*/
public DefaultPluginVersionRequest( Plugin plugin, MavenSession session )
{
this.groupId = plugin.getGroupId();
this.artifactId = plugin.getArtifactId();
this.repositoryRequest = new DefaultRepositoryRequest();
setCache( session.getRepositoryCache() );
setLocalRepository( session.getLocalRepository() );
setOffline( session.isOffline() );
MavenProject project = session.getCurrentProject();
if ( project != null )
{
setRemoteRepositories( project.getPluginArtifactRepositories() );
}
}
public String getGroupId()
{
return groupId;