Skip to content

Commit

Permalink
[MRESOLVER-387] New RepositorySystem supplier (#319)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cstamas authored Aug 2, 2023
1 parent 8f83485 commit 249c94c
Show file tree
Hide file tree
Showing 16 changed files with 988 additions and 12 deletions.
4 changes: 4 additions & 0 deletions maven-resolver-demos/maven-resolver-demo-snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-supplier</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-resolver-provider</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -142,4 +144,9 @@ Set<MetadataGeneratorFactory> provideMetadataGeneratorFactories(
ModelBuilder provideModelBuilder() {
return new DefaultModelBuilderFactory().newInstance();
}

@Provides
ModelCacheFactory provideModelCacheFactory() {
return new DefaultModelCacheFactory();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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];
}
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
5 changes: 0 additions & 5 deletions maven-resolver-demos/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@
<module>maven-resolver-demo-maven-plugin</module>
</modules>

<properties>
<!-- This is somewhat strange, but let's keep this in sync w/ minimalMavenBuildVersion -->
<mavenVersion>3.8.7</mavenVersion>
</properties>

<build>
<pluginManagement>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
* <em>Note:</em> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
*/
/**
* 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
* that do not wish to pull in more sophisticated solutions like dependency injection containers to have a small
* 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;
56 changes: 56 additions & 0 deletions maven-resolver-supplier/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!---
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.
-->

# 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<RepositorySystem>`
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.
148 changes: 148 additions & 0 deletions maven-resolver-supplier/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver</artifactId>
<version>1.9.15-SNAPSHOT</version>
</parent>

<artifactId>maven-resolver-supplier</artifactId>

<name>Maven Artifact Resolver Instance Supplier</name>
<description>A helper module to provide RepositorySystem instances.</description>

<properties>
<Automatic-Module-Name>org.apache.maven.resolver.supplier</Automatic-Module-Name>
<Bundle-SymbolicName>${Automatic-Module-Name}</Bundle-SymbolicName>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-spi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-named-locks</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-impl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-file</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-resolver-provider</artifactId>
<version>${mavenVersion}</version>
<exclusions>
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.inject</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model-builder</artifactId>
<version>${mavenVersion}</version>
<exclusions>
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.inject</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 249c94c

Please sign in to comment.