get rid of deprecated usage of maven resolver (#10495)

Signed-off-by: Olivier Lamy <olamy@apache.org>
This commit is contained in:
Olivier Lamy 2023-09-13 13:43:47 +10:00 committed by GitHub
parent 4bbfa3949b
commit 28f19a5592
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 28 deletions

View File

@ -106,7 +106,7 @@
<logback.version>1.4.9</logback.version>
<mariadb.version>3.1.4</mariadb.version>
<mariadb.docker.version>10.3.6</mariadb.docker.version>
<maven.deps.version>3.9.0</maven.deps.version>
<maven.deps.version>3.9.4</maven.deps.version>
<maven-build-cache.version>1.0.1</maven-build-cache.version>
<maven-artifact-transfer.version>0.13.1</maven-artifact-transfer.version>
<maven.resolver.version>1.9.15</maven.resolver.version>

View File

@ -52,6 +52,11 @@
<artifactId>maven-resolver-spi</artifactId>
<version>${maven.resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-supplier</artifactId>
<version>${maven.resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-impl</artifactId>

View File

@ -42,6 +42,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import org.apache.maven.model.building.ModelBuilder;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.awaitility.core.ConditionTimeoutException;
import org.codehaus.plexus.util.StringUtils;
@ -52,18 +53,16 @@ import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
import org.eclipse.aether.impl.DefaultServiceLocator;
import org.eclipse.aether.impl.RemoteRepositoryManager;
import org.eclipse.aether.impl.UpdatePolicyAnalyzer;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
import org.eclipse.aether.spi.connector.transport.TransporterFactory;
import org.eclipse.aether.spi.connector.checksum.ChecksumPolicyProvider;
import org.eclipse.aether.supplier.RepositorySystemSupplier;
import org.eclipse.aether.transfer.AbstractTransferListener;
import org.eclipse.aether.transport.file.FileTransporterFactory;
import org.eclipse.aether.transport.http.HttpTransporterFactory;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
@ -118,6 +117,8 @@ public class JettyHomeTester
private final Config config;
private JettyHomeTestsRepositorySystemSupplier jettyHomeTestsRepositorySystemSupplier = new JettyHomeTestsRepositorySystemSupplier();
private JettyHomeTester(Config config)
{
this.config = config;
@ -254,7 +255,7 @@ public class JettyHomeTester
*/
public File resolveArtifact(String coordinates) throws ArtifactResolutionException
{
RepositorySystem repositorySystem = newRepositorySystem();
RepositorySystem repositorySystem = this.jettyHomeTestsRepositorySystemSupplier.get();
Artifact artifact = new DefaultArtifact(coordinates);
@ -368,26 +369,6 @@ public class JettyHomeTester
return home;
}
private RepositorySystem newRepositorySystem()
{
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
locator.addService(TransporterFactory.class, FileTransporterFactory.class);
locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
locator.setErrorHandler(new DefaultServiceLocator.ErrorHandler()
{
@Override
public void serviceCreationFailed(Class<?> type, Class<?> impl, Throwable exception)
{
LOGGER.warn("Service creation failed for {} implementation {}: {}",
type, impl, exception.getMessage(), exception);
}
});
return locator.getService(RepositorySystem.class);
}
private List<RemoteRepository> newRepositories()
{
List<RemoteRepository> remoteRepositories = new ArrayList<>(config.mavenRemoteRepositories.size() + 1);
@ -831,4 +812,27 @@ public class JettyHomeTester
return tester;
}
}
private static class JettyHomeTestsRepositorySystemSupplier extends RepositorySystemSupplier
{
ModelBuilder modelBuilder;
RemoteRepositoryManager remoteRepositoryManager;
@Override
protected ModelBuilder getModelBuilder()
{
modelBuilder = super.getModelBuilder();
return modelBuilder;
}
@Override
protected RemoteRepositoryManager getRemoteRepositoryManager(
UpdatePolicyAnalyzer updatePolicyAnalyzer, ChecksumPolicyProvider checksumPolicyProvider)
{
remoteRepositoryManager = super.getRemoteRepositoryManager(updatePolicyAnalyzer, checksumPolicyProvider);
return remoteRepositoryManager;
}
}
}