o the introduction of the lifecycle stuff we've been chatting about so you

can now do things like:

  m2 package

  which makes the jar

  m2 install

  which installs the jar

  m2 test

  You can also execute individual goals still like:

  clean:clean
  pom:install
  idea:idea

  Execution of goals this way will still have the dependency resolution
  flag obeyed but they are run in isolation in that pre/post goals don't
  exist anymore. You need to slot your mojos into the lifecycle.

  I will add the mechanism whereby configuring a plugin will push
  the mojo into the lifecycle.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163359 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2005-02-16 07:16:33 +00:00
parent 1432ed959d
commit 780b693240
33 changed files with 784 additions and 893 deletions

View File

@ -17,22 +17,44 @@
* ====================================================================
*/
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequestHandler;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.manager.MavenExecutionRequestHandlerManager;
import org.apache.maven.execution.MavenProjectExecutionRequest;
import org.apache.maven.execution.MavenReactorExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.lifecycle.goal.GoalNotFoundException;
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.reactor.ReactorException;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
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.util.FileUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*
* @version $Id$
*/
public class DefaultMaven
extends AbstractLogEnabled
implements Maven
implements Maven, Contextualizable
{
// ----------------------------------------------------------------------
// Components
@ -40,7 +62,15 @@ public class DefaultMaven
private I18N i18n;
private MavenExecutionRequestHandlerManager requestHandlerManager;
protected MavenProjectBuilder projectBuilder;
protected PluginManager pluginManager;
protected MavenSessionPhaseManager sessionPhaseManager;
protected LifecycleExecutor lifecycleExecutor;
protected PlexusContainer container;
// ----------------------------------------------------------------------
// Project execution
@ -49,12 +79,299 @@ public class DefaultMaven
public MavenExecutionResponse execute( MavenExecutionRequest request )
throws GoalNotFoundException, Exception
{
MavenExecutionRequestHandler handler = (MavenExecutionRequestHandler) requestHandlerManager.lookup( request.getType() );
MavenExecutionResponse response = new MavenExecutionResponse();
handler.handle( request, response );
handleProject( request );
return response;
}
public void handleProject( MavenExecutionRequest request )
throws Exception
{
MavenExecutionResponse response = new MavenExecutionResponse();
MavenSession session = createSession( request );
MavenProject project = getProject( (File) request.getProjectFiles().get( 0 ), request.getLocalRepository() );
session.setProject( project );
try
{
response.setStart( new Date() );
resolveParameters( request );
lifecycleExecutor.execute( request.getGoals(), session );
response.setFinish( new Date() );
}
catch ( Exception e )
{
response.setFinish( new Date() );
response.setException( e );
logError( response );
return;
}
if ( response.isExecutionFailure() )
{
logFailure( response );
}
else
{
logSuccess( response );
}
}
// ----------------------------------------------------------------------
// Reactor
// ----------------------------------------------------------------------
public void handleReactor( MavenExecutionRequest request, MavenExecutionResponse response )
throws Exception
{
List projects = new ArrayList();
getLogger().info( "Starting the reactor..." );
try
{
List files = FileUtils.getFiles( new File( System.getProperty( "user.dir" ) ),
( (MavenReactorExecutionRequest) request ).getIncludes(),
( (MavenReactorExecutionRequest) request ).getExcludes() );
for ( Iterator iterator = files.iterator(); iterator.hasNext(); )
{
File file = (File) iterator.next();
MavenProject project = getProject( file, request.getLocalRepository() );
projects.add( project );
}
projects = projectBuilder.getSortedProjects( projects );
}
catch ( Exception e )
{
throw new ReactorException( "Error processing projects for the reactor: ", e );
}
getLogger().info( "Our processing order:" );
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
{
MavenProject project = (MavenProject) iterator.next();
getLogger().info( project.getName() );
}
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
{
MavenProject project = (MavenProject) iterator.next();
System.out.println( "\n\n\n" );
line();
getLogger().info( "Building " + project.getName() );
line();
//MavenProjectExecutionRequest projectExecutionRequest = request.createProjectExecutionRequest( project );
//handleProject( projectExecutionRequest, response );
if ( response.isExecutionFailure() )
{
break;
}
}
}
public MavenProject getProject( File pom, ArtifactRepository localRepository )
throws ProjectBuildingException
{
if ( pom.exists() )
{
if ( pom.length() == 0 )
{
throw new ProjectBuildingException( i18n.format( "empty.descriptor.error", pom.getName() ) );
}
}
return projectBuilder.build( pom, localRepository );
}
// ----------------------------------------------------------------------
// 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 )
throws Exception
{
MavenSession session = new MavenSession( container,
pluginManager,
request.getLocalRepository(),
request.getGoals() );
return session;
}
/**
* @todo [BP] this might not be required if there is a better way to pass them in. It doesn't feel quite right.
*/
private void resolveParameters( MavenExecutionRequest request )
throws ComponentLookupException
{
WagonManager wagonManager = (WagonManager) container.lookup( WagonManager.ROLE );
if ( request.getParameter( "maven.proxy.http.host" ) != null )
{
String p = request.getParameter( "maven.proxy.http.port" );
int port = 8080;
if ( p != null )
{
try
{
port = Integer.valueOf( p ).intValue();
}
catch ( NumberFormatException e )
{
getLogger().warn( "maven.proxy.http.port was not valid" );
}
}
wagonManager.setProxy( "http", request.getParameter( "maven.proxy.http.host" ), port,
request.getParameter( "maven.proxy.http.username" ),
request.getParameter( "maven.proxy.http.password" ),
request.getParameter( "maven.proxy.http.nonProxyHosts" ) );
}
}
// ----------------------------------------------------------------------
// Lifecylce Management
// ----------------------------------------------------------------------
public void contextualize( Context context ) throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
// ----------------------------------------------------------------------
// Reporting / Logging
// ----------------------------------------------------------------------
protected void logError( MavenExecutionResponse r )
{
line();
getLogger().error( "BUILD ERROR" );
line();
getLogger().error( "Cause: ", r.getException() );
line();
stats( r.getStart(), r.getFinish() );
line();
}
protected void logFailure( MavenExecutionResponse r )
{
line();
getLogger().info( "BUILD FAILURE" );
line();
getLogger().info( "Reason: " + r.getFailureResponse().shortMessage() );
line();
getLogger().info( r.getFailureResponse().longMessage() );
line();
stats( r.getStart(), r.getFinish() );
line();
}
protected void logSuccess( MavenExecutionResponse r )
{
line();
getLogger().info( "BUILD SUCCESSFUL" );
line();
stats( r.getStart(), r.getFinish() );
line();
}
protected void stats( Date start, Date finish )
{
long time = finish.getTime() - start.getTime();
getLogger().info( "Total time: " + formatTime( time ) );
getLogger().info( "Finished at: " + finish );
final long mb = 1024 * 1024;
System.gc();
Runtime r = Runtime.getRuntime();
getLogger().info( "Final Memory: " + ( ( r.totalMemory() - r.freeMemory() ) / mb ) + "M/" + ( r.totalMemory() / mb ) + "M" );
}
protected void line()
{
getLogger().info( "----------------------------------------------------------------------------" );
}
protected static String formatTime( long ms )
{
long secs = ms / 1000;
long min = secs / 60;
secs = secs % 60;
if ( min > 0 )
{
return min + " minutes " + secs + " seconds";
}
else
{
return secs + " seconds";
}
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Reactor
// ----------------------------------------------------------------------
public List getSortedProjects( List projects )
throws Exception
{
return projectBuilder.getSortedProjects( projects );
}
}

View File

@ -26,13 +26,13 @@
import org.apache.commons.cli.PosixParser;
import org.apache.maven.Maven;
import org.apache.maven.MavenConstants;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.initialize.MavenInitializingExecutionRequest;
import org.apache.maven.execution.project.MavenProjectExecutionRequest;
import org.apache.maven.execution.reactor.MavenReactorExecutionRequest;
import org.apache.maven.execution.MavenInitializingExecutionRequest;
import org.apache.maven.execution.MavenProjectExecutionRequest;
import org.apache.maven.execution.MavenReactorExecutionRequest;
import org.codehaus.classworlds.ClassWorld;
import org.codehaus.plexus.embed.ArtifactEnabledEmbedder;
@ -47,17 +47,20 @@
public class MavenCli
{
public static final String POMv4 = "pom.xml";
public static final String userHome = System.getProperty( "user.home" );
public static File userDir = new File( System.getProperty( "user.dir" ) );
public static int main( String[] args, ClassWorld classWorld )
throws Exception
throws Exception
{
// ----------------------------------------------------------------------
// Setup the command line parser
// ----------------------------------------------------------------------
CLIManager cliManager = new CLIManager();
CommandLine commandLine = cliManager.parse( args );
// ----------------------------------------------------------------------
@ -69,7 +72,9 @@ public static int main( String[] args, ClassWorld classWorld )
// ----------------------------------------------------------------------
File userConfigurationDirectory = getUserConfigurationDirectory();
Properties mavenProperties = getMavenProperties( userConfigurationDirectory );
ArtifactRepository localRepository = getLocalRepository( mavenProperties, userConfigurationDirectory );
// ----------------------------------------------------------------------
@ -100,27 +105,37 @@ public static int main( String[] args, ClassWorld classWorld )
// ----------------------------------------------------------------------
MavenExecutionRequest request = null;
File projectFile = new File( userDir, POMv4 );
if ( projectFile.exists() )
{
if ( commandLine.hasOption( CLIManager.REACTOR ) )
{
String includes = System.getProperty( "maven.reactor.includes", "**/" + POMv4 );
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 );
request = new MavenReactorExecutionRequest( localRepository, mavenProperties, commandLine.getArgList(),
includes, excludes, userDir );
request = new MavenReactorExecutionRequest( localRepository,
mavenProperties,
commandLine.getArgList(),
includes,
excludes,
userDir );
}
else
{
request = new MavenProjectExecutionRequest( localRepository, mavenProperties, commandLine.getArgList(),
request = new MavenProjectExecutionRequest( localRepository,
mavenProperties,
commandLine.getArgList(),
projectFile );
}
}
else
{
request = new MavenInitializingExecutionRequest( localRepository, mavenProperties,
commandLine.getArgList() );
request = new MavenInitializingExecutionRequest( localRepository, mavenProperties, commandLine.getArgList() );
}
MavenExecutionResponse response = new MavenExecutionResponse();
// ----------------------------------------------------------------------
@ -129,12 +144,13 @@ public static int main( String[] args, ClassWorld classWorld )
// ----------------------------------------------------------------------
ArtifactEnabledEmbedder embedder = new ArtifactEnabledEmbedder();
embedder.start( classWorld );
// TODO [BP]: doing this here as it is CLI specific, though it doesn't feel like the right place.
WagonManager wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
wagonManager.setDownloadMonitor( new ConsoleDownloadMonitor() );
wagonManager.setDownloadMonitor( new ConsoleDownloadMonitor() );
Maven maven = (Maven) embedder.lookup( Maven.ROLE );
@ -143,6 +159,7 @@ public static int main( String[] args, ClassWorld classWorld )
// ----------------------------------------------------------------------
response = maven.execute( request );
if ( response.isExecutionFailure() )
{
return 1;
@ -178,18 +195,24 @@ private static void initializeSystemProperties( CommandLine commandLine )
private static void setCliProperty( String property )
{
String name = null;
String value = null;
int i = property.indexOf( "=" );
if ( i <= 0 )
{
name = property.trim();
value = "true";
}
else
{
name = property.substring( 0, i ).trim();
value = property.substring( i + 1 ).trim();
}
System.setProperty( name, value );
}
@ -200,13 +223,21 @@ private static void setCliProperty( String property )
static class CLIManager
{
public static final char NO_BANNER = 'b';
public static final char SET_SYSTEM_PROPERTY = 'D';
public static final char WORK_OFFLINE = 'o';
public static final char REACTOR = 'r';
public static final char DEBUG = 'X';
public static final char HELP = 'h';
public static final char VERSION = 'v';
public static final char LIST_GOALS = 'g';
private Options options = null;
public CLIManager()
@ -253,7 +284,7 @@ public CLIManager()
}
public CommandLine parse( String[] args )
throws ParseException
throws ParseException
{
CommandLineParser parser = new PosixParser();
return parser.parse( options, args );
@ -288,7 +319,7 @@ protected static Properties getMavenProperties( File mavenHomeLocal )
Properties mavenProperties = new Properties();
File mavenPropertiesFile = new File( mavenHomeLocal, MavenConstants.MAVEN_PROPERTIES );
try
{
{
mavenProperties.load( new FileInputStream( mavenPropertiesFile ) );
}
catch ( Exception e )

View File

@ -18,8 +18,6 @@
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.project.MavenProjectExecutionRequest;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.project.MavenProject;
import java.util.List;
@ -29,20 +27,26 @@
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class AbstractMavenExecutionRequest
public abstract class AbstractMavenExecutionRequest
implements MavenExecutionRequest
{
/** @todo [BP] is this required? This hands off to MavenSession, but could be passed through the handler.handle function (+ createSession). */
protected ArtifactRepository localRepository;
protected final Properties parameters;
protected List goals;
protected String type;
protected MavenSession session;
public AbstractMavenExecutionRequest( ArtifactRepository localRepository, Properties parameters, List goals )
{
this.localRepository = localRepository;
this.parameters = parameters;
this.goals = goals;
}
@ -79,9 +83,4 @@ public void setSession( MavenSession session )
{
this.session = session;
}
public MavenProjectExecutionRequest createProjectExecutionRequest( MavenProject project )
{
return new MavenProjectExecutionRequest( getLocalRepository(), parameters, getGoals(), project.getFile() );
}
}

View File

@ -1,247 +0,0 @@
package org.apache.maven.execution;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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.artifact.manager.WagonManager;
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.MavenProjectBuilder;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
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;
import java.util.Date;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public abstract class AbstractMavenExecutionRequestHandler
extends AbstractLogEnabled
implements MavenExecutionRequestHandler, Contextualizable
{
// ----------------------------------------------------------------------
// Components
// ----------------------------------------------------------------------
protected MavenProjectBuilder projectBuilder;
protected PluginManager pluginManager;
protected PlexusContainer container;
protected MavenSessionPhaseManager sessionPhaseManager;
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 )
throws Exception
{
MavenSession session = new MavenSession( container,
pluginManager,
request.getLocalRepository(),
request.getGoals() );
return session;
}
/** @todo [BP] this might not be required if there is a better way to pass them in. It doesn't feel quite right. */
private void resolveParameters( MavenExecutionRequest request )
throws ComponentLookupException
{
WagonManager wagonManager = (WagonManager) container.lookup( WagonManager.ROLE );
if ( request.getParameter( "maven.proxy.http.host" ) != null )
{
String p = request.getParameter( "maven.proxy.http.port" );
int port = 8080;
if ( p != null )
{
try
{
port = Integer.valueOf( p ).intValue();
}
catch ( NumberFormatException e )
{
getLogger().warn( "maven.proxy.http.port was not valid" );
}
}
wagonManager.setProxy( "http", request.getParameter( "maven.proxy.http.host" ), port,
request.getParameter( "maven.proxy.http.username" ),
request.getParameter( "maven.proxy.http.password" ),
request.getParameter( "maven.proxy.http.nonProxyHosts" ) );
}
}
// ----------------------------------------------------------------------
// Lifecylce Management
// ----------------------------------------------------------------------
public void contextualize( Context context ) throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
// ----------------------------------------------------------------------
// Reporting / Logging
// ----------------------------------------------------------------------
protected void logError( MavenExecutionResponse r )
{
line();
getLogger().error( "BUILD ERROR" );
line();
getLogger().error( "Cause: ", r.getException() );
line();
stats( r.getStart(), r.getFinish() );
line();
}
protected void logFailure( MavenExecutionResponse r )
{
line();
getLogger().info( "BUILD FAILURE" );
line();
getLogger().info( "Reason: " + r.getFailureResponse().shortMessage() );
line();
getLogger().info( r.getFailureResponse().longMessage() );
line();
stats( r.getStart(), r.getFinish() );
line();
}
protected void logSuccess( MavenExecutionResponse r )
{
line();
getLogger().info( "BUILD SUCCESSFUL" );
line();
stats( r.getStart(), r.getFinish() );
line();
}
protected void stats( Date start, Date finish )
{
long time = finish.getTime() - start.getTime();
getLogger().info( "Total time: " + formatTime( time ) );
getLogger().info( "Finished at: " + finish );
final long mb = 1024 * 1024;
System.gc();
Runtime r = Runtime.getRuntime();
getLogger().info( "Final Memory: " + ( ( r.totalMemory() - r.freeMemory() ) / mb ) + "M/" + ( r.totalMemory() / mb ) + "M" );
}
protected void line()
{
getLogger().info( "----------------------------------------------------------------------------" );
}
protected static String formatTime( long ms )
{
long secs = ms / 1000;
long min = secs / 60;
secs = secs % 60;
if ( min > 0 )
{
return min + " minutes " + secs + " seconds";
}
else
{
return secs + " seconds";
}
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
public void handle( MavenExecutionRequest request, MavenExecutionResponse response )
throws Exception
{
try
{
request.setSession( createSession( request ) );
response.setStart( new Date() );
resolveParameters( request );
sessionPhaseManager.execute( request, response );
response.setFinish( new Date() );
}
catch ( Exception e )
{
response.setFinish( new Date() );
response.setException( e );
logError( response );
return;
}
if ( response.isExecutionFailure() )
{
logFailure( response );
}
else
{
logSuccess( response );
}
}
}

View File

@ -18,8 +18,6 @@
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.project.MavenProjectExecutionRequest;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.project.MavenProject;
import java.util.List;
@ -42,5 +40,6 @@ public interface MavenExecutionRequest
MavenSession getSession();
MavenProjectExecutionRequest createProjectExecutionRequest( MavenProject project );
List getProjectFiles()
throws Exception;
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.execution.initialize;
package org.apache.maven.execution;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
@ -33,6 +33,13 @@ public class MavenInitializingExecutionRequest
public MavenInitializingExecutionRequest( ArtifactRepository localRepository, Properties properties, List goals )
{
super( localRepository, properties, goals );
type = "initializing";
}
public List getProjectFiles()
throws Exception
{
return null;
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.execution.project;
package org.apache.maven.execution;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
@ -23,6 +23,7 @@
import java.io.File;
import java.util.List;
import java.util.Properties;
import java.util.ArrayList;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -33,11 +34,15 @@ public class MavenProjectExecutionRequest
{
private File pom;
public MavenProjectExecutionRequest( ArtifactRepository localRepository, Properties properties, List goals,
public MavenProjectExecutionRequest( ArtifactRepository localRepository,
Properties properties,
List goals,
File pom )
{
super( localRepository, properties, goals );
this.pom = pom;
type = "project";
}
@ -45,4 +50,14 @@ public File getPom()
{
return pom;
}
public List getProjectFiles()
throws Exception
{
List files = new ArrayList();
files.add( pom );
return files;
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.execution.reactor;
package org.apache.maven.execution;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
@ -19,6 +19,7 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.AbstractMavenExecutionRequest;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.util.List;
@ -32,16 +33,22 @@ public class MavenReactorExecutionRequest
extends AbstractMavenExecutionRequest
{
private String includes;
private String excludes;
private File baseDirectory;
public MavenReactorExecutionRequest( ArtifactRepository localRepository, Properties properties, List goals,
String includes, String excludes, File baseDirectory )
{
super( localRepository, properties, goals );
this.includes = includes;
this.excludes = excludes;
this.baseDirectory = baseDirectory;
type = "reactor";
}
@ -59,4 +66,12 @@ public File getBaseDirectory()
{
return baseDirectory;
}
public List getProjectFiles()
throws Exception
{
List files = FileUtils.getFiles( new File( System.getProperty( "user.dir" ) ), includes, excludes );
return files;
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.lifecycle.session;
package org.apache.maven.execution;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.

View File

@ -1,33 +0,0 @@
package org.apache.maven.execution.initialize;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequestHandler;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.AbstractMavenExecutionRequestHandler;
import org.apache.maven.execution.project.MavenProjectExecutionRequestHandler;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenInitializingExecutionRequestHandler
extends AbstractMavenExecutionRequestHandler
{
}

View File

@ -1,52 +0,0 @@
package org.apache.maven.execution.manager;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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.execution.MavenExecutionRequestHandler;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.util.Map;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class DefaultMavenExecutionRequestHandlerManager
extends AbstractLogEnabled
implements MavenExecutionRequestHandlerManager
{
private Map handlers;
public MavenExecutionRequestHandler lookup( String roleHint )
throws MavenExecutionRequestHandlerNotFoundException
{
MavenExecutionRequestHandler handler = (MavenExecutionRequestHandler) handlers.get( roleHint );
if ( handler == null )
{
throw new MavenExecutionRequestHandlerNotFoundException( "Cannot find the handler with type = " + roleHint );
}
return handler;
}
public int managedCount()
{
return handlers.size();
}
}

View File

@ -1,35 +0,0 @@
package org.apache.maven.execution.manager;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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.execution.MavenExecutionRequestHandler;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public interface MavenExecutionRequestHandlerManager
{
String ROLE = MavenExecutionRequestHandlerManager.class.getName();
MavenExecutionRequestHandler lookup( String roleHint )
throws MavenExecutionRequestHandlerNotFoundException;
int managedCount();
}

View File

@ -1,41 +0,0 @@
package org.apache.maven.execution.manager;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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.
* ====================================================================
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenExecutionRequestHandlerNotFoundException
extends Exception
{
public MavenExecutionRequestHandlerNotFoundException( String message )
{
super( message );
}
public MavenExecutionRequestHandlerNotFoundException( Throwable cause )
{
super( cause );
}
public MavenExecutionRequestHandlerNotFoundException( String message, Throwable cause )
{
super( message, cause );
}
}

View File

@ -1,67 +0,0 @@
package org.apache.maven.execution.project;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.AbstractMavenExecutionRequestHandler;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.lifecycle.session.MavenSession;
import java.io.File;
import java.util.Date;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenProjectExecutionRequestHandler
extends AbstractMavenExecutionRequestHandler
{
// ----------------------------------------------------------------------
// Project building
// ----------------------------------------------------------------------
public MavenProject getProject( File pom, ArtifactRepository localRepository )
throws ProjectBuildingException
{
if ( pom.exists() )
{
if ( pom.length() == 0 )
{
throw new ProjectBuildingException( i18n.format( "empty.descriptor.error", pom.getName() ) );
}
}
return projectBuilder.build( pom, localRepository );
}
protected MavenSession createSession( MavenExecutionRequest request )
throws Exception
{
MavenSession session = super.createSession( request );
MavenProject project = getProject( ( (MavenProjectExecutionRequest) request ).getPom(), request.getLocalRepository() );
session.setProject( project );
return session;
}
}

View File

@ -1,93 +0,0 @@
package org.apache.maven.execution.reactor;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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.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;
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 MavenReactorExecutionRequestHandler
extends MavenProjectExecutionRequestHandler
{
public void handle( MavenExecutionRequest request, MavenExecutionResponse response )
throws Exception
{
List projects = new ArrayList();
getLogger().info( "Starting the reactor..." );
try
{
List files = FileUtils.getFiles( new File( System.getProperty( "user.dir" ) ),
( (MavenReactorExecutionRequest) request ).getIncludes(),
( (MavenReactorExecutionRequest) request ).getExcludes() );
for ( Iterator iterator = files.iterator(); iterator.hasNext(); )
{
File file = (File) iterator.next();
MavenProject project = getProject( file, request.getLocalRepository() );
projects.add( project );
}
projects = projectBuilder.getSortedProjects( projects );
}
catch ( Exception e )
{
throw new ReactorException( "Error processing projects for the reactor: ", e );
}
getLogger().info( "Our processing order:" );
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
{
MavenProject project = (MavenProject) iterator.next();
getLogger().info( project.getName() );
}
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
{
MavenProject project = (MavenProject) iterator.next();
System.out.println( "\n\n\n" );
line();
getLogger().info( "Building " + project.getName() );
line();
MavenProjectExecutionRequest projectExecutionRequest = request.createProjectExecutionRequest( project );
super.handle( projectExecutionRequest, response );
if ( response.isExecutionFailure() )
{
break;
}
}
}
// ----------------------------------------------------------------------
// Reactor
// ----------------------------------------------------------------------
public List getSortedProjects( List projects )
throws Exception
{
return projectBuilder.getSortedProjects( projects );
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.execution;
package org.apache.maven.lifecycle;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
@ -17,13 +17,23 @@
* ====================================================================
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public interface MavenExecutionRequestHandler
public class Phase
{
void handle( MavenExecutionRequest request, MavenExecutionResponse response )
throws Exception;
String id;
String goal;
public String getId()
{
return id;
}
public String getGoal()
{
return goal;
}
}

View File

@ -18,7 +18,7 @@
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.FailureResponse;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;

View File

@ -20,11 +20,14 @@
import org.apache.maven.lifecycle.goal.AbstractMavenGoalPhase;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
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.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;
@ -46,182 +49,19 @@ public class GoalAttainmentPhase
public void execute( MavenGoalExecutionContext context )
throws GoalExecutionException
{
PluginExecutionRequest request;
PluginExecutionResponse response;
for ( Iterator it = context.getResolvedGoals().iterator(); it.hasNext(); )
{
String goalName = (String) it.next();
MojoDescriptor mojoDescriptor = context.getMojoDescriptor( goalName );
response = context.getSession().getPluginManager().executeMojo( context.getSession(), goalName );
getLogger().info( "[" + mojoDescriptor.getId() + "]" );
try
if ( response.isExecutionFailure() )
{
request = new PluginExecutionRequest( createParameters( mojoDescriptor, context ) );
}
catch ( PluginConfigurationException e )
{
throw new GoalExecutionException( "Error configuring plugin for execution.", e );
}
context.setExecutionFailure( goalName, response.getFailureResponse() );
response = new PluginExecutionResponse();
Plugin plugin = null;
try
{
String roleHint = context.getPluginId( mojoDescriptor );
plugin = (Plugin) context.lookup( Plugin.ROLE, roleHint );
plugin.execute( request, response );
if ( response.isExecutionFailure() )
{
context.setExecutionFailure( mojoDescriptor.getId(), response.getFailureResponse() );
break;
}
}
catch ( ComponentLookupException e )
{
throw new GoalExecutionException( "Error looking up plugin: ", e );
}
catch ( Exception e )
{
throw new GoalExecutionException( "Error executing plugin: ", e );
}
finally
{
releaseComponents( mojoDescriptor, request, context );
context.release( plugin );
}
}
}
private Map createParameters( MojoDescriptor goal, MavenGoalExecutionContext context )
throws PluginConfigurationException
{
Map map = null;
List parameters = goal.getParameters();
if ( parameters != null )
{
map = new HashMap();
for ( int i = 0; i < parameters.size(); i++ )
{
Parameter parameter = (Parameter) parameters.get( i );
String key = parameter.getName();
String expression = parameter.getExpression();
Object value = PluginParameterExpressionEvaluator.evaluate( expression, context );
if ( value == null )
{
if ( parameter.getDefaultValue() != null )
{
value = parameter.getDefaultValue();
}
}
map.put( key, value );
}
if ( context.getProject() != null )
{
map = mergeProjectDefinedPluginConfiguration( context.getProject(), goal.getId(), map );
}
}
for ( int i = 0; i < parameters.size(); i++ )
{
Parameter parameter = (Parameter) parameters.get( i );
String key = parameter.getName();
Object value = map.get( key );
// ----------------------------------------------------------------------
// We will perform a basic check here for parameters values that are
// required. Required parameters can't be null so we throw an
// Exception in the case where they are. We probably want some pluggable
// mechanism here but this will catch the most obvious of
// misconfigurations.
// ----------------------------------------------------------------------
if ( value == null && parameter.isRequired() )
{
throw new PluginConfigurationException( createPluginParameterRequiredMessage( goal, parameter ) );
}
}
return map;
}
private Map mergeProjectDefinedPluginConfiguration( MavenProject project, String goalId, Map map )
{
// ----------------------------------------------------------------------
// I would like to be able to lookup the Plugin object using a key but
// we have a limitation in modello that will be remedied shortly. So
// for now I have to iterate through and see what we have.
// ----------------------------------------------------------------------
if ( project.getPlugins() != null )
{
String pluginId = goalId.substring( 0, goalId.indexOf( ":" ) );
for ( Iterator iterator = project.getPlugins().iterator(); iterator.hasNext(); )
{
org.apache.maven.model.Plugin plugin = (org.apache.maven.model.Plugin) iterator.next();
if ( pluginId.equals( plugin.getId() ) )
{
return CollectionUtils.mergeMaps( plugin.getConfiguration(), map );
}
}
}
return map;
}
private String createPluginParameterRequiredMessage( MojoDescriptor mojo, Parameter parameter )
{
StringBuffer message = new StringBuffer();
message.append( "The '" + parameter.getName() ).
append( "' parameter is required for the execution of the " ).
append( mojo.getId() ).
append( " mojo and cannot be null." );
return message.toString();
}
private void releaseComponents( MojoDescriptor goal, PluginExecutionRequest request, MavenGoalExecutionContext context )
{
if ( request != null && request.getParameters() != null )
{
for ( Iterator iterator = goal.getParameters().iterator(); iterator.hasNext(); )
{
Parameter parameter = (Parameter) iterator.next();
String key = parameter.getName();
String expression = parameter.getExpression();
if ( expression != null & expression.startsWith( "#component" ) )
{
Object component = request.getParameter( key );
context.release( component );
}
break;
}
}
}

View File

@ -20,11 +20,12 @@
import org.apache.maven.lifecycle.goal.AbstractMavenGoalPhase;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.util.AbstractGoalVisitor;
import org.apache.maven.util.GoalWalker;
import org.apache.maven.util.GraphTraversalException;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import java.util.HashSet;

View File

@ -20,11 +20,12 @@
import org.apache.maven.lifecycle.goal.AbstractMavenGoalPhase;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.util.AbstractGoalVisitor;
import org.apache.maven.util.GoalWalker;
import org.apache.maven.util.GraphTraversalException;
import org.apache.maven.execution.MavenSession;
import java.util.LinkedList;
import java.util.List;

View File

@ -20,11 +20,12 @@
import org.apache.maven.lifecycle.goal.AbstractMavenGoalPhase;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.util.AbstractGoalVisitor;
import org.apache.maven.util.GoalWalker;
import org.apache.maven.util.GraphTraversalException;
import org.apache.maven.execution.MavenSession;
import java.util.HashSet;
import java.util.Set;

View File

@ -22,7 +22,7 @@
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.lifecycle.goal.MavenGoalPhaseManager;
import org.apache.maven.lifecycle.session.AbstractMavenSessionPhase;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.execution.MavenSession;
import java.util.Iterator;

View File

@ -25,22 +25,28 @@
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.ArtifactEnabledContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.util.CollectionUtils;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import java.util.HashMap;
@ -92,6 +98,14 @@ public Map getMojoDescriptors()
return mojoDescriptors;
}
/**
* Mojo descriptors are looked up using their id which is of the form
* <pluginId>:<mojoId>. So this might be archetype:create for example which
* is the create mojo that resides in the archetype plugin.
*
* @param name
* @return
*/
public MojoDescriptor getMojoDescriptor( String name )
{
return (MojoDescriptor) mojoDescriptors.get( name );
@ -225,6 +239,198 @@ protected void addPlugin( Artifact pluginArtifact, MavenSession session )
artifactFilter );
}
// ----------------------------------------------------------------------
// Plugin execution
// ----------------------------------------------------------------------
public PluginExecutionResponse executeMojo( MavenSession session, String goalName )
throws GoalExecutionException
{
try
{
verifyPluginForGoal( goalName, session );
}
catch ( Exception e )
{
e.printStackTrace();
}
PluginExecutionRequest request;
PluginExecutionResponse response;
MojoDescriptor mojoDescriptor = getMojoDescriptor( goalName );;
try
{
getLogger().info( "[" + mojoDescriptor.getId() + "]" );
request = new PluginExecutionRequest( DefaultPluginManager.createParameters( mojoDescriptor, session ) );
}
catch ( PluginConfigurationException e )
{
throw new GoalExecutionException( "Error configuring plugin for execution.", e );
}
response = new PluginExecutionResponse();
Plugin plugin = null;
try
{
plugin = (Plugin) container.lookup( Plugin.ROLE, goalName );
plugin.execute( request, response );
releaseComponents( mojoDescriptor, request );
container.release( plugin );
}
catch ( ComponentLookupException e )
{
throw new GoalExecutionException( "Error looking up plugin: ", e );
}
catch ( Exception e )
{
throw new GoalExecutionException( "Error executing plugin: ", e );
}
return response;
}
private void releaseComponents( MojoDescriptor goal, PluginExecutionRequest request )
throws Exception
{
if ( request != null && request.getParameters() != null )
{
for ( Iterator iterator = goal.getParameters().iterator(); iterator.hasNext(); )
{
Parameter parameter = (Parameter) iterator.next();
String key = parameter.getName();
String expression = parameter.getExpression();
if ( expression != null & expression.startsWith( "#component" ) )
{
Object component = request.getParameter( key );
container.release( component );
}
}
}
}
// ----------------------------------------------------------------------
// Mojo Parameter Handling
// ----------------------------------------------------------------------
public static Map createParameters( MojoDescriptor goal, MavenSession session )
throws PluginConfigurationException
{
Map map = null;
List parameters = goal.getParameters();
if ( parameters != null )
{
map = new HashMap();
for ( int i = 0; i < parameters.size(); i++ )
{
Parameter parameter = (Parameter) parameters.get( i );
String key = parameter.getName();
String expression = parameter.getExpression();
Object value = PluginParameterExpressionEvaluator.evaluate( expression, session );
if ( value == null )
{
if ( parameter.getDefaultValue() != null )
{
value = parameter.getDefaultValue();
}
}
map.put( key, value );
}
if ( session.getProject() != null )
{
map = mergeProjectDefinedPluginConfiguration( session.getProject(), goal.getId(), map );
}
}
for ( int i = 0; i < parameters.size(); i++ )
{
Parameter parameter = (Parameter) parameters.get( i );
String key = parameter.getName();
Object value = map.get( key );
// ----------------------------------------------------------------------
// We will perform a basic check here for parameters values that are
// required. Required parameters can't be null so we throw an
// Exception in the case where they are. We probably want some pluggable
// mechanism here but this will catch the most obvious of
// misconfigurations.
// ----------------------------------------------------------------------
if ( value == null && parameter.isRequired() )
{
throw new PluginConfigurationException( createPluginParameterRequiredMessage( goal, parameter ) );
}
}
return map;
}
public static Map mergeProjectDefinedPluginConfiguration( MavenProject project, String goalId, Map map )
{
// ----------------------------------------------------------------------
// I would like to be able to lookup the Plugin object using a key but
// we have a limitation in modello that will be remedied shortly. So
// for now I have to iterate through and see what we have.
// ----------------------------------------------------------------------
if ( project.getPlugins() != null )
{
String pluginId = goalId.substring( 0, goalId.indexOf( ":" ) );
for ( Iterator iterator = project.getPlugins().iterator(); iterator.hasNext(); )
{
org.apache.maven.model.Plugin plugin = (org.apache.maven.model.Plugin) iterator.next();
if ( pluginId.equals( plugin.getId() ) )
{
return CollectionUtils.mergeMaps( plugin.getConfiguration(), map );
}
}
}
return map;
}
public static String createPluginParameterRequiredMessage( MojoDescriptor mojo, Parameter parameter )
{
StringBuffer message = new StringBuffer();
message.append( "The '" + parameter.getName() ).
append( "' parameter is required for the execution of the " ).
append( mojo.getId() ).
append( " mojo and cannot be null." );
return message.toString();
}
// ----------------------------------------------------------------------
// Lifecycle
// ----------------------------------------------------------------------
public void contextualize( Context context )
throws ContextException
{

View File

@ -17,8 +17,10 @@
* ====================================================================
*/
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.execution.MavenSession;
import java.util.Map;
@ -30,6 +32,9 @@ public interface PluginManager
{
String ROLE = PluginManager.class.getName();
PluginExecutionResponse executeMojo( MavenSession session, String goalName )
throws GoalExecutionException;
void processPluginDescriptor( MavenPluginDescriptor pluginDescriptor )
throws Exception;

View File

@ -17,9 +17,10 @@
* ====================================================================
*/
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.util.introspection.ReflectionValueExtractor;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
/**
@ -28,7 +29,7 @@
*/
public class PluginParameterExpressionEvaluator
{
public static Object evaluate( String expression, MavenGoalExecutionContext context )
public static Object evaluate( String expression, MavenSession context )
throws PluginConfigurationException
{
Object value = null;
@ -48,12 +49,12 @@ public static Object evaluate( String expression, MavenGoalExecutionContext cont
}
else if ( expression.equals( "#localRepository" ) )
{
value = context.getSession().getLocalRepository();
value = context.getLocalRepository();
}
else if ( expression.equals( "#maven.repo.local" ) )
{
// TODO: remove this alias: but note that it is a string instead of an ArtifactRepository
value = context.getSession().getLocalRepository().getUrl().substring( "file://".length() );
value = context.getLocalRepository().getUrl().substring( "file://".length() );
}
else if ( expression.equals( "#maven.final.name" ) )
{

View File

@ -17,7 +17,8 @@
* ====================================================================
*/
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.MavenSession;
/**
* @author jdcasey

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.execution.MavenSession;
/**
* @author jdcasey

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;

View File

@ -8,34 +8,6 @@
<component>
<role>org.apache.maven.Maven</role>
<implementation>org.apache.maven.DefaultMaven</implementation>
<requirements>
<requirement>
<role>org.codehaus.plexus.i18n.I18N</role>
</requirement>
<requirement>
<role>org.apache.maven.execution.manager.MavenExecutionRequestHandlerManager</role>
</requirement>
</requirements>
</component>
<!--
|
|
|
-->
<component>
<role>org.apache.maven.execution.manager.MavenExecutionRequestHandlerManager</role>
<implementation>org.apache.maven.execution.manager.DefaultMavenExecutionRequestHandlerManager</implementation>
<requirements>
<requirement>
<role>org.apache.maven.execution.MavenExecutionRequestHandler</role>
<field-name>handlers</field-name>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.execution.MavenExecutionRequestHandler</role>
<role-hint>project</role-hint>
<implementation>org.apache.maven.execution.project.MavenProjectExecutionRequestHandler</implementation>
<requirements>
<requirement>
<role>org.codehaus.plexus.i18n.I18N</role>
@ -49,43 +21,8 @@
<requirement>
<role>org.apache.maven.lifecycle.session.MavenSessionPhaseManager</role>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.execution.MavenExecutionRequestHandler</role>
<role-hint>reactor</role-hint>
<implementation>org.apache.maven.execution.reactor.MavenReactorExecutionRequestHandler</implementation>
<requirements>
<requirement>
<role>org.codehaus.plexus.i18n.I18N</role>
</requirement>
<requirement>
<role>org.apache.maven.plugin.PluginManager</role>
</requirement>
<requirement>
<role>org.apache.maven.project.MavenProjectBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.lifecycle.session.MavenSessionPhaseManager</role>
</requirement>
</requirements>
</component>
1 <component>
<role>org.apache.maven.execution.MavenExecutionRequestHandler</role>
<role-hint>initializing</role-hint>
<implementation>org.apache.maven.execution.initialize.MavenInitializingExecutionRequestHandler</implementation>
<requirements>
<requirement>
<role>org.codehaus.plexus.i18n.I18N</role>
</requirement>
<requirement>
<role>org.apache.maven.plugin.PluginManager</role>
</requirement>
<requirement>
<role>org.apache.maven.project.MavenProjectBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.lifecycle.session.MavenSessionPhaseManager</role>
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
</requirement>
</requirements>
</component>
@ -235,5 +172,99 @@
<implementation>org.apache.maven.artifact.factory.DefaultArtifactFactory</implementation>
</component>
<!--
|
| Lifecycle executor
|
-->
<component>
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
<implementation>org.apache.maven.lifecycle.DefaultLifecycleExecutor</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
</requirement>
<requirement>
<role>org.apache.maven.project.MavenProjectBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.plugin.PluginManager</role>
</requirement>
</requirements>
<configuration>
<!-- START SNIPPET: lifecyle -->
<phases>
<!-- 1 -->
<phase>
<id>generate-sources</id>
</phase>
<!-- 2 -->
<phase>
<id>process-sources</id>
</phase>
<!-- 3 -->
<phase>
<id>generate-resources</id>
</phase>
<!-- 4 -->
<phase>
<id>process-resources</id>
<goal>resources:resources</goal>
</phase>
<!-- 5 -->
<phase>
<id>compile</id>
<goal>compiler:compile</goal>
</phase>
<!-- 6 -->
<phase>
<id>process-classes</id>
</phase>
<!-- 7 -->
<phase>
<id>generate-test-sources</id>
</phase>
<!-- 8 -->
<phase>
<id>process-test-sources</id>
</phase>
<!-- 9 -->
<phase>
<id>generate-test-sources</id>
</phase>
<!-- 10 -->
<phase>
<id>process-test-resources</id>
<goal>resources:testResources</goal>
</phase>
<!-- 11 -->
<phase>
<id>test-compile</id>
<goal>compiler:testCompile</goal>
</phase>
<!-- 12 -->
<phase>
<id>test</id>
<goal>surefire:test</goal>
</phase>
<!-- 13 -->
<phase>
<id>package</id>
<goal>jar:jar</goal>
</phase>
<!-- 14 -->
<phase>
<id>install</id>
<goal>jar:install</goal>
</phase>
<!-- 15 -->
<phase>
<id>deploy</id>
<goal>jar:deploy</goal>
</phase>
</phases>
<!-- END SNIPPET: lifecycle -->
</configuration>
</component>
</components>
</component-set>

View File

@ -22,10 +22,11 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.ArtifactEnabledPlexusTestCase;

View File

@ -1,23 +0,0 @@
package org.apache.maven.execution.manager;
import org.apache.maven.MavenTestCase;
import org.apache.maven.Maven;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenExecutionRequestHandlerManagerTest
extends MavenTestCase
{
public void testMaven()
throws Exception
{
MavenExecutionRequestHandlerManager manager =
(MavenExecutionRequestHandlerManager) lookup( MavenExecutionRequestHandlerManager.ROLE );
assertNotNull( manager );
assertEquals( 3, manager.managedCount() );
}
}

View File

@ -1,4 +1,6 @@
package org.apache.maven.execution;
package org.apache.maven.lifecycle;
import org.apache.maven.MavenTestCase;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
@ -17,21 +19,20 @@
* ====================================================================
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.List;
import java.util.Properties;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenSetupExecutionRequest
extends AbstractMavenExecutionRequest
public class LifecycleExecutorTest
extends MavenTestCase
{
public MavenSetupExecutionRequest( ArtifactRepository localRepository, Properties properties, List goals )
public void testLifecycleExecutor()
throws Exception
{
super( localRepository, properties, goals );
type = "setup";
LifecycleExecutor le = (LifecycleExecutor) lookup( LifecycleExecutor.ROLE );
assertEquals( 15, le.getPhases().size() );
//le.execute( "test", createGoalExecutionContext().getSession() );
}
}

View File

@ -34,7 +34,7 @@ protected void setUp()
public void testValueExtractionWithAPomValueContainingAPath()
throws Exception
{
Object value = PluginParameterExpressionEvaluator.evaluate( "#project.build.directory/classes", context );
Object value = PluginParameterExpressionEvaluator.evaluate( "#project.build.directory/classes", context.getSession() );
String expected = getTestFile( "target/test-classes/target/classes" ).getCanonicalPath();
@ -48,7 +48,7 @@ public void testParameterThatIsAComponent()
{
String role = "#component.org.apache.maven.project.MavenProjectBuilder";
Object value = PluginParameterExpressionEvaluator.evaluate( role, context );
Object value = PluginParameterExpressionEvaluator.evaluate( role, context.getSession() );
assertNotNull( value );
}
@ -56,7 +56,7 @@ public void testParameterThatIsAComponent()
public void testLocalRepositoryExtraction()
throws Exception
{
Object value = PluginParameterExpressionEvaluator.evaluate( "#localRepository", context );
Object value = PluginParameterExpressionEvaluator.evaluate( "#localRepository", context.getSession() );
assertEquals( "local", ((ArtifactRepository)value).getId() );
}