[MNG-7909] Upgrade to Resolver 2.0.0-alpha-1 (#1282)

Upgrade to Resolver 2.0.0.

Changes:
* many UT code used `new DefaultRepositorySystem()` ctor that is gone (was present due SL only), replaced with mocks
* dropped MavenResolverModule Guice module (as AetherGuice module is gone as well)
* updated Resolver version to 2.0.0-alpha-1
* added jdk transport (that prevails apache on Java 11)
* rename of "native" into "apache", deprecate "native" name
* introduce "jdk" transport

---

https://issues.apache.org/jira/browse/MNG-7909
This commit is contained in:
Tamas Cservenak 2023-11-07 16:06:40 +01:00 committed by GitHub
parent 7fcdd32e87
commit e6d1b4c5de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 59 additions and 97 deletions

View File

@ -80,13 +80,20 @@ under the License.
<groupId>org.apache.maven.resolver</groupId> <groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-file</artifactId> <artifactId>maven-resolver-transport-file</artifactId>
</dependency> </dependency>
<!-- HTTP/1.1, lowest priority, Java8+ (still must as some ITs force it) -->
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-wagon</artifactId>
</dependency>
<!-- HTTP/1.1, medium priority, Java8+ -->
<dependency> <dependency>
<groupId>org.apache.maven.resolver</groupId> <groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId> <artifactId>maven-resolver-transport-http</artifactId>
</dependency> </dependency>
<!-- HTTP/1.1 and HTTP/2, high priority, Java11+ -->
<dependency> <dependency>
<groupId>org.apache.maven.resolver</groupId> <groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-wagon</artifactId> <artifactId>maven-resolver-transport-jdk</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>

View File

@ -51,11 +51,11 @@ import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.testing.PlexusTest; import org.codehaus.plexus.testing.PlexusTest;
import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.DefaultRepositorySystem;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepository;
import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
import static org.mockito.Mockito.mock;
@PlexusTest @PlexusTest
public abstract class AbstractCoreMavenComponentTestCase { public abstract class AbstractCoreMavenComponentTestCase {
@ -150,7 +150,8 @@ public abstract class AbstractCoreMavenComponentTestCase {
getContainer(), configuration.getRepositorySession(), request, new DefaultMavenExecutionResult()); getContainer(), configuration.getRepositorySession(), request, new DefaultMavenExecutionResult());
session.setProjects(projects); session.setProjects(projects);
session.setAllProjects(session.getProjects()); session.setAllProjects(session.getProjects());
session.setSession(new DefaultSession(session, new DefaultRepositorySystem(), null, null, null, null)); session.setSession(
new DefaultSession(session, mock(org.eclipse.aether.RepositorySystem.class), null, null, null, null));
return session; return session;
} }

View File

