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

[MNG-8088] Using Resolver with MRESOLVER-512 #1442

Merged
merged 4 commits into from
Mar 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,10 @@ public enum DependencyScope {
/**
* Test runtime.
*/
TEST_RUNTIME("test-runtime", true),
TEST_RUNTIME("test-runtime", false),

/**
* System scope.
* <p>
* Important: this scope {@code id} MUST BE KEPT in sync with label in
* {@code org.eclipse.aether.util.artifact.DependencyScopes#SYSTEM}.
*/
SYSTEM("system", false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.maven.api.DependencyScope;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
Expand All @@ -42,9 +44,8 @@
import org.apache.maven.internal.impl.DefaultLookup;
import org.apache.maven.internal.impl.DefaultSessionFactory;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.repository.internal.scopes.MavenDependencyContextRefiner;
import org.apache.maven.repository.internal.scopes.MavenScopeDeriver;
import org.apache.maven.repository.internal.scopes.MavenScopeSelector;
import org.apache.maven.repository.internal.artifact.FatArtifactTraverser;
import org.apache.maven.repository.internal.scopes.Maven4ScopeManagerConfiguration;
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.codehaus.plexus.PlexusContainer;
Expand All @@ -57,17 +58,20 @@
import org.eclipse.aether.collection.DependencySelector;
import org.eclipse.aether.collection.DependencyTraverser;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.internal.impl.scope.ManagedDependencyContextRefiner;
import org.eclipse.aether.internal.impl.scope.ManagedScopeDeriver;
import org.eclipse.aether.internal.impl.scope.ManagedScopeSelector;
import org.eclipse.aether.internal.impl.scope.OptionalDependencySelector;
import org.eclipse.aether.internal.impl.scope.ScopeDependencySelector;
import org.eclipse.aether.internal.impl.scope.ScopeManagerImpl;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.util.graph.manager.ClassicDependencyManager;
import org.eclipse.aether.util.graph.selector.AndDependencySelector;
import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
import org.eclipse.aether.util.graph.selector.OptionalDependencySelector;
import org.eclipse.aether.util.graph.selector.ScopeDependencySelector;
import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
import org.eclipse.aether.util.graph.transformer.ConflictResolver;
import org.eclipse.aether.util.graph.transformer.NearestVersionSelector;
import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector;
import org.eclipse.aether.util.graph.traverser.FatArtifactTraverser;
import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
import org.junit.jupiter.api.BeforeEach;

Expand Down Expand Up @@ -299,24 +303,29 @@ protected void deleteArtifact(Artifact artifact, ArtifactRepository repository)
}

protected DefaultRepositorySystemSession initRepoSession() throws Exception {
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(h -> false);
session.setScopeManager(new ScopeManagerImpl(Maven4ScopeManagerConfiguration.INSTANCE));
session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(true, true));
DependencyTraverser depTraverser = new FatArtifactTraverser();
session.setDependencyTraverser(depTraverser);

DependencyManager depManager = new ClassicDependencyManager();
DependencyManager depManager = new ClassicDependencyManager(true, session.getScopeManager());
session.setDependencyManager(depManager);

DependencySelector depFilter = new AndDependencySelector(
new ScopeDependencySelector("test", "provided"),
new OptionalDependencySelector(),
ScopeDependencySelector.legacy(
null, Arrays.asList(DependencyScope.TEST.id(), DependencyScope.PROVIDED.id())),
OptionalDependencySelector.fromDirect(),
new ExclusionDependencySelector());
session.setDependencySelector(depFilter);

ScopeManagerImpl scopeManager = new ScopeManagerImpl(Maven4ScopeManagerConfiguration.INSTANCE);
session.setScopeManager(scopeManager);
DependencyGraphTransformer transformer = new ConflictResolver(
new NearestVersionSelector(), new MavenScopeSelector(),
new SimpleOptionalitySelector(), new MavenScopeDeriver());
transformer = new ChainedDependencyGraphTransformer(transformer, new MavenDependencyContextRefiner());
new NearestVersionSelector(), new ManagedScopeSelector(scopeManager),
new SimpleOptionalitySelector(), new ManagedScopeDeriver(scopeManager));
transformer =
new ChainedDependencyGraphTransformer(transformer, new ManagedDependencyContextRefiner(scopeManager));
session.setDependencyGraphTransformer(transformer);

