Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUREFIRE-1957] Get rid of maven-artifact-transfer #396

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions maven-surefire-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-common-artifact-filters</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-artifact-transfer</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.maven.plugin.surefire.extensions.SurefireStatelessReporter;
import org.apache.maven.plugin.surefire.extensions.SurefireStatelessTestsetInfoReporter;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
Expand Down Expand Up @@ -58,7 +57,6 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter;
import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
import org.apache.maven.surefire.shared.utils.io.FileUtils;
import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
import org.apache.maven.surefire.booter.Classpath;
Expand Down Expand Up @@ -825,9 +823,6 @@ public abstract class AbstractSurefireMojo
@Component
private RepositorySystem repositorySystem;

@Component
private DependencyResolver dependencyResolver;

private Toolchain toolchain;

private int effectiveForkCount = -1;
Expand Down Expand Up @@ -1018,7 +1013,7 @@ private void setupStuff() throws MojoFailureException
getConsoleLogger(), getLocalRepository(),
getRemoteRepositories(),
getProjectRemoteRepositories(),
getPluginName(), getDependencyResolver(),
getPluginName(),
getSession().isOffline() );

if ( getBooterArtifact() == null )
Expand Down Expand Up @@ -1405,16 +1400,6 @@ public void setRepositorySystem( RepositorySystem repositorySystem )
this.repositorySystem = repositorySystem;
}

public DependencyResolver getDependencyResolver()
{
return dependencyResolver;
}

public void setDependencyResolver( DependencyResolver dependencyResolver )
{
this.dependencyResolver = dependencyResolver;
}

