mirror of https://github.com/apache/maven.git
o move some shared execution request handling code to the super class
o cleanup the plugin manager interface, we don't need to set the local repository as that information is in the request and session. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163259 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7099cca292
commit
d7591b9f76
|
@ -123,7 +123,7 @@ public class MavenCli
|
|||
|
||||
if ( !projectFile.exists() )
|
||||
{
|
||||
System.err.println( "Could not find either a project descriptor." );
|
||||
System.err.println( "Could not find a project descriptor." );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,65 @@
|
|||
package org.apache.maven.execution;
|
||||
|
||||
import org.apache.maven.lifecycle.session.MavenSession;
|
||||
import org.apache.maven.lifecycle.session.MavenSessionPhaseManager;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.context.Context;
|
||||
import org.codehaus.plexus.context.ContextException;
|
||||
import org.codehaus.plexus.i18n.I18N;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AbstractMavenExecutionRequestHandler
|
||||
public abstract class AbstractMavenExecutionRequestHandler
|
||||
extends AbstractLogEnabled
|
||||
implements MavenExecutionRequestHandler, Contextualizable
|
||||
{
|
||||
// ----------------------------------------------------------------------
|
||||
// Components
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
protected MavenProjectBuilder projectBuilder;
|
||||
|
||||
protected PluginManager pluginManager;
|
||||
|
||||
protected PlexusContainer container;
|
||||
|
||||
protected MavenSessionPhaseManager lifecycleManager;
|
||||
|
||||
protected I18N i18n;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Methods used by all execution request handlers
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
//!! We should probably have the execution request handler create the session as
|
||||
// the session type would be specific to the request i.e. having a project
|
||||
// or not.
|
||||
|
||||
protected MavenSession createSession( MavenExecutionRequest request, MavenProject project )
|
||||
{
|
||||
MavenSession session = new MavenSession( container,
|
||||
pluginManager,
|
||||
project,
|
||||
request.getLocalRepository(),
|
||||
request.getGoals() );
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Lifecylce Management
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public void contextualize( Context context ) throws ContextException
|
||||
{
|
||||
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package org.apache.maven.execution.initialize;
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.execution.AbstractMavenExecutionRequest;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MavenInitializingExecutionRequest
|
||||
extends AbstractMavenExecutionRequest
|
||||
{
|
||||
public MavenInitializingExecutionRequest( ArtifactRepository localRepository, List goals )
|
||||
{
|
||||
super( localRepository, goals );
|
||||
|
||||
type = "initializing";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package org.apache.maven.execution.initialize;
|
||||
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.reactor.ReactorException;
|
||||
import org.apache.maven.execution.reactor.MavenReactorExecutionRequest;
|
||||
import org.apache.maven.execution.project.MavenProjectExecutionRequestHandler;
|
||||
import org.apache.maven.execution.MavenExecutionRequestHandler;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionResponse;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MavenInitializingExecutionRequestHandler
|
||||
extends MavenProjectExecutionRequestHandler
|
||||
implements MavenExecutionRequestHandler
|
||||
{
|
||||
public void handle( MavenExecutionRequest request, MavenExecutionResponse response )
|
||||
throws Exception
|
||||
{
|
||||
super.handle( null, null );
|
||||
}
|
||||
}
|
|
@ -1,24 +1,11 @@
|
|||
package org.apache.maven.execution.project;
|
||||
|
||||
import org.apache.maven.lifecycle.session.MavenSession;
|
||||
import org.apache.maven.lifecycle.session.MavenSessionPhaseManager;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.execution.project.MavenProjectExecutionRequest;
|
||||
import org.apache.maven.execution.AbstractMavenExecutionRequestHandler;
|
||||
import org.apache.maven.execution.MavenExecutionRequestHandler;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionResponse;
|
||||
import org.codehaus.plexus.ArtifactEnabledContainer;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
import org.codehaus.plexus.i18n.I18N;
|
||||
import org.codehaus.plexus.context.Context;
|
||||
import org.codehaus.plexus.context.ContextException;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
@ -29,20 +16,9 @@ import java.util.Date;
|
|||
*/
|
||||
public class MavenProjectExecutionRequestHandler
|
||||
extends AbstractMavenExecutionRequestHandler
|
||||
implements MavenExecutionRequestHandler, Contextualizable
|
||||
{
|
||||
private boolean logResults = true;
|
||||
|
||||
protected MavenProjectBuilder projectBuilder;
|
||||
|
||||
protected PluginManager pluginManager;
|
||||
|
||||
protected PlexusContainer container;
|
||||
|
||||
protected MavenSessionPhaseManager lifecycleManager;
|
||||
|
||||
protected I18N i18n;
|
||||
|
||||
public void handle( MavenExecutionRequest request, MavenExecutionResponse response )
|
||||
throws Exception
|
||||
{
|
||||
|
@ -52,17 +28,9 @@ public class MavenProjectExecutionRequestHandler
|
|||
|
||||
Date fullStart = new Date();
|
||||
|
||||
pluginManager.setLocalRepository( request.getLocalRepository() );
|
||||
|
||||
MavenSession session = new MavenSession( container,
|
||||
pluginManager,
|
||||
project,
|
||||
request.getLocalRepository(),
|
||||
request.getGoals() );
|
||||
|
||||
try
|
||||
{
|
||||
response = lifecycleManager.execute( session );
|
||||
response = lifecycleManager.execute( createSession( request, project ) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
|
@ -184,13 +152,4 @@ public class MavenProjectExecutionRequestHandler
|
|||
|
||||
return projectBuilder.build( pom, localRepository );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Lifecylce Management
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public void contextualize( Context context ) throws ContextException
|
||||
{
|
||||
container = (ArtifactEnabledContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package org.apache.maven.execution.reactor;
|
||||
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.reactor.ReactorException;
|
||||
import org.apache.maven.execution.reactor.MavenReactorExecutionRequest;
|
||||
import org.apache.maven.execution.project.MavenProjectExecutionRequestHandler;
|
||||
import org.apache.maven.execution.MavenExecutionRequestHandler;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionResponse;
|
||||
import org.apache.maven.execution.project.MavenProjectExecutionRequest;
|
||||
import org.apache.maven.execution.project.MavenProjectExecutionRequestHandler;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.reactor.ReactorException;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -20,7 +19,6 @@ import java.util.List;
|
|||
*/
|
||||
public class MavenReactorExecutionRequestHandler
|
||||
extends MavenProjectExecutionRequestHandler
|
||||
implements MavenExecutionRequestHandler
|
||||
{
|
||||
public void handle( MavenExecutionRequest request, MavenExecutionResponse response )
|
||||
throws Exception
|
||||
|
@ -72,11 +70,10 @@ public class MavenReactorExecutionRequestHandler
|
|||
|
||||
line();
|
||||
|
||||
//MavenProjectExecutionRequest r = new MavenProjectExecutionRequest();
|
||||
MavenProjectExecutionRequest projectExecutionRequest =
|
||||
new MavenProjectExecutionRequest( request.getLocalRepository(), request.getGoals(), project.getFile() );
|
||||
|
||||
super.handle( null, null );
|
||||
|
||||
//response = execute( new MavenProjectExecutionRequest( request.getLocalRepository(), request.getGoals(), project ) );
|
||||
super.handle( projectExecutionRequest, response );
|
||||
|
||||
if ( response.isExecutionFailure() )
|
||||
{
|
||||
|
|
|
@ -66,7 +66,7 @@ public class PluginResolutionPhase
|
|||
{
|
||||
try
|
||||
{
|
||||
pluginManager.verifyPluginForGoal( goal );
|
||||
pluginManager.verifyPluginForGoal( goal, session );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
|
|
|
@ -60,8 +60,11 @@ public class MavenSession
|
|||
|
||||
private Map postGoalMappings;
|
||||
|
||||
public MavenSession( PlexusContainer container, PluginManager pluginManager, MavenProject project,
|
||||
ArtifactRepository localRepository, List goals )
|
||||
public MavenSession( PlexusContainer container,
|
||||
PluginManager pluginManager,
|
||||
MavenProject project,
|
||||
ArtifactRepository localRepository,
|
||||
List goals )
|
||||
{
|
||||
this.container = container;
|
||||
|
||||
|
@ -161,14 +164,17 @@ public class MavenSession
|
|||
private void initGoalDecoratorMappings()
|
||||
{
|
||||
List allPreGoals = project.getPreGoals();
|
||||
|
||||
for ( Iterator it = allPreGoals.iterator(); it.hasNext(); )
|
||||
{
|
||||
PreGoal preGoal = (PreGoal) it.next();
|
||||
|
||||
List preGoalList = (List) preGoalMappings.get( preGoal.getName() );
|
||||
|
||||
if ( preGoalList == null )
|
||||
{
|
||||
preGoalList = new LinkedList();
|
||||
|
||||
preGoalMappings.put( preGoal.getName(), preGoalList );
|
||||
}
|
||||
|
||||
|
@ -176,14 +182,17 @@ public class MavenSession
|
|||
}
|
||||
|
||||
List allPostGoals = project.getPostGoals();
|
||||
|
||||
for ( Iterator it = allPostGoals.iterator(); it.hasNext(); )
|
||||
{
|
||||
PostGoal postGoal = (PostGoal) it.next();
|
||||
|
||||
List postGoalList = (List) postGoalMappings.get( postGoal.getName() );
|
||||
|
||||
if ( postGoalList == null )
|
||||
{
|
||||
postGoalList = new LinkedList();
|
||||
|
||||
postGoalMappings.put( postGoal.getName(), postGoalList );
|
||||
}
|
||||
|
||||
|
@ -213,5 +222,4 @@ public class MavenSession
|
|||
|
||||
return chainToHere;
|
||||
}
|
||||
|
||||
}
|
|
@ -22,6 +22,7 @@ import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
|
|||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
|
||||
import org.apache.maven.lifecycle.session.MavenSession;
|
||||
import org.codehaus.plexus.ArtifactEnabledContainer;
|
||||
import org.codehaus.plexus.PlexusConstants;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
|
@ -62,8 +63,6 @@ public class DefaultPluginManager
|
|||
|
||||
protected Set remotePluginRepositories;
|
||||
|
||||
protected ArtifactRepository localRepository;
|
||||
|
||||
protected ArtifactFilter artifactFilter;
|
||||
|
||||
public DefaultPluginManager()
|
||||
|
@ -163,7 +162,8 @@ public class DefaultPluginManager
|
|||
return goalName;
|
||||
}
|
||||
|
||||
public void verifyPluginForGoal( String goalName ) throws Exception
|
||||
public void verifyPluginForGoal( String goalName, MavenSession session )
|
||||
throws Exception
|
||||
{
|
||||
String pluginId = getPluginId( goalName );
|
||||
|
||||
|
@ -179,7 +179,7 @@ public class DefaultPluginManager
|
|||
|
||||
Artifact pluginArtifact = new DefaultArtifact( "maven", artifactId, version, "plugin", "jar" );
|
||||
|
||||
addPlugin( pluginArtifact );
|
||||
addPlugin( pluginArtifact, session );
|
||||
|
||||
// Now, we need to resolve the plugins for this goal's prereqs.
|
||||
MojoDescriptor mojoDescriptor = getMojoDescriptor( goalName );
|
||||
|
@ -192,25 +192,25 @@ public class DefaultPluginManager
|
|||
{
|
||||
String prereq = (String) it.next();
|
||||
|
||||
verifyPluginForGoal( prereq );
|
||||
verifyPluginForGoal( prereq, session );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlugin( Artifact pluginArtifact )
|
||||
protected void addPlugin( Artifact pluginArtifact, MavenSession session )
|
||||
throws Exception
|
||||
{
|
||||
artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );
|
||||
|
||||
MavenMetadataSource metadataSource = new MavenMetadataSource( remotePluginRepositories,
|
||||
localRepository,
|
||||
session.getLocalRepository(),
|
||||
artifactResolver );
|
||||
|
||||
( (ArtifactEnabledContainer) container ).addComponent( pluginArtifact,
|
||||
artifactResolver,
|
||||
remotePluginRepositories,
|
||||
localRepository,
|
||||
session.getLocalRepository(),
|
||||
metadataSource,
|
||||
artifactFilter );
|
||||
}
|
||||
|
@ -243,17 +243,5 @@ public class DefaultPluginManager
|
|||
// TODO: needs to be configured from the POM element
|
||||
remotePluginRepositories.add( new ArtifactRepository( "plugin-repository", "http://repo1.maven.org" ) );
|
||||
}
|
||||
|
||||
// TODO: is this needed or can it be found from the session?
|
||||
public ArtifactRepository getLocalRepository()
|
||||
{
|
||||
return localRepository;
|
||||
}
|
||||
|
||||
// TODO: is this needed or can it be found from the session? It is currently set from the session
|
||||
public void setLocalRepository( ArtifactRepository localRepository )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Map;
|
|||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.lifecycle.session.MavenSession;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
|
@ -29,31 +30,13 @@ public interface PluginManager
|
|||
{
|
||||
String ROLE = PluginManager.class.getName();
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Plugin processing
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void processPluginDescriptor( MavenPluginDescriptor pluginDescriptor )
|
||||
throws Exception;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Mojo descriptors
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
Map getMojoDescriptors();
|
||||
|
||||
MojoDescriptor getMojoDescriptor( String goalId );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
void verifyPluginForGoal( String pluginId )
|
||||
void verifyPluginForGoal( String pluginId, MavenSession session )
|
||||
throws Exception;
|
||||
|
||||
void setLocalRepository( ArtifactRepository localRepository );
|
||||
}
|
||||
|
|
|
@ -130,8 +130,6 @@ public class MavenTestCase
|
|||
|
||||
MavenSession session = new MavenSession( getContainer(), pluginManager, project, localRepository, goals );
|
||||
|
||||
pluginManager.setLocalRepository( localRepository );
|
||||
|
||||
MavenGoalExecutionContext context = new MavenGoalExecutionContext( session, goal );
|
||||
|
||||
return context;
|
||||
|
|
Loading…
Reference in New Issue