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 0659869770..41fddfbab8 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -104,13 +104,13 @@ public class DefaultMaven if ( request.getSettings().isOffline() ) { getLogger().info( "\n\nNOTE: Maven is running in offline mode.\n\n" ); - + WagonManager wagonManager = null; try { wagonManager = (WagonManager) container.lookup( WagonManager.ROLE ); - + wagonManager.setOnline( false ); } catch ( ComponentLookupException e ) @@ -160,7 +160,7 @@ public class DefaultMaven List files = getProjectFiles( request ); List projects = collectProjects( files, request.getLocalRepository(), request.isRecursive(), - request.getSettings(), globalProfileManager ); + request.getSettings(), globalProfileManager, !request.isReactorActive() ); // the reasoning here is that the list is still unsorted according to dependency, so the first project // SHOULD BE the top-level, or the one we want to start with if we're doing an aggregated build. @@ -264,7 +264,7 @@ public class DefaultMaven catch ( LifecycleExecutionException e ) { logFatal( e ); - + throw new ReactorException( "Error executing project within the reactor", e ); } @@ -351,7 +351,7 @@ public class DefaultMaven } private List collectProjects( List files, ArtifactRepository localRepository, boolean recursive, Settings settings, - ProfileManager globalProfileManager ) + ProfileManager globalProfileManager, boolean isRoot ) throws ProjectBuildingException, ReactorException, IOException, ArtifactResolutionException, ProfileActivationException { @@ -371,6 +371,11 @@ public class DefaultMaven MavenProject project = getProject( file, localRepository, settings, globalProfileManager ); + if ( isRoot ) + { + project.setExecutionRoot( true ); + } + if ( project.getPrerequisites() != null && project.getPrerequisites().getMaven() != null ) { DefaultArtifactVersion version = new DefaultArtifactVersion( project.getPrerequisites().getMaven() ); @@ -409,7 +414,7 @@ public class DefaultMaven } List collectedProjects = collectProjects( moduleFiles, localRepository, recursive, settings, - globalProfileManager ); + globalProfileManager, false ); projects.addAll( collectedProjects ); project.setCollectedProjects( collectedProjects ); } @@ -530,7 +535,7 @@ public class DefaultMaven // ---------------------------------------------------------------------- // Reporting / Logging // ---------------------------------------------------------------------- - + protected void logFatal( Throwable error ) { line(); @@ -540,7 +545,7 @@ public class DefaultMaven line(); diagnoseError( error ); - + line(); } @@ -553,7 +558,7 @@ public class DefaultMaven line(); diagnoseError( r.getException() ); - + line(); stats( r.getStart(), r.getFinish() ); diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 94db14f790..cc4d4eba27 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -346,7 +346,7 @@ public class DefaultMavenProjectBuilder try { artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository ); - + File file = projectArtifact.getFile(); model = readModel( file ); @@ -1167,6 +1167,8 @@ public class DefaultMavenProjectBuilder project = processProjectLogic( "", project, remoteRepositories, null, null ); + project.setExecutionRoot( true ); + return project; } catch ( ModelInterpolationException e ) diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java index 944fdad447..971b4f2b4a 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java @@ -134,6 +134,8 @@ public class MavenProject private Build buildOverlay; + private boolean executionRoot; + public MavenProject( Model model ) { this.model = model; @@ -181,6 +183,8 @@ public class MavenProject this.originalModel = ModelUtils.cloneModel( project.originalModel ); } + this.executionRoot = project.executionRoot; + // TODO: need to clone this too? this.artifact = project.artifact; } @@ -1449,4 +1453,14 @@ public class MavenProject { return projectReferences; } + + public boolean isExecutionRoot() + { + return executionRoot; + } + + public void setExecutionRoot( boolean executionRoot ) + { + this.executionRoot = executionRoot; + } } diff --git a/maven-project/src/main/java/org/apache/maven/project/ProjectSorter.java b/maven-project/src/main/java/org/apache/maven/project/ProjectSorter.java index aee378926b..5807ce5559 100644 --- a/maven-project/src/main/java/org/apache/maven/project/ProjectSorter.java +++ b/maven-project/src/main/java/org/apache/maven/project/ProjectSorter.java @@ -169,11 +169,14 @@ public class ProjectSorter { if ( topLevelProject == null ) { - List projectsByFile = new ArrayList( sortedProjects ); - - Collections.sort( projectsByFile, new ByProjectFileComparator() ); - - topLevelProject = (MavenProject) projectsByFile.get( 0 ); + for ( Iterator i = sortedProjects.iterator(); i.hasNext() && topLevelProject == null; ) + { + MavenProject project = (MavenProject) i.next(); + if ( project.isExecutionRoot() ) + { + topLevelProject = project; + } + } } return topLevelProject;