private boolean existsModuleDescriptor( ResolvePathResultWrapper resolvedJavaModularityResult )
{
return resolvedJavaModularityResult.getResolvePathResult() != null;
Expand Down Expand Up @@ -3292,10 +3277,9 @@ public Set<Artifact> getProviderClasspath() throws MojoExecutionException
surefireDependencyResolver.getProviderClasspathAsMap( "surefire-junit-platform", surefireVersion );
Map<String, Artifact> testDeps = testClasspath.getTestDependencies();

ProjectBuildingRequest request = getSession().getProjectBuildingRequest();
Plugin plugin = getPluginDescriptor().getPlugin();
Map<String, Artifact> pluginDeps =
surefireDependencyResolver.resolvePluginDependencies( request, plugin, getPluginArtifactMap() );
surefireDependencyResolver.resolvePluginDependencies( plugin, getPluginArtifactMap() );

if ( hasDependencyPlatformEngine( pluginDeps ) )
{
Expand Down Expand Up @@ -3521,10 +3505,9 @@ public List<String[]> getJpmsArguments( @Nonnull ProviderRequirements forkRequir
@Nonnull
public Set<Artifact> getProviderClasspath() throws MojoExecutionException
{
ProjectBuildingRequest request = getSession().getProjectBuildingRequest();
Plugin plugin = getPluginDescriptor().getPlugin();
Map<String, Artifact> providerArtifacts =
surefireDependencyResolver.resolvePluginDependencies( request, plugin, getPluginArtifactMap() );
surefireDependencyResolver.resolvePluginDependencies( plugin, getPluginArtifactMap() );
return new LinkedHashSet<>( providerArtifacts.values() );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* under the License.
*/

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
Expand All @@ -38,24 +41,15 @@
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult;
import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import static java.util.Arrays.asList;
import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE;
import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE_PLUS_RUNTIME;
import static org.apache.maven.artifact.Artifact.SCOPE_RUNTIME;
import static org.apache.maven.artifact.ArtifactUtils.artifactMapByVersionlessId;
import static org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec;
import static org.apache.maven.shared.artifact.filter.resolve.ScopeFilter.including;

/**
* Does dependency resolution and artifact handling for the surefire plugin.
Expand All @@ -68,19 +62,19 @@ final class SurefireDependencyResolver
static final String PROVIDER_GROUP_ID = "org.apache.maven.surefire";

private static final String[] PROVIDER_CLASSPATH_ORDER = {
"surefire-junit3",
"surefire-junit4",
"surefire-junit47",
"surefire-testng",
"surefire-junit-platform",
"surefire-api",
"surefire-logger-api",
"surefire-shared-utils",
"common-java5",
"common-junit3",
"common-junit4",
"common-junit48",
"common-testng-utils"
"surefire-junit3",
"surefire-junit4",
"surefire-junit47",
"surefire-testng",
"surefire-junit-platform",
"surefire-api",
"surefire-logger-api",
"surefire-shared-utils",
"common-java5",
"common-junit3",
"common-junit4",
"common-junit48",
"common-testng-utils"
};

private final RepositorySystem repositorySystem;
Expand All @@ -95,23 +89,21 @@ final class SurefireDependencyResolver

private final String pluginName;

private final DependencyResolver dependencyResolver;

private final boolean offline;

SurefireDependencyResolver( RepositorySystem repositorySystem, ConsoleLogger log,
ArtifactRepository localRepository,
List<ArtifactRepository> pluginRemoteRepositories,
List<ArtifactRepository> projectRemoteRepositories, String pluginName,
DependencyResolver dependencyResolver, boolean offline )
List<ArtifactRepository> projectRemoteRepositories,
String pluginName, boolean offline )
{
this.repositorySystem = repositorySystem;
this.log = log;
this.localRepository = localRepository;
this.pluginRemoteRepositories = pluginRemoteRepositories;
this.projectRemoteRepositories = projectRemoteRepositories;
this.pluginName = pluginName;
this.dependencyResolver = dependencyResolver;
this.offline = offline;
}

Expand Down Expand Up @@ -139,33 +131,26 @@ static boolean isWithinVersionSpec( @Nullable Artifact artifact, @Nonnull String
}
}

Map<String, Artifact> resolvePluginDependencies( ProjectBuildingRequest request,
Plugin plugin, Map<String, Artifact> pluginResolvedDependencies )
throws MojoExecutionException
Map<String, Artifact> resolvePluginDependencies( Plugin plugin, Map<String, Artifact> pluginResolvedDependencies )
{
Map<String, Artifact> resolved = new LinkedHashMap<>();
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 )
for ( Dependency dependency : pluginDependencies )
{
Artifact dependencyArtifact = repositorySystem.createDependencyArtifact( dependency );
ArtifactResolutionResult artifactResolutionResult = resolvePluginArtifact( dependencyArtifact );
for ( Artifact artifact : artifactResolutionResult.getArtifacts() )
{
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 );
}
return resolved;
}

ArtifactResolutionResult resolvePluginArtifact( Artifact artifact )
Expand All @@ -192,12 +177,12 @@ private ArtifactResolutionResult resolveArtifact( Artifact artifact, List<Artifa
ArtifactFilter filter )
{
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
.setOffline( offline )
.setArtifact( artifact )
.setLocalRepository( localRepository )
.setResolveTransitively( true )
.setCollectionFilter( filter )
.setRemoteRepositories( repositories );
.setOffline( offline )
.setArtifact( artifact )
.setLocalRepository( localRepository )
.setResolveTransitively( true )
.setCollectionFilter( filter )
.setRemoteRepositories( repositories );

return repositorySystem.resolve( request );
}
Expand Down Expand Up @@ -230,6 +215,9 @@ Map<String, Artifact> getProviderClasspathAsMap( String providerArtifactId, Stri
return artifactMapByVersionlessId( getProviderClasspath( providerArtifactId, providerVersion ) );
}

// FIXME
// method argument should be unchanged
// what if providerArtifacts will be unmodifiable
private static Set<Artifact> orderProviderArtifacts( Set<Artifact> providerArtifacts )
{
Set<Artifact> orderedProviderArtifacts = new LinkedHashSet<>();
Expand Down Expand Up @@ -263,7 +251,7 @@ private static Dependency toProviderDependency( String providerArtifactId, Strin
static class RuntimeArtifactFilter implements ArtifactFilter
{
private static final Collection<String> SCOPES =
asList( SCOPE_COMPILE, SCOPE_COMPILE_PLUS_RUNTIME, SCOPE_RUNTIME );
asList( SCOPE_COMPILE, SCOPE_COMPILE_PLUS_RUNTIME, SCOPE_RUNTIME );

private final Artifact filter;

Expand Down
Loading