[MNG-2576] Make Like Reactor Mode

o Restored resume-from

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@795062 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-07-17 12:10:38 +00:00
parent bb5c402250
commit ec440de1de
1 changed files with 67 additions and 23 deletions

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
@ -379,43 +378,43 @@ public class DefaultMaven
{ {
ProjectDependencyGraph graph = new DefaultProjectDependencyGraph( sorter ); ProjectDependencyGraph graph = new DefaultProjectDependencyGraph( sorter );
Collection<MavenProject> activeProjects = sorter.getSortedProjects();
File reactorDirectory = request.getPom().getAbsoluteFile().getParentFile();
if ( !request.getSelectedProjects().isEmpty() ) if ( !request.getSelectedProjects().isEmpty() )
{ {
File reactorDirectory = request.getPom().getParentFile().getAbsoluteFile();
Map<File, MavenProject> projectsByFile = new HashMap<File, MavenProject>();
for ( MavenProject project : sorter.getSortedProjects() )
{
projectsByFile.put( project.getFile(), project );
}
List<MavenProject> selectedProjects = new ArrayList<MavenProject>( request.getSelectedProjects().size() ); List<MavenProject> selectedProjects = new ArrayList<MavenProject>( request.getSelectedProjects().size() );
for ( String selectedProject : request.getSelectedProjects() ) for ( String selectedProject : request.getSelectedProjects() )
{ {
File pomFile = new File( reactorDirectory, selectedProject ); MavenProject project = null;
if ( pomFile.isDirectory() ) for ( MavenProject activeProject : activeProjects )
{ {
pomFile = new File( pomFile, Maven.POMv4 ); if ( isMatchingProject( activeProject, selectedProject, reactorDirectory ) )
{
project = activeProject;
break;
}
} }
MavenProject project = projectsByFile.get( pomFile );
if ( project != null ) if ( project != null )
{ {
selectedProjects.add( project ); selectedProjects.add( project );
} }
else else
{ {
throw new MavenExecutionException( "Could not find project in reactor: " + selectedProject, throw new MavenExecutionException( "Could not find the selected project in the reactor: "
request.getPom() ); + selectedProject, request.getPom() );
} }
} }
activeProjects = selectedProjects;
boolean makeUpstream = false; boolean makeUpstream = false;
boolean makeDownstream = false; boolean makeDownstream = false;
if ( MavenExecutionRequest.REACTOR_MAKE_UPSTREAM.equals( request.getMakeBehavior() ) ) if ( MavenExecutionRequest.REACTOR_MAKE_UPSTREAM.equals( request.getMakeBehavior() ) )
{ {
makeUpstream = true; makeUpstream = true;
@ -435,29 +434,74 @@ public class DefaultMaven
request.getPom() ); request.getPom() );
} }
Collection<MavenProject> makeProjects = new LinkedHashSet<MavenProject>( selectedProjects );
if ( makeUpstream || makeDownstream ) if ( makeUpstream || makeDownstream )
{ {
activeProjects = new LinkedHashSet<MavenProject>( selectedProjects );
for ( MavenProject selectedProject : selectedProjects ) for ( MavenProject selectedProject : selectedProjects )
{ {
if ( makeUpstream ) if ( makeUpstream )
{ {
makeProjects.addAll( graph.getUpstreamProjects( selectedProject, true ) ); activeProjects.addAll( graph.getUpstreamProjects( selectedProject, true ) );
} }
if ( makeDownstream ) if ( makeDownstream )
{ {
makeProjects.addAll( graph.getDownstreamProjects( selectedProject, true ) ); activeProjects.addAll( graph.getDownstreamProjects( selectedProject, true ) );
} }
} }
} }
}
// TODO: process resume from if ( StringUtils.isNotEmpty( request.getResumeFrom() ) )
{
String selectedProject = request.getResumeFrom();
graph = new FilteredProjectDependencyGraph( graph, makeProjects ); List<MavenProject> projects = new ArrayList<MavenProject>( activeProjects.size() );
boolean resumed = false;
for ( MavenProject project : activeProjects )
{
if ( !resumed && isMatchingProject( project, selectedProject, reactorDirectory ) )
{
resumed = true;
}
if ( resumed )
{
projects.add( project );
}
}
if ( !resumed )
{
throw new MavenExecutionException( "Could not find project to resume reactor build from: "
+ selectedProject + " vs " + activeProjects, request.getPom() );
}
activeProjects = projects;
}
if ( activeProjects.size() != sorter.getSortedProjects().size() )
{
graph = new FilteredProjectDependencyGraph( graph, activeProjects );
} }
return graph; return graph;
} }
private boolean isMatchingProject( MavenProject project, String selector, File reactorDirectory )
{
File selectedProject = new File( reactorDirectory, selector );
if ( selectedProject.isFile() )
{
return selectedProject.equals( project.getFile() );
}
else
{
return selectedProject.equals( project.getBasedir() );
}
}
} }