mirror of https://github.com/apache/maven.git
refactoring to simplify - taking notes of potential clean up after lifecycle is completed
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163410 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f3fce5f156
commit
360ae403b2
|
@ -17,16 +17,10 @@ package org.apache.maven.lifecycle;
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
import org.apache.maven.artifact.MavenMetadataSource;
|
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
||||||
import org.apache.maven.plugin.PluginManager;
|
import org.apache.maven.plugin.PluginManager;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
|
||||||
import org.apache.maven.project.MavenProject;
|
|
||||||
import org.apache.maven.project.MavenProjectBuilder;
|
import org.apache.maven.project.MavenProjectBuilder;
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||||
|
|
||||||
|
@ -89,12 +83,6 @@ public class DefaultLifecycleExecutor
|
||||||
protected void executePhase( String phase, MavenSession session )
|
protected void executePhase( String phase, MavenSession session )
|
||||||
throws LifecycleExecutionException
|
throws LifecycleExecutionException
|
||||||
{
|
{
|
||||||
resolveTransitiveDependencies( session );
|
|
||||||
|
|
||||||
downloadDependencies( session );
|
|
||||||
|
|
||||||
System.out.println( "executing phase = " + phase );
|
|
||||||
|
|
||||||
int i = phases.indexOf( phaseMap.get( phase ) );
|
int i = phases.indexOf( phaseMap.get( phase ) );
|
||||||
|
|
||||||
for ( int j = 0; j <= i; j++ )
|
for ( int j = 0; j <= i; j++ )
|
||||||
|
@ -103,14 +91,7 @@ public class DefaultLifecycleExecutor
|
||||||
|
|
||||||
if ( p.getGoal() != null )
|
if ( p.getGoal() != null )
|
||||||
{
|
{
|
||||||
try
|
executeMojo( p.getGoal(), session );
|
||||||
{
|
|
||||||
pluginManager.executeMojo( session, p.getGoal() );
|
|
||||||
}
|
|
||||||
catch ( GoalExecutionException e )
|
|
||||||
{
|
|
||||||
throw new LifecycleExecutionException( "Problem executing " + p.getGoal(), e );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,29 +108,6 @@ public class DefaultLifecycleExecutor
|
||||||
// archetype:create
|
// archetype:create
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pluginManager.verifyPluginForGoal( id, session );
|
|
||||||
}
|
|
||||||
catch ( Exception e )
|
|
||||||
{
|
|
||||||
throw new LifecycleExecutionException( "Problem getting plugin for " + id, e );
|
|
||||||
}
|
|
||||||
|
|
||||||
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( id );
|
|
||||||
if ( mojoDescriptor == null )
|
|
||||||
{
|
|
||||||
// TODO: goal not found exception?
|
|
||||||
throw new LifecycleExecutionException( "Goal not found: " + id );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mojoDescriptor.requiresDependencyResolution() )
|
|
||||||
{
|
|
||||||
resolveTransitiveDependencies( session );
|
|
||||||
|
|
||||||
downloadDependencies( session );
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pluginManager.executeMojo( session, id );
|
pluginManager.executeMojo( session, id );
|
||||||
|
@ -160,57 +118,6 @@ public class DefaultLifecycleExecutor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// Artifact resolution
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
private void resolveTransitiveDependencies( MavenSession context )
|
|
||||||
throws LifecycleExecutionException
|
|
||||||
{
|
|
||||||
MavenProject project = context.getProject();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, projectBuilder );
|
|
||||||
|
|
||||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
|
|
||||||
context.getRemoteRepositories(),
|
|
||||||
context.getLocalRepository(),
|
|
||||||
sourceReader );
|
|
||||||
|
|
||||||
project.getArtifacts().addAll( result.getArtifacts().values() );
|
|
||||||
|
|
||||||
}
|
|
||||||
catch ( Exception e )
|
|
||||||
{
|
|
||||||
throw new LifecycleExecutionException( "Error resolving transitive dependencies.", e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// Artifact downloading
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
public void downloadDependencies( MavenSession context )
|
|
||||||
throws LifecycleExecutionException
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for ( Iterator it = context.getProject().getArtifacts().iterator(); it.hasNext(); )
|
|
||||||
{
|
|
||||||
Artifact artifact = (Artifact) it.next();
|
|
||||||
|
|
||||||
artifactResolver.resolve( artifact,
|
|
||||||
context.getRemoteRepositories(),
|
|
||||||
context.getLocalRepository() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( ArtifactResolutionException e )
|
|
||||||
{
|
|
||||||
throw new LifecycleExecutionException( "Can't resolve artifact: ", e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
|
@ -20,24 +20,9 @@ package org.apache.maven.lifecycle.goal.phase;
|
||||||
import org.apache.maven.lifecycle.goal.AbstractMavenGoalPhase;
|
import org.apache.maven.lifecycle.goal.AbstractMavenGoalPhase;
|
||||||
import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
||||||
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
|
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
|
||||||
import org.apache.maven.execution.MavenSession;
|
|
||||||
import org.apache.maven.plugin.Plugin;
|
|
||||||
import org.apache.maven.plugin.PluginConfigurationException;
|
|
||||||
import org.apache.maven.plugin.PluginExecutionRequest;
|
|
||||||
import org.apache.maven.plugin.PluginExecutionResponse;
|
import org.apache.maven.plugin.PluginExecutionResponse;
|
||||||
import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
|
|
||||||
import org.apache.maven.plugin.DefaultPluginManager;
|
|
||||||
import org.apache.maven.plugin.PluginManager;
|
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
|
||||||
import org.apache.maven.plugin.descriptor.Parameter;
|
|
||||||
import org.apache.maven.project.MavenProject;
|
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
|
||||||
import org.codehaus.plexus.util.CollectionUtils;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||||
|
@ -51,6 +36,7 @@ public class GoalAttainmentPhase
|
||||||
{
|
{
|
||||||
PluginExecutionResponse response;
|
PluginExecutionResponse response;
|
||||||
|
|
||||||
|
// TODO: remove - most likely empty as there are no prereqs and I don't think the pre/postGoals are being walked
|
||||||
for ( Iterator it = context.getResolvedGoals().iterator(); it.hasNext(); )
|
for ( Iterator it = context.getResolvedGoals().iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
String goalName = (String) it.next();
|
String goalName = (String) it.next();
|
||||||
|
|
|
@ -42,6 +42,8 @@ public class DefaultMavenSessionPhaseManager
|
||||||
public void execute( MavenExecutionRequest request, MavenExecutionResponse response )
|
public void execute( MavenExecutionRequest request, MavenExecutionResponse response )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
// TODO: no longer executed. Remove this, components, etc.
|
||||||
|
|
||||||
for ( Iterator iterator = lifecyclePhases.iterator(); iterator.hasNext(); )
|
for ( Iterator iterator = lifecyclePhases.iterator(); iterator.hasNext(); )
|
||||||
{
|
{
|
||||||
MavenSessionPhase phase = (MavenSessionPhase) iterator.next();
|
MavenSessionPhase phase = (MavenSessionPhase) iterator.next();
|
||||||
|
|
|
@ -22,6 +22,8 @@ import org.apache.maven.artifact.DefaultArtifact;
|
||||||
import org.apache.maven.artifact.MavenMetadataSource;
|
import org.apache.maven.artifact.MavenMetadataSource;
|
||||||
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
|
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
|
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
|
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
|
||||||
|
@ -236,14 +238,21 @@ public class DefaultPluginManager
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
throw new GoalExecutionException( "Unable to execute goal: " + goalName, e );
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginExecutionRequest request;
|
PluginExecutionRequest request;
|
||||||
|
|
||||||
PluginExecutionResponse response;
|
PluginExecutionResponse response;
|
||||||
|
|
||||||
MojoDescriptor mojoDescriptor = getMojoDescriptor( goalName );;
|
MojoDescriptor mojoDescriptor = getMojoDescriptor( goalName );
|
||||||
|
|
||||||
|
if ( mojoDescriptor.requiresDependencyResolution() )
|
||||||
|
{
|
||||||
|
resolveTransitiveDependencies( session );
|
||||||
|
|
||||||
|
downloadDependencies( session );
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -442,5 +451,57 @@ public class DefaultPluginManager
|
||||||
// TODO: needs to be configured from the POM element
|
// TODO: needs to be configured from the POM element
|
||||||
remotePluginRepositories.add( new ArtifactRepository( "plugin-repository", "http://repo1.maven.org" ) );
|
remotePluginRepositories.add( new ArtifactRepository( "plugin-repository", "http://repo1.maven.org" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Artifact resolution
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
private void resolveTransitiveDependencies( MavenSession context )
|
||||||
|
throws GoalExecutionException
|
||||||
|
{
|
||||||
|
MavenProject project = context.getProject();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, mavenProjectBuilder );
|
||||||
|
|
||||||
|
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
|
||||||
|
context.getRemoteRepositories(),
|
||||||
|
context.getLocalRepository(),
|
||||||
|
sourceReader );
|
||||||
|
|
||||||
|
project.getArtifacts().addAll( result.getArtifacts().values() );
|
||||||
|
|
||||||
|
}
|
||||||
|
catch ( Exception e )
|
||||||
|
{
|
||||||
|
throw new GoalExecutionException( "Error resolving transitive dependencies.", e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Artifact downloading
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
private void downloadDependencies( MavenSession context )
|
||||||
|
throws GoalExecutionException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for ( Iterator it = context.getProject().getArtifacts().iterator(); it.hasNext(); )
|
||||||
|
{
|
||||||
|
Artifact artifact = (Artifact) it.next();
|
||||||
|
|
||||||
|
artifactResolver.resolve( artifact,
|
||||||
|
context.getRemoteRepositories(),
|
||||||
|
context.getLocalRepository() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( ArtifactResolutionException e )
|
||||||
|
{
|
||||||
|
throw new GoalExecutionException( "Can't resolve artifact: ", e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.maven.plugin;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
import org.apache.maven.execution.MavenSession;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -38,8 +37,10 @@ public interface PluginManager
|
||||||
void processPluginDescriptor( MavenPluginDescriptor pluginDescriptor )
|
void processPluginDescriptor( MavenPluginDescriptor pluginDescriptor )
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
|
// TODO: not currently used
|
||||||
Map getMojoDescriptors();
|
Map getMojoDescriptors();
|
||||||
|
|
||||||
|
// TODO: not currently used (usages are in the phases that are no longer used)
|
||||||
MojoDescriptor getMojoDescriptor( String goalId );
|
MojoDescriptor getMojoDescriptor( String goalId );
|
||||||
|
|
||||||
void verifyPluginForGoal( String pluginId, MavenSession session )
|
void verifyPluginForGoal( String pluginId, MavenSession session )
|
||||||
|
|
Loading…
Reference in New Issue