mirror of https://github.com/apache/maven.git
[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:
parent
0f48aabf52
commit
91499839cf
|
@ -729,6 +729,7 @@ public class DefaultMaven
|
||||||
List<MavenProject> activeProjects = projectSorter.getSortedProjects();
|
List<MavenProject> activeProjects = projectSorter.getSortedProjects();
|
||||||
|
|
||||||
activeProjects = trimSelectedProjects( activeProjects, projectDependencyGraph, request );
|
activeProjects = trimSelectedProjects( activeProjects, projectDependencyGraph, request );
|
||||||
|
activeProjects = trimExcludedProjects( activeProjects, request );
|
||||||
activeProjects = trimResumedProjects( activeProjects, request );
|
activeProjects = trimResumedProjects( activeProjects, request );
|
||||||
|
|
||||||
if ( activeProjects.size() != projectSorter.getSortedProjects().size() )
|
if ( activeProjects.size() != projectSorter.getSortedProjects().size() )
|
||||||
|
@ -849,6 +850,59 @@ public class DefaultMaven
|
||||||
return result;
|
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 )
|
private List<MavenProject> trimResumedProjects( List<MavenProject> projects, MavenExecutionRequest request )
|
||||||
throws MavenExecutionException
|
throws MavenExecutionException
|
||||||
{
|
{
|
||||||
|
|
|
@ -102,6 +102,8 @@ public class DefaultMavenExecutionRequest
|
||||||
|
|
||||||
private List<String> selectedProjects;
|
private List<String> selectedProjects;
|
||||||
|
|
||||||
|
private List<String> excludedProjects;
|
||||||
|
|
||||||
private String resumeFrom;
|
private String resumeFrom;
|
||||||
|
|
||||||
private String makeBehavior;
|
private String makeBehavior;
|
||||||
|
@ -259,6 +261,16 @@ public class DefaultMavenExecutionRequest
|
||||||
return selectedProjects;
|
return selectedProjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getExcludedProjects()
|
||||||
|
{
|
||||||
|
if ( excludedProjects == null )
|
||||||
|
{
|
||||||
|
excludedProjects = new ArrayList<String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return excludedProjects;
|
||||||
|
}
|
||||||
|
|
||||||
public String getResumeFrom()
|
public String getResumeFrom()
|
||||||
{
|
{
|
||||||
return resumeFrom;
|
return resumeFrom;
|
||||||
|
@ -514,6 +526,20 @@ public class DefaultMavenExecutionRequest
|
||||||
return this;
|
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 )
|
public MavenExecutionRequest setResumeFrom( String project )
|
||||||
{
|
{
|
||||||
this.resumeFrom = project;
|
this.resumeFrom = project;
|
||||||
|
|
|
@ -146,6 +146,20 @@ public interface MavenExecutionRequest
|
||||||
MavenExecutionRequest setSelectedProjects( List<String> projects );
|
MavenExecutionRequest setSelectedProjects( List<String> projects );
|
||||||
List<String> getSelectedProjects();
|
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 );
|
MavenExecutionRequest setResumeFrom( String project );
|
||||||
String getResumeFrom();
|
String getResumeFrom();
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -976,14 +975,39 @@ public class MavenCli
|
||||||
|
|
||||||
if ( commandLine.hasOption( CLIManager.PROJECT_LIST ) )
|
if ( commandLine.hasOption( CLIManager.PROJECT_LIST ) )
|
||||||
{
|
{
|
||||||
String[] values = commandLine.getOptionValues( CLIManager.PROJECT_LIST );
|
String[] projectOptionValues = commandLine.getOptionValues( CLIManager.PROJECT_LIST );
|
||||||
List<String> projects = new ArrayList<String>();
|
|
||||||
for ( String value : values )
|
List<String> inclProjects = new ArrayList<String>();
|
||||||
|
List<String> exclProjects = new ArrayList<String>();
|
||||||
|
|
||||||
|
if ( projectOptionValues != null )
|
||||||
{
|
{
|
||||||
String[] tmp = StringUtils.split( value, "," );
|
for ( String projectOptionValue : projectOptionValues )
|
||||||
projects.addAll( Arrays.asList( tmp ) );
|
{
|
||||||
|
StringTokenizer projectTokens = new StringTokenizer( projectOptionValue, "," );
|
||||||
|
|
||||||
|
while ( projectTokens.hasMoreTokens() )
|
||||||
|
{
|
||||||
|
String projectAction = projectTokens.nextToken().trim();
|
||||||
|
|
||||||
|
if ( projectAction.startsWith( "-" ) || projectAction.startsWith( "!" ) )
|
||||||
|
{
|
||||||
|
exclProjects.add( projectAction.substring( 1 ) );
|
||||||
|
}
|
||||||
|
else if ( projectAction.startsWith( "+" ) )
|
||||||
|
{
|
||||||
|
inclProjects.add( projectAction.substring( 1 ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
inclProjects.add( projectAction );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
request.setSelectedProjects( projects );
|
|
||||||
|
request.setSelectedProjects( inclProjects );
|
||||||
|
request.setExcludedProjects( exclProjects );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( commandLine.hasOption( CLIManager.ALSO_MAKE )
|
if ( commandLine.hasOption( CLIManager.ALSO_MAKE )
|
||||||
|
|
Loading…
Reference in New Issue