LocalRepository localRepo = new LocalRepository(localRepository().getBasedir());
Expand All @@ -326,7 +335,7 @@ protected DefaultRepositorySystemSession initRepoSession() throws Exception {

private static final char[] hexCode = "0123456789ABCDEF".toCharArray();

private static final String printHexBinary(byte[] data) {
private static String printHexBinary(byte[] data) {
StringBuilder r = new StringBuilder(data.length * 2);
for (byte b : data) {
r.append(hexCode[(b >> 4) & 0xF]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.apache.maven.RepositoryUtils;
import org.apache.maven.api.services.TypeRegistry;
import org.apache.maven.api.xml.XmlNode;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.eventspy.internal.EventSpyDispatcher;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.internal.xml.XmlNodeImpl;
Expand All @@ -61,7 +59,6 @@
import org.eclipse.aether.collection.VersionFilter;
import org.eclipse.aether.repository.RepositoryPolicy;
import org.eclipse.aether.resolution.ResolutionErrorPolicy;
import org.eclipse.aether.util.graph.manager.ClassicDependencyManager;
import org.eclipse.aether.util.graph.version.*;
import org.eclipse.aether.util.listener.ChainedRepositoryListener;
import org.eclipse.aether.util.repository.AuthenticationBuilder;
Expand Down Expand Up @@ -169,8 +166,6 @@ class DefaultRepositorySystemSessionFactory implements RepositorySystemSessionFa

private final Logger logger = LoggerFactory.getLogger(getClass());

private final ArtifactHandlerManager artifactHandlerManager;

private final RepositorySystem repoSystem;

private final SettingsDecrypter settingsDecrypter;
Expand All @@ -190,7 +185,6 @@ class DefaultRepositorySystemSessionFactory implements RepositorySystemSessionFa
@SuppressWarnings("checkstyle:ParameterNumber")
@Inject
DefaultRepositorySystemSessionFactory(
ArtifactHandlerManager artifactHandlerManager,
RepositorySystem repoSystem,
SettingsDecrypter settingsDecrypter,
EventSpyDispatcher eventSpyDispatcher,
Expand All @@ -199,7 +193,6 @@ class DefaultRepositorySystemSessionFactory implements RepositorySystemSessionFa
VersionScheme versionScheme,
Map<String, MavenExecutionRequestExtender> requestExtenders,
Map<String, RepositorySystemSessionExtender> sessionExtenders) {
this.artifactHandlerManager = artifactHandlerManager;
this.repoSystem = repoSystem;
this.settingsDecrypter = settingsDecrypter;
this.eventSpyDispatcher = eventSpyDispatcher;
Expand All @@ -224,8 +217,9 @@ public SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request)
requestExtender.extend(request);
}

SessionBuilder sessionBuilder = new MavenSessionBuilderSupplier(repoSystem).get();
sessionBuilder.setArtifactTypeRegistry(new TypeRegistryAdapter(typeRegistry));
MavenSessionBuilderSupplier supplier = new MavenSessionBuilderSupplier(repoSystem);
SessionBuilder sessionBuilder = supplier.get();
sessionBuilder.setArtifactTypeRegistry(new TypeRegistryAdapter(typeRegistry)); // dynamic
sessionBuilder.setCache(request.getRepositoryCache());

// this map is read ONLY to get config from (profiles + env + system + user)
Expand Down Expand Up @@ -262,8 +256,6 @@ public SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request)
sessionBuilder.setVersionFilter(versionFilter);
}

sessionBuilder.setArtifactTypeRegistry(RepositoryUtils.newArtifactTypeRegistry(artifactHandlerManager));

DefaultSettingsDecryptionRequest decrypt = new DefaultSettingsDecryptionRequest();
decrypt.setProxies(request.getProxies());
decrypt.setServers(request.getServers());
Expand Down Expand Up @@ -433,10 +425,11 @@ public SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request)
}
sessionBuilder.setRepositoryListener(repositoryListener);

// may be overridden
String resolverDependencyManagerTransitivity =
mergedProps.getOrDefault(MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVITY_KEY, Boolean.TRUE.toString());
sessionBuilder.setDependencyManager(new ClassicDependencyManager(
Boolean.parseBoolean(resolverDependencyManagerTransitivity), SystemScopeHandler.LEGACY));
sessionBuilder.setDependencyManager(
supplier.getDependencyManager(Boolean.parseBoolean(resolverDependencyManagerTransitivity)));

