o push in changes to sync up with shane

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@769031 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-04-27 15:43:01 +00:00
parent 2805dee2cf
commit 54d0418185
14 changed files with 149 additions and 82 deletions

View File

@ -116,6 +116,8 @@ public class DefaultWagonManager
{
String protocol = repository.getProtocol();
System.out.println( "PROTOCOL: " + protocol );
if ( protocol == null )
{
throw new UnsupportedProtocolException( "The repository " + repository + " does not specify a protocol" );

View File

@ -72,6 +72,12 @@ public class DefaultWagonManagerTest
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
}
public void testAvailableProtocols()
throws Exception
{
wagonManager.getWagon( "file" );
}
public void testUnnecessaryRepositoryLookup() throws Exception {
Artifact artifact = createTestPomArtifact( "target/test-data/get-missing-pom" );

View File

@ -171,7 +171,7 @@ public class DefaultMaven
protected List<MavenProject> getProjects( MavenExecutionRequest request )
throws MavenExecutionException
{
List<File> files = Arrays.asList( new File[] { new File( request.getPomFile() ) } );
List<File> files = Arrays.asList( new File[] { request.getPom() } );
List<MavenProject> projects = collectProjects( files, request );

View File

@ -182,12 +182,6 @@ public class DefaultMavenExecutionRequest
return properties;
}
/** @deprecated use {@link #getPom()} */
public String getPomFile()
{
return pom.getAbsolutePath();
}
public File getPom()
{
return pom;

View File

@ -105,11 +105,6 @@ public interface MavenExecutionRequest
MavenExecutionRequest setRecursive( boolean recursive );
boolean isRecursive();
// Pom
MavenExecutionRequest setPomFile( String pomFilename );
String getPomFile();
MavenExecutionRequest setPom( File pom );
File getPom();

View File

@ -60,6 +60,10 @@ public class DefaultLifecycleExecutor
@Requirement
private PluginManager pluginManager;
/**
* 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;
@ -92,28 +96,7 @@ public class DefaultLifecycleExecutor
throw new BuildFailureException( "\n\nYou must specify at least one goal. Try 'mvn install' to build or 'mvn --help' for options \nSee http://maven.apache.org for more information.\n\n" );
}
executeTaskSegments( goals, session, rootProject );
}
public List<String> getLifecyclePhases()
{
for ( Lifecycle lifecycle : lifecycles )
{
if ( lifecycle.getId().equals( "default" ) )
{
return (List<String>) lifecycle.getPhases();
}
}
return null;
}
private void executeTaskSegments( List<String> goals, MavenSession session, MavenProject rootProject )
throws LifecycleExecutionException, BuildFailureException
{
List<MavenProject> sortedProjects = session.getSortedProjects();
for ( MavenProject currentProject : sortedProjects )
for ( MavenProject currentProject : session.getSortedProjects() )
{
if ( !session.getReactorManager().isBlackListed( currentProject ) )
{
@ -128,6 +111,7 @@ public class DefaultLifecycleExecutor
for ( String goal : goals )
{
String target = currentProject.getId() + " ( " + goal + " )";
System.out.println( "target: " + target );
executeGoalAndHandleFailures( goal, session, currentProject, buildStartTime, target );
}
}
@ -192,6 +176,8 @@ public class DefaultLifecycleExecutor
{
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
System.out.println( mojoExecution.getMojoDescriptor().getGoal() );
try
{
pluginManager.executeMojo( session, mojoExecution );
@ -219,22 +205,51 @@ public class DefaultLifecycleExecutor
// 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 List<MojoDescriptor> calculateLifecyclePlan( String task, MavenSession session )
public List<MojoDescriptor> calculateLifecyclePlan( String lifecyclePhase, MavenSession session )
throws LifecycleExecutionException
{
// Extract the project from the session
MavenProject project = session.getCurrentProject();
// 1.
Lifecycle lifecycle = phaseToLifecycleMap.get( task );
//
// 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.
//
Map<String, String> lifecyclePhasesForPackaging;
if ( lifecyclePhase.equals( "clean" ) )
{
lifecyclePhasesForPackaging = new HashMap<String,String>();
for( String phase : lifecycle.getDefaultPhases() )
{
lifecyclePhasesForPackaging.put( "clean", "org.apache.maven.plugins:maven-clean-plugin:clean" );
}
}
else
{
LifecycleMapping lifecycleMappingForPackaging = lifecycleMappings.get( project.getPackaging() );
// 3.
Map<String, String> lifecyclePhasesForPackaging = lifecycleMappingForPackaging.getLifecycles().get( "default" ).getPhases();
lifecyclePhasesForPackaging = lifecycleMappingForPackaging.getLifecycles().get( lifecycle.getId() ).getPhases();
}
// Create an order Map of the phases in the lifecycle to a list of mojos to execute.
// 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<String>> phaseToMojoMapping = new LinkedHashMap<String,List<String>>();
// 4.
@ -255,21 +270,26 @@ public class DefaultLifecycleExecutor
phaseToMojoMapping.put( phase, mojos );
// We only want to execute up to and including the specified lifecycle phase.
if ( phase.equals( task ) )
if ( phase.equals( lifecyclePhase ) )
{
break;
}
}
// 5.
//
// 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( Plugin plugin : project.getBuild().getPlugins() )
{
System.out.println( plugin.getArtifactId() );
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 )
if ( execution.getPhase() != null && execution.getPhase().equals( lifecyclePhase ) )
{
for( String goal : execution.getGoals() )
{
@ -285,12 +305,22 @@ public class DefaultLifecycleExecutor
for( String goal : execution.getGoals() )
{
String s = plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() + ":" + goal;
MojoDescriptor md = getMojoDescriptor( s, session, project);
MojoDescriptor md = getMojoDescriptor( s, session, project );
boolean include = lifecycle.getPhases().contains( md.getPhase() );
System.out.println( ">>> " + goal );
System.out.println( ">>> " + md.getPhase() );
System.out.println( ">>> " + include );
// need to know if this plugin belongs to a phase in the lifecycle that's running
if ( md.getPhase() != null && include )
{
phaseToMojoMapping.get( md.getPhase() ).add( s );
}
}
}
}
}
List<MojoDescriptor> lifecyclePlan = new ArrayList<MojoDescriptor>();
@ -307,6 +337,11 @@ public class DefaultLifecycleExecutor
}
}
for ( MojoDescriptor md : lifecyclePlan )
{
System.out.println( md.getGoal() );
}
return lifecyclePlan;
}
@ -427,4 +462,17 @@ public class DefaultLifecycleExecutor
}
}
}
public List<String> getLifecyclePhases()
{
for ( Lifecycle lifecycle : lifecycles )
{
if ( lifecycle.getId().equals( "default" ) )
{
return (List<String>) lifecycle.getPhases();
}
}
return null;
}
}

View File

@ -32,7 +32,15 @@ public interface LifecycleExecutor
{
List<String> getLifecyclePhases();
List<MojoDescriptor> calculateLifecyclePlan( String task, MavenSession session )
/**
* Calculate the list of {@link org.apache.maven.plugin.descriptor.MojoDescriptor} objects to run for the selected lifecycle phase.
*
* @param phase
* @param session
* @return
* @throws LifecycleExecutionException
*/
List<MojoDescriptor> calculateLifecyclePlan( String lifecyclePhase, MavenSession session )
throws LifecycleExecutionException;
void execute( MavenSession session )

View File

@ -197,15 +197,15 @@ public class DefaultPluginManager
ArtifactRepository localRepository = session.getLocalRepository();
MavenProject pluginProject = buildPluginProject( plugin, localRepository, project.getRemoteArtifactRepositories() );
MavenProject pluginProject = buildPluginProject( plugin, localRepository, new ArrayList( project.getRemoteArtifactRepositories() ) );
Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin );
checkRequiredMavenVersion( plugin, pluginProject, localRepository, project.getRemoteArtifactRepositories() );
checkRequiredMavenVersion( plugin, pluginProject, localRepository, new ArrayList( project.getRemoteArtifactRepositories() ) );
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, project.getRemoteArtifactRepositories() );
ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, new ArrayList( project.getRemoteArtifactRepositories() ) );
ArtifactResolutionResult result = repositorySystem.resolve( request );
@ -290,7 +290,7 @@ public class DefaultPluginManager
Artifact pluginPomArtifact = repositorySystem.createProjectArtifact( pluginArtifact.getGroupId(), pluginArtifact.getArtifactId(), pluginArtifact.getVersion() );
// This does not populate the artifacts of the dependenct projects
MavenProject pluginProject = mavenProjectBuilder.buildFromRepository( pluginPomArtifact, project.getRemoteArtifactRepositories(), localRepository );
MavenProject pluginProject = mavenProjectBuilder.buildFromRepository( pluginPomArtifact, new ArrayList( project.getRemoteArtifactRepositories() ), localRepository );
// This needs to be changed so that the resolver deals with this
for ( Dependency d : pluginProject.getDependencies() )
@ -320,7 +320,7 @@ public class DefaultPluginManager
.setArtifact( pluginArtifact )
.setArtifactDependencies( dependencies )
.setLocalRepository( localRepository )
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
.setRemoteRepostories( new ArrayList( project.getRemoteArtifactRepositories() ) )
.setManagedVersionMap( pluginManagedDependencies )
.setFilter( filter )
.setResolveRoot( false ); // We are setting this to false because the artifact itself has been resolved.
@ -1084,7 +1084,7 @@ public class DefaultPluginManager
.setResolveRoot( false )
.setArtifactDependencies( project.getDependencyArtifacts() )
.setLocalRepository( session.getLocalRepository() )
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
.setRemoteRepostories( new ArrayList( project.getRemoteArtifactRepositories() ) )
.setManagedVersionMap( project.getManagedVersionMap() )
.setFilter( filter );
@ -1095,7 +1095,7 @@ public class DefaultPluginManager
project.setArtifacts( result.getArtifacts() );
ArtifactRepository localRepository = session.getLocalRepository();
List<ArtifactRepository> remoteArtifactRepositories = session.getCurrentProject().getRemoteArtifactRepositories();
List<ArtifactRepository> remoteArtifactRepositories = new ArrayList( session.getCurrentProject().getRemoteArtifactRepositories() );
for ( Artifact projectArtifact : session.getCurrentProject().getArtifacts() )
{

View File

@ -1,13 +0,0 @@
package org.apache.maven.plugin;
import org.sonatype.plexus.plugin.manager.DefaultPlexusPluginManager;
/**
*
* @author jvanzyl
*/
public class MavenPluginManager
extends DefaultPlexusPluginManager
{
}

View File

@ -28,6 +28,7 @@ import java.util.StringTokenizer;
import java.util.Map.Entry;
import org.apache.commons.cli.CommandLine;
import org.apache.maven.Maven;
import org.apache.maven.MavenTransferListener;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
@ -256,7 +257,10 @@ public final class CLIRequestUtils
if ( alternatePomFile != null )
{
request.setPom( new File( alternatePomFile ) );
System.out.println( "Request pom set to: " + request.getPom() );
}
else
{
request.setPom( new File( baseDirectory, Maven.POMv4 ) );
}
return request;

View File

@ -737,7 +737,7 @@ public class DefaultMavenProjectBuilder
{
if ( isParentLocal( parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) )
{
domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, localRepository, remoteRepositories, topProject.getFile(), projectBuilderConfiguration ) );
domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, localRepository, remoteRepositories, topProject.getFile().getParentFile(), projectBuilderConfiguration ) );
}
else
{

View File

@ -124,6 +124,8 @@ public class MavenProject
private List<String> scriptSourceRoots = new ArrayList<String>();
private List<ArtifactRepository> pluginArtifactRepositories;
private ArtifactRepository releaseArtifactRepository;
private ArtifactRepository snapshotArtifactRepository;
@ -164,6 +166,7 @@ public class MavenProject
private ProjectBuilderConfiguration projectBuilderConfiguration;
private RepositorySystem repositorySystem;
//
private File parentFile;
@ -1327,7 +1330,21 @@ public class MavenProject
return build;
}
//!!jvz remove ModelUtils
public void addPlugin( Plugin plugin )
{
Build build = getModelBuild();
if ( !build.getPluginsAsMap().containsKey( plugin.getKey() ) )
{
injectPluginManagementInfo( plugin );
build.addPlugin( plugin );
build.flushPluginMap();
}
}
//TODO: remove ModelUtils
public void injectPluginManagementInfo( Plugin plugin )
{
PluginManagement pm = getModelBuild().getPluginManagement();
@ -1359,6 +1376,7 @@ public class MavenProject
public void setPluginArtifactRepositories( List<ArtifactRepository> pluginArtifactRepositories )
{
this.pluginArtifactRepositories = pluginArtifactRepositories;
}
/**

View File

@ -383,9 +383,7 @@ public class LegacyRepositorySystem
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
{
ArtifactResolutionResult res = artifactResolver.resolve( request );
return res;
return artifactResolver.resolve( request );
}
public void setOnline( boolean online )

View File

@ -439,6 +439,7 @@ under the License.
<useJava5>true</useJava5>
</configuration>
<executions>
<!--
<execution>
<id>site-docs</id>
<phase>pre-site</phase>
@ -447,6 +448,7 @@ under the License.
<goal>xsd</goal>
</goals>
</execution>
-->
<execution>
<id>standard</id>
<goals>
@ -477,6 +479,11 @@ under the License.
<artifactId>maven-resources-plugin</artifactId>
<version>2.4-SNAPSHOT</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.0.1-SNAPSHOT</version>
</plugin>
</plugins>
</pluginManagement>
</build>