From ec440de1deba05f320a7439539e8f7f26d96737f Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Fri, 17 Jul 2009 12:10:38 +0000 Subject: [PATCH] [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 --- .../java/org/apache/maven/DefaultMaven.java | 90 ++++++++++++++----- 1 file changed, 67 insertions(+), 23 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 421a00a564..aa7d9e01cf 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Date; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -379,43 +378,43 @@ public class DefaultMaven { ProjectDependencyGraph graph = new DefaultProjectDependencyGraph( sorter ); + Collection activeProjects = sorter.getSortedProjects(); + + File reactorDirectory = request.getPom().getAbsoluteFile().getParentFile(); + if ( !request.getSelectedProjects().isEmpty() ) { - File reactorDirectory = request.getPom().getParentFile().getAbsoluteFile(); - - Map projectsByFile = new HashMap(); - - for ( MavenProject project : sorter.getSortedProjects() ) - { - projectsByFile.put( project.getFile(), project ); - } - List selectedProjects = new ArrayList( request.getSelectedProjects().size() ); 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 ) { selectedProjects.add( project ); } else { - throw new MavenExecutionException( "Could not find project in reactor: " + selectedProject, - request.getPom() ); + throw new MavenExecutionException( "Could not find the selected project in the reactor: " + + selectedProject, request.getPom() ); } } + activeProjects = selectedProjects; + boolean makeUpstream = false; boolean makeDownstream = false; + if ( MavenExecutionRequest.REACTOR_MAKE_UPSTREAM.equals( request.getMakeBehavior() ) ) { makeUpstream = true; @@ -435,29 +434,74 @@ public class DefaultMaven request.getPom() ); } - Collection makeProjects = new LinkedHashSet( selectedProjects ); - if ( makeUpstream || makeDownstream ) { + activeProjects = new LinkedHashSet( selectedProjects ); + for ( MavenProject selectedProject : selectedProjects ) { if ( makeUpstream ) { - makeProjects.addAll( graph.getUpstreamProjects( selectedProject, true ) ); + activeProjects.addAll( graph.getUpstreamProjects( selectedProject, true ) ); } 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 projects = new ArrayList( 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; } + 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() ); + } + } + }