mirror of https://github.com/apache/maven.git
multi-module support
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163528 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f6c2684903
commit
5f424a5ac0
|
@ -19,10 +19,9 @@ package org.apache.maven;
|
|||
|
||||
import org.apache.maven.artifact.manager.WagonManager;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionResponse;
|
||||
import org.apache.maven.execution.MavenProjectExecutionRequest;
|
||||
import org.apache.maven.execution.MavenReactorExecutionRequest;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.GoalNotFoundException;
|
||||
import org.apache.maven.lifecycle.LifecycleExecutor;
|
||||
|
@ -44,11 +43,14 @@ 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 org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -79,43 +81,133 @@ public class DefaultMaven
|
|||
// Project execution
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public MavenExecutionResponse execute( MavenExecutionRequest request ) throws GoalNotFoundException, Exception
|
||||
public MavenExecutionResponse execute( MavenExecutionRequest request )
|
||||
throws GoalNotFoundException, Exception
|
||||
{
|
||||
// TODO: not happy about this:
|
||||
if ( request instanceof MavenReactorExecutionRequest )
|
||||
EventDispatcher dispatcher = request.getEventDispatcher();
|
||||
String event = MavenEvents.REACTOR_EXECUTION;
|
||||
|
||||
// TODO: goals are outer loop
|
||||
dispatcher.dispatchStart( event, request.getBaseDirectory() );
|
||||
try
|
||||
{
|
||||
return handleReactor( (MavenReactorExecutionRequest) request );
|
||||
List projects = new ArrayList();
|
||||
|
||||
try
|
||||
{
|
||||
List files = request.getProjectFiles();
|
||||
|
||||
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 );
|
||||
|
||||
if ( projects.isEmpty() )
|
||||
{
|
||||
projects.add( projectBuilder.buildSuperProject( request.getLocalRepository() ) );
|
||||
}
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ReactorException( "Error processing projects for the reactor: ", e );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
throw new ReactorException( "Error processing projects for the reactor: ", e );
|
||||
}
|
||||
catch ( CycleDetectedException e )
|
||||
{
|
||||
throw new ReactorException( "Error processing projects for the reactor: ", e );
|
||||
}
|
||||
|
||||
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
|
||||
{
|
||||
MavenProject project = (MavenProject) iterator.next();
|
||||
|
||||
line();
|
||||
|
||||
getLogger().info( "Building " + project.getName() );
|
||||
|
||||
line();
|
||||
|
||||
try
|
||||
{
|
||||
boolean isPom = "pom".equals( project.getPackaging() );
|
||||
if ( isPom )
|
||||
{
|
||||
// TODO: not required if discovered and cached
|
||||
MavenExecutionResponse response = processProject( request, project, dispatcher,
|
||||
Collections.singletonList( "pom:install" ) );
|
||||
if ( response.isExecutionFailure() )
|
||||
{
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
if ( project.getModules() != null && !project.getModules().isEmpty() )
|
||||
{
|
||||
String includes = StringUtils.join( project.getModules().iterator(), "/pom.xml," ) +
|
||||
"/pom.xml";
|
||||
File baseDir = project.getFile().getParentFile();
|
||||
MavenExecutionRequest reactorRequest = new DefaultMavenExecutionRequest(
|
||||
request.getLocalRepository(), request.getUserModel(), request.getEventDispatcher(),
|
||||
request.getGoals(), FileUtils.getFiles( baseDir, includes, null ), baseDir.getPath() );
|
||||
MavenExecutionResponse response = execute( reactorRequest );
|
||||
if ( response != null && response.isExecutionFailure() )
|
||||
{
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( !isPom )
|
||||
{
|
||||
MavenExecutionResponse response = processProject( request, project, dispatcher,
|
||||
request.getGoals() );
|
||||
|
||||
if ( response.isExecutionFailure() )
|
||||
{
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new ReactorException( "Error executing project within the reactor", e );
|
||||
}
|
||||
}
|
||||
|
||||
dispatcher.dispatchEnd( event, request.getBaseDirectory() );
|
||||
|
||||
// TODO: not really satisfactory
|
||||
return null;
|
||||
}
|
||||
else
|
||||
catch ( ReactorException e )
|
||||
{
|
||||
return handleProject( request );
|
||||
dispatcher.dispatchError( event, request.getBaseDirectory(), e );
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: don't throw generic exception
|
||||
public MavenExecutionResponse handleProject( MavenExecutionRequest request ) throws Exception
|
||||
private MavenExecutionResponse processProject( MavenExecutionRequest request, MavenProject project,
|
||||
EventDispatcher dispatcher, List goals )
|
||||
throws ComponentLookupException
|
||||
{
|
||||
MavenSession session = createSession( request );
|
||||
|
||||
List projectFiles = request.getProjectFiles();
|
||||
|
||||
MavenProject project = null;
|
||||
if(projectFiles != null && !projectFiles.isEmpty())
|
||||
{
|
||||
project = getProject( (File) request.getProjectFiles().get( 0 ), request.getLocalRepository() );
|
||||
}
|
||||
else
|
||||
{
|
||||
project = projectBuilder.buildSuperProject( request.getLocalRepository() );
|
||||
}
|
||||
|
||||
session.setProject( project );
|
||||
|
||||
resolveParameters( request );
|
||||
|
||||
// !! This is ripe for refactoring to an aspect.
|
||||
// Event monitoring.
|
||||
EventDispatcher dispatcher = request.getEventDispatcher();
|
||||
String event = MavenEvents.PROJECT_EXECUTION;
|
||||
|
||||
dispatcher.dispatchStart( event, project.getId() );
|
||||
|
@ -124,7 +216,7 @@ public class DefaultMaven
|
|||
try
|
||||
{
|
||||
// Actual meat of the code.
|
||||
response = lifecycleExecutor.execute( request.getGoals(), session );
|
||||
response = lifecycleExecutor.execute( goals, session );
|
||||
|
||||
dispatcher.dispatchEnd( event, project.getId() );
|
||||
}
|
||||
|
@ -157,104 +249,8 @@ public class DefaultMaven
|
|||
return response;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Reactor
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public MavenExecutionResponse handleReactor( MavenReactorExecutionRequest request ) throws ReactorException
|
||||
{
|
||||
EventDispatcher dispatcher = request.getEventDispatcher();
|
||||
String event = MavenEvents.REACTOR_EXECUTION;
|
||||
|
||||
dispatcher.dispatchStart( event, request.getBaseDirectory().getPath() );
|
||||
try
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
|
||||
getLogger().info( "Starting the reactor..." );
|
||||
|
||||
try
|
||||
{
|
||||
List files = request.getProjectFiles();
|
||||
|
||||
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 ( IOException e )
|
||||
{
|
||||
throw new ReactorException( "Error processing projects for the reactor: ", e );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
throw new ReactorException( "Error processing projects for the reactor: ", e );
|
||||
}
|
||||
catch ( CycleDetectedException 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 );
|
||||
|
||||
try
|
||||
{
|
||||
MavenExecutionResponse response = handleProject( projectExecutionRequest );
|
||||
|
||||
if ( response.isExecutionFailure() )
|
||||
{
|
||||
return response;
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new ReactorException( "Error executing project within the reactor", e );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dispatcher.dispatchEnd( event, request.getBaseDirectory().getPath() );
|
||||
|
||||
// TODO: not really satisfactory
|
||||
return null;
|
||||
}
|
||||
catch ( ReactorException e )
|
||||
{
|
||||
dispatcher.dispatchError( event, request.getBaseDirectory().getPath(), e );
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public MavenProject getProject( File pom, ArtifactRepository localRepository ) throws ProjectBuildingException
|
||||
public MavenProject getProject( File pom, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
if ( pom.exists() )
|
||||
{
|
||||
|
@ -284,9 +280,10 @@ public class DefaultMaven
|
|||
|
||||
/**
|
||||
* @todo [BP] this might not be required if there is a better way to pass
|
||||
* them in. It doesn't feel quite right.
|
||||
* them in. It doesn't feel quite right.
|
||||
*/
|
||||
private void resolveParameters( MavenExecutionRequest request ) throws ComponentLookupException
|
||||
private void resolveParameters( MavenExecutionRequest request )
|
||||
throws ComponentLookupException
|
||||
{
|
||||
WagonManager wagonManager = (WagonManager) container.lookup( WagonManager.ROLE );
|
||||
|
||||
|
@ -307,7 +304,8 @@ public class DefaultMaven
|
|||
// Lifecylce Management
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public void contextualize( Context context ) throws ContextException
|
||||
public void contextualize( Context context )
|
||||
throws ContextException
|
||||
{
|
||||
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
||||
}
|
||||
|
@ -381,9 +379,8 @@ public class DefaultMaven
|
|||
|
||||
Runtime r = Runtime.getRuntime();
|
||||
|
||||
getLogger().info(
|
||||
"Final Memory: " + ( ( r.totalMemory() - r.freeMemory() ) / mb ) + "M/"
|
||||
+ ( r.totalMemory() / mb ) + "M" );
|
||||
getLogger().info( "Final Memory: " + ( ( r.totalMemory() - r.freeMemory() ) / mb ) + "M/" +
|
||||
( r.totalMemory() / mb ) + "M" );
|
||||
}
|
||||
|
||||
protected void line()
|
||||
|
@ -417,7 +414,8 @@ public class DefaultMaven
|
|||
// Reactor
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public List getSortedProjects( List projects ) throws CycleDetectedException
|
||||
public List getSortedProjects( List projects )
|
||||
throws CycleDetectedException
|
||||
{
|
||||
return projectBuilder.getSortedProjects( projects );
|
||||
}
|
||||
|
|
|
@ -28,11 +28,9 @@ import org.apache.maven.Maven;
|
|||
import org.apache.maven.MavenConstants;
|
||||
import org.apache.maven.artifact.manager.WagonManager;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionResponse;
|
||||
import org.apache.maven.execution.MavenInitializingExecutionRequest;
|
||||
import org.apache.maven.execution.MavenProjectExecutionRequest;
|
||||
import org.apache.maven.execution.MavenReactorExecutionRequest;
|
||||
import org.apache.maven.model.user.MavenProfile;
|
||||
import org.apache.maven.model.user.UserModel;
|
||||
import org.apache.maven.monitor.event.DefaultEventDispatcher;
|
||||
|
@ -45,10 +43,13 @@ import org.codehaus.classworlds.ClassWorld;
|
|||
import org.codehaus.plexus.embed.ArtifactEnabledEmbedder;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.logging.LoggerManager;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
|
@ -63,7 +64,8 @@ public class MavenCli
|
|||
|
||||
public static File userDir = new File( System.getProperty( "user.dir" ) );
|
||||
|
||||
public static int main( String[] args, ClassWorld classWorld ) throws Exception
|
||||
public static int main( String[] args, ClassWorld classWorld )
|
||||
throws Exception
|
||||
{
|
||||
// ----------------------------------------------------------------------
|
||||
// Setup the command line parser
|
||||
|
@ -122,27 +124,26 @@ public class MavenCli
|
|||
|
||||
UserModel userModel = UserModelUtils.getUserModel();
|
||||
|
||||
if ( projectFile.exists() )
|
||||
if ( commandLine.hasOption( CLIManager.REACTOR ) )
|
||||
{
|
||||
if ( commandLine.hasOption( CLIManager.REACTOR ) )
|
||||
{
|
||||
String includes = System.getProperty( "maven.reactor.includes", "**/" + POMv4 );
|
||||
String includes = System.getProperty( "maven.reactor.includes", "**/" + POMv4 );
|
||||
|
||||
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 );
|
||||
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 );
|
||||
|
||||
request = new MavenReactorExecutionRequest( localRepository, userModel, eventDispatcher,
|
||||
commandLine.getArgList(), includes, excludes, userDir );
|
||||
}
|
||||
else
|
||||
{
|
||||
request = new MavenProjectExecutionRequest( localRepository, userModel, eventDispatcher,
|
||||
commandLine.getArgList(), projectFile );
|
||||
}
|
||||
request =
|
||||
new DefaultMavenExecutionRequest( localRepository, userModel, eventDispatcher,
|
||||
commandLine.getArgList(),
|
||||
FileUtils.getFiles( userDir, includes, excludes ), userDir.getPath() );
|
||||
}
|
||||
else
|
||||
{
|
||||
request = new MavenInitializingExecutionRequest( localRepository, userModel, eventDispatcher,
|
||||
commandLine.getArgList() );
|
||||
List files = Collections.EMPTY_LIST;
|
||||
if ( projectFile.exists() )
|
||||
{
|
||||
files = Collections.singletonList( projectFile );
|
||||
}
|
||||
request = new DefaultMavenExecutionRequest( localRepository, userModel, eventDispatcher,
|
||||
commandLine.getArgList(), files, userDir.getPath() );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -191,9 +192,9 @@ public class MavenCli
|
|||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// System properties handling
|
||||
// ----------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------
|
||||
// System properties handling
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private static void initializeSystemProperties( CommandLine commandLine )
|
||||
{
|
||||
|
@ -237,9 +238,9 @@ public class MavenCli
|
|||
System.setProperty( name, value );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Command line manager
|
||||
// ----------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------
|
||||
// Command line manager
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
static class CLIManager
|
||||
{
|
||||
|
@ -264,30 +265,28 @@ public class MavenCli
|
|||
public CLIManager()
|
||||
{
|
||||
options = new Options();
|
||||
options.addOption( OptionBuilder.withLongOpt( "nobanner" ).withDescription( "Suppress logo banner" )
|
||||
.create( NO_BANNER ) );
|
||||
options
|
||||
.addOption( OptionBuilder.withLongOpt( "define" ).hasArg()
|
||||
.withDescription( "Define a system property" ).create( SET_SYSTEM_PROPERTY ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "offline" ).hasArg().withDescription( "Work offline" )
|
||||
.create( WORK_OFFLINE ) );
|
||||
options
|
||||
.addOption( OptionBuilder.withLongOpt( "mojoDescriptors" )
|
||||
.withDescription( "Display available mojoDescriptors" ).create( LIST_GOALS ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" )
|
||||
.create( HELP ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "offline" ).withDescription( "Build is happening offline" )
|
||||
.create( WORK_OFFLINE ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" )
|
||||
.create( VERSION ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" )
|
||||
.create( DEBUG ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "reactor" )
|
||||
.withDescription( "Execute goals for project found in the reactor" )
|
||||
.create( REACTOR ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "nobanner" ).withDescription( "Suppress logo banner" ).create(
|
||||
NO_BANNER ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "define" ).hasArg().withDescription(
|
||||
"Define a system property" ).create( SET_SYSTEM_PROPERTY ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "offline" ).hasArg().withDescription( "Work offline" ).create(
|
||||
WORK_OFFLINE ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "mojoDescriptors" ).withDescription(
|
||||
"Display available mojoDescriptors" ).create( LIST_GOALS ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" ).create(
|
||||
HELP ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "offline" ).withDescription( "Build is happening offline" ).create(
|
||||
WORK_OFFLINE ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" ).create(
|
||||
VERSION ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" ).create(
|
||||
DEBUG ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "reactor" ).withDescription(
|
||||
"Execute goals for project found in the reactor" ).create( REACTOR ) );
|
||||
}
|
||||
|
||||
public CommandLine parse( String[] args ) throws ParseException
|
||||
public CommandLine parse( String[] args )
|
||||
throws ParseException
|
||||
{
|
||||
CommandLineParser parser = new PosixParser();
|
||||
return parser.parse( options, args );
|
||||
|
@ -300,9 +299,9 @@ public class MavenCli
|
|||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
protected static File getUserConfigurationDirectory()
|
||||
{
|
||||
|
@ -311,7 +310,7 @@ public class MavenCli
|
|||
{
|
||||
if ( !mavenUserConfigurationDirectory.mkdirs() )
|
||||
{
|
||||
//throw a configuration exception
|
||||
//throw a configuration exception
|
||||
}
|
||||
}
|
||||
return mavenUserConfigurationDirectory;
|
||||
|
@ -332,7 +331,8 @@ public class MavenCli
|
|||
return mavenProperties;
|
||||
}
|
||||
|
||||
protected static ArtifactRepository getLocalRepository() throws Exception
|
||||
protected static ArtifactRepository getLocalRepository()
|
||||
throws Exception
|
||||
{
|
||||
UserModel userModel = UserModelUtils.getUserModel();
|
||||
MavenProfile mavenProfile = UserModelUtils.getActiveMavenProfile( userModel );
|
||||
|
@ -346,10 +346,11 @@ public class MavenCli
|
|||
if ( localRepository == null )
|
||||
{
|
||||
String userConfigurationDirectory = System.getProperty( "user.home" ) + "/.m2";
|
||||
localRepository = new File( userConfigurationDirectory, MavenConstants.MAVEN_REPOSITORY ).getAbsolutePath();
|
||||
localRepository =
|
||||
new File( userConfigurationDirectory, MavenConstants.MAVEN_REPOSITORY ).getAbsolutePath();
|
||||
}
|
||||
|
||||
// TODO [BP]: this should not be necessary - grep for and remove
|
||||
// TODO [BP]: this should not be necessary - grep for and remove
|
||||
System.setProperty( MavenConstants.MAVEN_REPO_LOCAL, localRepository );
|
||||
return new ArtifactRepository( "local", "file://" + localRepository );
|
||||
}
|
||||
|
|
|
@ -24,46 +24,59 @@ import org.apache.maven.monitor.event.EventMonitor;
|
|||
import org.apache.maven.monitor.logging.Log;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public abstract class AbstractMavenExecutionRequest
|
||||
implements MavenExecutionRequest
|
||||
public class DefaultMavenExecutionRequest
|
||||
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;
|
||||
/**
|
||||
* @todo [BP] is this required? This hands off to MavenSession, but could be passed through the handler.handle function (+ createSession).
|
||||
*/
|
||||
private final ArtifactRepository localRepository;
|
||||
|
||||
protected List goals;
|
||||
private final List goals;
|
||||
|
||||
protected String type;
|
||||
private final List files;
|
||||
|
||||
protected MavenSession session;
|
||||
|
||||
private Log log;
|
||||
|
||||
private EventDispatcher eventDispatcher;
|
||||
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
private final UserModel userModel;
|
||||
|
||||
public AbstractMavenExecutionRequest( ArtifactRepository localRepository, UserModel userModel, EventDispatcher eventDispatcher, List goals )
|
||||
private final String baseDirectory;
|
||||
|
||||
public DefaultMavenExecutionRequest( ArtifactRepository localRepository, UserModel userModel,
|
||||
EventDispatcher eventDispatcher, List goals, List files, String baseDirectory )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
|
||||
|
||||
this.userModel = userModel;
|
||||
|
||||
this.goals = goals;
|
||||
|
||||
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
|
||||
this.files = files;
|
||||
|
||||
this.baseDirectory = baseDirectory;
|
||||
}
|
||||
|
||||
|
||||
public UserModel getUserModel()
|
||||
{
|
||||
return userModel;
|
||||
}
|
||||
|
||||
public String getBaseDirectory()
|
||||
{
|
||||
return baseDirectory;
|
||||
}
|
||||
|
||||
public ArtifactRepository getLocalRepository()
|
||||
{
|
||||
return localRepository;
|
||||
|
@ -74,11 +87,6 @@ implements MavenExecutionRequest
|
|||
return goals;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Putting the session here but it can probably be folded right in here.
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -88,29 +96,38 @@ implements MavenExecutionRequest
|
|||
return session;
|
||||
}
|
||||
|
||||
public List getProjectFiles()
|
||||
{
|
||||
return files;
|
||||
}
|
||||
|
||||
public void setSession( MavenSession session )
|
||||
{
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public void setLog(Log log)
|
||||
|
||||
public void setLog( Log log )
|
||||
{
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
|
||||
public Log getLog()
|
||||
{
|
||||
return log;
|
||||
}
|
||||
|
||||
public void addEventMonitor(EventMonitor monitor)
|
||||
|
||||
public void addEventMonitor( EventMonitor monitor )
|
||||
{
|
||||
eventDispatcher.addEventMonitor(monitor);
|
||||
eventDispatcher.addEventMonitor( monitor );
|
||||
}
|
||||
|
||||
|
||||
public EventDispatcher getEventDispatcher()
|
||||
{
|
||||
return eventDispatcher;
|
||||
}
|
||||
|
||||
|
||||
public List getFiles()
|
||||
{
|
||||
return files;
|
||||
}
|
||||
}
|
|
@ -36,21 +36,22 @@ public interface MavenExecutionRequest
|
|||
|
||||
List getGoals();
|
||||
|
||||
String getType();
|
||||
|
||||
void setSession( MavenSession session );
|
||||
|
||||
MavenSession getSession();
|
||||
|
||||
List getProjectFiles() throws IOException;
|
||||
List getProjectFiles()
|
||||
throws IOException;
|
||||
|
||||
void setLog( Log log );
|
||||
|
||||
|
||||
Log getLog();
|
||||
|
||||
void addEventMonitor( EventMonitor monitor );
|
||||
|
||||
|
||||
EventDispatcher getEventDispatcher();
|
||||
|
||||
|
||||
UserModel getUserModel();
|
||||
|
||||
String getBaseDirectory();
|
||||
}
|
||||
|
|
|
@ -1,45 +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.repository.ArtifactRepository;
|
||||
import org.apache.maven.model.user.UserModel;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
|
||||
import java.util.Collections;
|
||||
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, UserModel userModel, EventDispatcher eventDispatcher, List goals )
|
||||
{
|
||||
super( localRepository, userModel, eventDispatcher, goals );
|
||||
|
||||
type = "initializing";
|
||||
}
|
||||
|
||||
public List getProjectFiles()
|
||||
{
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
}
|
|
@ -1,63 +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.repository.ArtifactRepository;
|
||||
import org.apache.maven.model.user.UserModel;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MavenProjectExecutionRequest
|
||||
extends AbstractMavenExecutionRequest
|
||||
{
|
||||
private File pom;
|
||||
|
||||
public MavenProjectExecutionRequest( ArtifactRepository localRepository,
|
||||
UserModel userModel,
|
||||
EventDispatcher eventDispatcher,
|
||||
List goals,
|
||||
File pom )
|
||||
{
|
||||
super( localRepository, userModel, eventDispatcher, goals );
|
||||
|
||||
this.pom = pom;
|
||||
|
||||
type = "project";
|
||||
}
|
||||
|
||||
public File getPom()
|
||||
{
|
||||
return pom;
|
||||
}
|
||||
|
||||
public List getProjectFiles()
|
||||
{
|
||||
List files = new ArrayList();
|
||||
|
||||
files.add( pom );
|
||||
|
||||
return files;
|
||||
}
|
||||
}
|
|
@ -1,84 +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.repository.ArtifactRepository;
|
||||
import org.apache.maven.model.user.UserModel;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MavenReactorExecutionRequest
|
||||
extends AbstractMavenExecutionRequest
|
||||
{
|
||||
private String includes;
|
||||
|
||||
private String excludes;
|
||||
|
||||
private File baseDirectory;
|
||||
|
||||
public MavenReactorExecutionRequest( ArtifactRepository localRepository, UserModel userModel, EventDispatcher eventDispatcher,
|
||||
List goals, String includes,
|
||||
String excludes, File baseDirectory )
|
||||
{
|
||||
super( localRepository, userModel, eventDispatcher, goals );
|
||||
|
||||
this.includes = includes;
|
||||
|
||||
this.excludes = excludes;
|
||||
|
||||
this.baseDirectory = baseDirectory;
|
||||
|
||||
type = "reactor";
|
||||
}
|
||||
|
||||
public String getIncludes()
|
||||
{
|
||||
return includes;
|
||||
}
|
||||
|
||||
public String getExcludes()
|
||||
{
|
||||
return excludes;
|
||||
}
|
||||
|
||||
public File getBaseDirectory()
|
||||
{
|
||||
return baseDirectory;
|
||||
}
|
||||
|
||||
public List getProjectFiles()
|
||||
throws IOException
|
||||
{
|
||||
return FileUtils.getFiles( new File( System.getProperty( "user.dir" ) ), includes, excludes );
|
||||
}
|
||||
|
||||
public MavenProjectExecutionRequest createProjectExecutionRequest( MavenProject project )
|
||||
{
|
||||
return new MavenProjectExecutionRequest( localRepository, getUserModel(), getEventDispatcher(), goals, project.getFile() );
|
||||
}
|
||||
}
|
|
@ -119,10 +119,11 @@ public class DefaultMavenProjectBuilder
|
|||
previous = current;
|
||||
}
|
||||
|
||||
pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor );
|
||||
|
||||
project = processProjectLogic( project, localRepository, resolveDependencies );
|
||||
|
||||
project.setFile( projectDescriptor );
|
||||
pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor );
|
||||
|
||||
return project;
|
||||
}
|
||||
|
@ -133,7 +134,7 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
|
||||
private MavenProject processProjectLogic( MavenProject project, ArtifactRepository localRepository,
|
||||
boolean resolveDependencies )
|
||||
boolean resolveDependencies )
|
||||
throws ProjectBuildingException, ModelInterpolationException, ArtifactResolutionException
|
||||
{
|
||||
Model model = modelInterpolator.interpolate( project.getModel() );
|
||||
|
@ -186,7 +187,7 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
|
||||
private MavenProject assembleLineage( File projectDescriptor, ArtifactRepository localRepository,
|
||||
LinkedList lineage, List aggregatedRemoteWagonRepositories )
|
||||
LinkedList lineage, List aggregatedRemoteWagonRepositories )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Model model = readModel( projectDescriptor );
|
||||
|
@ -253,7 +254,8 @@ public class DefaultMavenProjectBuilder
|
|||
return repos;
|
||||
}
|
||||
|
||||
private Model readModel( File file ) throws ProjectBuildingException
|
||||
private Model readModel( File file )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -266,12 +268,12 @@ public class DefaultMavenProjectBuilder
|
|||
catch ( Exception e )
|
||||
{
|
||||
throw new ProjectBuildingException(
|
||||
"Error while reading model from file '" + file.getAbsolutePath() + "'.",
|
||||
e );
|
||||
"Error while reading model from file '" + file.getAbsolutePath() + "'.", e );
|
||||
}
|
||||
}
|
||||
|
||||
private Model readModel( URL url ) throws ProjectBuildingException
|
||||
private Model readModel( URL url )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -300,8 +302,8 @@ public class DefaultMavenProjectBuilder
|
|||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
// @todo use parent.toString() if modello could generate it, or specify in a code segment
|
||||
throw new ProjectBuildingException( "Missing parent POM: " + parent.getGroupId() + ":"
|
||||
+ parent.getArtifactId() + "-" + parent.getVersion(), e );
|
||||
throw new ProjectBuildingException( "Missing parent POM: " + parent.getGroupId() + ":" +
|
||||
parent.getArtifactId() + "-" + parent.getVersion(), e );
|
||||
}
|
||||
|
||||
return artifact.getFile();
|
||||
|
@ -318,7 +320,8 @@ public class DefaultMavenProjectBuilder
|
|||
* <li>do a topo sort on the graph that remains.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public List getSortedProjects( List projects ) throws CycleDetectedException
|
||||
public List getSortedProjects( List projects )
|
||||
throws CycleDetectedException
|
||||
{
|
||||
DAG dag = new DAG();
|
||||
|
||||
|
@ -367,11 +370,11 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
|
||||
public MavenProject buildSuperProject( ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
return buildSuperProject( localRepository, false );
|
||||
return buildSuperProject( localRepository, false );
|
||||
}
|
||||
|
||||
|
||||
public MavenProject buildSuperProject( ArtifactRepository localRepository, boolean resolveDependencies )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
|
@ -380,7 +383,7 @@ public class DefaultMavenProjectBuilder
|
|||
try
|
||||
{
|
||||
project = processProjectLogic( project, localRepository, resolveDependencies );
|
||||
|
||||
|
||||
File projectFile = new File( ".", "pom.xml" );
|
||||
project.setFile( projectFile );
|
||||
pathTranslator.alignToBaseDirectory( project.getModel(), projectFile );
|
||||
|
@ -401,7 +404,8 @@ public class DefaultMavenProjectBuilder
|
|||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private Model getSuperModel() throws ProjectBuildingException
|
||||
private Model getSuperModel()
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
URL url = DefaultMavenProjectBuilder.class.getResource( "pom-" + MavenConstants.MAVEN_MODEL_VERSION + ".xml" );
|
||||
|
||||
|
|
|
@ -525,6 +525,11 @@ public class MavenProject
|
|||
return model.getBuild().getPlugins();
|
||||
}
|
||||
|
||||
public List getModules()
|
||||
{
|
||||
return model.getModules();
|
||||
}
|
||||
|
||||
public PluginManagement getPluginManagement()
|
||||
{
|
||||
PluginManagement pluginMgmt = null;
|
||||
|
|
|
@ -10,9 +10,6 @@
|
|||
| o i18n: would be good to be able to have names/descriptions/specifications
|
||||
| in as many languages as possible.
|
||||
|
|
||||
| o versioning of individual elements on the class level and the field level so that
|
||||
| different versions of the model can be output.
|
||||
|
|
||||
| o annotation mechanism so that changes to the model can be accurately tracked.
|
||||
|
|
||||
| o need to clean up all the descriptions, matching anything to the current project-descriptor.xml file and
|
||||
|
@ -98,6 +95,15 @@
|
|||
<type>String</type>
|
||||
<defaultValue>jar</defaultValue>
|
||||
</field>
|
||||
<field>
|
||||
<name>modules</name>
|
||||
<version>4.0.0</version>
|
||||
<description>The modules to build in addition to the current project</description>
|
||||
<association>
|
||||
<type>String</type>
|
||||
<multiplicity>*</multiplicity>
|
||||
</association>
|
||||
</field>
|
||||
<field>
|
||||
<name>name</name>
|
||||
<version>3.0.0+</version>
|
||||
|
|
|
@ -104,7 +104,9 @@ public class Main
|
|||
|
||||
org.apache.maven.model.Model newModel = new org.apache.maven.model.Model();
|
||||
newModel.setArtifactId( model.getArtifactId() );
|
||||
newModel.setBuild( convertBuild( model.getBuild(), convertPlugins( model.getPlugins() ) ) );
|
||||
newModel.setBuild(
|
||||
convertBuild( model.getBuild(), convertPlugins( model.getPlugins() ),
|
||||
convertPluginManagement( model.getPluginManagement() ) ) );
|
||||
newModel.setCiManagement( convertCiManagement( model.getCiManagement() ) );
|
||||
newModel.setContributors( convertContributors( model.getContributors() ) );
|
||||
newModel.setDependencies( convertDependencies( model.getDependencies() ) );
|
||||
|
@ -124,7 +126,6 @@ public class Main
|
|||
newModel.setOrganization( convertOrganization( model.getOrganization() ) );
|
||||
newModel.setPackaging( model.getType() );
|
||||
newModel.setParent( convertParent( model.getParent() ) );
|
||||
newModel.setPluginManagement( convertPluginManagement( model.getPluginManagement() ) );
|
||||
newModel.setPluginRepositories( convertRepositories( model.getPluginRepositories() ) );
|
||||
newModel.setReports( convertReports( model.getReports() ) );
|
||||
newModel.setRepositories( convertRepositories( model.getRepositories() ) );
|
||||
|
@ -464,7 +465,8 @@ public class Main
|
|||
return newPlugins;
|
||||
}
|
||||
|
||||
private static org.apache.maven.model.Build convertBuild( Build build, Map plugins )
|
||||
private static org.apache.maven.model.Build convertBuild( Build build, Map plugins,
|
||||
org.apache.maven.model.PluginManagement pluginManagement )
|
||||
{
|
||||
if ( build == null && plugins.isEmpty() )
|
||||
{
|
||||
|
@ -490,6 +492,7 @@ public class Main
|
|||
newBuild.setTestOutputDirectory( build.getTestOutput() );
|
||||
newBuild.setTestSourceDirectory( build.getUnitTestSourceDirectory() );
|
||||
newBuild.setResources( convertResources( build.getResources() ) );
|
||||
newBuild.setPluginManagement( pluginManagement );
|
||||
|
||||
if ( build.getUnitTest() != null )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue