From 249c94ce67fd5935d7affc13864106bcac3123a2 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 2 Aug 2023 15:37:04 +0200 Subject: [PATCH] [MRESOLVER-387] New RepositorySystem supplier (#319) Added a new module that provides RepositorySystem supplier. To complete RepositorySystem instance, one needs some of Maven dependencies as well, hence the new module. The supplier provides non intrusive lightweight replacement for ServiceLocator. Changes: * new module with supplier * add new booter to demos using supplier (and make it default, instead of SL) * align Maven version used across "demo" and new module (fix demo guice module for that) * update javadoc of deprecated SL --- https://issues.apache.org/jira/browse/MRESOLVER-387 --- .../maven-resolver-demo-snippets/pom.xml | 4 + .../examples/guice/DemoResolverModule.java | 7 + .../SupplierRepositorySystemFactory.java | 31 + .../maven/resolver/examples/util/Booter.java | 7 +- .../examples/AllResolverDemosTest.java | 5 + maven-resolver-demos/pom.xml | 5 - .../aether/impl/DefaultServiceLocator.java | 3 +- .../org/eclipse/aether/impl/package-info.java | 2 +- .../eclipse/aether/spi/locator/Service.java | 3 +- .../aether/spi/locator/ServiceLocator.java | 3 +- .../aether/spi/locator/package-info.java | 5 +- maven-resolver-supplier/README.md | 56 ++ maven-resolver-supplier/pom.xml | 148 ++++ .../supplier/RepositorySystemSupplier.java | 645 ++++++++++++++++++ .../RepositorySystemSupplierTest.java | 68 ++ pom.xml | 8 + 16 files changed, 988 insertions(+), 12 deletions(-) create mode 100644 maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/supplier/SupplierRepositorySystemFactory.java create mode 100644 maven-resolver-supplier/README.md create mode 100644 maven-resolver-supplier/pom.xml create mode 100644 maven-resolver-supplier/src/main/java/org/eclipse/aether/supplier/RepositorySystemSupplier.java create mode 100644 maven-resolver-supplier/src/test/java/org/eclipse/aether/supplier/RepositorySystemSupplierTest.java diff --git a/maven-resolver-demos/maven-resolver-demo-snippets/pom.xml b/maven-resolver-demos/maven-resolver-demo-snippets/pom.xml index 7364a4a92..f4c34e50a 100644 --- a/maven-resolver-demos/maven-resolver-demo-snippets/pom.xml +++ b/maven-resolver-demos/maven-resolver-demo-snippets/pom.xml @@ -65,6 +65,10 @@ org.apache.maven.resolver maven-resolver-transport-http + + org.apache.maven.resolver + maven-resolver-supplier + org.apache.maven maven-resolver-provider diff --git a/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/guice/DemoResolverModule.java b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/guice/DemoResolverModule.java index c382e7480..155d0ef51 100644 --- a/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/guice/DemoResolverModule.java +++ b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/guice/DemoResolverModule.java @@ -32,8 +32,10 @@ import org.apache.maven.model.building.DefaultModelBuilderFactory; import org.apache.maven.model.building.ModelBuilder; import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader; +import org.apache.maven.repository.internal.DefaultModelCacheFactory; import org.apache.maven.repository.internal.DefaultVersionRangeResolver; import org.apache.maven.repository.internal.DefaultVersionResolver; +import org.apache.maven.repository.internal.ModelCacheFactory; import org.apache.maven.repository.internal.SnapshotMetadataGeneratorFactory; import org.apache.maven.repository.internal.VersionsMetadataGeneratorFactory; import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory; @@ -142,4 +144,9 @@ Set provideMetadataGeneratorFactories( ModelBuilder provideModelBuilder() { return new DefaultModelBuilderFactory().newInstance(); } + + @Provides + ModelCacheFactory provideModelCacheFactory() { + return new DefaultModelCacheFactory(); + } } diff --git a/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/supplier/SupplierRepositorySystemFactory.java b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/supplier/SupplierRepositorySystemFactory.java new file mode 100644 index 000000000..a649322bd --- /dev/null +++ b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/supplier/SupplierRepositorySystemFactory.java @@ -0,0 +1,31 @@ +/* + * 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.resolver.examples.supplier; + +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.supplier.RepositorySystemSupplier; + +/** + * A factory for repository system instances that employs Maven Artifact Resolver's provided supplier. + */ +public class SupplierRepositorySystemFactory { + public static RepositorySystem newRepositorySystem() { + return new RepositorySystemSupplier().get(); + } +} diff --git a/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/util/Booter.java b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/util/Booter.java index 2744650b6..e650786d6 100644 --- a/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/util/Booter.java +++ b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/util/Booter.java @@ -36,6 +36,8 @@ public class Booter { public static final String SERVICE_LOCATOR = "serviceLocator"; + public static final String SUPPLIER = "supplier"; + public static final String GUICE = "guice"; public static final String SISU = "sisu"; @@ -44,7 +46,7 @@ public class Booter { public static String selectFactory(String[] args) { if (args == null || args.length == 0) { - return SERVICE_LOCATOR; + return SUPPLIER; } else { return args[0]; } @@ -54,6 +56,9 @@ public static RepositorySystem newRepositorySystem(final String factory) { switch (factory) { case SERVICE_LOCATOR: return org.apache.maven.resolver.examples.manual.ManualRepositorySystemFactory.newRepositorySystem(); + case SUPPLIER: + return org.apache.maven.resolver.examples.supplier.SupplierRepositorySystemFactory + .newRepositorySystem(); case GUICE: return org.apache.maven.resolver.examples.guice.GuiceRepositorySystemFactory.newRepositorySystem(); case SISU: diff --git a/maven-resolver-demos/maven-resolver-demo-snippets/src/test/java/org/apache/maven/resolver/examples/AllResolverDemosTest.java b/maven-resolver-demos/maven-resolver-demo-snippets/src/test/java/org/apache/maven/resolver/examples/AllResolverDemosTest.java index 40024aec4..ef31f936b 100644 --- a/maven-resolver-demos/maven-resolver-demo-snippets/src/test/java/org/apache/maven/resolver/examples/AllResolverDemosTest.java +++ b/maven-resolver-demos/maven-resolver-demo-snippets/src/test/java/org/apache/maven/resolver/examples/AllResolverDemosTest.java @@ -30,6 +30,11 @@ public void serviceLocator() throws Exception { AllResolverDemos.main(new String[] {Booter.SERVICE_LOCATOR}); } + @Test + public void supplier() throws Exception { + AllResolverDemos.main(new String[] {Booter.SUPPLIER}); + } + @Test public void guice() throws Exception { AllResolverDemos.main(new String[] {Booter.GUICE}); diff --git a/maven-resolver-demos/pom.xml b/maven-resolver-demos/pom.xml index ebbcc92b5..49a7a267a 100644 --- a/maven-resolver-demos/pom.xml +++ b/maven-resolver-demos/pom.xml @@ -37,11 +37,6 @@ maven-resolver-demo-maven-plugin - - - 3.8.7 - - diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/DefaultServiceLocator.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/DefaultServiceLocator.java index 0c8f7598f..4f96f227f 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/DefaultServiceLocator.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/DefaultServiceLocator.java @@ -87,7 +87,8 @@ * Note: This class is not thread-safe. Clients are expected to create the service locator and the repository * system on a single thread. * - * @deprecated Use some out-of-the-box DI implementation instead. + * @deprecated Use of out-of-the-box DI implementation recommended, or, as alternative new supplier from + * module {@code maven-resolver-supplier}. */ @Deprecated public final class DefaultServiceLocator implements ServiceLocator { diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/package-info.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/package-info.java index 7c7344f06..7c61005e1 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/package-info.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/package-info.java @@ -18,7 +18,7 @@ * under the License. */ /** - * The provisional interfaces defining the various sub components that implement the repository system. Aether Core + * The provisional interfaces defining the various subcomponents that implement the repository system. Aether Core * provides stock implementations for most of these components but not all. To obtain a complete/runnable repository * system, the application needs to provide implementations of the following component contracts: * {@link org.eclipse.aether.impl.ArtifactDescriptorReader}, {@link org.eclipse.aether.impl.VersionResolver}, diff --git a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/locator/Service.java b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/locator/Service.java index dcdf2c503..077c7662d 100644 --- a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/locator/Service.java +++ b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/locator/Service.java @@ -23,7 +23,8 @@ * means to programmatically wire the several components of the repository system together when it is used outside of an * IoC container. * - * @deprecated Use some out-of-the-box DI implementation instead. + * @deprecated Use of out-of-the-box DI implementation recommended, or, as alternative new supplier from + * module {@code maven-resolver-supplier}. */ @Deprecated public interface Service { diff --git a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/locator/ServiceLocator.java b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/locator/ServiceLocator.java index 5de51268a..ac2f34a60 100644 --- a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/locator/ServiceLocator.java +++ b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/locator/ServiceLocator.java @@ -32,7 +32,8 @@ * to acquire the repository system. Components that implement {@link Service} will be given an opportunity to acquire * further components from the locator, thereby allowing to create the complete object graph of the repository system. * - * @deprecated Use some out-of-the-box DI implementation instead. + * @deprecated Use of out-of-the-box DI implementation recommended, or, as alternative new supplier from + * module {@code maven-resolver-supplier}. */ @Deprecated public interface ServiceLocator { diff --git a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/locator/package-info.java b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/locator/package-info.java index e3d149387..75c08b6c8 100644 --- a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/locator/package-info.java +++ b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/locator/package-info.java @@ -19,7 +19,7 @@ */ /** * A lightweight service locator infrastructure to help components acquire dependent components. The implementation of - * the repository system is decomposed into many sub components that interact with each other via interfaces, allowing + * the repository system is decomposed into many subcomponents that interact with each other via interfaces, allowing * an application to customize the system by swapping in different implementation classes for these interfaces. The * service locator defined by this package is one means for components to get hold of the proper implementation for its * dependencies. While not the most popular approach to component wiring, this service locator enables applications @@ -27,6 +27,7 @@ * footprint. Therefore, all components should implement {@link org.eclipse.aether.spi.locator.Service} to support this * goal. * - * @deprecated Use some out-of-the-box DI implementation instead. + * @deprecated Use of out-of-the-box DI implementation recommended, or, as alternative new supplier from + * module {@code maven-resolver-supplier}. */ package org.eclipse.aether.spi.locator; diff --git a/maven-resolver-supplier/README.md b/maven-resolver-supplier/README.md new file mode 100644 index 000000000..6b2a023b9 --- /dev/null +++ b/maven-resolver-supplier/README.md @@ -0,0 +1,56 @@ + + +# Maven Resolver Supplier + +This simple module serves the purpose to "bootstrap" resolver when there is no desire to use +[Eclipse Sisu](https://eclipse.dev/sisu/). It provides one simple class +`org.eclipse.aether.supplier.RepositorySystemSupplier` that implements `Supplier` +and supplies ready-to-use `RepositorySystem` instances. + +The supplier class is written in such way, to allow easy customization if needed: just extend the class and override +method one need (all methods are protected). + +Consumer/users of this module **must provide SLF4J backend**. Resolver uses `slf4j-api` for logging purposes, but this +module does NOT provide any backend for it. It is the consumer/user obligation to provide one at runtime. + +Version of `maven-resolver-supplier` artifact used **must be strictly aligned** with other Resolver artifacts +on classpath. + +By default, "full resolver experience" is provided: +* for connector, the connector-basic is provided +* for transport the two transport-file and transport-http implementations are provided. If Wagon is needed, add + transport-wagon as dependency, and customize `RepositorySystemSupplier` to include it. This makes it available, but + NOT used yet! To use it, you still need to configure resolver to favor Wagon over native HTTP. + +# Resolver configuration + +The supplier will provide only a "vanilla" instance. To configure resolver, use session user (or +configuration) properties, when constructing session. All the configuration options are available as +[listed here](https://maven.apache.org/resolver/configuration.html). + +# Extending Resolver + +Extending supplied resolver is simple, and basically requires same three steps for whatever extra you want to include +(like Wagon transport, distributed locking, etc). + +First, you need to include needed module (with transitive deps) to your dependencies. + +Second, you need to customize `RepositorySystemSupplier` to make new components (`WagonTransporterFactory`, or +distributed lock factories) available. + +Third, you need to configure session (via user of config properties) to make Resolver use newly added components. \ No newline at end of file diff --git a/maven-resolver-supplier/pom.xml b/maven-resolver-supplier/pom.xml new file mode 100644 index 000000000..d652bb01f --- /dev/null +++ b/maven-resolver-supplier/pom.xml @@ -0,0 +1,148 @@ + + + + 4.0.0 + + + org.apache.maven.resolver + maven-resolver + 1.9.15-SNAPSHOT + + + maven-resolver-supplier + + Maven Artifact Resolver Instance Supplier + A helper module to provide RepositorySystem instances. + + + org.apache.maven.resolver.supplier + ${Automatic-Module-Name} + + + + + org.apache.maven.resolver + maven-resolver-api + + + org.apache.maven.resolver + maven-resolver-util + + + org.apache.maven.resolver + maven-resolver-spi + + + org.apache.maven.resolver + maven-resolver-named-locks + + + org.apache.maven.resolver + maven-resolver-impl + + + org.apache.maven.resolver + maven-resolver-connector-basic + + + org.apache.maven.resolver + maven-resolver-transport-file + + + org.apache.maven.resolver + maven-resolver-transport-http + + + + org.apache.maven + maven-resolver-provider + ${mavenVersion} + + + javax.inject + javax.inject + + + org.eclipse.sisu + org.eclipse.sisu.inject + + + + + org.apache.maven + maven-model-builder + ${mavenVersion} + + + javax.inject + javax.inject + + + org.eclipse.sisu + org.eclipse.sisu.inject + + + + + + org.slf4j + slf4j-api + + + + org.slf4j + slf4j-simple + test + + + org.hamcrest + hamcrest + test + + + org.hamcrest + hamcrest-core + test + + + junit + junit + test + + + + + + + biz.aQute.bnd + bnd-maven-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + + diff --git a/maven-resolver-supplier/src/main/java/org/eclipse/aether/supplier/RepositorySystemSupplier.java b/maven-resolver-supplier/src/main/java/org/eclipse/aether/supplier/RepositorySystemSupplier.java new file mode 100644 index 000000000..f20023352 --- /dev/null +++ b/maven-resolver-supplier/src/main/java/org/eclipse/aether/supplier/RepositorySystemSupplier.java @@ -0,0 +1,645 @@ +/* + * 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.eclipse.aether.supplier; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.function.Supplier; + +import org.apache.maven.model.building.DefaultModelBuilderFactory; +import org.apache.maven.model.building.ModelBuilder; +import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader; +import org.apache.maven.repository.internal.DefaultModelCacheFactory; +import org.apache.maven.repository.internal.DefaultVersionRangeResolver; +import org.apache.maven.repository.internal.DefaultVersionResolver; +import org.apache.maven.repository.internal.ModelCacheFactory; +import org.apache.maven.repository.internal.PluginsMetadataGeneratorFactory; +import org.apache.maven.repository.internal.SnapshotMetadataGeneratorFactory; +import org.apache.maven.repository.internal.VersionsMetadataGeneratorFactory; +import org.eclipse.aether.RepositoryListener; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory; +import org.eclipse.aether.impl.ArtifactDescriptorReader; +import org.eclipse.aether.impl.ArtifactResolver; +import org.eclipse.aether.impl.DependencyCollector; +import org.eclipse.aether.impl.Deployer; +import org.eclipse.aether.impl.Installer; +import org.eclipse.aether.impl.LocalRepositoryProvider; +import org.eclipse.aether.impl.MetadataGeneratorFactory; +import org.eclipse.aether.impl.MetadataResolver; +import org.eclipse.aether.impl.OfflineController; +import org.eclipse.aether.impl.RemoteRepositoryFilterManager; +import org.eclipse.aether.impl.RemoteRepositoryManager; +import org.eclipse.aether.impl.RepositoryConnectorProvider; +import org.eclipse.aether.impl.RepositoryEventDispatcher; +import org.eclipse.aether.impl.RepositorySystemLifecycle; +import org.eclipse.aether.impl.UpdateCheckManager; +import org.eclipse.aether.impl.UpdatePolicyAnalyzer; +import org.eclipse.aether.impl.VersionRangeResolver; +import org.eclipse.aether.impl.VersionResolver; +import org.eclipse.aether.internal.impl.DefaultArtifactResolver; +import org.eclipse.aether.internal.impl.DefaultChecksumPolicyProvider; +import org.eclipse.aether.internal.impl.DefaultDeployer; +import org.eclipse.aether.internal.impl.DefaultFileProcessor; +import org.eclipse.aether.internal.impl.DefaultInstaller; +import org.eclipse.aether.internal.impl.DefaultLocalPathComposer; +import org.eclipse.aether.internal.impl.DefaultLocalPathPrefixComposerFactory; +import org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider; +import org.eclipse.aether.internal.impl.DefaultMetadataResolver; +import org.eclipse.aether.internal.impl.DefaultOfflineController; +import org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager; +import org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider; +import org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher; +import org.eclipse.aether.internal.impl.DefaultRepositoryLayoutProvider; +import org.eclipse.aether.internal.impl.DefaultRepositorySystem; +import org.eclipse.aether.internal.impl.DefaultRepositorySystemLifecycle; +import org.eclipse.aether.internal.impl.DefaultTrackingFileManager; +import org.eclipse.aether.internal.impl.DefaultTransporterProvider; +import org.eclipse.aether.internal.impl.DefaultUpdateCheckManager; +import org.eclipse.aether.internal.impl.DefaultUpdatePolicyAnalyzer; +import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory; +import org.eclipse.aether.internal.impl.LocalPathComposer; +import org.eclipse.aether.internal.impl.LocalPathPrefixComposerFactory; +import org.eclipse.aether.internal.impl.Maven2RepositoryLayoutFactory; +import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; +import org.eclipse.aether.internal.impl.TrackingFileManager; +import org.eclipse.aether.internal.impl.checksum.DefaultChecksumAlgorithmFactorySelector; +import org.eclipse.aether.internal.impl.checksum.Md5ChecksumAlgorithmFactory; +import org.eclipse.aether.internal.impl.checksum.Sha1ChecksumAlgorithmFactory; +import org.eclipse.aether.internal.impl.checksum.Sha256ChecksumAlgorithmFactory; +import org.eclipse.aether.internal.impl.checksum.Sha512ChecksumAlgorithmFactory; +import org.eclipse.aether.internal.impl.checksum.SparseDirectoryTrustedChecksumsSource; +import org.eclipse.aether.internal.impl.checksum.SummaryFileTrustedChecksumsSource; +import org.eclipse.aether.internal.impl.checksum.TrustedToProvidedChecksumsSourceAdapter; +import org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector; +import org.eclipse.aether.internal.impl.collect.DependencyCollectorDelegate; +import org.eclipse.aether.internal.impl.collect.bf.BfDependencyCollector; +import org.eclipse.aether.internal.impl.collect.df.DfDependencyCollector; +import org.eclipse.aether.internal.impl.filter.DefaultRemoteRepositoryFilterManager; +import org.eclipse.aether.internal.impl.filter.GroupIdRemoteRepositoryFilterSource; +import org.eclipse.aether.internal.impl.filter.PrefixesRemoteRepositoryFilterSource; +import org.eclipse.aether.internal.impl.resolution.TrustedChecksumsArtifactResolverPostProcessor; +import org.eclipse.aether.internal.impl.synccontext.DefaultSyncContextFactory; +import org.eclipse.aether.internal.impl.synccontext.named.NameMapper; +import org.eclipse.aether.internal.impl.synccontext.named.NameMappers; +import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactory; +import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactoryImpl; +import org.eclipse.aether.named.NamedLockFactory; +import org.eclipse.aether.named.providers.FileLockNamedLockFactory; +import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory; +import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory; +import org.eclipse.aether.named.providers.NoopNamedLockFactory; +import org.eclipse.aether.spi.checksums.ProvidedChecksumsSource; +import org.eclipse.aether.spi.checksums.TrustedChecksumsSource; +import org.eclipse.aether.spi.connector.RepositoryConnectorFactory; +import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactory; +import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactorySelector; +import org.eclipse.aether.spi.connector.checksum.ChecksumPolicyProvider; +import org.eclipse.aether.spi.connector.filter.RemoteRepositoryFilterSource; +import org.eclipse.aether.spi.connector.layout.RepositoryLayoutFactory; +import org.eclipse.aether.spi.connector.layout.RepositoryLayoutProvider; +import org.eclipse.aether.spi.connector.transport.TransporterFactory; +import org.eclipse.aether.spi.connector.transport.TransporterProvider; +import org.eclipse.aether.spi.io.FileProcessor; +import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory; +import org.eclipse.aether.spi.resolution.ArtifactResolverPostProcessor; +import org.eclipse.aether.spi.synccontext.SyncContextFactory; +import org.eclipse.aether.transport.file.FileTransporterFactory; +import org.eclipse.aether.transport.http.ChecksumExtractor; +import org.eclipse.aether.transport.http.HttpTransporterFactory; +import org.eclipse.aether.transport.http.Nexus2ChecksumExtractor; +import org.eclipse.aether.transport.http.XChecksumChecksumExtractor; + +/** + * A simple {@link Supplier} of {@link org.eclipse.aether.RepositorySystem} instances, that on each call supplies newly + * constructed instance. For proper shut down, use {@link RepositorySystem#shutdown()} method on supplied instance(s). + *

+ * Extend this class and override methods to customize, if needed. + * + * @since 1.9.15 + */ +public class RepositorySystemSupplier implements Supplier { + protected FileProcessor getFileProcessor() { + return new DefaultFileProcessor(); + } + + protected TrackingFileManager getTrackingFileManager() { + return new DefaultTrackingFileManager(); + } + + protected LocalPathComposer getLocalPathComposer() { + return new DefaultLocalPathComposer(); + } + + protected LocalPathPrefixComposerFactory getLocalPathPrefixComposerFactory() { + return new DefaultLocalPathPrefixComposerFactory(); + } + + protected RepositorySystemLifecycle getRepositorySystemLifecycle() { + return new DefaultRepositorySystemLifecycle(); + } + + protected OfflineController getOfflineController() { + return new DefaultOfflineController(); + } + + protected UpdatePolicyAnalyzer getUpdatePolicyAnalyzer() { + return new DefaultUpdatePolicyAnalyzer(); + } + + protected ChecksumPolicyProvider getChecksumPolicyProvider() { + return new DefaultChecksumPolicyProvider(); + } + + protected UpdateCheckManager getUpdateCheckManager( + TrackingFileManager trackingFileManager, UpdatePolicyAnalyzer updatePolicyAnalyzer) { + return new DefaultUpdateCheckManager(trackingFileManager, updatePolicyAnalyzer); + } + + protected Map getNamedLockFactories() { + HashMap result = new HashMap<>(); + result.put(NoopNamedLockFactory.NAME, new NoopNamedLockFactory()); + result.put(LocalReadWriteLockNamedLockFactory.NAME, new LocalReadWriteLockNamedLockFactory()); + result.put(LocalSemaphoreNamedLockFactory.NAME, new LocalSemaphoreNamedLockFactory()); + result.put(FileLockNamedLockFactory.NAME, new FileLockNamedLockFactory()); + return result; + } + + protected Map getNameMappers() { + HashMap result = new HashMap<>(); + result.put(NameMappers.STATIC_NAME, NameMappers.staticNameMapper()); + result.put(NameMappers.GAV_NAME, NameMappers.gavNameMapper()); + result.put(NameMappers.DISCRIMINATING_NAME, NameMappers.discriminatingNameMapper()); + result.put(NameMappers.FILE_GAV_NAME, NameMappers.fileGavNameMapper()); + result.put(NameMappers.FILE_HGAV_NAME, NameMappers.fileHashingGavNameMapper()); + return result; + } + + protected NamedLockFactoryAdapterFactory getNamedLockFactoryAdapterFactory( + Map namedLockFactories, + Map nameMappers, + RepositorySystemLifecycle repositorySystemLifecycle) { + return new NamedLockFactoryAdapterFactoryImpl(namedLockFactories, nameMappers, repositorySystemLifecycle); + } + + protected SyncContextFactory getSyncContextFactory(NamedLockFactoryAdapterFactory namedLockFactoryAdapterFactory) { + return new DefaultSyncContextFactory(namedLockFactoryAdapterFactory); + } + + protected Map getChecksumAlgorithmFactories() { + HashMap result = new HashMap<>(); + result.put(Sha512ChecksumAlgorithmFactory.NAME, new Sha512ChecksumAlgorithmFactory()); + result.put(Sha256ChecksumAlgorithmFactory.NAME, new Sha256ChecksumAlgorithmFactory()); + result.put(Sha1ChecksumAlgorithmFactory.NAME, new Sha1ChecksumAlgorithmFactory()); + result.put(Md5ChecksumAlgorithmFactory.NAME, new Md5ChecksumAlgorithmFactory()); + return result; + } + + protected ChecksumAlgorithmFactorySelector getChecksumAlgorithmFactorySelector( + Map checksumAlgorithmFactories) { + return new DefaultChecksumAlgorithmFactorySelector(checksumAlgorithmFactories); + } + + protected Map getRepositoryLayoutFactories( + ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector) { + HashMap result = new HashMap<>(); + result.put("maven2", new Maven2RepositoryLayoutFactory(checksumAlgorithmFactorySelector)); + return result; + } + + protected RepositoryLayoutProvider getRepositoryLayoutProvider( + Map repositoryLayoutFactories) { + return new DefaultRepositoryLayoutProvider(new HashSet<>(repositoryLayoutFactories.values())); + } + + protected LocalRepositoryProvider getLocalRepositoryProvider( + LocalPathComposer localPathComposer, + TrackingFileManager trackingFileManager, + LocalPathPrefixComposerFactory localPathPrefixComposerFactory) { + HashSet localRepositoryProviders = new HashSet<>(2); + localRepositoryProviders.add(new SimpleLocalRepositoryManagerFactory(localPathComposer)); + localRepositoryProviders.add(new EnhancedLocalRepositoryManagerFactory( + localPathComposer, trackingFileManager, localPathPrefixComposerFactory)); + return new DefaultLocalRepositoryProvider(localRepositoryProviders); + } + + protected RemoteRepositoryManager getRemoteRepositoryManager( + UpdatePolicyAnalyzer updatePolicyAnalyzer, ChecksumPolicyProvider checksumPolicyProvider) { + return new DefaultRemoteRepositoryManager(updatePolicyAnalyzer, checksumPolicyProvider); + } + + protected Map getRemoteRepositoryFilterSources( + RepositorySystemLifecycle repositorySystemLifecycle, RepositoryLayoutProvider repositoryLayoutProvider) { + HashMap result = new HashMap<>(); + result.put( + GroupIdRemoteRepositoryFilterSource.NAME, + new GroupIdRemoteRepositoryFilterSource(repositorySystemLifecycle)); + result.put( + PrefixesRemoteRepositoryFilterSource.NAME, + new PrefixesRemoteRepositoryFilterSource(repositoryLayoutProvider)); + return result; + } + + protected RemoteRepositoryFilterManager getRemoteRepositoryFilterManager( + Map remoteRepositoryFilterSources) { + return new DefaultRemoteRepositoryFilterManager(remoteRepositoryFilterSources); + } + + protected Map getRepositoryListeners() { + return new HashMap<>(); + } + + protected RepositoryEventDispatcher getRepositoryEventDispatcher( + Map repositoryListeners) { + return new DefaultRepositoryEventDispatcher(new HashSet<>(repositoryListeners.values())); + } + + protected Map getTrustedChecksumsSources( + FileProcessor fileProcessor, + LocalPathComposer localPathComposer, + RepositorySystemLifecycle repositorySystemLifecycle) { + HashMap result = new HashMap<>(); + result.put( + SparseDirectoryTrustedChecksumsSource.NAME, + new SparseDirectoryTrustedChecksumsSource(fileProcessor, localPathComposer)); + result.put( + SummaryFileTrustedChecksumsSource.NAME, + new SummaryFileTrustedChecksumsSource(localPathComposer, repositorySystemLifecycle)); + return result; + } + + protected Map getProvidedChecksumsSources( + Map trustedChecksumsSources) { + HashMap result = new HashMap<>(); + result.put( + TrustedToProvidedChecksumsSourceAdapter.NAME, + new TrustedToProvidedChecksumsSourceAdapter(trustedChecksumsSources)); + return result; + } + + protected Map getChecksumExtractors() { + HashMap result = new HashMap<>(); + result.put(Nexus2ChecksumExtractor.NAME, new Nexus2ChecksumExtractor()); + result.put(XChecksumChecksumExtractor.NAME, new XChecksumChecksumExtractor()); + return result; + } + + protected Map getTransporterFactories(Map extractors) { + HashMap result = new HashMap<>(); + result.put("file", new FileTransporterFactory()); + result.put("http", new HttpTransporterFactory(extractors)); + return result; + } + + protected TransporterProvider getTransporterProvider(Map transporterFactories) { + return new DefaultTransporterProvider(new HashSet<>(transporterFactories.values())); + } + + protected BasicRepositoryConnectorFactory getBasicRepositoryConnectorFactory( + TransporterProvider transporterProvider, + RepositoryLayoutProvider repositoryLayoutProvider, + ChecksumPolicyProvider checksumPolicyProvider, + FileProcessor fileProcessor, + Map providedChecksumsSources) { + return new BasicRepositoryConnectorFactory( + transporterProvider, + repositoryLayoutProvider, + checksumPolicyProvider, + fileProcessor, + providedChecksumsSources); + } + + protected Map getRepositoryConnectorFactories( + BasicRepositoryConnectorFactory basicRepositoryConnectorFactory) { + HashMap result = new HashMap<>(); + result.put("basic", basicRepositoryConnectorFactory); + return result; + } + + protected RepositoryConnectorProvider getRepositoryConnectorProvider( + Map repositoryConnectorFactories, + RemoteRepositoryFilterManager remoteRepositoryFilterManager) { + return new DefaultRepositoryConnectorProvider( + new HashSet<>(repositoryConnectorFactories.values()), remoteRepositoryFilterManager); + } + + protected Installer getInstaller( + FileProcessor fileProcessor, + RepositoryEventDispatcher repositoryEventDispatcher, + Map metadataGeneratorFactories, + SyncContextFactory syncContextFactory) { + return new DefaultInstaller( + fileProcessor, + repositoryEventDispatcher, + new HashSet<>(metadataGeneratorFactories.values()), + syncContextFactory); + } + + @SuppressWarnings("checkstyle:parameternumber") + protected Deployer getDeployer( + FileProcessor fileProcessor, + RepositoryEventDispatcher repositoryEventDispatcher, + RepositoryConnectorProvider repositoryConnectorProvider, + RemoteRepositoryManager remoteRepositoryManager, + UpdateCheckManager updateCheckManager, + Map metadataGeneratorFactories, + SyncContextFactory syncContextFactory, + OfflineController offlineController) { + return new DefaultDeployer( + fileProcessor, + repositoryEventDispatcher, + repositoryConnectorProvider, + remoteRepositoryManager, + updateCheckManager, + new HashSet<>(metadataGeneratorFactories.values()), + syncContextFactory, + offlineController); + } + + protected Map getDependencyCollectorDelegates( + RemoteRepositoryManager remoteRepositoryManager, + ArtifactDescriptorReader artifactDescriptorReader, + VersionRangeResolver versionRangeResolver) { + HashMap result = new HashMap<>(); + result.put( + DfDependencyCollector.NAME, + new DfDependencyCollector(remoteRepositoryManager, artifactDescriptorReader, versionRangeResolver)); + result.put( + BfDependencyCollector.NAME, + new BfDependencyCollector(remoteRepositoryManager, artifactDescriptorReader, versionRangeResolver)); + return result; + } + + protected DependencyCollector getDependencyCollector( + Map dependencyCollectorDelegates) { + return new DefaultDependencyCollector(dependencyCollectorDelegates); + } + + protected Map getArtifactResolverPostProcessors( + ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector, + Map trustedChecksumsSources) { + HashMap result = new HashMap<>(); + result.put( + TrustedChecksumsArtifactResolverPostProcessor.NAME, + new TrustedChecksumsArtifactResolverPostProcessor( + checksumAlgorithmFactorySelector, trustedChecksumsSources)); + return result; + } + + @SuppressWarnings("checkstyle:parameternumber") + protected ArtifactResolver getArtifactResolver( + FileProcessor fileProcessor, + RepositoryEventDispatcher repositoryEventDispatcher, + VersionResolver versionResolver, + UpdateCheckManager updateCheckManager, + RepositoryConnectorProvider repositoryConnectorProvider, + RemoteRepositoryManager remoteRepositoryManager, + SyncContextFactory syncContextFactory, + OfflineController offlineController, + Map artifactResolverPostProcessors, + RemoteRepositoryFilterManager remoteRepositoryFilterManager) { + return new DefaultArtifactResolver( + fileProcessor, + repositoryEventDispatcher, + versionResolver, + updateCheckManager, + repositoryConnectorProvider, + remoteRepositoryManager, + syncContextFactory, + offlineController, + artifactResolverPostProcessors, + remoteRepositoryFilterManager); + } + + protected MetadataResolver getMetadataResolver( + RepositoryEventDispatcher repositoryEventDispatcher, + UpdateCheckManager updateCheckManager, + RepositoryConnectorProvider repositoryConnectorProvider, + RemoteRepositoryManager remoteRepositoryManager, + SyncContextFactory syncContextFactory, + OfflineController offlineController, + RemoteRepositoryFilterManager remoteRepositoryFilterManager) { + return new DefaultMetadataResolver( + repositoryEventDispatcher, + updateCheckManager, + repositoryConnectorProvider, + remoteRepositoryManager, + syncContextFactory, + offlineController, + remoteRepositoryFilterManager); + } + + // Maven provided + + protected Map getMetadataGeneratorFactories() { + // from maven-resolver-provider + HashMap result = new HashMap<>(); + result.put("plugins", new PluginsMetadataGeneratorFactory()); + result.put("versions", new VersionsMetadataGeneratorFactory()); + result.put("snapshot", new SnapshotMetadataGeneratorFactory()); + return result; + } + + protected ArtifactDescriptorReader getArtifactDescriptorReader( + RemoteRepositoryManager remoteRepositoryManager, + VersionResolver versionResolver, + VersionRangeResolver versionRangeResolver, + ArtifactResolver artifactResolver, + ModelBuilder modelBuilder, + RepositoryEventDispatcher repositoryEventDispatcher, + ModelCacheFactory modelCacheFactory) { + // from maven-resolver-provider + DefaultArtifactDescriptorReader result = new DefaultArtifactDescriptorReader(); + result.setRemoteRepositoryManager(remoteRepositoryManager); + result.setVersionResolver(versionResolver); + result.setVersionRangeResolver(versionRangeResolver); + result.setArtifactResolver(artifactResolver); + result.setModelBuilder(modelBuilder); + result.setRepositoryEventDispatcher(repositoryEventDispatcher); + result.setModelCacheFactory(modelCacheFactory); + return result; + } + + protected VersionResolver getVersionResolver( + MetadataResolver metadataResolver, + SyncContextFactory syncContextFactory, + RepositoryEventDispatcher repositoryEventDispatcher) { + // from maven-resolver-provider + DefaultVersionResolver result = new DefaultVersionResolver(); + result.setMetadataResolver(metadataResolver); + result.setSyncContextFactory(syncContextFactory); + result.setRepositoryEventDispatcher(repositoryEventDispatcher); + return result; + } + + protected VersionRangeResolver getVersionRangeResolver( + MetadataResolver metadataResolver, + SyncContextFactory syncContextFactory, + RepositoryEventDispatcher repositoryEventDispatcher) { + // from maven-resolver-provider + DefaultVersionRangeResolver result = new DefaultVersionRangeResolver(); + result.setMetadataResolver(metadataResolver); + result.setSyncContextFactory(syncContextFactory); + result.setRepositoryEventDispatcher(repositoryEventDispatcher); + return result; + } + + protected ModelBuilder getModelBuilder() { + // from maven-model-builder + return new DefaultModelBuilderFactory().newInstance(); + } + + protected ModelCacheFactory getModelCacheFactory() { + // from maven-resolver-provider + return new DefaultModelCacheFactory(); + } + + @Override + public RepositorySystem get() { + FileProcessor fileProcessor = getFileProcessor(); + TrackingFileManager trackingFileManager = getTrackingFileManager(); + LocalPathComposer localPathComposer = getLocalPathComposer(); + LocalPathPrefixComposerFactory localPathPrefixComposerFactory = getLocalPathPrefixComposerFactory(); + RepositorySystemLifecycle repositorySystemLifecycle = getRepositorySystemLifecycle(); + OfflineController offlineController = getOfflineController(); + UpdatePolicyAnalyzer updatePolicyAnalyzer = getUpdatePolicyAnalyzer(); + ChecksumPolicyProvider checksumPolicyProvider = getChecksumPolicyProvider(); + + UpdateCheckManager updateCheckManager = getUpdateCheckManager(trackingFileManager, updatePolicyAnalyzer); + + Map namedLockFactories = getNamedLockFactories(); + Map nameMappers = getNameMappers(); + NamedLockFactoryAdapterFactory namedLockFactoryAdapterFactory = + getNamedLockFactoryAdapterFactory(namedLockFactories, nameMappers, repositorySystemLifecycle); + SyncContextFactory syncContextFactory = getSyncContextFactory(namedLockFactoryAdapterFactory); + + Map checksumAlgorithmFactories = getChecksumAlgorithmFactories(); + ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector = + getChecksumAlgorithmFactorySelector(checksumAlgorithmFactories); + + Map repositoryLayoutFactories = + getRepositoryLayoutFactories(checksumAlgorithmFactorySelector); + RepositoryLayoutProvider repositoryLayoutProvider = getRepositoryLayoutProvider(repositoryLayoutFactories); + + LocalRepositoryProvider localRepositoryProvider = + getLocalRepositoryProvider(localPathComposer, trackingFileManager, localPathPrefixComposerFactory); + + RemoteRepositoryManager remoteRepositoryManager = + getRemoteRepositoryManager(updatePolicyAnalyzer, checksumPolicyProvider); + Map remoteRepositoryFilterSources = + getRemoteRepositoryFilterSources(repositorySystemLifecycle, repositoryLayoutProvider); + RemoteRepositoryFilterManager remoteRepositoryFilterManager = + getRemoteRepositoryFilterManager(remoteRepositoryFilterSources); + + Map repositoryListeners = getRepositoryListeners(); + RepositoryEventDispatcher repositoryEventDispatcher = getRepositoryEventDispatcher(repositoryListeners); + + Map trustedChecksumsSources = + getTrustedChecksumsSources(fileProcessor, localPathComposer, repositorySystemLifecycle); + Map providedChecksumsSources = + getProvidedChecksumsSources(trustedChecksumsSources); + + Map checksumExtractors = getChecksumExtractors(); + Map transporterFactories = getTransporterFactories(checksumExtractors); + TransporterProvider transporterProvider = getTransporterProvider(transporterFactories); + + BasicRepositoryConnectorFactory basic = getBasicRepositoryConnectorFactory( + transporterProvider, + repositoryLayoutProvider, + checksumPolicyProvider, + fileProcessor, + providedChecksumsSources); + Map repositoryConnectorFactories = getRepositoryConnectorFactories(basic); + RepositoryConnectorProvider repositoryConnectorProvider = + getRepositoryConnectorProvider(repositoryConnectorFactories, remoteRepositoryFilterManager); + + Map metadataGeneratorFactories = getMetadataGeneratorFactories(); + + Installer installer = + getInstaller(fileProcessor, repositoryEventDispatcher, metadataGeneratorFactories, syncContextFactory); + Deployer deployer = getDeployer( + fileProcessor, + repositoryEventDispatcher, + repositoryConnectorProvider, + remoteRepositoryManager, + updateCheckManager, + metadataGeneratorFactories, + syncContextFactory, + offlineController); + + MetadataResolver metadataResolver = getMetadataResolver( + repositoryEventDispatcher, + updateCheckManager, + repositoryConnectorProvider, + remoteRepositoryManager, + syncContextFactory, + offlineController, + remoteRepositoryFilterManager); + + VersionResolver versionResolver = + getVersionResolver(metadataResolver, syncContextFactory, repositoryEventDispatcher); + VersionRangeResolver versionRangeResolver = + getVersionRangeResolver(metadataResolver, syncContextFactory, repositoryEventDispatcher); + + Map artifactResolverPostProcessors = + getArtifactResolverPostProcessors(checksumAlgorithmFactorySelector, trustedChecksumsSources); + ArtifactResolver artifactResolver = getArtifactResolver( + fileProcessor, + repositoryEventDispatcher, + versionResolver, + updateCheckManager, + repositoryConnectorProvider, + remoteRepositoryManager, + syncContextFactory, + offlineController, + artifactResolverPostProcessors, + remoteRepositoryFilterManager); + + ModelBuilder modelBuilder = getModelBuilder(); + ModelCacheFactory modelCacheFactory = getModelCacheFactory(); + + ArtifactDescriptorReader artifactDescriptorReader = getArtifactDescriptorReader( + remoteRepositoryManager, + versionResolver, + versionRangeResolver, + artifactResolver, + modelBuilder, + repositoryEventDispatcher, + modelCacheFactory); + + Map dependencyCollectorDelegates = getDependencyCollectorDelegates( + remoteRepositoryManager, artifactDescriptorReader, versionRangeResolver); + DependencyCollector dependencyCollector = getDependencyCollector(dependencyCollectorDelegates); + + return new DefaultRepositorySystem( + versionResolver, + versionRangeResolver, + artifactResolver, + metadataResolver, + artifactDescriptorReader, + dependencyCollector, + installer, + deployer, + localRepositoryProvider, + syncContextFactory, + remoteRepositoryManager, + repositorySystemLifecycle); + } +} diff --git a/maven-resolver-supplier/src/test/java/org/eclipse/aether/supplier/RepositorySystemSupplierTest.java b/maven-resolver-supplier/src/test/java/org/eclipse/aether/supplier/RepositorySystemSupplierTest.java new file mode 100644 index 000000000..ffedd07ca --- /dev/null +++ b/maven-resolver-supplier/src/test/java/org/eclipse/aether/supplier/RepositorySystemSupplierTest.java @@ -0,0 +1,68 @@ +/* + * 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.eclipse.aether.supplier; + +import java.util.Collections; +import java.util.List; + +import org.apache.maven.repository.internal.MavenRepositorySystemUtils; +import org.eclipse.aether.DefaultRepositorySystemSession; +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.repository.LocalRepository; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.VersionRangeRequest; +import org.eclipse.aether.resolution.VersionRangeResult; +import org.eclipse.aether.version.Version; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasSize; + +public class RepositorySystemSupplierTest { + private final RepositorySystemSupplier subject = new RepositorySystemSupplier(); + + public static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system) { + DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); + LocalRepository localRepo = new LocalRepository("target/local-repo"); + session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo)); + return session; + } + + @Test + public void smoke() throws Exception { + RepositorySystem system = subject.get(); + RepositorySystemSession session = newRepositorySystemSession(system); + + Artifact artifact = new DefaultArtifact("org.apache.maven.resolver:maven-resolver-util:[0,)"); + VersionRangeRequest rangeRequest = new VersionRangeRequest(); + rangeRequest.setArtifact(artifact); + rangeRequest.setRepositories(Collections.singletonList( + new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2/").build())); + VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest); + List versions = rangeResult.getVersions(); + + // As of 2023-08-01, Maven Central has 33 versions of this artifact (and it will just grow) + assertThat(versions, hasSize(greaterThanOrEqualTo(33))); + System.out.println("Available versions " + versions); + } +} diff --git a/pom.xml b/pom.xml index c96433022..e6a65fcbf 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,7 @@ maven-resolver-transport-file maven-resolver-transport-http maven-resolver-transport-wagon + maven-resolver-supplier maven-resolver-demos @@ -91,6 +92,8 @@ 0.3.5 5.1.0 1.7.36 + + 3.9.3 [3.8.7,) [1.8.0-362,) 2023-07-20T09:56:17Z @@ -148,6 +151,11 @@ maven-resolver-transport-wagon ${project.version} + + org.apache.maven.resolver + maven-resolver-supplier + ${project.version} + org.apache.maven.resolver maven-resolver-test-util