o refactoring the way plugin prefix metadata is found. the lifecycle executor is not the right place for this and the plugin manager is now strictly for already fully configured executions. so it belongs somewhere specific to augmenting the base set of information in order to make it complete but this first pass will do here. i just want to check it in as well because i'm traveling.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@783361 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-06-10 13:40:14 +00:00
parent 5cde8bfe4b
commit 864ea15216
14 changed files with 456 additions and 488 deletions

View File

@ -64,11 +64,6 @@ public class DefaultMaven
@Requirement
protected PlexusContainer container;
public List<String> getLifecyclePhases()
{
return lifecycleExecutor.getLifecyclePhases();
}
public MavenExecutionResult execute( MavenExecutionRequest request )
{
//TODO: Need a general way to inject standard properties
@ -93,7 +88,7 @@ public MavenExecutionResult execute( MavenExecutionRequest request )
try
{
projects = getProjects( request );
projects = getProjectsForMavenReactor( request );
//TODO: We really need to get rid of this requirement in here. If we know there is no project present
if ( projects.isEmpty() )
@ -171,7 +166,7 @@ private MavenExecutionResult processResult( MavenExecutionResult result, Excepti
return result;
}
public Map<String,MavenProject> getProjects( MavenExecutionRequest request )
protected Map<String,MavenProject> getProjectsForMavenReactor( MavenExecutionRequest request )
throws MavenExecutionException, ProjectBuildingException
{
// We have no POM file.

View File

@ -19,8 +19,6 @@
* under the License.
*/
import java.util.List;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
@ -32,6 +30,4 @@ public interface Maven
String POMv4 = "pom.xml";
MavenExecutionResult execute( MavenExecutionRequest request );
List<String> getLifecyclePhases();
}

View File

@ -1,57 +0,0 @@
package org.apache.maven.execution;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Describe a build failure in the reactor.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class BuildFailure
{
private final Exception cause;
private final String task;
private final long time;
BuildFailure( Exception cause, String task, long time )
{
this.cause = cause;
this.task = task;
this.time = time;
}
public String getTask()
{
return task;
}
public Exception getCause()
{
return cause;
}
public long getTime()
{
return time;
}
}

View File

@ -1,51 +0,0 @@
package org.apache.maven.execution;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.project.MavenProject;
/**
* Describe a build success in the reactor.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class BuildSuccess
{
private final MavenProject project;
private final long time;
public BuildSuccess( MavenProject project, long time )
{
this.project = project;
this.time = time;
}
public MavenProject getProject()
{
return project;
}
public long getTime()
{
return time;
}
}

View File

@ -68,14 +68,8 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
//TODO: The configuration for the lifecycle needs to be externalized so that I can use the annotations
// properly for the wiring and reference and external source for the lifecycle configuration.
//TODO: The configuration for the lifecycle needs to be externalized so that I can use the annotations properly for the wiring and reference and external source for the lifecycle configuration.
//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
@ -92,23 +86,32 @@ public class DefaultLifecycleExecutor
@Requirement
protected RepositorySystem repositorySystem;
/**
* These mappings correspond to packaging types, like WAR packaging, which configure a particular mojos
* to run in a given phase.
*/
@Requirement
private Map<String, LifecycleMapping> lifecycleMappings;
@Requirement
private ProjectDependenciesResolver projectDependenciesResolver;
// @Configuration(source="org/apache/maven/lifecycle/lifecycles.xml")
private List<Lifecycle> lifecycles;
/**
* We use this to display all the lifecycles available and their phases to users. Currently this is primarily
* used in the IDE integrations where a UI is presented to the user and they can select the lifecycle phase
* they would like to execute.
*/
private Map<String,Lifecycle> lifecycleMap;
/**
* We use this to map all phases to the lifecycle that contains it. This is used so that a user can specify the
* phase they want to execute and we can easily determine what lifecycle we need to run.
*/
private Map<String, Lifecycle> phaseToLifecycleMap;
/**
* These mappings correspond to packaging types, like WAR packaging, which configure a particular mojos
* to run in a given phase.
*/
@Requirement
private Map<String, LifecycleMapping> lifecycleMappings;
public void execute( MavenSession session )
{
// TODO: Use a listener here instead of loggers
@ -216,203 +219,217 @@ public void execute( MavenSession session )
}
}
// 1. Find the lifecycle given the phase (default lifecycle when given install)
// 2. Find the lifecycle mapping that corresponds to the project packaging (jar lifecycle mapping given the jar packaging)
// 3. Find the mojos associated with the lifecycle given the project packaging (jar lifecycle mapping for the default lifecycle)
// 4. Bind those mojos found in the lifecycle mapping for the packaging to the lifecycle
// 5. Bind mojos specified in the project itself to the lifecycle
public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, PluginManagerException
{
MavenProject project = session.getCurrentProject();
List<MojoExecution> phasesWithMojosToExecute = new ArrayList<MojoExecution>();
List<MojoExecution> lifecyclePlan = new ArrayList<MojoExecution>();
String requiredDependencyResolutionScope = null;
for ( String task : tasks )
{
if ( task.indexOf( ":" ) > 0 )
{
// If this is a goal like "mvn modello:java" and the POM looks like the following:
// <project>
// <modelVersion>4.0.0</modelVersion>
// <groupId>org.apache.maven.plugins</groupId>
// <artifactId>project-plugin-level-configuration-only</artifactId>
// <version>1.0.1</version>
// <build>
// <plugins>
// <plugin>
// <groupId>org.codehaus.modello</groupId>
// <artifactId>modello-maven-plugin</artifactId>
// <version>1.0.1</version>
// <configuration>
// <version>1.1.0</version>
// <models>
// <model>src/main/mdo/remote-resources.mdo</model>
// </models>
// </configuration>
// </plugin>
// </plugins>
// </build>
// </project>
//
// We want to
//
// - take the plugin/configuration in the POM and merge it with the plugin's default configuration found in its plugin.xml
// - attach that to the MojoExecution for its configuration
// - give the MojoExecution an id of default-<goal>.
MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session );
requiredDependencyResolutionScope = mojoDescriptor.isDependencyResolutionRequired();
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, "default-" + mojoDescriptor.getGoal() );
populateMojoExecutionConfiguration( project, mojoExecution, true );
lifecyclePlan.add( mojoExecution );
calculateExecutionForIndividualGoal( session, lifecyclePlan, task );
}
else
{
// 1.
//
// Based on the lifecycle phase we are given, let's find the corresponding lifecycle.
//
Lifecycle lifecycle = phaseToLifecycleMap.get( task );
// 2.
//
// If we are dealing with the "clean" or "site" lifecycle then there are currently no lifecycle mappings but there are default phases
// that need to be run instead.
//
// Now we need to take into account the packaging type of the project. For a project of type WAR, the lifecycle where mojos are mapped
// on to the given phases in the lifecycle are going to be a little different then, say, a project of type JAR.
//
// 3.
//
// Once we have the lifecycle mapping for the given packaging, we need to know whats phases we need to worry about executing.
//
// Create an ordered Map of the phases in the lifecycle to a list of mojos to execute.
Map<String, List<MojoExecution>> phaseToMojoMapping = new LinkedHashMap<String, List<MojoExecution>>();
// 4.
//TODO: need to separate the lifecycles
for ( String phase : lifecycle.getPhases() )
{
List<MojoExecution> mojos = new ArrayList<MojoExecution>();
//TODO: remove hard coding
if ( phase.equals( "clean" ) )
{
Plugin plugin = new Plugin();
plugin.setGroupId( "org.apache.maven.plugins" );
plugin.setArtifactId( "maven-clean-plugin" );
plugin.setVersion( "2.3" );
mojos.add( new MojoExecution( plugin, "clean", "default-clean" ) );
}
// This is just just laying out the initial structure of the mojos to run in each phase of the
// lifecycle. Everything is now done in the project builder correctly so this could likely
// go away shortly. We no longer need to pull out bits from the default lifecycle. The MavenProject
// comes to us intact as it should.
phaseToMojoMapping.put( phase, mojos );
}
// 5. Just build up the list of mojos that will execute for every phase.
//
// This will be useful for having the complete build plan and then we can filter/optimize later.
//
for ( Plugin plugin : project.getBuild().getPlugins() )
{
for ( PluginExecution execution : plugin.getExecutions() )
{
// if the phase is specified then I don't have to go fetch the plugin yet and pull it down
// to examine the phase it is associated to.
if ( execution.getPhase() != null )
{
for ( String goal : execution.getGoals() )
{
if ( phaseToMojoMapping.get( execution.getPhase() ) == null )
{
// This is happening because executions in the POM are getting mixed into the clean lifecycle
// So for the lifecycle mapping we need a map with the phases as keys so we can easily check
// if this phase belongs to the given lifecycle. this shows the system is messed up. this
// shouldn't happen.
phaseToMojoMapping.put( execution.getPhase(), new ArrayList<MojoExecution>() );
}
MojoExecution mojoExecution = new MojoExecution( plugin, goal, execution.getId() );
phaseToMojoMapping.get( execution.getPhase() ).add( mojoExecution );
}
}
// if not then i need to grab the mojo descriptor and look at the phase that is specified
else
{
for ( String goal : execution.getGoals() )
{
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session.getLocalRepository(), project.getRemoteArtifactRepositories() );
if ( mojoDescriptor.getPhase() != null && phaseToMojoMapping.get( mojoDescriptor.getPhase() ) != null )
{
MojoExecution mojoExecution = new MojoExecution( plugin, goal, execution.getId() );
phaseToMojoMapping.get( mojoDescriptor.getPhase() ).add( mojoExecution );
}
}
}
}
}
// 6.
//
// We are only interested in the phases that correspond to the lifecycle we are trying to run. If we are running the "clean"
// lifecycle we are not interested in goals -- like "generate-sources -- that belong to the default lifecycle.
//
for ( String phase : phaseToMojoMapping.keySet() )
{
phasesWithMojosToExecute.addAll( phaseToMojoMapping.get( phase ) );
if ( phase.equals( task ) )
{
break;
}
}
calculateExecutionForLifecyclePhase( session, lifecyclePlan, task );
}
}
// 7. Now we create the correct configuration for the mojo to execute.
//TODO: this needs to go to the model builder.
//TODO: just used a hollowed out MojoExecution
for ( MojoExecution mojoExecution : phasesWithMojosToExecute )
//
for ( MojoExecution mojoExecution : lifecyclePlan )
{
// These are bits that look like this:
//
// org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process
//
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor(
mojoExecution.getPlugin(), mojoExecution.getGoal(), session.getLocalRepository(), project.getPluginArtifactRepositories() );
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( mojoExecution.getGroupId(), mojoExecution.getArtifactId(), mojoExecution.getVersion(), mojoExecution.getGoal(), session
.getLocalRepository(), project.getRemoteArtifactRepositories() );
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
if ( pluginDescriptor.getPlugin().isExtensions() )
{
pluginDescriptor.setClassRealm( pluginManager.getPluginRealm( session, pluginDescriptor ) );
}
requiredDependencyResolutionScope = calculateRequiredDependencyResolutionScope( requiredDependencyResolutionScope, mojoDescriptor.isDependencyResolutionRequired() );
mojoExecution.setMojoDescriptor( mojoDescriptor );
populateMojoExecutionConfiguration( project, mojoExecution, false );
lifecyclePlan.add( mojoExecution );
}
return new MavenExecutionPlan( lifecyclePlan, requiredDependencyResolutionScope );
}
private void calculateExecutionForIndividualGoal( MavenSession session, List<MojoExecution> lifecyclePlan, String goal )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException
{
MavenProject project = session.getCurrentProject();
// If this is a goal like "mvn modello:java" and the POM looks like the following:
//
// <project>
// <modelVersion>4.0.0</modelVersion>
// <groupId>org.apache.maven.plugins</groupId>
// <artifactId>project-plugin-level-configuration-only</artifactId>
// <version>1.0.1</version>
// <build>
// <plugins>
// <plugin>
// <groupId>org.codehaus.modello</groupId>
// <artifactId>modello-maven-plugin</artifactId>
// <version>1.0.1</version>
// <configuration>
// <version>1.1.0</version>
// <models>
// <model>src/main/mdo/remote-resources.mdo</model>
// </models>
// </configuration>
// </plugin>
// </plugins>
// </build>
// </project>
//
// We want to
//
// - take the plugin/configuration in the POM and merge it with the plugin's default configuration found in its plugin.xml
// - attach that to the MojoExecution for its configuration
// - give the MojoExecution an id of default-<goal>.
MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session );
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, "default-" + mojoDescriptor.getGoal() );
populateMojoExecutionConfiguration( project, mojoExecution, true );
lifecyclePlan.add( mojoExecution );
}
// 1. Find the lifecycle given the phase (default lifecycle when given install)
// 2. Find the lifecycle mapping that corresponds to the project packaging (jar lifecycle mapping given the jar packaging)
// 3. Find the mojos associated with the lifecycle given the project packaging (jar lifecycle mapping for the default lifecycle)
// 4. Bind those mojos found in the lifecycle mapping for the packaging to the lifecycle
// 5. Bind mojos specified in the project itself to the lifecycle
private void calculateExecutionForLifecyclePhase( MavenSession session, List<MojoExecution> lifecyclePlan, String lifecyclePhase )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, CycleDetectedInPluginGraphException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException
{
MavenProject project = session.getCurrentProject();
// 1.
//
// Based on the lifecycle phase we are given, let's find the corresponding lifecycle.
//
Lifecycle lifecycle = phaseToLifecycleMap.get( lifecyclePhase );
// 2.
//
// If we are dealing with the "clean" or "site" lifecycle then there are currently no lifecycle mappings but there are default phases
// that need to be run instead.
//
// Now we need to take into account the packaging type of the project. For a project of type WAR, the lifecycle where mojos are mapped
// on to the given phases in the lifecycle are going to be a little different then, say, a project of type JAR.
//
// 3.
//
// Once we have the lifecycle mapping for the given packaging, we need to know whats phases we need to worry about executing.
//
// Create an ordered Map of the phases in the lifecycle to a list of mojos to execute.
Map<String, List<MojoExecution>> phaseToMojoMapping = new LinkedHashMap<String, List<MojoExecution>>();
// 4.
//TODO: need to separate the lifecycles
for ( String phase : lifecycle.getPhases() )
{
List<MojoExecution> mojos = new ArrayList<MojoExecution>();
//TODO: remove hard coding
if ( phase.equals( "clean" ) )
{
Plugin plugin = new Plugin();
plugin.setGroupId( "org.apache.maven.plugins" );
plugin.setArtifactId( "maven-clean-plugin" );
plugin.setVersion( "2.3" );
mojos.add( new MojoExecution( plugin, "clean", "default-clean" ) );
}
// This is just just laying out the initial structure of the mojos to run in each phase of the
// lifecycle. Everything is now done in the project builder correctly so this could likely
// go away shortly. We no longer need to pull out bits from the default lifecycle. The MavenProject
// comes to us intact as it should.
phaseToMojoMapping.put( phase, mojos );
}
// 5. Just build up the list of mojos that will execute for every phase.
//
// This will be useful for having the complete build plan and then we can filter/optimize later.
//
for ( Plugin plugin : project.getBuild().getPlugins() )
{
for ( PluginExecution execution : plugin.getExecutions() )
{
// if the phase is specified then I don't have to go fetch the plugin yet and pull it down
// to examine the phase it is associated to.
if ( execution.getPhase() != null )
{
for ( String goal : execution.getGoals() )
{
if ( phaseToMojoMapping.get( execution.getPhase() ) == null )
{
// This is happening because executions in the POM are getting mixed into the clean lifecycle
// So for the lifecycle mapping we need a map with the phases as keys so we can easily check
// if this phase belongs to the given lifecycle. this shows the system is messed up. this
// shouldn't happen.
phaseToMojoMapping.put( execution.getPhase(), new ArrayList<MojoExecution>() );
}
MojoExecution mojoExecution = new MojoExecution( plugin, goal, execution.getId() );
phaseToMojoMapping.get( execution.getPhase() ).add( mojoExecution );
}
}
// if not then i need to grab the mojo descriptor and look at the phase that is specified
else
{
for ( String goal : execution.getGoals() )
{
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session.getLocalRepository(), project.getRemoteArtifactRepositories() );
if ( mojoDescriptor.getPhase() != null && phaseToMojoMapping.get( mojoDescriptor.getPhase() ) != null )
{
MojoExecution mojoExecution = new MojoExecution( plugin, goal, execution.getId() );
phaseToMojoMapping.get( mojoDescriptor.getPhase() ).add( mojoExecution );
}
}
}
}
}
// 6.
//
// We are only interested in the phases that correspond to the lifecycle we are trying to run. If we are running the "clean"
// lifecycle we are not interested in goals -- like "generate-sources -- that belong to the default lifecycle.
//
for ( String phase : phaseToMojoMapping.keySet() )
{
lifecyclePlan.addAll( phaseToMojoMapping.get( phase ) );
if ( phase.equals( lifecyclePhase ) )
{
break;
}
}
}
// SCOPE_COMPILE
// SCOPE_TEST
// SCOPE_RUNTIME
@ -567,10 +584,49 @@ MojoDescriptor getMojoDescriptor( String task, MavenSession session )
Plugin plugin = null;
StringTokenizer tok = new StringTokenizer( task, ":" );
int numTokens = tok.countTokens();
if ( numTokens == 4 )
{
// We have everything that we need
//
// org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process
//
// groupId
// artifactId
// version
// goal
//
plugin = new Plugin();
plugin.setGroupId( tok.nextToken() );
plugin.setArtifactId( tok.nextToken() );
plugin.setVersion( tok.nextToken() );
goal = tok.nextToken();
}
else if ( numTokens == 3 )
{
// We have everything that we need except the version
//
// org.apache.maven.plugins:maven-remote-resources-plugin:???:process
//
// groupId
// artifactId
// ???
// goal
//
plugin = new Plugin();
plugin.setGroupId( tok.nextToken() );
plugin.setArtifactId( tok.nextToken() );
goal = tok.nextToken();
}
if ( numTokens == 2 )
{
// We have a prefix and goal
//
// idea:idea
//
String prefix = tok.nextToken();
goal = tok.nextToken();
@ -585,78 +641,69 @@ MojoDescriptor getMojoDescriptor( String task, MavenSession session )
plugin = findPluginForPrefix( prefix, session );
}
else if ( numTokens == 3 || numTokens == 4 )
{
plugin = new Plugin();
plugin.setGroupId( tok.nextToken() );
plugin.setArtifactId( tok.nextToken() );
if ( numTokens == 4 )
{
plugin.setVersion( tok.nextToken() );
}
goal = tok.nextToken();
}
if ( plugin.getVersion() == null )
{
// We need to get it from the POM first before anything else
//
for ( Plugin pluginInPom : project.getBuildPlugins() )
{
if ( pluginInPom.getArtifactId().equals( plugin.getArtifactId() ) )
{
plugin.setVersion( pluginInPom.getVersion() );
break;
}
}
if ( plugin.getVersion() == null && project.getPluginManagement() != null )
{
for ( Plugin pluginInPom : project.getPluginManagement().getPlugins() )
{
if ( pluginInPom.getArtifactId().equals( plugin.getArtifactId() ) )
{
plugin.setVersion( pluginInPom.getVersion() );
break;
}
}
}
plugin.setVersion( attemptToGetPluginVersionFromProject( plugin, project ) );
// If there is no version to be found then we need to look in the repository metadata for
// this plugin and see what's specified as the latest release.
//
if ( plugin.getVersion() == null )
{
for ( ArtifactRepository repository : session.getCurrentProject().getRemoteArtifactRepositories() )
File artifactMetadataFile;
String localPath;
// Search in the local repositiory for a version
//
// maven-metadata-local.xml
//
localPath = plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata-" + session.getLocalRepository().getId() + ".xml";
artifactMetadataFile = new File( session.getLocalRepository().getBasedir(), localPath );
if ( !artifactMetadataFile.exists() /* || user requests snapshot updates */ )
{
String localPath = plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata-" + repository.getId() + ".xml";
File destination = new File( session.getLocalRepository().getBasedir(), localPath );
if ( !destination.exists() )
// Search in remote repositories for a version.
//
// maven-metadata-{central|nexus|...}.xml
//
//TODO: we should cycle through the repositories but take the repository which actually
// satisfied the prefix.
for ( ArtifactRepository repository : project.getRemoteArtifactRepositories() )
{
try
{
String remotePath = plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata.xml";
localPath = plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata-" + repository.getId() + ".xml";
repositorySystem.retrieve( repository, destination, remotePath, session.getRequest().getTransferListener() );
}
catch ( TransferFailedException e )
artifactMetadataFile = new File( session.getLocalRepository().getBasedir(), localPath );
if ( !artifactMetadataFile.exists() )
{
continue;
}
catch ( ResourceDoesNotExistException e )
{
continue;
try
{
String remotePath = plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata.xml";
repositorySystem.retrieve( repository, artifactMetadataFile, remotePath, session.getRequest().getTransferListener() );
}
catch ( TransferFailedException e )
{
continue;
}
catch ( ResourceDoesNotExistException e )
{
continue;
}
}
}
}
// We have retrieved the metadata
if ( artifactMetadataFile.exists() )
{
try
{
Metadata pluginMetadata = readMetadata( destination );
Metadata pluginMetadata = readMetadata( artifactMetadataFile );
String release = pluginMetadata.getVersioning().getRelease();
@ -664,18 +711,55 @@ else if ( numTokens == 3 || numTokens == 4 )
{
plugin.setVersion( release );
}
else
{
String latest = pluginMetadata.getVersioning().getLatest();
if ( latest != null )
{
plugin.setVersion( latest );
}
}
}
catch ( RepositoryMetadataReadException e )
{
logger.warn( "Error reading plugin metadata: ", e );
}
}
else
{
throw new PluginNotFoundException( plugin, null );
}
}
}
return pluginManager.getMojoDescriptor( plugin, goal, session.getLocalRepository(), project.getRemoteArtifactRepositories() );
}
private String attemptToGetPluginVersionFromProject( Plugin plugin, MavenProject project )
{
for ( Plugin pluginInPom : project.getBuildPlugins() )
{
if ( pluginInPom.getArtifactId().equals( plugin.getArtifactId() ) )
{
return pluginInPom.getVersion();
}
}
if ( plugin.getVersion() == null && project.getPluginManagement() != null )
{
for ( Plugin pluginInPom : project.getPluginManagement().getPlugins() )
{
if ( pluginInPom.getArtifactId().equals( plugin.getArtifactId() ) )
{
return pluginInPom.getVersion();
}
}
}
return null;
}
public void initialize()
throws InitializationException
{
@ -701,19 +785,6 @@ public void initialize()
}
}
public List<String> getLifecyclePhases()
{
for ( Lifecycle lifecycle : lifecycles )
{
if ( lifecycle.getId().equals( "default" ) )
{
return lifecycle.getPhases();
}
}
return null;
}
// These methods deal with construction intact Plugin object that look like they come from a standard
// <plugin/> block in a Maven POM. We have to do some wiggling to pull the sources of information
// together and this really shows the problem of constructing a sensible default configuration but
@ -798,7 +869,7 @@ private void populateDefaultConfigurationForPlugin( Plugin plugin, ArtifactRepos
{
for( String goal : pluginExecution.getGoals() )
{
Xpp3Dom dom = getDefaultPluginConfiguration( plugin, goal, localRepository, remoteRepositories );
Xpp3Dom dom = getDefaultPluginConfiguration( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), goal, localRepository, remoteRepositories );
pluginExecution.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) pluginExecution.getConfiguration(), dom, Boolean.TRUE ) );
}
}
@ -813,14 +884,14 @@ public void populateDefaultConfigurationForPlugins( Collection<Plugin> plugins,
}
}
private Xpp3Dom getDefaultPluginConfiguration( Plugin plugin, String goal, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
private Xpp3Dom getDefaultPluginConfiguration( String groupId, String artifactId, String version, String goal, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws LifecycleExecutionException
{
MojoDescriptor mojoDescriptor;
try
{
mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, localRepository, remoteRepositories );
mojoDescriptor = pluginManager.getMojoDescriptor( groupId, artifactId, version, goal, localRepository, remoteRepositories );
}
catch ( PluginNotFoundException e )
{
@ -902,68 +973,107 @@ public Plugin findPluginForPrefix( String prefix, MavenSession session )
return plugin;
}
for ( ArtifactRepository repository : session.getCurrentProject().getRemoteArtifactRepositories() )
// Process all plugin groups in the local repository first to see if we get a hit. A developer may have been
// developing a plugin locally and installing.
//
for ( String pluginGroup : session.getPluginGroups() )
{
for ( String pluginGroup : session.getPluginGroups() )
String localPath = pluginGroup.replace( '.', '/' ) + "/" + "maven-metadata-" + session.getLocalRepository().getId() + ".xml";
File destination = new File( session.getLocalRepository().getBasedir(), localPath );
if ( destination.exists() )
{
// org.apache.maven.plugins
// org/apache/maven/plugins/maven-metadata.xml
processPluginGroupMetadata( pluginGroup, destination, pluginPrefixes );
String localPath = pluginGroup.replace( '.', '/' ) + "/" + "maven-metadata-" + repository.getId() + ".xml";
plugin = pluginPrefixes.get( prefix );
File destination = new File( session.getLocalRepository().getBasedir(), localPath );
if ( !destination.exists() )
if ( plugin != null )
{
try
{
String remotePath = pluginGroup.replace( '.', '/' ) + "/" + "maven-metadata.xml";
repositorySystem.retrieve( repository, destination, remotePath, session.getRequest().getTransferListener() );
}
catch ( TransferFailedException e )
{
continue;
}
catch ( ResourceDoesNotExistException e )
{
continue;
}
}
// We have retrieved the metadata
try
{
Metadata pluginGroupMetadata = readMetadata( destination );
List<org.apache.maven.artifact.repository.metadata.Plugin> plugins = pluginGroupMetadata.getPlugins();
if ( plugins != null )
{
for ( org.apache.maven.artifact.repository.metadata.Plugin metadataPlugin : plugins )
{
Plugin p = new Plugin();
p.setGroupId( pluginGroup );
p.setArtifactId( metadataPlugin.getArtifactId() );
pluginPrefixes.put( metadataPlugin.getPrefix(), p );
}
}
}
catch ( RepositoryMetadataReadException e )
{
logger.warn( "Error reading plugin group metadata: ", e );
return plugin;
}
}
}
plugin = pluginPrefixes.get( prefix );
if ( plugin != null )
// Process all the remote repositories.
//
for ( String pluginGroup : session.getPluginGroups() )
{
return plugin;
for ( ArtifactRepository repository : session.getCurrentProject().getRemoteArtifactRepositories() )
{
try
{
String localPath = pluginGroup.replace( '.', '/' ) + "/" + "maven-metadata-" + repository.getId() + ".xml";
File destination = new File( session.getLocalRepository().getBasedir(), localPath );
String remotePath = pluginGroup.replace( '.', '/' ) + "/" + "maven-metadata.xml";
repositorySystem.retrieve( repository, destination, remotePath, session.getRequest().getTransferListener() );
processPluginGroupMetadata( pluginGroup, destination, pluginPrefixes );
plugin = pluginPrefixes.get( prefix );
if ( plugin != null )
{
return plugin;
}
}
catch ( TransferFailedException e )
{
continue;
}
catch ( ResourceDoesNotExistException e )
{
continue;
}
}
}
throw new NoPluginFoundForPrefixException( prefix );
throw new NoPluginFoundForPrefixException( prefix, session.getLocalRepository(), session.getCurrentProject().getRemoteArtifactRepositories() );
}
// Keep track of the repository that provided the prefix mapping
//
private class PluginPrefix
{
private Plugin plugin;
private ArtifactRepository repository;
public PluginPrefix( Plugin plugin, ArtifactRepository repository )
{
this.plugin = plugin;
this.repository = repository;
}
}
private void processPluginGroupMetadata( String pluginGroup, File pluginGroupMetadataFile, Map<String,Plugin> pluginPrefixes )
{
try
{
Metadata pluginGroupMetadata = readMetadata( pluginGroupMetadataFile );
List<org.apache.maven.artifact.repository.metadata.Plugin> plugins = pluginGroupMetadata.getPlugins();
if ( plugins != null )
{
for ( org.apache.maven.artifact.repository.metadata.Plugin metadataPlugin : plugins )
{
Plugin p = new Plugin();
p.setGroupId( pluginGroup );
p.setArtifactId( metadataPlugin.getArtifactId() );
pluginPrefixes.put( metadataPlugin.getPrefix(), p );
}
}
}
catch ( RepositoryMetadataReadException e )
{
logger.warn( "Error reading plugin group metadata: ", e );
}
}
protected Metadata readMetadata( File mappingFile )

View File

@ -39,8 +39,6 @@
*/
public interface LifecycleExecutor
{
List<String> getLifecyclePhases();
/**
* Calculate the list of {@link org.apache.maven.plugin.descriptor.MojoDescriptor} objects to run for the selected lifecycle phase.
*

View File

@ -1,12 +1,23 @@
package org.apache.maven.lifecycle;
import java.util.List;
import org.apache.maven.artifact.repository.ArtifactRepository;
public class NoPluginFoundForPrefixException
extends Exception
{
private String prefix;
public NoPluginFoundForPrefixException( String prefix )
private ArtifactRepository localRepository;
private List<ArtifactRepository> remoteRepositories;
public NoPluginFoundForPrefixException( String prefix, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
{
super( "No plugin found for prefix '" + prefix + "'" );
this.prefix = prefix;
this.localRepository = localRepository;
this.remoteRepositories = remoteRepositories;
}
}

View File

@ -32,7 +32,7 @@
public class PluginNotFoundException
extends AbstractArtifactResolutionException
{
private final Plugin plugin;
private Plugin plugin;
public PluginNotFoundException( Plugin plugin, ArtifactNotFoundException e )
{

View File

@ -41,15 +41,6 @@ protected String getProjectsDirectory()
return "src/test/projects/lifecycle-executor";
}
// -----------------------------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------------------------
public void testLifecyclePhases()
{
assertNotNull( lifecycleExecutor.getLifecyclePhases() );
}
// -----------------------------------------------------------------------------------------------
// Tests which exercise the lifecycle executor when it is dealing with default lifecycle phases.
// -----------------------------------------------------------------------------------------------

View File

@ -252,14 +252,20 @@ else if ( quiet )
.setGlobalChecksumPolicy( globalChecksumPolicy ) // default: warn
.setUserToolchainsFile( userToolchainsFile );
File pom;
if ( alternatePomFile != null )
{
request.setPom( new File( alternatePomFile ) );
pom = new File( alternatePomFile );
}
else
{
request.setPom( new File( baseDirectory, Maven.POMv4 ) );
pom = new File( baseDirectory, Maven.POMv4 );
}
if ( pom.exists() )
{
request.setPom( pom );
}
return request;

View File

@ -23,7 +23,6 @@
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.List;
import org.apache.maven.Maven;
import org.apache.maven.MavenExecutionException;
@ -549,9 +548,4 @@ public PlexusContainer getPlexusContainer()
{
return container;
}
public List<String> getLifecyclePhases()
{
return maven.getLifecyclePhases();
}
}

View File

@ -94,14 +94,6 @@ public MavenExecutionRequest populateDefaults( MavenExecutionRequest request, Co
private void pom( MavenExecutionRequest request )
{
// ------------------------------------------------------------------------
// POM
//
// If we are not given a specific POM file, but passed a base directory
// then we will use a release POM in the directory provided, and then
// look for the standard POM.
// ------------------------------------------------------------------------
if ( request.getPom() != null && !request.getPom().isAbsolute() )
{
request.setPom( request.getPom().getAbsoluteFile() );

View File

@ -326,22 +326,6 @@ public void testTwoExecutionsDoNotCacheChangedData()
assertEquals( "2.4.3", p.getVersion() );
}
// ----------------------------------------------------------------------
// Lifecycle phases
// ----------------------------------------------------------------------
public void testRetrievingLifecyclePhases()
throws Exception
{
List phases = mavenEmbedder.getLifecyclePhases();
assertEquals( "validate", (String) phases.get( 0 ) );
assertEquals( "initialize", (String) phases.get( 1 ) );
assertEquals( "generate-sources", (String) phases.get( 2 ) );
}
// ----------------------------------------------------------------------
// Repository
// ----------------------------------------------------------------------

View File

@ -64,10 +64,9 @@ public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, Artifact
return userLocalArtifactRepository.pathOfLocalRepositoryMetadata( metadata, userLocalArtifactRepository );
}
// This ID is necessary of the metadata lookup doesn't work correctly.
public String getId()
{
return "delegating";
return "local";
}
@Override