mirror of
https://github.com/apache/maven.git
synced 2025-02-21 01:15:42 +00:00
[MNG-8088] Using Resolver with MRESOLVER-512 (#1442)
This makes all the new scopes implemented out of the box, but MNG-8041 still stands (is unsolved). Related PR https://github.com/apache/maven-resolver/pull/445 --- https://issues.apache.org/jira/browse/MRESOLVER-512 https://issues.apache.org/jira/browse/MNG-8088
This commit is contained in:
parent
a5ea944c99
commit
2594047014
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
||||
@ -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());
|
||||
@ -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]);
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -190,7 +185,6 @@ class DefaultRepositorySystemSessionFactory implements RepositorySystemSessionFa
|
||||
@SuppressWarnings("checkstyle:ParameterNumber")
|
||||
@Inject
|
||||
DefaultRepositorySystemSessionFactory(
|
||||
ArtifactHandlerManager artifactHandlerManager,
|
||||
RepositorySystem repoSystem,
|
||||
SettingsDecrypter settingsDecrypter,
|
||||
EventSpyDispatcher eventSpyDispatcher,
|
||||
@ -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;
|
||||
@ -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)
|
||||
@ -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());
|
||||
@ -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()));
|
||||
@ -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());
|
||||
|
@ -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;
|
||||
@ -68,9 +67,6 @@ public class DefaultRepositorySystemSessionFactoryTest {
|
||||
@Inject
|
||||
protected org.eclipse.aether.RepositorySystem aetherRepositorySystem;
|
||||
|
||||
@Inject
|
||||
protected ArtifactHandlerManager artifactHandlerManager;
|
||||
|
||||
@Inject
|
||||
protected RuntimeInformation information;
|
||||
|
||||
@ -83,7 +79,6 @@ public class DefaultRepositorySystemSessionFactoryTest {
|
||||
@Test
|
||||
void isNoSnapshotUpdatesTest() throws InvalidRepositoryException {
|
||||
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
|
||||
artifactHandlerManager,
|
||||
aetherRepositorySystem,
|
||||
settingsDecrypter,
|
||||
eventSpyDispatcher,
|
||||
@ -108,7 +103,6 @@ void isNoSnapshotUpdatesTest() throws InvalidRepositoryException {
|
||||
@Test
|
||||
void isSnapshotUpdatesTest() throws InvalidRepositoryException {
|
||||
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
|
||||
artifactHandlerManager,
|
||||
aetherRepositorySystem,
|
||||
settingsDecrypter,
|
||||
eventSpyDispatcher,
|
||||
@ -145,7 +139,6 @@ void wagonProviderConfigurationTest() throws InvalidRepositoryException {
|
||||
request.setServers(servers);
|
||||
|
||||
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
|
||||
artifactHandlerManager,
|
||||
aetherRepositorySystem,
|
||||
settingsDecrypter,
|
||||
eventSpyDispatcher,
|
||||
@ -190,7 +183,6 @@ void httpConfigurationWithHttpHeadersTest() throws InvalidRepositoryException {
|
||||
request.setServers(servers);
|
||||
|
||||
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
|
||||
artifactHandlerManager,
|
||||
aetherRepositorySystem,
|
||||
settingsDecrypter,
|
||||
eventSpyDispatcher,
|
||||
@ -229,7 +221,6 @@ void connectTimeoutConfigurationTest() throws InvalidRepositoryException {
|
||||
request.setServers(servers);
|
||||
|
||||
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
|
||||
artifactHandlerManager,
|
||||
aetherRepositorySystem,
|
||||
settingsDecrypter,
|
||||
eventSpyDispatcher,
|
||||
@ -272,7 +263,6 @@ void connectionTimeoutFromHttpConfigurationTest() throws InvalidRepositoryExcept
|
||||
request.setServers(servers);
|
||||
|
||||
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
|
||||
artifactHandlerManager,
|
||||
aetherRepositorySystem,
|
||||
settingsDecrypter,
|
||||
eventSpyDispatcher,
|
||||
@ -309,7 +299,6 @@ void requestTimeoutConfigurationTest() throws InvalidRepositoryException {
|
||||
request.setServers(servers);
|
||||
|
||||
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
|
||||
artifactHandlerManager,
|
||||
aetherRepositorySystem,
|
||||
settingsDecrypter,
|
||||
eventSpyDispatcher,
|
||||
@ -352,7 +341,6 @@ void readTimeoutFromHttpConfigurationTest() throws InvalidRepositoryException {
|
||||
request.setServers(servers);
|
||||
|
||||
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
|
||||
artifactHandlerManager,
|
||||
aetherRepositorySystem,
|
||||
settingsDecrypter,
|
||||
eventSpyDispatcher,
|
||||
@ -372,7 +360,6 @@ void readTimeoutFromHttpConfigurationTest() throws InvalidRepositoryException {
|
||||
@Test
|
||||
void transportConfigurationTest() throws InvalidRepositoryException {
|
||||
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
|
||||
artifactHandlerManager,
|
||||
aetherRepositorySystem,
|
||||
settingsDecrypter,
|
||||
eventSpyDispatcher,
|
||||
@ -420,7 +407,6 @@ void transportConfigurationTest() throws InvalidRepositoryException {
|
||||
@Test
|
||||
void versionFilteringTest() throws InvalidRepositoryException {
|
||||
DefaultRepositorySystemSessionFactory systemSessionFactory = new DefaultRepositorySystemSessionFactory(
|
||||
artifactHandlerManager,
|
||||
aetherRepositorySystem,
|
||||
settingsDecrypter,
|
||||
eventSpyDispatcher,
|
||||
|
@ -18,30 +18,33 @@
|
||||
*/
|
||||
package org.apache.maven.repository.internal;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.maven.api.DependencyScope;
|
||||
import org.apache.maven.repository.internal.artifact.FatArtifactTraverser;
|
||||
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.scopes.MavenSystemScopeHandler;
|
||||
import org.apache.maven.repository.internal.scopes.Maven4ScopeManagerConfiguration;
|
||||
import org.apache.maven.repository.internal.type.DefaultTypeProvider;
|
||||
import org.eclipse.aether.RepositorySystem;
|
||||
import org.eclipse.aether.RepositorySystemSession.CloseableSession;
|
||||
import org.eclipse.aether.RepositorySystemSession.SessionBuilder;
|
||||
import org.eclipse.aether.SystemScopeHandler;
|
||||
import org.eclipse.aether.artifact.ArtifactTypeRegistry;
|
||||
import org.eclipse.aether.collection.DependencyGraphTransformer;
|
||||
import org.eclipse.aether.collection.DependencyManager;
|
||||
import org.eclipse.aether.collection.DependencySelector;
|
||||
import org.eclipse.aether.collection.DependencyTraverser;
|
||||
import org.eclipse.aether.impl.scope.InternalScopeManager;
|
||||
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.resolution.ArtifactDescriptorPolicy;
|
||||
import org.eclipse.aether.util.artifact.DefaultArtifactTypeRegistry;
|
||||
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;
|
||||
@ -61,9 +64,11 @@
|
||||
*/
|
||||
public class MavenSessionBuilderSupplier implements Supplier<SessionBuilder> {
|
||||
protected final RepositorySystem repositorySystem;
|
||||
protected final InternalScopeManager scopeManager;
|
||||
|
||||
public MavenSessionBuilderSupplier(RepositorySystem repositorySystem) {
|
||||
this.repositorySystem = requireNonNull(repositorySystem);
|
||||
this.scopeManager = new ScopeManagerImpl(Maven4ScopeManagerConfiguration.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,33 +77,39 @@ public MavenSessionBuilderSupplier(RepositorySystem repositorySystem) {
|
||||
@Deprecated
|
||||
MavenSessionBuilderSupplier() {
|
||||
this.repositorySystem = null;
|
||||
this.scopeManager = new ScopeManagerImpl(Maven4ScopeManagerConfiguration.INSTANCE);
|
||||
}
|
||||
|
||||
protected InternalScopeManager getScopeManager() {
|
||||
return scopeManager;
|
||||
}
|
||||
|
||||
protected DependencyTraverser getDependencyTraverser() {
|
||||
return new FatArtifactTraverser();
|
||||
}
|
||||
|
||||
protected SystemScopeHandler getSystemScopeHandler() {
|
||||
return new MavenSystemScopeHandler();
|
||||
protected DependencyManager getDependencyManager() {
|
||||
return getDependencyManager(true); // same default as in Maven4
|
||||
}
|
||||
|
||||
protected DependencyManager getDependencyManager() {
|
||||
return new ClassicDependencyManager(true, getSystemScopeHandler()); // same default as in Maven4
|
||||
public DependencyManager getDependencyManager(boolean transitive) {
|
||||
return new ClassicDependencyManager(transitive, getScopeManager());
|
||||
}
|
||||
|
||||
protected DependencySelector getDependencySelector() {
|
||||
return new AndDependencySelector(
|
||||
new ScopeDependencySelector("test", "provided"),
|
||||
new OptionalDependencySelector(),
|
||||
ScopeDependencySelector.legacy(
|
||||
null, Arrays.asList(DependencyScope.TEST.id(), DependencyScope.PROVIDED.id())),
|
||||
OptionalDependencySelector.fromDirect(),
|
||||
new ExclusionDependencySelector());
|
||||
}
|
||||
|
||||
protected DependencyGraphTransformer getDependencyGraphTransformer() {
|
||||
return new ChainedDependencyGraphTransformer(
|
||||
new ConflictResolver(
|
||||
new NearestVersionSelector(), new MavenScopeSelector(),
|
||||
new SimpleOptionalitySelector(), new MavenScopeDeriver()),
|
||||
new MavenDependencyContextRefiner());
|
||||
new NearestVersionSelector(), new ManagedScopeSelector(getScopeManager()),
|
||||
new SimpleOptionalitySelector(), new ManagedScopeDeriver(getScopeManager())),
|
||||
new ManagedDependencyContextRefiner(getScopeManager()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,6 +138,7 @@ protected void configureSessionBuilder(SessionBuilder session) {
|
||||
session.setDependencyGraphTransformer(getDependencyGraphTransformer());
|
||||
session.setArtifactTypeRegistry(getArtifactTypeRegistry());
|
||||
session.setArtifactDescriptorPolicy(getArtifactDescriptorPolicy());
|
||||
session.setScopeManager(getScopeManager());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,6 +153,7 @@ protected void configureSessionBuilder(SessionBuilder session) {
|
||||
*/
|
||||
@Override
|
||||
public SessionBuilder get() {
|
||||
requireNonNull(repositorySystem, "repositorySystem");
|
||||
SessionBuilder builder = repositorySystem.createSessionBuilder();
|
||||
configureSessionBuilder(builder);
|
||||
return builder;
|
||||
|
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.maven.repository.internal.scopes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.aether.artifact.ArtifactProperties;
|
||||
import org.eclipse.aether.impl.scope.BuildScopeMatrixSource;
|
||||
import org.eclipse.aether.impl.scope.BuildScopeSource;
|
||||
import org.eclipse.aether.impl.scope.CommonBuilds;
|
||||
import org.eclipse.aether.impl.scope.InternalScopeManager;
|
||||
import org.eclipse.aether.impl.scope.ScopeManagerConfiguration;
|
||||
import org.eclipse.aether.internal.impl.scope.ScopeManagerDump;
|
||||
import org.eclipse.aether.scope.DependencyScope;
|
||||
import org.eclipse.aether.scope.ResolutionScope;
|
||||
|
||||
import static org.eclipse.aether.impl.scope.BuildScopeQuery.all;
|
||||
import static org.eclipse.aether.impl.scope.BuildScopeQuery.byBuildPath;
|
||||
import static org.eclipse.aether.impl.scope.BuildScopeQuery.byProjectPath;
|
||||
import static org.eclipse.aether.impl.scope.BuildScopeQuery.select;
|
||||
import static org.eclipse.aether.impl.scope.BuildScopeQuery.singleton;
|
||||
import static org.eclipse.aether.impl.scope.BuildScopeQuery.union;
|
||||
|
||||
/**
|
||||
* Maven3 scope configurations. Configures scope manager to support Maven3 scopes.
|
||||
* <p>
|
||||
* This manager supports the old Maven 3 dependency scopes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public final class Maven3ScopeManagerConfiguration implements ScopeManagerConfiguration {
|
||||
public static final Maven3ScopeManagerConfiguration INSTANCE = new Maven3ScopeManagerConfiguration();
|
||||
public static final String DS_COMPILE = "compile";
|
||||
public static final String DS_RUNTIME = "runtime";
|
||||
public static final String DS_PROVIDED = "provided";
|
||||
public static final String DS_SYSTEM = "system";
|
||||
public static final String DS_TEST = "test";
|
||||
public static final String RS_NONE = "none";
|
||||
public static final String RS_MAIN_COMPILE = "main-compile";
|
||||
public static final String RS_MAIN_COMPILE_PLUS_RUNTIME = "main-compilePlusRuntime";
|
||||
public static final String RS_MAIN_RUNTIME = "main-runtime";
|
||||
public static final String RS_MAIN_RUNTIME_PLUS_SYSTEM = "main-runtimePlusSystem";
|
||||
public static final String RS_TEST_COMPILE = "test-compile";
|
||||
public static final String RS_TEST_RUNTIME = "test-runtime";
|
||||
|
||||
private Maven3ScopeManagerConfiguration() {}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "Maven3";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStrictDependencyScopes() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStrictResolutionScopes() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildScopeSource getBuildScopeSource() {
|
||||
return new BuildScopeMatrixSource(
|
||||
Collections.singletonList(CommonBuilds.PROJECT_PATH_MAIN),
|
||||
Arrays.asList(CommonBuilds.BUILD_PATH_COMPILE, CommonBuilds.BUILD_PATH_RUNTIME),
|
||||
CommonBuilds.MAVEN_TEST_BUILD_SCOPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<DependencyScope> buildDependencyScopes(InternalScopeManager internalScopeManager) {
|
||||
ArrayList<DependencyScope> result = new ArrayList<>();
|
||||
result.add(internalScopeManager.createDependencyScope(DS_COMPILE, true, all()));
|
||||
result.add(internalScopeManager.createDependencyScope(
|
||||
DS_RUNTIME, true, byBuildPath(CommonBuilds.BUILD_PATH_RUNTIME)));
|
||||
result.add(internalScopeManager.createDependencyScope(
|
||||
DS_PROVIDED,
|
||||
false,
|
||||
union(
|
||||
byBuildPath(CommonBuilds.BUILD_PATH_COMPILE),
|
||||
select(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_RUNTIME))));
|
||||
result.add(internalScopeManager.createDependencyScope(
|
||||
DS_TEST, false, byProjectPath(CommonBuilds.PROJECT_PATH_TEST)));
|
||||
result.add(internalScopeManager.createSystemDependencyScope(
|
||||
DS_SYSTEM, false, all(), ArtifactProperties.LOCAL_PATH));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResolutionScope> buildResolutionScopes(InternalScopeManager internalScopeManager) {
|
||||
Collection<DependencyScope> allDependencyScopes = internalScopeManager.getDependencyScopeUniverse();
|
||||
Collection<DependencyScope> nonTransitiveDependencyScopes =
|
||||
allDependencyScopes.stream().filter(s -> !s.isTransitive()).collect(Collectors.toSet());
|
||||
DependencyScope system =
|
||||
internalScopeManager.getDependencyScope(DS_SYSTEM).orElse(null);
|
||||
|
||||
ArrayList<ResolutionScope> result = new ArrayList<>();
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_NONE,
|
||||
InternalScopeManager.Mode.REMOVE,
|
||||
Collections.emptySet(),
|
||||
Collections.emptySet(),
|
||||
allDependencyScopes));
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_MAIN_COMPILE,
|
||||
InternalScopeManager.Mode.ELIMINATE,
|
||||
singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_COMPILE),
|
||||
Collections.singletonList(system),
|
||||
nonTransitiveDependencyScopes));
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_MAIN_COMPILE_PLUS_RUNTIME,
|
||||
InternalScopeManager.Mode.ELIMINATE,
|
||||
byProjectPath(CommonBuilds.PROJECT_PATH_MAIN),
|
||||
Collections.singletonList(system),
|
||||
nonTransitiveDependencyScopes));
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_MAIN_RUNTIME,
|
||||
InternalScopeManager.Mode.ELIMINATE,
|
||||
singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_RUNTIME),
|
||||
Collections.emptySet(),
|
||||
nonTransitiveDependencyScopes));
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_MAIN_RUNTIME_PLUS_SYSTEM,
|
||||
InternalScopeManager.Mode.ELIMINATE,
|
||||
singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_RUNTIME),
|
||||
Collections.singletonList(system),
|
||||
nonTransitiveDependencyScopes));
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_TEST_COMPILE,
|
||||
InternalScopeManager.Mode.ELIMINATE,
|
||||
select(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_COMPILE),
|
||||
Collections.singletonList(system),
|
||||
nonTransitiveDependencyScopes));
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_TEST_RUNTIME,
|
||||
InternalScopeManager.Mode.ELIMINATE,
|
||||
select(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_RUNTIME),
|
||||
Collections.singletonList(system),
|
||||
nonTransitiveDependencyScopes));
|
||||
return result;
|
||||
}
|
||||
|
||||
// ===
|
||||
|
||||
public static void main(String... args) {
|
||||
ScopeManagerDump.dump(Maven3ScopeManagerConfiguration.INSTANCE);
|
||||
}
|
||||
}
|
@ -0,0 +1,197 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.maven.repository.internal.scopes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.maven.api.DependencyScope;
|
||||
import org.apache.maven.repository.internal.artifact.MavenArtifactProperties;
|
||||
import org.eclipse.aether.impl.scope.BuildScopeMatrixSource;
|
||||
import org.eclipse.aether.impl.scope.BuildScopeSource;
|
||||
import org.eclipse.aether.impl.scope.CommonBuilds;
|
||||
import org.eclipse.aether.impl.scope.InternalScopeManager;
|
||||
import org.eclipse.aether.impl.scope.ScopeManagerConfiguration;
|
||||
import org.eclipse.aether.internal.impl.scope.ScopeManagerDump;
|
||||
|
||||
import static org.eclipse.aether.impl.scope.BuildScopeQuery.all;
|
||||
import static org.eclipse.aether.impl.scope.BuildScopeQuery.byBuildPath;
|
||||
import static org.eclipse.aether.impl.scope.BuildScopeQuery.byProjectPath;
|
||||
import static org.eclipse.aether.impl.scope.BuildScopeQuery.select;
|
||||
import static org.eclipse.aether.impl.scope.BuildScopeQuery.singleton;
|
||||
import static org.eclipse.aether.impl.scope.BuildScopeQuery.union;
|
||||
|
||||
/**
|
||||
* Maven4 scope configurations. Configures scope manager to support Maven4 scopes.
|
||||
* <p>
|
||||
* This manager supports all the new Maven 4 dependency scopes defined in {@link DependencyScope}.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public final class Maven4ScopeManagerConfiguration implements ScopeManagerConfiguration {
|
||||
public static final Maven4ScopeManagerConfiguration INSTANCE = new Maven4ScopeManagerConfiguration();
|
||||
|
||||
public static final String RS_NONE = "none";
|
||||
public static final String RS_MAIN_COMPILE = "main-compile";
|
||||
public static final String RS_MAIN_COMPILE_PLUS_RUNTIME = "main-compilePlusRuntime";
|
||||
public static final String RS_MAIN_RUNTIME = "main-runtime";
|
||||
public static final String RS_MAIN_RUNTIME_PLUS_SYSTEM = "main-runtimePlusSystem";
|
||||
public static final String RS_TEST_COMPILE = "test-compile";
|
||||
public static final String RS_TEST_RUNTIME = "test-runtime";
|
||||
|
||||
private Maven4ScopeManagerConfiguration() {}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "Maven4";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStrictDependencyScopes() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStrictResolutionScopes() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuildScopeSource getBuildScopeSource() {
|
||||
return new BuildScopeMatrixSource(
|
||||
Arrays.asList(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.PROJECT_PATH_TEST),
|
||||
Arrays.asList(CommonBuilds.BUILD_PATH_COMPILE, CommonBuilds.BUILD_PATH_RUNTIME));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<org.eclipse.aether.scope.DependencyScope> buildDependencyScopes(
|
||||
InternalScopeManager internalScopeManager) {
|
||||
ArrayList<org.eclipse.aether.scope.DependencyScope> result = new ArrayList<>();
|
||||
result.add(internalScopeManager.createDependencyScope(
|
||||
DependencyScope.COMPILE.id(), DependencyScope.COMPILE.isTransitive(), all()));
|
||||
result.add(internalScopeManager.createDependencyScope(
|
||||
DependencyScope.RUNTIME.id(),
|
||||
DependencyScope.RUNTIME.isTransitive(),
|
||||
byBuildPath(CommonBuilds.BUILD_PATH_RUNTIME)));
|
||||
result.add(internalScopeManager.createDependencyScope(
|
||||
DependencyScope.PROVIDED.id(),
|
||||
DependencyScope.PROVIDED.isTransitive(),
|
||||
union(
|
||||
byBuildPath(CommonBuilds.BUILD_PATH_COMPILE),
|
||||
select(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_RUNTIME))));
|
||||
result.add(internalScopeManager.createDependencyScope(
|
||||
DependencyScope.TEST.id(),
|
||||
DependencyScope.TEST.isTransitive(),
|
||||
byProjectPath(CommonBuilds.PROJECT_PATH_TEST)));
|
||||
result.add(internalScopeManager.createDependencyScope(
|
||||
DependencyScope.NONE.id(), DependencyScope.NONE.isTransitive(), Collections.emptySet()));
|
||||
result.add(internalScopeManager.createDependencyScope(
|
||||
DependencyScope.COMPILE_ONLY.id(),
|
||||
DependencyScope.COMPILE_ONLY.isTransitive(),
|
||||
singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_COMPILE)));
|
||||
result.add(internalScopeManager.createDependencyScope(
|
||||
DependencyScope.TEST_RUNTIME.id(),
|
||||
DependencyScope.TEST_RUNTIME.isTransitive(),
|
||||
singleton(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_RUNTIME)));
|
||||
result.add(internalScopeManager.createDependencyScope(
|
||||
DependencyScope.TEST_ONLY.id(),
|
||||
DependencyScope.TEST_ONLY.isTransitive(),
|
||||
singleton(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_COMPILE)));
|
||||
|
||||
// system
|
||||
result.add(internalScopeManager.createSystemDependencyScope(
|
||||
DependencyScope.SYSTEM.id(),
|
||||
DependencyScope.SYSTEM.isTransitive(),
|
||||
all(),
|
||||
MavenArtifactProperties.LOCAL_PATH));
|
||||
|
||||
// == sanity check
|
||||
if (result.size() != org.apache.maven.api.DependencyScope.values().length - 1) { // sans "undefined"
|
||||
throw new IllegalStateException("Maven4 API dependency scope mismatch");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<org.eclipse.aether.scope.ResolutionScope> buildResolutionScopes(
|
||||
InternalScopeManager internalScopeManager) {
|
||||
Collection<org.eclipse.aether.scope.DependencyScope> allDependencyScopes =
|
||||
internalScopeManager.getDependencyScopeUniverse();
|
||||
Collection<org.eclipse.aether.scope.DependencyScope> nonTransitiveDependencyScopes =
|
||||
allDependencyScopes.stream().filter(s -> !s.isTransitive()).collect(Collectors.toSet());
|
||||
org.eclipse.aether.scope.DependencyScope system = internalScopeManager
|
||||
.getDependencyScope(DependencyScope.SYSTEM.id())
|
||||
.orElse(null);
|
||||
|
||||
ArrayList<org.eclipse.aether.scope.ResolutionScope> result = new ArrayList<>();
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_NONE,
|
||||
InternalScopeManager.Mode.REMOVE,
|
||||
Collections.emptySet(),
|
||||
Collections.emptySet(),
|
||||
allDependencyScopes));
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_MAIN_COMPILE,
|
||||
InternalScopeManager.Mode.ELIMINATE,
|
||||
singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_COMPILE),
|
||||
Collections.singletonList(system),
|
||||
nonTransitiveDependencyScopes));
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_MAIN_COMPILE_PLUS_RUNTIME,
|
||||
InternalScopeManager.Mode.ELIMINATE,
|
||||
byProjectPath(CommonBuilds.PROJECT_PATH_MAIN),
|
||||
Collections.singletonList(system),
|
||||
nonTransitiveDependencyScopes));
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_MAIN_RUNTIME,
|
||||
InternalScopeManager.Mode.REMOVE,
|
||||
singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_RUNTIME),
|
||||
Collections.emptySet(),
|
||||
nonTransitiveDependencyScopes));
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_MAIN_RUNTIME_PLUS_SYSTEM,
|
||||
InternalScopeManager.Mode.REMOVE,
|
||||
singleton(CommonBuilds.PROJECT_PATH_MAIN, CommonBuilds.BUILD_PATH_RUNTIME),
|
||||
Collections.singletonList(system),
|
||||
nonTransitiveDependencyScopes));
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_TEST_COMPILE,
|
||||
InternalScopeManager.Mode.ELIMINATE,
|
||||
select(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_COMPILE),
|
||||
Collections.singletonList(system),
|
||||
nonTransitiveDependencyScopes));
|
||||
result.add(internalScopeManager.createResolutionScope(
|
||||
RS_TEST_RUNTIME,
|
||||
InternalScopeManager.Mode.ELIMINATE,
|
||||
select(CommonBuilds.PROJECT_PATH_TEST, CommonBuilds.BUILD_PATH_RUNTIME),
|
||||
Collections.singletonList(system),
|
||||
nonTransitiveDependencyScopes));
|
||||
return result;
|
||||
}
|
||||
|
||||
// ===
|
||||
|
||||
public static void main(String... args) {
|
||||
ScopeManagerDump.dump(Maven4ScopeManagerConfiguration.INSTANCE);
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.maven.repository.internal.scopes;
|
||||
|
||||
import org.eclipse.aether.RepositoryException;
|
||||
import org.eclipse.aether.collection.DependencyGraphTransformationContext;
|
||||
import org.eclipse.aether.collection.DependencyGraphTransformer;
|
||||
import org.eclipse.aether.graph.Dependency;
|
||||
import org.eclipse.aether.graph.DependencyNode;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* A dependency graph transformer that refines the request context for nodes that belong to the "project" context by
|
||||
* appending the buildpath type to which the node belongs. For instance, a compile-time project dependency will be
|
||||
* assigned the request context "project/compile".
|
||||
*
|
||||
* @see DependencyNode#getRequestContext()
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public final class MavenDependencyContextRefiner implements DependencyGraphTransformer {
|
||||
|
||||
public MavenDependencyContextRefiner() {}
|
||||
|
||||
@Override
|
||||
public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context)
|
||||
throws RepositoryException {
|
||||
requireNonNull(node, "node cannot be null");
|
||||
requireNonNull(context, "context cannot be null");
|
||||
String ctx = node.getRequestContext();
|
||||
|
||||
if ("project".equals(ctx)) {
|
||||
String scope = getBuildpathScope(node);
|
||||
if (scope != null) {
|
||||
ctx += '/' + scope;
|
||||
node.setRequestContext(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
for (DependencyNode child : node.getChildren()) {
|
||||
transformGraph(child, context);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
private String getBuildpathScope(DependencyNode node) {
|
||||
Dependency dependency = node.getDependency();
|
||||
if (dependency == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String scope = dependency.getScope();
|
||||
|
||||
if (MavenDependencyScopes.COMPILE.equals(scope)
|
||||
|| MavenDependencyScopes.SYSTEM.equals(scope)
|
||||
|| MavenDependencyScopes.PROVIDED.equals(scope)) {
|
||||
return MavenDependencyScopes.COMPILE;
|
||||
} else if (MavenDependencyScopes.RUNTIME.equals(scope)) {
|
||||
return MavenDependencyScopes.RUNTIME;
|
||||
} else if (MavenDependencyScopes.TEST.equals(scope)) {
|
||||
return MavenDependencyScopes.TEST;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.maven.repository.internal.scopes;
|
||||
|
||||
import org.apache.maven.api.DependencyScope;
|
||||
|
||||
/**
|
||||
* The dependency scopes used for Java dependencies in Maven. This class defines labels only, that are doing pass-thru
|
||||
* over Resolver. The labels are defined in {@link DependencyScope} class, these are here used only for "easier
|
||||
* reachability" in internal classes.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public final class MavenDependencyScopes {
|
||||
|
||||
public static final String SYSTEM = DependencyScope.SYSTEM.id();
|
||||
|
||||
public static final String NONE = DependencyScope.NONE.id();
|
||||
|
||||
public static final String COMPILE_ONLY = DependencyScope.COMPILE_ONLY.id();
|
||||
|
||||
public static final String COMPILE = DependencyScope.COMPILE.id();
|
||||
|
||||
public static final String PROVIDED = DependencyScope.PROVIDED.id();
|
||||
|
||||
public static final String RUNTIME = DependencyScope.RUNTIME.id();
|
||||
|
||||
public static final String TEST_ONLY = DependencyScope.TEST_ONLY.id();
|
||||
|
||||
public static final String TEST = DependencyScope.TEST.id();
|
||||
|
||||
public static final String TEST_RUNTIME = DependencyScope.TEST_RUNTIME.id();
|
||||
|
||||
private MavenDependencyScopes() {
|
||||
// hide constructor
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.maven.repository.internal.scopes;
|
||||
|
||||
import org.eclipse.aether.RepositoryException;
|
||||
import org.eclipse.aether.util.graph.transformer.ConflictResolver;
|
||||
import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeContext;
|
||||
import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeDeriver;
|
||||
|
||||
/**
|
||||
* A scope deriver for use with {@link ConflictResolver} that supports the scopes from {@link MavenDependencyScopes}.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public final class MavenScopeDeriver extends ScopeDeriver {
|
||||
|
||||
public MavenScopeDeriver() {}
|
||||
|
||||
@Override
|
||||
public void deriveScope(ScopeContext context) throws RepositoryException {
|
||||
context.setDerivedScope(getDerivedScope(context.getParentScope(), context.getChildScope()));
|
||||
}
|
||||
|
||||
private String getDerivedScope(String parentScope, String childScope) {
|
||||
String derivedScope;
|
||||
|
||||
if (MavenDependencyScopes.SYSTEM.equals(childScope) || MavenDependencyScopes.TEST.equals(childScope)) {
|
||||
derivedScope = childScope;
|
||||
} else if (parentScope == null || parentScope.isEmpty() || MavenDependencyScopes.COMPILE.equals(parentScope)) {
|
||||
derivedScope = childScope;
|
||||
} else if (MavenDependencyScopes.TEST.equals(parentScope)
|
||||
|| MavenDependencyScopes.RUNTIME.equals(parentScope)) {
|
||||
derivedScope = parentScope;
|
||||
} else if (MavenDependencyScopes.SYSTEM.equals(parentScope)
|
||||
|| MavenDependencyScopes.PROVIDED.equals(parentScope)) {
|
||||
derivedScope = MavenDependencyScopes.PROVIDED;
|
||||
} else {
|
||||
derivedScope = MavenDependencyScopes.RUNTIME;
|
||||
}
|
||||
|
||||
return derivedScope;
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.maven.repository.internal.scopes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.aether.RepositoryException;
|
||||
import org.eclipse.aether.util.graph.transformer.ConflictResolver;
|
||||
import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictContext;
|
||||
import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictItem;
|
||||
import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeSelector;
|
||||
|
||||
/**
|
||||
* A scope selector for use with {@link ConflictResolver} that supports the scopes from {@link MavenDependencyScopes}.
|
||||
* In general, this selector picks the widest scope present among conflicting dependencies where e.g. "compile" is
|
||||
* wider than "runtime" which is wider than "test". If however a direct dependency is involved, its scope is selected.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public final class MavenScopeSelector extends ScopeSelector {
|
||||
|
||||
public MavenScopeSelector() {}
|
||||
|
||||
@Override
|
||||
public void selectScope(ConflictContext context) throws RepositoryException {
|
||||
String scope = context.getWinner().getDependency().getScope();
|
||||
if (!MavenDependencyScopes.SYSTEM.equals(scope)) {
|
||||
scope = chooseEffectiveScope(context.getItems());
|
||||
}
|
||||
context.setScope(scope);
|
||||
}
|
||||
|
||||
private String chooseEffectiveScope(Collection<ConflictItem> items) {
|
||||
Set<String> scopes = new HashSet<>();
|
||||
for (ConflictItem item : items) {
|
||||
if (item.getDepth() <= 1) {
|
||||
return item.getDependency().getScope();
|
||||
}
|
||||
scopes.addAll(item.getScopes());
|
||||
}
|
||||
return chooseEffectiveScope(scopes);
|
||||
}
|
||||
|
||||
private String chooseEffectiveScope(Set<String> scopes) {
|
||||
if (scopes.size() > 1) {
|
||||
scopes.remove(MavenDependencyScopes.SYSTEM);
|
||||
}
|
||||
|
||||
String effectiveScope = "";
|
||||
|
||||
if (scopes.size() == 1) {
|
||||
effectiveScope = scopes.iterator().next();
|
||||
} else if (scopes.contains(MavenDependencyScopes.COMPILE)) {
|
||||
effectiveScope = MavenDependencyScopes.COMPILE;
|
||||
} else if (scopes.contains(MavenDependencyScopes.RUNTIME)) {
|
||||
effectiveScope = MavenDependencyScopes.RUNTIME;
|
||||
} else if (scopes.contains(MavenDependencyScopes.PROVIDED)) {
|
||||
effectiveScope = MavenDependencyScopes.PROVIDED;
|
||||
} else if (scopes.contains(MavenDependencyScopes.TEST)) {
|
||||
effectiveScope = MavenDependencyScopes.TEST;
|
||||
}
|
||||
|
||||
return effectiveScope;
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.maven.repository.internal.scopes;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.maven.repository.internal.artifact.MavenArtifactProperties;
|
||||
import org.eclipse.aether.SystemScopeHandler;
|
||||
import org.eclipse.aether.artifact.Artifact;
|
||||
|
||||
/**
|
||||
* A system scope handler.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public final class MavenSystemScopeHandler implements SystemScopeHandler {
|
||||
@Override
|
||||
public boolean isSystemScope(String scope) {
|
||||
return MavenDependencyScopes.SYSTEM.equals(scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSystemPath(Artifact artifact) {
|
||||
return artifact.getProperty(MavenArtifactProperties.LOCAL_PATH, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSystemPath(Map<String, String> properties, String systemPath) {
|
||||
if (systemPath == null) {
|
||||
properties.remove(MavenArtifactProperties.LOCAL_PATH);
|
||||
} else {
|
||||
properties.put(MavenArtifactProperties.LOCAL_PATH, systemPath);
|
||||
}
|
||||
}
|
||||
}
|
2
pom.xml
2
pom.xml
@ -182,7 +182,7 @@ under the License.
|
||||
<plexusInterpolationVersion>1.26</plexusInterpolationVersion>
|
||||
<plexusTestingVersion>1.0.0</plexusTestingVersion>
|
||||
<plexusXmlVersion>4.0.1</plexusXmlVersion>
|
||||
<resolverVersion>2.0.0-alpha-8</resolverVersion>
|
||||
<resolverVersion>2.0.0-SNAPSHOT</resolverVersion>
|
||||
<securityDispatcherVersion>2.0</securityDispatcherVersion>
|
||||
<sisuVersion>0.9.0.M2</sisuVersion>
|
||||
<slf4jVersion>2.0.11</slf4jVersion>
|
||||
|
Loading…
x
Reference in New Issue
Block a user