ArrayList<Path> paths = new ArrayList<>();
paths.add(Paths.get(request.getLocalRepository().getBasedir()));
Expand Down Expand Up @@ -471,7 +464,7 @@ private VersionFilter buildVersionFilter(String filterExpression) {
if (filterExpression != null) {
List<String> expressions = Arrays.stream(filterExpression.split(";"))
.filter(s -> s != null && !s.trim().isEmpty())
.collect(Collectors.toList());
.toList();
for (String expression : expressions) {
if ("h".equals(expression)) {
filters.add(new HighestVersionFilter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Properties;

import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.bridge.MavenRepositorySystem;
import org.apache.maven.eventspy.internal.EventSpyDispatcher;
Expand Down Expand Up @@ -68,9 +67,6 @@ public class DefaultRepositorySystemSessionFactoryTest {
@Inject
protected org.eclipse.aether.RepositorySystem aetherRepositorySystem;

@Inject
protected ArtifactHandlerManager artifactHandlerManager;

@Inject
protected RuntimeInformation information;

Expand All @@ -83,7 +79,6 @@ public class DefaultRepositorySystemSessionFactoryTest {
@Test
void isNoSnapshotUpdatesTest() throws InvalidRepositoryException {
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
artifactHandlerManager,
aetherRepositorySystem,
settingsDecrypter,
eventSpyDispatcher,
Expand All @@ -108,7 +103,6 @@ void isNoSnapshotUpdatesTest() throws InvalidRepositoryException {
@Test
void isSnapshotUpdatesTest() throws InvalidRepositoryException {
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
artifactHandlerManager,
aetherRepositorySystem,
settingsDecrypter,
eventSpyDispatcher,
Expand Down Expand Up @@ -145,7 +139,6 @@ void wagonProviderConfigurationTest() throws InvalidRepositoryException {
request.setServers(servers);

DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
artifactHandlerManager,
aetherRepositorySystem,
settingsDecrypter,
eventSpyDispatcher,
Expand Down Expand Up @@ -190,7 +183,6 @@ void httpConfigurationWithHttpHeadersTest() throws InvalidRepositoryException {
request.setServers(servers);

DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
artifactHandlerManager,
aetherRepositorySystem,
settingsDecrypter,
eventSpyDispatcher,
Expand Down Expand Up @@ -229,7 +221,6 @@ void connectTimeoutConfigurationTest() throws InvalidRepositoryException {
request.setServers(servers);

DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
artifactHandlerManager,
aetherRepositorySystem,
settingsDecrypter,
eventSpyDispatcher,
Expand Down Expand Up @@ -272,7 +263,6 @@ void connectionTimeoutFromHttpConfigurationTest() throws InvalidRepositoryExcept
request.setServers(servers);

DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
artifactHandlerManager,
aetherRepositorySystem,
settingsDecrypter,
eventSpyDispatcher,
Expand Down Expand Up @@ -309,7 +299,6 @@ void requestTimeoutConfigurationTest() throws InvalidRepositoryException {
request.setServers(servers);

DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
artifactHandlerManager,
aetherRepositorySystem,
settingsDecrypter,
eventSpyDispatcher,
Expand Down Expand Up @@ -352,7 +341,6 @@ void readTimeoutFromHttpConfigurationTest() throws InvalidRepositoryException {
request.setServers(servers);

DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
artifactHandlerManager,
aetherRepositorySystem,
settingsDecrypter,
eventSpyDispatcher,
Expand All @@ -372,7 +360,6 @@ void readTimeoutFromHttpConfigurationTest() throws InvalidRepositoryException {
@Test
void transportConfigurationTest() throws InvalidRepositoryException {
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
artifactHandlerManager,
aetherRepositorySystem,
settingsDecrypter,
eventSpyDispatcher,
Expand Down Expand Up @@ -420,7 +407,6 @@ void transportConfigurationTest() throws InvalidRepositoryException {
@Test
void versionFilteringTest() throws InvalidRepositoryException {
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
artifactHandlerManager,
aetherRepositorySystem,
settingsDecrypter,
eventSpyDispatcher,
Expand Down
Loading