mirror of https://github.com/apache/maven.git
[MNG-6529] ProjectBuilder.build(List<Project> ...) honor
request.isResolveDependency
This commit is contained in:
parent
e4e33f73b8
commit
732e7de893
|
@ -371,7 +371,7 @@ public class DefaultProjectBuilder
|
|||
{
|
||||
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 @@ public class DefaultProjectBuilder
|
|||
|
||||
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 @@ public class DefaultProjectBuilder
|
|||
|
||||
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 )
|
||||
{
|
||||
|
|
|
@ -20,6 +20,8 @@ package org.apache.maven.project;
|
|||
*/
|
||||
|
||||
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 @@ import org.apache.maven.model.building.ModelSource;
|
|||
public class ProjectBuilderTest
|
||||
extends AbstractCoreMavenComponentTestCase
|
||||
{
|
||||
@Override
|
||||
protected String getProjectsDirectory()
|
||||
{
|
||||
return "src/test/projects/project-builder";
|
||||
|
@ -84,4 +87,43 @@ public class ProjectBuilderTest
|
|||
// 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() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue