@Test public void testAddProviderToClasspath() throws Exception { Dependency providerAsDependency = new Dependency(); providerAsDependency.setGroupId( PROVIDER_GROUP_ID ); providerAsDependency.setArtifactId( "surefire-shadefire" ); providerAsDependency.setVersion( "1" ); final Artifact providerAsArtifact = createArtifact( "surefire-shadefire" ); PluginDescriptor pluginDescriptor = PowerMockito.mock( PluginDescriptor.class ); Plugin plugin = PowerMockito.mock( Plugin.class ); when( pluginDescriptor.getPlugin() ) .thenReturn( plugin ); when( plugin.getDependencies() ) .thenReturn( singletonList( providerAsDependency ) ); DependencyResolver depencencyResolver = mock( DependencyResolver.class ); SurefireDependencyResolver surefireDependencyResolver = new SurefireDependencyResolver( null, null, null, null, null, null, depencencyResolver, false ); ProjectBuildingRequest request = mock( ProjectBuildingRequest.class ); ArgumentCaptor<Collection<Dependency>> dep = ArgumentCaptor.forClass( Collection.class ); ArgumentCaptor<ScopeFilter> filter = ArgumentCaptor.forClass( ScopeFilter.class ); ArtifactResult result = mock( ArtifactResult.class ); when( result.getArtifact() ).thenReturn( providerAsArtifact ); when( depencencyResolver.resolveDependencies( same( request ), dep.capture(), isNull( Collection.class ), filter.capture() ) ) .thenReturn( singleton( result ) ); final ArtifactResolutionResult resolutionResult = mock( ArtifactResolutionResult.class ); when( resolutionResult.getArtifacts() ) .thenReturn( singleton( providerAsArtifact ) ); Map<String, Artifact> pluginResolvedDependencies = singletonMap( PROVIDER_GROUP_ID + ":surefire-shadefire", providerAsArtifact ); Map<String, Artifact> providers = surefireDependencyResolver.resolvePluginDependencies( request, plugin, pluginResolvedDependencies ); verify( depencencyResolver, times( 1 ) ) .resolveDependencies( request, dep.getValue(), null, filter.getValue() ); assertThat( providers.values() ) .hasSize( 1 ) .containsOnly( providerAsArtifact ); assertThat( dep.getValue() ) .hasSize( 1 ) .containsOnly( providerAsDependency ); assertThat( filter.getValue().getIncluded() ) .containsOnly( SCOPE_COMPILE, SCOPE_COMPILE_PLUS_RUNTIME, SCOPE_RUNTIME ); assertThat( filter.getValue().getExcluded() ) .isNull(); }
Map<String, Artifact> resolvePluginDependencies( ProjectBuildingRequest request, Plugin plugin, Map<String, Artifact> pluginResolvedDependencies ) throws MojoExecutionException { Collection<Dependency> pluginDependencies = plugin.getDependencies(); try { Iterable<ArtifactResult> resolvedArtifacts = dependencyResolver.resolveDependencies( request, pluginDependencies, null, including( RuntimeArtifactFilter.SCOPES ) ); Map<String, Artifact> resolved = new LinkedHashMap<>(); for ( ArtifactResult resolvedArtifact : resolvedArtifacts ) { Artifact artifact = resolvedArtifact.getArtifact(); String key = artifact.getGroupId() + ":" + artifact.getArtifactId(); Artifact resolvedPluginDependency = pluginResolvedDependencies.get( key ); if ( resolvedPluginDependency != null ) { resolved.put( key, artifact ); } } return resolved; } catch ( DependencyResolverException e ) { throw new MojoExecutionException( e.getLocalizedMessage(), e ); } }
SurefireDependencyResolver { Map<String, Artifact> resolvePluginDependencies( ProjectBuildingRequest request, Plugin plugin, Map<String, Artifact> pluginResolvedDependencies ) throws MojoExecutionException { Collection<Dependency> pluginDependencies = plugin.getDependencies(); try { Iterable<ArtifactResult> resolvedArtifacts = dependencyResolver.resolveDependencies( request, pluginDependencies, null, including( RuntimeArtifactFilter.SCOPES ) ); Map<String, Artifact> resolved = new LinkedHashMap<>(); for ( ArtifactResult resolvedArtifact : resolvedArtifacts ) { Artifact artifact = resolvedArtifact.getArtifact(); String key = artifact.getGroupId() + ":" + artifact.getArtifactId(); Artifact resolvedPluginDependency = pluginResolvedDependencies.get( key ); if ( resolvedPluginDependency != null ) { resolved.put( key, artifact ); } } return resolved; } catch ( DependencyResolverException e ) { throw new MojoExecutionException( e.getLocalizedMessage(), e ); } } }
SurefireDependencyResolver { Map<String, Artifact> resolvePluginDependencies( ProjectBuildingRequest request, Plugin plugin, Map<String, Artifact> pluginResolvedDependencies ) throws MojoExecutionException { Collection<Dependency> pluginDependencies = plugin.getDependencies(); try { Iterable<ArtifactResult> resolvedArtifacts = dependencyResolver.resolveDependencies( request, pluginDependencies, null, including( RuntimeArtifactFilter.SCOPES ) ); Map<String, Artifact> resolved = new LinkedHashMap<>(); for ( ArtifactResult resolvedArtifact : resolvedArtifacts ) { Artifact artifact = resolvedArtifact.getArtifact(); String key = artifact.getGroupId() + ":" + artifact.getArtifactId(); Artifact resolvedPluginDependency = pluginResolvedDependencies.get( key ); if ( resolvedPluginDependency != null ) { resolved.put( key, artifact ); } } return resolved; } catch ( DependencyResolverException e ) { throw new MojoExecutionException( e.getLocalizedMessage(), e ); } } SurefireDependencyResolver( RepositorySystem repositorySystem, ConsoleLogger log,
                                ArtifactRepository localRepository,
                                List<ArtifactRepository> pluginRemoteRepositories,
                                List<ArtifactRepository> projectRemoteRepositories, String pluginName,
                                DependencyResolver dependencyResolver, boolean offline ); }
SurefireDependencyResolver { Map<String, Artifact> resolvePluginDependencies( ProjectBuildingRequest request, Plugin plugin, Map<String, Artifact> pluginResolvedDependencies ) throws MojoExecutionException { Collection<Dependency> pluginDependencies = plugin.getDependencies(); try { Iterable<ArtifactResult> resolvedArtifacts = dependencyResolver.resolveDependencies( request, pluginDependencies, null, including( RuntimeArtifactFilter.SCOPES ) ); Map<String, Artifact> resolved = new LinkedHashMap<>(); for ( ArtifactResult resolvedArtifact : resolvedArtifacts ) { Artifact artifact = resolvedArtifact.getArtifact(); String key = artifact.getGroupId() + ":" + artifact.getArtifactId(); Artifact resolvedPluginDependency = pluginResolvedDependencies.get( key ); if ( resolvedPluginDependency != null ) { resolved.put( key, artifact ); } } return resolved; } catch ( DependencyResolverException e ) { throw new MojoExecutionException( e.getLocalizedMessage(), e ); } } SurefireDependencyResolver( RepositorySystem repositorySystem, ConsoleLogger log,
                                ArtifactRepository localRepository,
                                List<ArtifactRepository> pluginRemoteRepositories,
                                List<ArtifactRepository> projectRemoteRepositories, String pluginName,
                                DependencyResolver dependencyResolver, boolean offline );  }
SurefireDependencyResolver { Map<String, Artifact> resolvePluginDependencies( ProjectBuildingRequest request, Plugin plugin, Map<String, Artifact> pluginResolvedDependencies ) throws MojoExecutionException { Collection<Dependency> pluginDependencies = plugin.getDependencies(); try { Iterable<ArtifactResult> resolvedArtifacts = dependencyResolver.resolveDependencies( request, pluginDependencies, null, including( RuntimeArtifactFilter.SCOPES ) ); Map<String, Artifact> resolved = new LinkedHashMap<>(); for ( ArtifactResult resolvedArtifact : resolvedArtifacts ) { Artifact artifact = resolvedArtifact.getArtifact(); String key = artifact.getGroupId() + ":" + artifact.getArtifactId(); Artifact resolvedPluginDependency = pluginResolvedDependencies.get( key ); if ( resolvedPluginDependency != null ) { resolved.put( key, artifact ); } } return resolved; } catch ( DependencyResolverException e ) { throw new MojoExecutionException( e.getLocalizedMessage(), e ); } } SurefireDependencyResolver( RepositorySystem repositorySystem, ConsoleLogger log,
                                ArtifactRepository localRepository,
                                List<ArtifactRepository> pluginRemoteRepositories,
                                List<ArtifactRepository> projectRemoteRepositories, String pluginName,
                                DependencyResolver dependencyResolver, boolean offline );   }