[MNG-5230] Command line option to exclude modules from reactor

Contributed by Luuk van den Broek, slightly changed by Robert Scholte
Exclude/include marker char now match profiles, i.e +, ! and -
This commit is contained in:
Robert Scholte 2014-01-09 00:05:02 +01:00
parent 0f48aabf52
commit 91499839cf
4 changed files with 125 additions and 7 deletions

View File

@ -729,6 +729,7 @@ private ProjectDependencyGraph createProjectDependencyGraph( Collection<MavenPro
List<MavenProject> activeProjects = projectSorter.getSortedProjects();
activeProjects = trimSelectedProjects( activeProjects, projectDependencyGraph, request );
activeProjects = trimExcludedProjects( activeProjects, request );
activeProjects = trimResumedProjects( activeProjects, request );
if ( activeProjects.size() != projectSorter.getSortedProjects().size() )
@ -849,6 +850,59 @@ else if ( StringUtils.isNotEmpty( request.getMakeBehavior() ) )
return result;
}
private List<MavenProject> trimExcludedProjects( List<MavenProject> projects, MavenExecutionRequest request )
throws MavenExecutionException
{
List<MavenProject> result = projects;
if ( !request.getExcludedProjects().isEmpty() )
{
File reactorDirectory = null;
if ( request.getBaseDirectory() != null )
{
reactorDirectory = new File( request.getBaseDirectory() );
}
Collection<MavenProject> excludedProjects = new LinkedHashSet<MavenProject>( projects.size() );
for ( String selector : request.getExcludedProjects() )
{
MavenProject excludedProject = null;
for ( MavenProject project : projects )
{
if ( isMatchingProject( project, selector, reactorDirectory ) )
{
excludedProject = project;
break;
}
}
if ( excludedProject != null )
{
excludedProjects.add( excludedProject );
}
else
{
throw new MavenExecutionException( "Could not find the selected project in the reactor: "
+ selector, request.getPom() );
}
}
result = new ArrayList<MavenProject>( projects.size() );
for ( MavenProject project : projects )
{
if ( !excludedProjects.contains( project ) )
{
result.add( project );
}
}
}
return result;
}
private List<MavenProject> trimResumedProjects( List<MavenProject> projects, MavenExecutionRequest request )
throws MavenExecutionException
{

View File

@ -102,6 +102,8 @@ public class DefaultMavenExecutionRequest
private List<String> selectedProjects;
private List<String> excludedProjects;
private String resumeFrom;
private String makeBehavior;
@ -259,6 +261,16 @@ public List<String> getSelectedProjects()
return selectedProjects;
}
public List<String> getExcludedProjects()
{
if ( excludedProjects == null )
{
excludedProjects = new ArrayList<String>();
}
return excludedProjects;
}
public String getResumeFrom()
{
return resumeFrom;
@ -514,6 +526,20 @@ public MavenExecutionRequest setSelectedProjects( List<String> selectedProjects
return this;
}
public MavenExecutionRequest setExcludedProjects( List<String> excludedProjects )
{
if ( excludedProjects != null )
{
this.excludedProjects = new ArrayList<String>( excludedProjects );
}
else
{
this.excludedProjects = null;
}
return this;
}
public MavenExecutionRequest setResumeFrom( String project )
{
this.resumeFrom = project;

View File

@ -146,6 +146,20 @@ public interface MavenExecutionRequest
MavenExecutionRequest setSelectedProjects( List<String> projects );
List<String> getSelectedProjects();
/**
*
* @param projects the projects to exclude
* @return this MavenExecutionRequest
* @since 3.2
*/
MavenExecutionRequest setExcludedProjects( List<String> projects );
/**
*
* @return the excluded projects, never {@code null}
* @since 3.2
*/
List<String> getExcludedProjects();
MavenExecutionRequest setResumeFrom( String project );
String getResumeFrom();

View File

@ -24,7 +24,6 @@
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -976,14 +975,39 @@ else if ( request.isInteractiveMode() && !cliRequest.commandLine.hasOption( CLIM
if ( commandLine.hasOption( CLIManager.PROJECT_LIST ) )
{
String[] values = commandLine.getOptionValues( CLIManager.PROJECT_LIST );
List<String> projects = new ArrayList<String>();
for ( String value : values )
String[] projectOptionValues = commandLine.getOptionValues( CLIManager.PROJECT_LIST );
List<String> inclProjects = new ArrayList<String>();
List<String> exclProjects = new ArrayList<String>();
if ( projectOptionValues != null )
{
String[] tmp = StringUtils.split( value, "," );
projects.addAll( Arrays.asList( tmp ) );
for ( String projectOptionValue : projectOptionValues )
{
StringTokenizer projectTokens = new StringTokenizer( projectOptionValue, "," );
while ( projectTokens.hasMoreTokens() )
{
String projectAction = projectTokens.nextToken().trim();
if ( projectAction.startsWith( "-" ) || projectAction.startsWith( "!" ) )
{
exclProjects.add( projectAction.substring( 1 ) );
}
request.setSelectedProjects( projects );
else if ( projectAction.startsWith( "+" ) )
{
inclProjects.add( projectAction.substring( 1 ) );
}
else
{
inclProjects.add( projectAction );
}
}
}
}
request.setSelectedProjects( inclProjects );
request.setExcludedProjects( exclProjects );
}
if ( commandLine.hasOption( CLIManager.ALSO_MAKE )