@Test public void testGetProviderClasspath() throws Exception { Artifact api = createArtifact( "surefire-api" ); api.setFile( new File( "" ) ); final Artifact provider = createArtifact( "surefire-junit-platform" ); provider.setFile( new File( "" ) ); Artifact ext = createArtifact( "org.apiguardian", "apiguardian-api" ); ext.setFile( new File( "" ) ); Artifact logger = createArtifact( "surefire-logger-api" ); logger.setFile( new File( "" ) ); Set<Artifact> providerArtifacts = new LinkedHashSet<>(); providerArtifacts.add( api ); providerArtifacts.add( provider ); providerArtifacts.add( ext ); providerArtifacts.add( logger ); final ArtifactResolutionResult result = mock( ArtifactResolutionResult.class ); when( result.getArtifacts() ) .thenReturn( providerArtifacts ); RepositorySystem repositorySystem = mock( RepositorySystem.class ); when( repositorySystem.resolve( any( ArtifactResolutionRequest.class ) ) ) .then( new Answer<ArtifactResolutionResult>() { @Override public ArtifactResolutionResult answer( InvocationOnMock invocation ) { Object[] args = invocation.getArguments(); assertThat( args ) .hasSize( 1 ); ArtifactResolutionRequest request = (ArtifactResolutionRequest) args[0]; assertThat( request.getArtifact() ) .isSameAs( provider ); assertThat( request.isResolveTransitively() ) .isTrue(); assertThat( request.getArtifactDependencies() ) .isNull(); assertThat( request.getRemoteRepositories() ) .isNull(); assertThat( request.getLocalRepository() ) .isNull(); assertThat( request.getCache() ) .isNull(); assertThat( request.getCollectionFilter() ) .isNotNull(); assertThat( request.getCollectionFilter() ) .isInstanceOf( RuntimeArtifactFilter.class ); assertThat( request.getManagedVersionMap() ) .isNull(); assertThat( request.getMirrors() ) .isEmpty(); assertThat( request.getProxies() ) .isEmpty(); assertThat( request.getResolutionFilter() ) .isNull(); assertThat( request.getServers() ) .isEmpty(); return result; } } ); when( repositorySystem.createDependencyArtifact( any( Dependency.class ) ) ) .then( new Answer<Artifact>() { @Override public Artifact answer( InvocationOnMock invocation ) { Object[] args = invocation.getArguments(); assertThat( args ) .hasSize( 1 ); Dependency request = (Dependency) args[0]; assertThat( request.getGroupId() ) .isEqualTo( provider.getGroupId() ); assertThat( request.getArtifactId() ) .isEqualTo( provider.getArtifactId() ); assertThat( request.getVersion() ) .isEqualTo( provider.getVersion() ); assertThat( request.getType() ) .isEqualTo( provider.getType() ); assertThat( request.getScope() ) .isNull(); return provider; } } ); ConsoleLogger log = mock( ConsoleLogger.class ); SurefireDependencyResolver surefireDependencyResolver = new SurefireDependencyResolver( repositorySystem, log, null, null, null, null, null, false ); when( log.isDebugEnabled() ) .thenReturn( true ); Set<Artifact> classpath = surefireDependencyResolver.getProviderClasspath( "surefire-junit-platform", "1" ); assertThat( classpath ) .hasSize( 4 ); Iterator<Artifact> it = classpath.iterator(); assertThat( it.next() ) .isSameAs( provider ); assertThat( it.next() ) .isSameAs( api ); assertThat( it.next() ) .isSameAs( logger ); assertThat( it.next() ) .isSameAs( ext ); }
@Nonnull Set<Artifact> getProviderClasspath( String providerArtifactId, String providerVersion ) { Dependency provider = toProviderDependency( providerArtifactId, providerVersion ); Artifact providerArtifact = repositorySystem.createDependencyArtifact( provider ); ArtifactResolutionResult result = resolvePluginArtifact( providerArtifact ); if ( log.isDebugEnabled() ) { for ( Artifact artifact : result.getArtifacts() ) { String artifactPath = artifact.getFile().getAbsolutePath(); String scope = artifact.getScope(); log.debug( "Adding to " + pluginName + " test classpath: " + artifactPath + " Scope: " + scope ); } } return orderProviderArtifacts( result.getArtifacts() ); }
SurefireDependencyResolver { @Nonnull Set<Artifact> getProviderClasspath( String providerArtifactId, String providerVersion ) { Dependency provider = toProviderDependency( providerArtifactId, providerVersion ); Artifact providerArtifact = repositorySystem.createDependencyArtifact( provider ); ArtifactResolutionResult result = resolvePluginArtifact( providerArtifact ); if ( log.isDebugEnabled() ) { for ( Artifact artifact : result.getArtifacts() ) { String artifactPath = artifact.getFile().getAbsolutePath(); String scope = artifact.getScope(); log.debug( "Adding to " + pluginName + " test classpath: " + artifactPath + " Scope: " + scope ); } } return orderProviderArtifacts( result.getArtifacts() ); } }
SurefireDependencyResolver { @Nonnull Set<Artifact> getProviderClasspath( String providerArtifactId, String providerVersion ) { Dependency provider = toProviderDependency( providerArtifactId, providerVersion ); Artifact providerArtifact = repositorySystem.createDependencyArtifact( provider ); ArtifactResolutionResult result = resolvePluginArtifact( providerArtifact ); if ( log.isDebugEnabled() ) { for ( Artifact artifact : result.getArtifacts() ) { String artifactPath = artifact.getFile().getAbsolutePath(); String scope = artifact.getScope(); log.debug( "Adding to " + pluginName + " test classpath: " + artifactPath + " Scope: " + scope ); } } return orderProviderArtifacts( result.getArtifacts() ); } SurefireDependencyResolver( RepositorySystem repositorySystem, ConsoleLogger log,
                                ArtifactRepository localRepository,
                                List<ArtifactRepository> pluginRemoteRepositories,
                                List<ArtifactRepository> projectRemoteRepositories, String pluginName,
                                DependencyResolver dependencyResolver, boolean offline ); }
