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 723e50b23b..efcb024bdc 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -236,7 +236,7 @@ public class DefaultMaven // if ( request.getPom() == null || !request.getPom().exists() ) { - MavenProject project = projectBuilder.buildStandaloneSuperProject( request.getProjectBuildingRequest() ); + MavenProject project = projectBuilder.buildStandaloneSuperProject( request.getProjectBuildingRequest() ).getProject(); projects.add( project ); request.setProjectPresent( false ); return projects; 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 5cd6f3704e..a4adaa35d5 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 @@ -51,7 +51,7 @@ public class DefaultMavenProjectBuilder public MavenProject build( File pomFile, ProjectBuilderConfiguration configuration ) throws ProjectBuildingException { - return projectBuilder.build( pomFile, configuration ); + return projectBuilder.build( pomFile, configuration ).getProject(); } public MavenProject buildFromRepository( Artifact artifact, ProjectBuilderConfiguration configuration ) @@ -59,7 +59,7 @@ public class DefaultMavenProjectBuilder { normalizeToArtifactRepositories( configuration ); - return projectBuilder.build( artifact, configuration ); + return projectBuilder.build( artifact, configuration ).getProject(); } private void normalizeToArtifactRepositories( ProjectBuilderConfiguration configuration ) @@ -143,13 +143,7 @@ public class DefaultMavenProjectBuilder public MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration config ) throws ProjectBuildingException { - return projectBuilder.buildStandaloneSuperProject( config ); - } - - public MavenProjectBuildingResult buildProjectWithDependencies( File pomFile, ProjectBuilderConfiguration configuration ) - throws ProjectBuildingException - { - return projectBuilder.buildProjectWithDependencies( pomFile, configuration ); + return projectBuilder.buildStandaloneSuperProject( config ).getProject(); } } \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 22134f5f84..b6b8ca23fb 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -81,13 +81,14 @@ public class DefaultProjectBuilder // MavenProjectBuilder Implementation // ---------------------------------------------------------------------- - public MavenProject build( File pomFile, ProjectBuildingRequest configuration ) + public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest configuration ) throws ProjectBuildingException { - return build( pomFile, true, configuration ); + return build( pomFile, true, configuration, false ); } - private MavenProject build( File pomFile, boolean localProject, ProjectBuildingRequest configuration ) + private DefaultProjectBuildingResult build( File pomFile, boolean localProject, + ProjectBuildingRequest configuration, boolean resolveDependencies ) throws ProjectBuildingException { ModelBuildingRequest request = getModelBuildingRequest( configuration, null ); @@ -141,7 +142,29 @@ public class DefaultProjectBuilder MavenProject project = toProject( result, configuration, listener ); - return project; + ArtifactResolutionResult artifactResult = null; + + if ( resolveDependencies ) + { + Artifact artifact = new ProjectArtifact( project ); + + ArtifactResolutionRequest artifactRequest = new ArtifactResolutionRequest() + .setArtifact( artifact ) + .setResolveRoot( false ) + .setResolveTransitively( true ) + .setCache( configuration.getRepositoryCache() ) + .setLocalRepository( configuration.getLocalRepository() ) + .setRemoteRepositories( project.getRemoteArtifactRepositories() ) + .setOffline( configuration.isOffline() ) + .setManagedVersionMap( project.getManagedVersionMap() ); + // FIXME setTransferListener + + artifactResult = repositorySystem.resolve( artifactRequest ); + + project.setArtifacts( artifactResult.getArtifacts() ); + } + + return new DefaultProjectBuildingResult( project, result.getProblems(), artifactResult ); } finally { @@ -188,7 +211,7 @@ public class DefaultProjectBuilder return request; } - public MavenProject build( Artifact artifact, ProjectBuildingRequest configuration ) + public ProjectBuildingResult build( Artifact artifact, ProjectBuildingRequest configuration ) throws ProjectBuildingException { if ( !artifact.getType().equals( "pom" ) ) @@ -214,7 +237,7 @@ public class DefaultProjectBuilder throw new ProjectBuildingException( artifact.getId(), "Error resolving project artifact.", e ); } - return build( artifact.getFile(), false, configuration ); + return build( artifact.getFile(), false, configuration, false ); } /** @@ -223,7 +246,7 @@ public class DefaultProjectBuilder * I am taking out the profile handling and the interpolation of the base directory until we * spec this out properly. */ - public MavenProject buildStandaloneSuperProject( ProjectBuildingRequest config ) + public ProjectBuildingResult buildStandaloneSuperProject( ProjectBuildingRequest config ) throws ProjectBuildingException { ModelBuildingRequest request = getModelBuildingRequest( config, null ); @@ -252,55 +275,13 @@ public class DefaultProjectBuilder standaloneProject.setExecutionRoot( true ); - return standaloneProject; + return new DefaultProjectBuildingResult( standaloneProject, result.getProblems(), null ); } - public MavenProjectBuildingResult buildProjectWithDependencies( File pomFile, ProjectBuildingRequest request ) + public ProjectBuildingResult buildProjectWithDependencies( File pomFile, ProjectBuildingRequest request ) throws ProjectBuildingException { - MavenProject project = build( pomFile, request ); - - Artifact artifact = new ProjectArtifact( project ); - - ArtifactResolutionRequest artifactRequest = new ArtifactResolutionRequest() - .setArtifact( artifact ) - .setResolveRoot( false ) - .setResolveTransitively( true ) - .setCache( request.getRepositoryCache() ) - .setLocalRepository( request.getLocalRepository() ) - .setRemoteRepositories( project.getRemoteArtifactRepositories() ) - .setOffline( request.isOffline() ) - .setManagedVersionMap( project.getManagedVersionMap() ); - // FIXME setTransferListener - ArtifactResolutionResult result; - - ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader(); - - try - { - if ( project.getClassRealm() != null ) - { - Thread.currentThread().setContextClassLoader( project.getClassRealm() ); - } - - result = repositorySystem.resolve( artifactRequest ); - } - finally - { - Thread.currentThread().setContextClassLoader( oldContextClassLoader ); - } - - if ( result.hasExceptions() ) - { - Exception e = result.getExceptions().get( 0 ); - - throw new ProjectBuildingException( safeVersionlessKey( project.getGroupId(), project.getArtifactId() ), "Unable to build project due to an invalid dependency version: " + e.getMessage(), - pomFile, e ); - } - - project.setArtifacts( result.getArtifacts() ); - - return new MavenProjectBuildingResult( project, result ); + return build( pomFile, true, request, true ); } public List build( List pomFiles, boolean recursive, ProjectBuildingRequest config ) @@ -334,7 +315,7 @@ public class DefaultProjectBuilder MavenProject project = toProject( result, config, interimResult.listener ); - results.add( new DefaultProjectBuildingResult( project, result.getProblems() ) ); + results.add( new DefaultProjectBuildingResult( project, result.getProblems(), null ) ); } catch ( ModelBuildingException e ) { diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingResult.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingResult.java index db3e2c8ce3..f2df5638d3 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingResult.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingResult.java @@ -23,6 +23,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.model.building.ModelProblem; /** @@ -42,18 +43,24 @@ class DefaultProjectBuildingResult private List problems; + private ArtifactResolutionResult artifactResolutionResult; + /** * Creates a new result with the specified contents. * * @param project The project that was built, may be {@code null}. * @param problems The problems that were encouterned, may be {@code null}. + * @param dependencyResolutionResult The result of the artifact resolution for the project dependencies, may be + * {@code null}. */ - public DefaultProjectBuildingResult( MavenProject project, List problems ) + public DefaultProjectBuildingResult( MavenProject project, List problems, + ArtifactResolutionResult dependencyResolutionResult ) { this.projectId = ( project != null ) ? project.getId() : ""; this.pomFile = ( project != null ) ? project.getFile() : null; this.project = project; this.problems = problems; + this.artifactResolutionResult = dependencyResolutionResult; } /** @@ -95,4 +102,9 @@ class DefaultProjectBuildingResult return problems; } + public ArtifactResolutionResult getArtifactResolutionResult() + { + return artifactResolutionResult; + } + } diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index c967eab1f5..e277cf431d 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -351,7 +351,7 @@ public class MavenProject { try { - parent = mavenProjectBuilder.build( parentFile, projectBuilderConfiguration ); + parent = mavenProjectBuilder.build( parentFile, projectBuilderConfiguration ).getProject(); } catch ( ProjectBuildingException e ) { @@ -363,7 +363,7 @@ public class MavenProject { try { - parent = mavenProjectBuilder.build( getParentArtifact(), projectBuilderConfiguration ); + parent = mavenProjectBuilder.build( getParentArtifact(), projectBuilderConfiguration ).getProject(); } catch ( ProjectBuildingException e ) { 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 dc48833a50..d343083943 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 @@ -41,11 +41,6 @@ public interface MavenProjectBuilder MavenProject buildFromRepository( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository, boolean force ) 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; - // 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 // would ever need this so it should not be exposed in a public API diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuildingResult.java b/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuildingResult.java deleted file mode 100644 index ea39f2bf7e..0000000000 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuildingResult.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.apache.maven.project; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.artifact.resolver.ArtifactResolutionResult; - -/** - * @author Jason van Zyl - * @version $Id$ - */ -public class MavenProjectBuildingResult -{ - private MavenProject project; - - private ArtifactResolutionResult artifactResolutionResult; - - public MavenProjectBuildingResult( MavenProject project, ArtifactResolutionResult artifactResolutionResult ) - { - this.project = project; - - this.artifactResolutionResult = artifactResolutionResult; - } - - public MavenProject getProject() - { - return project; - } - - public ArtifactResolutionResult getArtifactResolutionResult() - { - return artifactResolutionResult; - } -} diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/ProjectBuilder.java index 2c66560ae4..2100134307 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuilder.java @@ -23,22 +23,22 @@ import org.apache.maven.artifact.Artifact; public interface ProjectBuilder { - MavenProject build( File projectFile, ProjectBuildingRequest request ) + ProjectBuildingResult build( File projectFile, ProjectBuildingRequest request ) throws ProjectBuildingException; - MavenProject build( Artifact projectArtifact, ProjectBuildingRequest request ) + ProjectBuildingResult build( Artifact projectArtifact, ProjectBuildingRequest request ) 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 // would ever need this so it should not be exposed in a public API - MavenProject buildStandaloneSuperProject( ProjectBuildingRequest request ) + ProjectBuildingResult buildStandaloneSuperProject( ProjectBuildingRequest request ) 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. @Deprecated - MavenProjectBuildingResult buildProjectWithDependencies( File project, ProjectBuildingRequest request ) + ProjectBuildingResult buildProjectWithDependencies( File project, ProjectBuildingRequest request ) throws ProjectBuildingException; /** diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingResult.java b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingResult.java index 9bdc75ec28..4128c69147 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingResult.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingResult.java @@ -22,6 +22,7 @@ package org.apache.maven.project; import java.io.File; import java.util.List; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.model.building.ModelProblem; /** @@ -51,7 +52,8 @@ public interface ProjectBuildingResult /** * Gets the project that was built. * - * @return The project that was built or {@code null} if an error occurred. + * @return The project that was built or {@code null} if an error occurred and this result accompanies a + * {@link ProjectBuildingException}. */ MavenProject getProject(); @@ -62,4 +64,12 @@ public interface ProjectBuildingResult */ List getProblems(); + /** + * Gets the result of the dependency resolution for the project. + * + * @return The result of the dependency resolution for the project or {@code null} if the project dependencies were + * not requested. + */ + ArtifactResolutionResult getArtifactResolutionResult(); + } diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 7db7de3b72..12123d9964 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -474,7 +474,7 @@ public class MavenMetadataSource configuration.setProcessPlugins( false ); configuration.setSystemProperties( System.getProperties() ); - project = getProjectBuilder().build( pomArtifact, configuration ); + project = getProjectBuilder().build( pomArtifact, configuration ).getProject(); } catch ( ProjectBuildingException e ) { diff --git a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java index 062357470c..cbb0973d3f 100644 --- a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java @@ -121,7 +121,7 @@ public abstract class AbstractCoreMavenComponentTestCase if ( pom != null ) { - project = projectBuilder.build( pom, configuration ); + project = projectBuilder.build( pom, configuration ).getProject(); } else { diff --git a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java index b64d587488..c964efb1ac 100644 --- a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -158,7 +158,7 @@ public abstract class AbstractMavenProjectTestCase ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest(); configuration.setLocalRepository( getLocalRepository() ); - return projectBuilder.build( pom, configuration ); + return projectBuilder.build( pom, configuration ).getProject(); } } diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java index 4a3d0adb44..042b99236f 100644 --- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -1696,7 +1696,7 @@ public class PomConstructionTest config.setValidationLevel( lenientValidation ? ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 : ModelBuildingRequest.VALIDATION_LEVEL_STRICT ); - return new PomTestWrapper( pomFile, projectBuilder.build( pomFile, config ) ); + return new PomTestWrapper( pomFile, projectBuilder.build( pomFile, config ).getProject() ); } protected void assertModelEquals( PomTestWrapper pom, Object expected, String expression ) diff --git a/maven-core/src/test/java/org/apache/maven/project/TestProjectBuilder.java b/maven-core/src/test/java/org/apache/maven/project/TestProjectBuilder.java index 843b8ae864..c2a907bba4 100644 --- a/maven-core/src/test/java/org/apache/maven/project/TestProjectBuilder.java +++ b/maven-core/src/test/java/org/apache/maven/project/TestProjectBuilder.java @@ -17,7 +17,7 @@ public class TestProjectBuilder { @Override - public MavenProject build( Artifact artifact, ProjectBuildingRequest request ) + public ProjectBuildingResult build( Artifact artifact, ProjectBuildingRequest request ) throws ProjectBuildingException { if ( "maven-test".equals( artifact.getGroupId() ) ) @@ -37,20 +37,20 @@ public class TestProjectBuilder { MavenProject project = new MavenProject(); project.setArtifact( artifact ); - return project; + return new DefaultProjectBuildingResult( project, null, null ); } return build( artifact.getFile(), request ); } @Override - public MavenProject build( File pomFile, ProjectBuildingRequest configuration ) + public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest configuration ) throws ProjectBuildingException { - MavenProject project = super.build( pomFile, configuration ); + ProjectBuildingResult result = super.build( pomFile, configuration ); - project.setRemoteArtifactRepositories( Collections. emptyList() ); + result.getProject().setRemoteArtifactRepositories( Collections. emptyList() ); - return project; + return result; } } \ No newline at end of file diff --git a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java index d348fab09b..6baf214a62 100644 --- a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java +++ b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java @@ -90,7 +90,7 @@ public class PomConstructionWithSettingsTest config.setLocalRepository( repositorySystem.createArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout(), null, null ) ); config.setActiveProfileIds( settings.getActiveProfiles() ); - return new PomTestWrapper( pomFile, projectBuilder.build( pomFile, config ) ); + return new PomTestWrapper( pomFile, projectBuilder.build( pomFile, config ).getProject() ); } private static Settings readSettingsFile(File settingsFile) 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 e7a4f42722..f42d405cdd 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 @@ -25,21 +25,14 @@ import java.io.Reader; import java.io.Writer; import org.apache.maven.Maven; -import org.apache.maven.MavenExecutionException; -import org.apache.maven.MissingModuleException; -import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.embedder.execution.MavenExecutionRequestPopulator; -import org.apache.maven.execution.DefaultMavenExecutionRequest; import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionResult; import org.apache.maven.model.Model; import org.apache.maven.model.io.ModelReader; import org.apache.maven.model.io.ModelWriter; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectBuildingResult; import org.apache.maven.project.ProjectBuilder; -import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.settings.Settings; import org.apache.maven.settings.SettingsConfigurationException; diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractCoreMavenComponentTestCase.java b/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractCoreMavenComponentTestCase.java index 0745876831..e451f8adb9 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractCoreMavenComponentTestCase.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractCoreMavenComponentTestCase.java @@ -127,7 +127,7 @@ public abstract class AbstractCoreMavenComponentTestCase if ( pom != null ) { - project = projectBuilder.build( pom, configuration ); + project = projectBuilder.build( pom, configuration ).getProject(); } else {