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 2ae252dc5c..c5c1f7227f 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -126,7 +126,7 @@ public class DefaultMaven try { ProjectSorter projectSorter = new ProjectSorter( projects.values() ); - + session = new MavenSession( container, request, result, projectSorter.getSortedProjects() ); } catch ( CycleDetectedException e ) @@ -163,7 +163,7 @@ public class DefaultMaven } result.setTopologicallySortedProjects( session.getProjects() ); - + result.setProject( session.getTopLevelProject() ); return result; diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java index 7fe554a958..af55036303 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java @@ -71,8 +71,9 @@ public class MavenSession if ( projects.size() > 0 ) { this.currentProject = projects.get( 0 ); + this.topLevelProject = projects.get( 0 ); } - this.projects = projects; + this.projects = projects; } @Deprecated diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 6556405284..2e18555118 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -106,7 +106,7 @@ public class DefaultMavenProjectBuilder public MavenProject build( File pomFile, ProjectBuilderConfiguration configuration ) throws ProjectBuildingException - { + { MavenProject project = projectCache.get( pomFile.getAbsolutePath() ); if ( project != null ) diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java index 120a6c3bac..580d9327db 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java @@ -24,22 +24,24 @@ import org.apache.maven.profiles.ProfileManager; public interface MavenProjectBuilder { - // site - MavenProject build( File project, ArtifactRepository localRepository, ProfileManager profileManager ) - throws ProjectBuildingException; - - // remote-resources-plugin - MavenProject buildFromRepository( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) - throws ProjectBuildingException; - - MavenProject build( File project, ProjectBuilderConfiguration configuration ) + MavenProject build( File projectFile, ProjectBuilderConfiguration configuration ) throws ProjectBuildingException; + MavenProject buildFromRepository( Artifact projectArtifact, ProjectBuilderConfiguration configuration ) + throws ProjectBuildingException; + + //TODO maven-site-plugin + MavenProject build( File project, ArtifactRepository localRepository, ProfileManager profileManager ) + throws ProjectBuildingException; + + //TODO remote-resources-plugin + MavenProject buildFromRepository( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) + throws ProjectBuildingException; + + // TODO: This also doesn't really belong here as it's a mix of project builder and artifact resolution and belongs + // in an integration component like the embedder. MavenProjectBuildingResult buildProjectWithDependencies( File project, ProjectBuilderConfiguration configuration ) throws ProjectBuildingException; - - MavenProject buildFromRepository( Artifact artifact, ProjectBuilderConfiguration configuration ) - throws ProjectBuildingException; // TODO: this is only to provide a project for plugins that don't need a project to execute but need some // of the values from a MavenProject. Ideally this should be something internal and nothing outside Maven diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index def6a3f43f..5b7c1b090a 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -514,7 +514,6 @@ public class MavenEmbedder public boolean isOffline( MavenExecutionRequest request ) throws MavenEmbedderException { - // first, grab defaults including settings, in case true is set. request = populator.populateDefaults( request, configuration ); return request.isOffline(); @@ -525,9 +524,7 @@ public class MavenEmbedder LoggerManager loggerManager = container.getLoggerManager(); int oldThreshold = loggerManager.getThreshold(); - - - + try { loggerManager.setThresholds( request.getLoggingLevel() ); diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java index 115e779778..01bdf4df0d 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Properties; import java.util.Set; +import org.apache.maven.Maven; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.embedder.Configuration; @@ -72,6 +73,8 @@ public class DefaultMavenExecutionRequestPopulator { executionProperties( request, configuration ); + pom( request, configuration ); + settings( request, configuration ); localRepository( request, configuration ); @@ -81,7 +84,7 @@ public class DefaultMavenExecutionRequestPopulator profileManager( request, configuration ); processSettings( request, configuration ); - + return request; } @@ -113,6 +116,34 @@ public class DefaultMavenExecutionRequestPopulator } } } + + private void pom( MavenExecutionRequest request, Configuration configuration ) + { + // ------------------------------------------------------------------------ + // POM + // + // If we are not given a specific POM file, but passed a base directory + // then we will use a release POM in the directory provide, or and then + // look for the standard POM. + // ------------------------------------------------------------------------ + + if ( ( request.getPom() != null ) && ( request.getPom().getParentFile() != null ) ) + { + request.setBaseDirectory( request.getPom().getParentFile() ); + } + else if ( ( request.getPom() == null ) && ( request.getBaseDirectory() != null ) ) + { + File pom = new File( request.getBaseDirectory(), Maven.POMv4 ); + + request.setPom( pom ); + } + // TODO: Is this correct? + else if ( request.getBaseDirectory() == null ) + { + request.setBaseDirectory( new File( System.getProperty( "user.dir" ) ) ); + } + } + private void processSettings( MavenExecutionRequest request, Configuration configuration ) throws MavenEmbedderException