@ -109,13 +109,25 @@ public class DefaultRepositorySystemSessionFactory {
private static final String MAVEN_RESOLVER_TRANSPORT_WAGON = "wagon"; private static final String MAVEN_RESOLVER_TRANSPORT_WAGON = "wagon";
private static final String MAVEN_RESOLVER_TRANSPORT_APACHE = "apache";
private static final String MAVEN_RESOLVER_TRANSPORT_JDK = "jdk";
/**
* This name for Apache HttpClient transport is deprecated.
*
* @deprecated Renamed to {@link #MAVEN_RESOLVER_TRANSPORT_APACHE}
*/
@Deprecated
private static final String MAVEN_RESOLVER_TRANSPORT_NATIVE = "native"; private static final String MAVEN_RESOLVER_TRANSPORT_NATIVE = "native";
private static final String MAVEN_RESOLVER_TRANSPORT_AUTO = "auto"; private static final String MAVEN_RESOLVER_TRANSPORT_AUTO = "auto";
private static final String WAGON_TRANSPORTER_PRIORITY_KEY = "aether.priority.WagonTransporterFactory"; private static final String WAGON_TRANSPORTER_PRIORITY_KEY = "aether.priority.WagonTransporterFactory";
private static final String NATIVE_HTTP_TRANSPORTER_PRIORITY_KEY = "aether.priority.HttpTransporterFactory"; private static final String APACHE_HTTP_TRANSPORTER_PRIORITY_KEY = "aether.priority.HttpTransporterFactory";
private static final String JDK_HTTP_TRANSPORTER_PRIORITY_KEY = "aether.priority.JdkTransporterFactory";
private static final String NATIVE_FILE_TRANSPORTER_PRIORITY_KEY = "aether.priority.FileTransporterFactory"; private static final String NATIVE_FILE_TRANSPORTER_PRIORITY_KEY = "aether.priority.FileTransporterFactory";
@ -322,17 +334,29 @@ public class DefaultRepositorySystemSessionFactory {
Object transport = configProps.getOrDefault(MAVEN_RESOLVER_TRANSPORT_KEY, MAVEN_RESOLVER_TRANSPORT_DEFAULT); Object transport = configProps.getOrDefault(MAVEN_RESOLVER_TRANSPORT_KEY, MAVEN_RESOLVER_TRANSPORT_DEFAULT);
if (MAVEN_RESOLVER_TRANSPORT_DEFAULT.equals(transport)) { if (MAVEN_RESOLVER_TRANSPORT_DEFAULT.equals(transport)) {
// The "default" mode (user did not set anything) from now on defaults to AUTO // The "default" mode (user did not set anything) from now on defaults to AUTO
} else if (MAVEN_RESOLVER_TRANSPORT_NATIVE.equals(transport)) { } else if (MAVEN_RESOLVER_TRANSPORT_JDK.equals(transport)) {
// Make sure (whatever extra priority is set) that resolver native is selected // Make sure (whatever extra priority is set) that resolver file/jdk is selected
configProps.put(NATIVE_FILE_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY); configProps.put(NATIVE_FILE_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
configProps.put(NATIVE_HTTP_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY); configProps.put(JDK_HTTP_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
} else if (MAVEN_RESOLVER_TRANSPORT_APACHE.equals(transport)
|| MAVEN_RESOLVER_TRANSPORT_NATIVE.equals(transport)) {
if (MAVEN_RESOLVER_TRANSPORT_NATIVE.equals(transport)) {
logger.warn(
"Transport name '{}' is DEPRECATED/RENAMED, use '{}' instead",
MAVEN_RESOLVER_TRANSPORT_NATIVE,
MAVEN_RESOLVER_TRANSPORT_APACHE);
}
// Make sure (whatever extra priority is set) that resolver file/apache is selected
configProps.put(NATIVE_FILE_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
configProps.put(APACHE_HTTP_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
} else if (MAVEN_RESOLVER_TRANSPORT_WAGON.equals(transport)) { } else if (MAVEN_RESOLVER_TRANSPORT_WAGON.equals(transport)) {
// Make sure (whatever extra priority is set) that wagon is selected // Make sure (whatever extra priority is set) that wagon is selected
configProps.put(WAGON_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY); configProps.put(WAGON_TRANSPORTER_PRIORITY_KEY, RESOLVER_MAX_PRIORITY);
} else if (!MAVEN_RESOLVER_TRANSPORT_AUTO.equals(transport)) { } else if (!MAVEN_RESOLVER_TRANSPORT_AUTO.equals(transport)) {
throw new IllegalArgumentException("Unknown resolver transport '" + transport throw new IllegalArgumentException("Unknown resolver transport '" + transport
+ "'. Supported transports are: " + MAVEN_RESOLVER_TRANSPORT_WAGON + ", " + "'. Supported transports are: " + MAVEN_RESOLVER_TRANSPORT_WAGON + ", "
+ MAVEN_RESOLVER_TRANSPORT_NATIVE + ", " + MAVEN_RESOLVER_TRANSPORT_AUTO); + MAVEN_RESOLVER_TRANSPORT_APACHE + ", " + MAVEN_RESOLVER_TRANSPORT_JDK + ", "
+ MAVEN_RESOLVER_TRANSPORT_AUTO);
} }
session.setUserProperties(request.getUserProperties()); session.setUserProperties(request.getUserProperties());

View File

@ -50,11 +50,12 @@ import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.testing.PlexusTest; import org.codehaus.plexus.testing.PlexusTest;
import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.DefaultRepositorySystem; import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepository;
import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
import static org.mockito.Mockito.mock;
@PlexusTest @PlexusTest
public abstract class AbstractCoreMavenComponentTestCase { public abstract class AbstractCoreMavenComponentTestCase {
@ -149,7 +150,7 @@ public abstract class AbstractCoreMavenComponentTestCase {
getContainer(), configuration.getRepositorySession(), request, new DefaultMavenExecutionResult()); getContainer(), configuration.getRepositorySession(), request, new DefaultMavenExecutionResult());
session.setProjects(projects); session.setProjects(projects);
session.setAllProjects(session.getProjects()); session.setAllProjects(session.getProjects());
session.setSession(new DefaultSession(session, new DefaultRepositorySystem(), null, null, null, null)); session.setSession(new DefaultSession(session, mock(RepositorySystem.class), null, null, null, null));
return session; return session;
} }

View File

@ -362,7 +362,7 @@ public class DefaultRepositorySystemSessionFactoryTest {
// native // native
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("maven.resolver.transport", "native"); properties.setProperty("maven.resolver.transport", "apache");
request.setSystemProperties(properties); request.setSystemProperties(properties);
Map<String, Object> configProperties = Map<String, Object> configProperties =
systemSessionFactory.newRepositorySession(request).getConfigProperties(); systemSessionFactory.newRepositorySession(request).getConfigProperties();
@ -387,7 +387,7 @@ public class DefaultRepositorySystemSessionFactoryTest {
IllegalArgumentException exception = assertThrowsExactly( IllegalArgumentException exception = assertThrowsExactly(
IllegalArgumentException.class, () -> systemSessionFactory.newRepositorySession(request)); IllegalArgumentException.class, () -> systemSessionFactory.newRepositorySession(request));
assertEquals( assertEquals(
"Unknown resolver transport 'illegal'. Supported transports are: wagon, native, auto", "Unknown resolver transport 'illegal'. Supported transports are: wagon, apache, jdk, auto",
exception.getMessage()); exception.getMessage());
properties.remove("maven.resolver.transport"); properties.remove("maven.resolver.transport");
} }

View File

@ -25,12 +25,13 @@ import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.root.RootLocator; import org.apache.maven.model.root.RootLocator;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.internal.impl.DefaultRepositorySystem;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
public class DefaultSessionTest { public class DefaultSessionTest {
@ -40,7 +41,7 @@ public class DefaultSessionTest {
DefaultMavenExecutionRequest mer = new DefaultMavenExecutionRequest(); DefaultMavenExecutionRequest mer = new DefaultMavenExecutionRequest();
MavenSession ms = new MavenSession(null, rss, mer, null); MavenSession ms = new MavenSession(null, rss, mer, null);
DefaultSession session = DefaultSession session =
new DefaultSession(ms, new DefaultRepositorySystem(), Collections.emptyList(), null, null, null); new DefaultSession(ms, mock(RepositorySystem.class), Collections.emptyList(), null, null, null);
assertEquals( assertEquals(
RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE, RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE,
@ -55,7 +56,7 @@ public class DefaultSessionTest {
MavenSession ms = new MavenSession(null, rss, mer, null); MavenSession ms = new MavenSession(null, rss, mer, null);
ms.getRequest().setRootDirectory(Paths.get("myRootDirectory")); ms.getRequest().setRootDirectory(Paths.get("myRootDirectory"));
DefaultSession session = DefaultSession session =
new DefaultSession(ms, new DefaultRepositorySystem(), Collections.emptyList(), null, null, null); new DefaultSession(ms, mock(RepositorySystem.class), Collections.emptyList(), null, null, null);
assertEquals(Paths.get("myRootDirectory"), session.getRootDirectory()); assertEquals(Paths.get("myRootDirectory"), session.getRootDirectory());
} }

View File

@ -61,7 +61,7 @@ import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator
import org.codehaus.plexus.configuration.DefaultPlexusConfiguration; import org.codehaus.plexus.configuration.DefaultPlexusConfiguration;
import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.Os;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.DefaultRepositorySystem; import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.NoLocalRepositoryManagerException; import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
@ -75,6 +75,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
/** /**
*/ */
@ -419,8 +420,7 @@ public class PluginParameterExpressionEvaluatorV4Test extends AbstractCoreMavenC
mavenSession.setCurrentProject(project); mavenSession.setCurrentProject(project);
mavenSession.getRequest().setRootDirectory(rootDirectory); mavenSession.getRequest().setRootDirectory(rootDirectory);
DefaultSession session = DefaultSession session = new DefaultSession(mavenSession, mock(RepositorySystem.class), null, null, null, null);
new DefaultSession(mavenSession, new DefaultRepositorySystem(), null, null, null, null);
MojoDescriptor mojo = new MojoDescriptor(); MojoDescriptor mojo = new MojoDescriptor();
mojo.setPluginDescriptor(pluginDescriptor); mojo.setPluginDescriptor(pluginDescriptor);
@ -458,7 +458,7 @@ public class PluginParameterExpressionEvaluatorV4Test extends AbstractCoreMavenC
} }
private DefaultSession newSession() throws Exception { private DefaultSession newSession() throws Exception {
return new DefaultSession(newMavenSession(), new DefaultRepositorySystem(), null, null, null, null); return new DefaultSession(newMavenSession(), mock(RepositorySystem.class), null, null, null, null);
} }
private MavenSession newMavenSession() throws Exception { private MavenSession newMavenSession() throws Exception {

View File

@ -1,77 +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;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.name.Names;
import org.apache.maven.model.building.DefaultModelBuilderFactory;
import org.apache.maven.model.building.ModelBuilder;
import org.eclipse.aether.impl.ArtifactDescriptorReader;
import org.eclipse.aether.impl.MetadataGeneratorFactory;
import org.eclipse.aether.impl.VersionRangeResolver;
import org.eclipse.aether.impl.VersionResolver;
import org.eclipse.aether.impl.guice.AetherModule;
import org.eclipse.aether.version.VersionScheme;
/**
* MavenResolverModule
*/
@Deprecated
public final class MavenResolverModule extends AbstractModule {
@Override
protected void configure() {
install(new AetherModule());
bind(VersionScheme.class).toProvider(new DefaultVersionSchemeProvider());
bind(ArtifactDescriptorReader.class)
.to(DefaultArtifactDescriptorReader.class)
.in(Singleton.class);
bind(VersionResolver.class).to(DefaultVersionResolver.class).in(Singleton.class);
bind(VersionRangeResolver.class).to(DefaultVersionRangeResolver.class).in(Singleton.class);
bind(MetadataGeneratorFactory.class)
.annotatedWith(Names.named("snapshot"))
.to(SnapshotMetadataGeneratorFactory.class)
.in(Singleton.class);
bind(MetadataGeneratorFactory.class)
.annotatedWith(Names.named("versions"))
.to(VersionsMetadataGeneratorFactory.class)
.in(Singleton.class);
bind(ModelBuilder.class).toInstance(new DefaultModelBuilderFactory().newInstance());
bind(ModelCacheFactory.class).to(DefaultModelCacheFactory.class).in(Singleton.class);
}
@Provides
@Singleton
Set<MetadataGeneratorFactory> provideMetadataGeneratorFactories(
@Named("snapshot") MetadataGeneratorFactory snapshot,
@Named("versions") MetadataGeneratorFactory versions) {
Set<MetadataGeneratorFactory> factories = new HashSet<>(2);
factories.add(snapshot);
factories.add(versions);
return Collections.unmodifiableSet(factories);
}
}

View File

@ -161,7 +161,7 @@ under the License.
<securityDispatcherVersion>2.0</securityDispatcherVersion> <securityDispatcherVersion>2.0</securityDispatcherVersion>
<cipherVersion>2.0</cipherVersion> <cipherVersion>2.0</cipherVersion>
<jxpathVersion>1.3</jxpathVersion> <jxpathVersion>1.3</jxpathVersion>
<resolverVersion>1.9.16</resolverVersion> <resolverVersion>2.0.0-alpha-1</resolverVersion>
<sisuVersion>0.9.0.M2</sisuVersion> <sisuVersion>0.9.0.M2</sisuVersion>
<asmVersion>9.5</asmVersion> <asmVersion>9.5</asmVersion>
<slf4jVersion>1.7.36</slf4jVersion> <slf4jVersion>1.7.36</slf4jVersion>
@ -377,6 +377,11 @@ under the License.
<artifactId>maven-resolver-transport-http</artifactId> <artifactId>maven-resolver-transport-http</artifactId>
<version>${resolverVersion}</version> <version>${resolverVersion}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-jdk</artifactId>
<version>${resolverVersion}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.maven.resolver</groupId> <groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-wagon</artifactId> <artifactId>maven-resolver-transport-wagon</artifactId>