diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/filter/AbstractScopeArtifactFilter.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/filter/AbstractScopeArtifactFilter.java new file mode 100644 index 0000000000..7a0cb065a1 --- /dev/null +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/filter/AbstractScopeArtifactFilter.java @@ -0,0 +1,108 @@ +package org.apache.maven.artifact.resolver.filter; + +/* + * 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.Artifact; + +/** + * Filter to only retain objects in the given artifactScope or better. + * + * @author Brett Porter + * @version $Id$ + */ +abstract class AbstractScopeArtifactFilter + implements ArtifactFilter +{ + + private boolean compileScope; + + private boolean runtimeScope; + + private boolean testScope; + + private boolean providedScope; + + private boolean systemScope; + + void addScope( String scope ) + { + if ( Artifact.SCOPE_COMPILE.equals( scope ) ) + { + systemScope = true; + providedScope = true; + compileScope = true; + } + else if ( Artifact.SCOPE_RUNTIME.equals( scope ) ) + { + compileScope = true; + runtimeScope = true; + } + else if ( Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals( scope ) ) + { + systemScope = true; + providedScope = true; + compileScope = true; + runtimeScope = true; + } + else if ( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals( scope ) ) + { + systemScope = true; + compileScope = true; + runtimeScope = true; + } + else if ( Artifact.SCOPE_TEST.equals( scope ) ) + { + systemScope = true; + providedScope = true; + compileScope = true; + runtimeScope = true; + testScope = true; + } + } + + public boolean include( Artifact artifact ) + { + if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) ) + { + return compileScope; + } + else if ( Artifact.SCOPE_RUNTIME.equals( artifact.getScope() ) ) + { + return runtimeScope; + } + else if ( Artifact.SCOPE_TEST.equals( artifact.getScope() ) ) + { + return testScope; + } + else if ( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) ) + { + return providedScope; + } + else if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) ) + { + return systemScope; + } + else + { + return true; + } + } + +} diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/filter/CumulativeScopeArtifactFilter.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/filter/CumulativeScopeArtifactFilter.java new file mode 100644 index 0000000000..519a370aa2 --- /dev/null +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/filter/CumulativeScopeArtifactFilter.java @@ -0,0 +1,95 @@ +package org.apache.maven.artifact.resolver.filter; + +/* + * 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 java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +/** + * Filter to only retain objects in the given scope or better. This implementation allows the accumulation of multiple + * scopes and their associated implied scopes, so that the user can filter apply a series of implication rules in a + * single step. This should be a more efficient implementation of multiple standard {@link ScopeArtifactFilter} + * instances ORed together. + * + * @author Brett Porter + * @author jdcasey + * @version $Id$ + */ +public class CumulativeScopeArtifactFilter + extends AbstractScopeArtifactFilter +{ + + private Set scopes; + + /** + * Create a new filter with the specified scopes and their implied scopes enabled. + * + * @param scopes The scopes to enable, along with all implied scopes, may be {@code null}. + */ + public CumulativeScopeArtifactFilter( Collection scopes ) + { + this.scopes = new HashSet(); + + if ( scopes != null ) + { + this.scopes.addAll( scopes ); + + for ( String scope : scopes ) + { + addScope( scope ); + } + } + } + + public Set getScopes() + { + return scopes; + } + + @Override + public int hashCode() + { + int hash = 17; + + hash = hash * 31 + scopes.hashCode(); + + return hash; + } + + @Override + public boolean equals( Object obj ) + { + if ( this == obj ) + { + return true; + } + + if ( !( obj instanceof CumulativeScopeArtifactFilter ) ) + { + return false; + } + + CumulativeScopeArtifactFilter that = (CumulativeScopeArtifactFilter) obj; + + return scopes.equals( that.scopes ); + } + +} diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java index 4d0faf53ed..c351d92176 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java @@ -19,8 +19,6 @@ package org.apache.maven.artifact.resolver.filter; * under the License. */ -import org.apache.maven.artifact.Artifact; - /** * Filter to only retain objects in the given artifactScope or better. * @@ -28,100 +26,16 @@ import org.apache.maven.artifact.Artifact; * @version $Id$ */ public class ScopeArtifactFilter - implements ArtifactFilter + extends AbstractScopeArtifactFilter { - private final boolean compileScope; - - private final boolean runtimeScope; - - private final boolean testScope; - - private final boolean providedScope; - - private final boolean systemScope; private final String scope; - + public ScopeArtifactFilter( String scope ) { this.scope = scope; - - if ( Artifact.SCOPE_COMPILE.equals( scope ) ) - { - systemScope = true; - providedScope = true; - compileScope = true; - runtimeScope = false; - testScope = false; - } - else if ( Artifact.SCOPE_RUNTIME.equals( scope ) ) - { - systemScope = false; - providedScope = false; - compileScope = true; - runtimeScope = true; - testScope = false; - } - else if ( Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals( scope ) ) - { - systemScope = true; - providedScope = true; - compileScope = true; - runtimeScope = true; - testScope = false; - } - else if ( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals( scope ) ) - { - systemScope = true; - providedScope = false; - compileScope = true; - runtimeScope = true; - testScope = false; - } - else if ( Artifact.SCOPE_TEST.equals( scope ) ) - { - systemScope = true; - providedScope = true; - compileScope = true; - runtimeScope = true; - testScope = true; - } - else - { - systemScope = false; - providedScope = false; - compileScope = false; - runtimeScope = false; - testScope = false; - } - } - public boolean include( Artifact artifact ) - { - if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) ) - { - return compileScope; - } - else if ( Artifact.SCOPE_RUNTIME.equals( artifact.getScope() ) ) - { - return runtimeScope; - } - else if ( Artifact.SCOPE_TEST.equals( artifact.getScope() ) ) - { - return testScope; - } - else if ( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) ) - { - return providedScope; - } - else if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) ) - { - return systemScope; - } - else - { - return true; - } + addScope( scope ); } public String getScope() @@ -146,19 +60,20 @@ public class ScopeArtifactFilter { return true; } - + if ( !( obj instanceof ScopeArtifactFilter ) ) { return false; } - + ScopeArtifactFilter other = (ScopeArtifactFilter) obj; return equals( scope, other.scope ); } - private static boolean equals( String str1, String str2 ) + private static boolean equals( T str1, T str2 ) { return str1 != null ? str1.equals( str2 ) : str2 == null; } + } diff --git a/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java index 15ee94d235..09029d8ad5 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java @@ -20,21 +20,23 @@ package org.apache.maven; */ import java.util.Collection; +import java.util.Collections; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.RepositoryRequest; +import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException; import org.apache.maven.artifact.resolver.ResolutionErrorHandler; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.artifact.resolver.filter.OrArtifactFilter; -import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; -import org.apache.maven.model.Dependency; +import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter; +import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.ProjectArtifact; import org.apache.maven.repository.RepositorySystem; @@ -45,17 +47,32 @@ import org.codehaus.plexus.component.annotations.Requirement; public class DefaultProjectDependenciesResolver implements ProjectDependenciesResolver { + @Requirement private RepositorySystem repositorySystem; - + @Requirement private ResolutionErrorHandler resolutionErrorHandler; - - public Set resolve( MavenProject project, Collection scopes, RepositoryRequest repositoryRequest ) + + public Set resolve( MavenProject project, Collection scopes, MavenSession session ) throws ArtifactResolutionException, ArtifactNotFoundException - { + { + return resolve( Collections.singleton( project ), scopes, session ); + } + + public Set resolve( Collection projects, Collection scopes, + MavenSession session ) + throws ArtifactResolutionException, ArtifactNotFoundException + { + Set resolved = new LinkedHashSet(); + + if ( projects == null || projects.isEmpty() ) + { + return resolved; + } + /* - + Logic for transitve global exclusions List exclusions = new ArrayList(); @@ -85,46 +102,67 @@ public class DefaultProjectDependenciesResolver } */ - OrArtifactFilter scopeFilter = new OrArtifactFilter(); - - for ( String scope : scopes ) - { - scopeFilter.add( new ScopeArtifactFilter( scope ) ); - } + ArtifactFilter scopeFilter = new CumulativeScopeArtifactFilter( scopes ); ArtifactFilter filter = scopeFilter; - ArtifactResolutionRequest request = new ArtifactResolutionRequest( repositoryRequest ) - .setArtifact( new ProjectArtifact( project ) ) + ArtifactResolutionRequest request = new ArtifactResolutionRequest() .setResolveRoot( false ) .setResolveTransitively( true ) - .setManagedVersionMap( project.getManagedVersionMap() ) - .setFilter( filter ); + .setFilter( filter ) + .setLocalRepository( session.getLocalRepository() ) + .setOffline( session.isOffline() ) + .setCache( session.getRepositoryCache() ); // FIXME setTransferListener - - ArtifactResolutionResult result = repositorySystem.resolve( request ); - project.setArtifacts( result.getArtifacts() ); + Set projectIds = null; - Set directDependencies = new HashSet( project.getDependencies().size() * 2 ); - for ( Dependency dependency : project.getDependencies() ) + for ( MavenProject project : projects ) { - directDependencies.add( dependency.getManagementKey() ); - } + request.setArtifact( new ProjectArtifact( project ) ); + request.setManagedVersionMap( project.getManagedVersionMap() ); + request.setRemoteRepositories( project.getRemoteArtifactRepositories() ); - Set dependencyArtifacts = new LinkedHashSet( project.getDependencies().size() * 2 ); - for ( Artifact artifact : result.getArtifacts() ) - { - if ( directDependencies.contains( artifact.getDependencyConflictId() ) ) + ArtifactResolutionResult result = repositorySystem.resolve( request ); + + try { - dependencyArtifacts.add( artifact ); + resolutionErrorHandler.throwErrors( request, result ); } + catch ( MultipleArtifactsNotFoundException e ) + { + if ( projectIds == null ) + { + projectIds = new HashSet( projects.size() * 2 ); + + for ( MavenProject p : projects ) + { + String key = ArtifactUtils.key( p.getGroupId(), p.getArtifactId(), p.getVersion() ); + projectIds.add( key ); + } + } + + Collection missing = new HashSet( e.getMissingArtifacts() ); + + for ( Iterator it = missing.iterator(); it.hasNext(); ) + { + String key = ArtifactUtils.key( it.next() ); + if ( projectIds.contains( key ) ) + { + it.remove(); + } + } + + if ( !missing.isEmpty() ) + { + throw e; + } + } + + resolved.addAll( result.getArtifacts() ); } - project.setDependencyArtifacts( dependencyArtifacts ); - resolutionErrorHandler.throwErrors( request, result ); - - return result.getArtifacts(); + return resolved; } } diff --git a/maven-core/src/main/java/org/apache/maven/ProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/ProjectDependenciesResolver.java index 7efd908292..5572c81e60 100644 --- a/maven-core/src/main/java/org/apache/maven/ProjectDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/ProjectDependenciesResolver.java @@ -23,13 +23,39 @@ import java.util.Collection; import java.util.Set; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.RepositoryRequest; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.execution.MavenSession; import org.apache.maven.project.MavenProject; public interface ProjectDependenciesResolver { - public Set resolve( MavenProject project, Collection scopes, RepositoryRequest repositoryRequest ) + + /** + * Resolves the transitive dependencies of the specified project. + * + * @param project The project whose dependencies should be resolved, must not be {@code null}. + * @param scopes The dependency scopes that should be resolved, may be {@code null}. + * @param session The current build session, must not be {@code null}. + * @return The transitive dependencies of the specified project that match the requested scopes, never {@code null}. + */ + public Set resolve( MavenProject project, Collection scopes, MavenSession session ) throws ArtifactResolutionException, ArtifactNotFoundException; + + /** + * Resolves the transitive dependencies of the specified projects. Note that dependencies which can't be resolved + * from any repository but are present among the set of specified projects will not cause an exception. Instead, + * those unresolved artifacts will be returned in the result set, allowing the caller to take special care of + * artifacts that haven't been build yet. + * + * @param projects The projects whose dependencies should be resolved, may be {@code null}. + * @param scopes The dependency scopes that should be resolved, may be {@code null}. + * @param session The current build session, must not be {@code null}. + * @return The transitive dependencies of the specified projects that match the requested scopes, never {@code null} + * . + */ + public Set resolve( Collection projects, Collection scopes, + MavenSession session ) + throws ArtifactResolutionException, ArtifactNotFoundException; + } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 7861482fca..5681847119 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -35,6 +36,8 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.repository.DefaultRepositoryRequest; import org.apache.maven.artifact.repository.RepositoryRequest; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException; import org.apache.maven.execution.BuildFailure; import org.apache.maven.execution.BuildSuccess; @@ -306,37 +309,7 @@ public class DefaultLifecycleExecutor for ( MavenProject project : projectsToResolve ) { - repositoryRequest.setRemoteRepositories( project.getRemoteArtifactRepositories() ); - - try - { - projectDependenciesResolver.resolve( project, executionPlan.getRequiredResolutionScopes(), - repositoryRequest ); - } - catch ( MultipleArtifactsNotFoundException e ) - { - /* - * MNG-2277, the check below compensates for our bad plugin support where we ended up with - * aggregator plugins that require dependency resolution although they usually run in phases of - * the build where project artifacts haven't been assembled yet. The prime example of this is - * "mvn release:prepare". - */ - if ( projectBuild.taskSegment.aggregating - && areAllArtifactsInReactor( session.getProjects(), e.getMissingArtifacts() ) ) - { - logger.warn( "The following artifacts could not be resolved at this point of the build" - + " but seem to be part of the reactor:" ); - for ( Artifact artifact : e.getMissingArtifacts() ) - { - logger.warn( "o " + artifact.getId() ); - } - logger.warn( "Try running the build up to the lifecycle phase \"package\"" ); - } - else - { - throw e; - } - } + resolveProjectDependencies( project, executionPlan, session, projectBuild.taskSegment.aggregating ); } for ( MojoExecution mojoExecution : executionPlan.getExecutions() ) @@ -391,6 +364,64 @@ public class DefaultLifecycleExecutor fireEvent( session, null, LifecycleEventCatapult.SESSION_ENDED ); } + private void resolveProjectDependencies( MavenProject project, MavenExecutionPlan executionPlan, + MavenSession session, boolean aggregating ) + throws ArtifactResolutionException, ArtifactNotFoundException + { + Set artifacts; + + try + { + Collection scopesToResolve = executionPlan.getRequiredResolutionScopes(); + + artifacts = projectDependenciesResolver.resolve( project, scopesToResolve, session ); + } + catch ( MultipleArtifactsNotFoundException e ) + { + /* + * MNG-2277, the check below compensates for our bad plugin support where we ended up with aggregator + * plugins that require dependency resolution although they usually run in phases of the build where project + * artifacts haven't been assembled yet. The prime example of this is "mvn release:prepare". + */ + if ( aggregating && areAllArtifactsInReactor( session.getProjects(), e.getMissingArtifacts() ) ) + { + logger.warn( "The following artifacts could not be resolved at this point of the build" + + " but seem to be part of the reactor:" ); + + for ( Artifact artifact : e.getMissingArtifacts() ) + { + logger.warn( "o " + artifact.getId() ); + } + + logger.warn( "Try running the build up to the lifecycle phase \"package\"" ); + + artifacts = new LinkedHashSet( e.getResolvedArtifacts() ); + } + else + { + throw e; + } + } + + project.setArtifacts( artifacts ); + + Set directDependencies = new HashSet( project.getDependencies().size() * 2 ); + for ( Dependency dependency : project.getDependencies() ) + { + directDependencies.add( dependency.getManagementKey() ); + } + + Set dependencyArtifacts = new LinkedHashSet( project.getDependencies().size() * 2 ); + for ( Artifact artifact : artifacts ) + { + if ( directDependencies.contains( artifact.getDependencyConflictId() ) ) + { + dependencyArtifacts.add( artifact ); + } + } + project.setDependencyArtifacts( dependencyArtifacts ); + } + private boolean areAllArtifactsInReactor( Collection projects, Collection artifacts ) { Set projectKeys = new HashSet( projects.size() * 2 ); 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 cbb0973d3f..e156bf3f45 100644 --- a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java @@ -126,6 +126,8 @@ public abstract class AbstractCoreMavenComponentTestCase else { project = createStubMavenProject(); + project.setRemoteArtifactRepositories( request.getRemoteRepositories() ); + project.setPluginArtifactRepositories( request.getPluginArtifactRepositories() ); } MavenSession session = new MavenSession( getContainer(), request, new DefaultMavenExecutionResult(), project ); @@ -166,7 +168,12 @@ public abstract class AbstractCoreMavenComponentTestCase protected class ProjectBuilder { private MavenProject project; - + + public ProjectBuilder( MavenProject project ) + { + this.project = project; + } + public ProjectBuilder( String groupId, String artifactId, String version ) { Model model = new Model(); diff --git a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java b/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java index da092b2fb1..4f67895feb 100644 --- a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java +++ b/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java @@ -7,9 +7,6 @@ import java.util.Properties; import java.util.Set; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.InvalidRepositoryException; -import org.apache.maven.artifact.repository.DefaultRepositoryRequest; -import org.apache.maven.artifact.repository.RepositoryRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Exclusion; import org.apache.maven.project.MavenProject; @@ -41,46 +38,40 @@ public class ProjectDependenciesResolverTest return "src/test/projects/project-dependencies-resolver"; } - protected RepositoryRequest getRepositoryRequest() - throws InvalidRepositoryException - { - RepositoryRequest request = new DefaultRepositoryRequest(); - request.setLocalRepository( getLocalRepository() ); - request.setRemoteRepositories( getRemoteRepositories() ); - return request; - } - public void testExclusionsInDependencies() throws Exception { + MavenSession session = createMavenSession( null ); + MavenProject project = session.getCurrentProject(); + Exclusion exclusion = new Exclusion(); exclusion.setGroupId( "commons-lang" ); exclusion.setArtifactId( "commons-lang" ); - - MavenProject project = new ProjectBuilder( "org.apache.maven", "project-test", "1.0" ) - .addDependency( "org.apache.maven.its", "maven-core-it-support", "1.3", Artifact.SCOPE_RUNTIME, exclusion ) - .get(); + + new ProjectBuilder( project ).addDependency( "org.apache.maven.its", "maven-core-it-support", "1.3", + Artifact.SCOPE_RUNTIME, exclusion ); Set artifactDependencies = - resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), getRepositoryRequest() ); + resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), session ); assertEquals( 0, artifactDependencies.size() ); - - artifactDependencies = - resolver.resolve( project, Collections.singleton( Artifact.SCOPE_RUNTIME ), getRepositoryRequest() ); + + artifactDependencies = resolver.resolve( project, Collections.singleton( Artifact.SCOPE_RUNTIME ), session ); assertEquals( 1, artifactDependencies.size() ); - assertEquals( "maven-core-it-support" , artifactDependencies.iterator().next().getArtifactId() ); + assertEquals( "maven-core-it-support", artifactDependencies.iterator().next().getArtifactId() ); } public void testSystemScopeDependencies() throws Exception { - MavenProject project = new ProjectBuilder( "org.apache.maven", "project-test", "1.0" ) - .addDependency( "com.mycompany", "system-dependency", "1.0", Artifact.SCOPE_SYSTEM, new File( getBasedir(), "pom.xml" ).getAbsolutePath() ) - .get(); + MavenSession session = createMavenSession( null ); + MavenProject project = session.getCurrentProject(); + + new ProjectBuilder( project ) + .addDependency( "com.mycompany", "system-dependency", "1.0", Artifact.SCOPE_SYSTEM, new File( getBasedir(), "pom.xml" ).getAbsolutePath() ); Set artifactDependencies = - resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), getRepositoryRequest() ); - assertEquals( 1, artifactDependencies.size() ); + resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), session ); + assertEquals( 1, artifactDependencies.size() ); } public void testSystemScopeDependencyIsPresentInTheCompileClasspathElements() @@ -94,7 +85,7 @@ public class ProjectDependenciesResolverTest MavenSession session = createMavenSession( pom, eps ); MavenProject project = session.getCurrentProject(); - resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), getRepositoryRequest() ); + project.setArtifacts( resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), session ) ); List elements = project.getCompileClasspathElements(); assertEquals( 2, elements.size() );