maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] asfgit closed pull request #193: MNG-6529 - ProjectBuild.build(projectsList, ...) ignores request.isResolveDependencies()
Date Wed, 26 Dec 2018 10:48:02 GMT
asfgit closed pull request #193: MNG-6529 - ProjectBuild.build(projectsList, ...) ignores request.isResolveDependencies()
URL: https://github.com/apache/maven/pull/193
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 a6590463a0..35a4e9f596 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
@@ -371,7 +371,7 @@ private ModelSource createStubModelSource( Artifact artifact )
         {
             noErrors =
                 build( results, new ArrayList<MavenProject>(), projectIndex, interimResults,
request,
-                       new HashMap<File, Boolean>() ) && noErrors;
+                       new HashMap<File, Boolean>(), config.session ) && noErrors;
         }
         finally
         {
@@ -572,7 +572,8 @@ private void populateReactorModelPool( ReactorModelPool reactorModelPool,
List<I
 
     private boolean build( List<ProjectBuildingResult> results, List<MavenProject>
projects,
                            Map<String, MavenProject> projectIndex, List<InterimResult>
interimResults,
-                           ProjectBuildingRequest request, Map<File, Boolean> profilesXmls
)
+                           ProjectBuildingRequest request, Map<File, Boolean> profilesXmls,
+                           RepositorySystemSession session )
     {
         boolean noErrors = true;
 
@@ -587,15 +588,21 @@ private boolean build( List<ProjectBuildingResult> results, List<MavenProject>
p
 
                 List<MavenProject> modules = new ArrayList<>();
                 noErrors =
-                    build( results, modules, projectIndex, interimResult.modules, request,
profilesXmls ) && noErrors;
+                    build( results, modules, projectIndex, interimResult.modules, request,
profilesXmls, session )
+                    && noErrors;
 
                 projects.addAll( modules );
                 projects.add( project );
 
                 project.setExecutionRoot( interimResult.root );
                 project.setCollectedProjects( modules );
+                DependencyResolutionResult resolutionResult = null;
+                if ( request.isResolveDependencies() )
+                {
+                    resolutionResult = resolveDependencies( project, session );
+                }
 
-                results.add( new DefaultProjectBuildingResult( project, result.getProblems(),
null ) );
+                results.add( new DefaultProjectBuildingResult( project, result.getProblems(),
resolutionResult ) );
             }
             catch ( ModelBuildingException e )
             {
diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
index 5511cb1a4d..18f22bd297 100644
--- a/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
@@ -20,6 +20,8 @@
  */
 
 import java.io.File;
+import java.util.Collections;
+import java.util.List;
 import java.util.Properties;
 
 import org.apache.maven.AbstractCoreMavenComponentTestCase;
@@ -30,6 +32,7 @@
 public class ProjectBuilderTest
     extends AbstractCoreMavenComponentTestCase
 {
+    @Override
     protected String getProjectsDirectory()
     {
         return "src/test/projects/project-builder";
@@ -84,4 +87,43 @@ public void testVersionlessManagedDependency()
             // this is expected
         }
     }
+
+    public void testResolveDependencies()
+        throws Exception
+    {
+        File pomFile = new File( "src/test/resources/projects/basic-resolveDependencies.xml"
);
+        MavenSession mavenSession = createMavenSession( null );
+        ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
+        configuration.setRepositorySession( mavenSession.getRepositorySession() );
+        configuration.setResolveDependencies( true );
+
+        // single project build entry point
+        ProjectBuildingResult result = lookup( org.apache.maven.project.ProjectBuilder.class
).build( pomFile, configuration );
+        assertEquals( 1, result.getProject().getArtifacts().size() );
+        // multi projects build entry point
+        List<ProjectBuildingResult> results = lookup( org.apache.maven.project.ProjectBuilder.class
).build( Collections.singletonList( pomFile ), false, configuration );
+        assertEquals( 1, results.size() );
+        MavenProject mavenProject = results.get( 0 ).getProject();
+        assertEquals( 1, mavenProject.getArtifacts().size() );
+    }
+
+    public void testDontResolveDependencies()
+        throws Exception
+    {
+        File pomFile = new File( "src/test/resources/projects/basic-resolveDependencies.xml"
);
+        MavenSession mavenSession = createMavenSession( null );
+        ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
+        configuration.setRepositorySession( mavenSession.getRepositorySession() );
+        configuration.setResolveDependencies( false );
+
+        // single project build entry point
+        ProjectBuildingResult result = lookup( org.apache.maven.project.ProjectBuilder.class
).build( pomFile, configuration );
+        assertEquals( 0, result.getProject().getArtifacts().size() );
+        // multi projects build entry point
+        List<ProjectBuildingResult> results = lookup( org.apache.maven.project.ProjectBuilder.class
).build( Collections.singletonList( pomFile ), false, configuration );
+        assertEquals( 1, results.size() );
+        MavenProject mavenProject = results.get( 0 ).getProject();
+        assertEquals( 0, mavenProject.getArtifacts().size() );
+    }
+
 }
diff --git a/maven-core/src/test/resources/projects/basic-resolveDependencies.xml b/maven-core/src/test/resources/projects/basic-resolveDependencies.xml
new file mode 100644
index 0000000000..d25326bfce
--- /dev/null
+++ b/maven-core/src/test/resources/projects/basic-resolveDependencies.xml
@@ -0,0 +1,15 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>test</groupId>
+  <artifactId>basic-resolveDependencies.xml</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.its</groupId>
+      <artifactId>a</artifactId>
+      <version>0.1</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message