SurefireDependencyResolver { @Nonnull Set<Artifact> getProviderClasspath( String providerArtifactId, String providerVersion ) { Dependency provider = toProviderDependency( providerArtifactId, providerVersion ); Artifact providerArtifact = repositorySystem.createDependencyArtifact( provider ); ArtifactResolutionResult result = resolvePluginArtifact( providerArtifact ); if ( log.isDebugEnabled() ) { for ( Artifact artifact : result.getArtifacts() ) { String artifactPath = artifact.getFile().getAbsolutePath(); String scope = artifact.getScope(); log.debug( "Adding to " + pluginName + " test classpath: " + artifactPath + " Scope: " + scope ); } } return orderProviderArtifacts( result.getArtifacts() ); } SurefireDependencyResolver( RepositorySystem repositorySystem, ConsoleLogger log,
                                ArtifactRepository localRepository,
                                List<ArtifactRepository> pluginRemoteRepositories,
                                List<ArtifactRepository> projectRemoteRepositories, String pluginName,
                                DependencyResolver dependencyResolver, boolean offline );  }
SurefireDependencyResolver { @Nonnull Set<Artifact> getProviderClasspath( String providerArtifactId, String providerVersion ) { Dependency provider = toProviderDependency( providerArtifactId, providerVersion ); Artifact providerArtifact = repositorySystem.createDependencyArtifact( provider ); ArtifactResolutionResult result = resolvePluginArtifact( providerArtifact ); if ( log.isDebugEnabled() ) { for ( Artifact artifact : result.getArtifacts() ) { String artifactPath = artifact.getFile().getAbsolutePath(); String scope = artifact.getScope(); log.debug( "Adding to " + pluginName + " test classpath: " + artifactPath + " Scope: " + scope ); } } return orderProviderArtifacts( result.getArtifacts() ); } SurefireDependencyResolver( RepositorySystem repositorySystem, ConsoleLogger log,
                                ArtifactRepository localRepository,
                                List<ArtifactRepository> pluginRemoteRepositories,
                                List<ArtifactRepository> projectRemoteRepositories, String pluginName,
                                DependencyResolver dependencyResolver, boolean offline );   }