This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
The following commit(s) were added to refs/heads/master by this push:
new ddf55342 [MRESOLVER-446] Introduce version scheme selector (#384)
ddf55342 is described below
commit ddf553420b839196d0534158dd1b9b427b99a188
Author: Tamas Cservenak <[email protected]>
AuthorDate: Mon Dec 4 16:50:40 2023 +0100
[MRESOLVER-446] Introduce version scheme selector (#384)
Open the gates to support multiple version schemes (currently per session).
---
https://issues.apache.org/jira/browse/MRESOLVER-446
---
.../impl/version/DefaultVersionSchemeSelector.java | 84 ++++++++++++++++++++++
.../impl/version/GenericVersionSchemeProvider.java | 43 +++++++++++
.../aether/spi/version/VersionSchemeSelector.java | 59 +++++++++++++++
.../aether/supplier/RepositorySystemSupplier.java | 28 ++++++--
src/site/markdown/configuration.md | 1 +
5 files changed, 208 insertions(+), 7 deletions(-)
diff --git
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/version/DefaultVersionSchemeSelector.java
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/version/DefaultVersionSchemeSelector.java
new file mode 100644
index 00000000..2e46f855
--- /dev/null
+++
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/version/DefaultVersionSchemeSelector.java
@@ -0,0 +1,84 @@
+/*
+ * 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.internal.impl.version;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.eclipse.aether.ConfigurationProperties;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.spi.version.VersionSchemeSelector;
+import org.eclipse.aether.util.ConfigUtils;
+import org.eclipse.aether.version.VersionScheme;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Default implementation.
+ *
+ * @since 2.0.0
+ */
+@Singleton
+@Named
+public class DefaultVersionSchemeSelector implements VersionSchemeSelector {
+ static final String CONFIG_PROPS_PREFIX =
ConfigurationProperties.PREFIX_AETHER + "versionScheme.";
+
+ /**
+ * The name of the version scheme to be used in session.
+ *
+ * @configurationSource {@link
RepositorySystemSession#getConfigProperties()}
+ * @configurationType {@link java.lang.String}
+ * @configurationDefaultValue {@link #DEFAULT_VERSION_SCHEME_NAME}
+ */
+ public static final String CONFIG_PROP_VERSION_SCHEME_NAME =
CONFIG_PROPS_PREFIX + "name";
+
+ public static final String DEFAULT_VERSION_SCHEME_NAME =
GenericVersionSchemeProvider.NAME;
+
+ private final Map<String, VersionScheme> versionSchemes;
+
+ @Inject
+ public DefaultVersionSchemeSelector(Map<String, VersionScheme>
versionSchemes) {
+ this.versionSchemes = requireNonNull(versionSchemes);
+ }
+
+ @Override
+ public VersionScheme selectVersionScheme(String schemeName) {
+ requireNonNull(schemeName, "null schemeName");
+ VersionScheme versionScheme = versionSchemes.get(schemeName);
+ if (versionScheme == null) {
+ throw new IllegalArgumentException("scheme not supported");
+ }
+ return versionScheme;
+ }
+
+ @Override
+ public VersionScheme selectVersionScheme(RepositorySystemSession session) {
+ return selectVersionScheme(
+ ConfigUtils.getString(session, DEFAULT_VERSION_SCHEME_NAME,
CONFIG_PROP_VERSION_SCHEME_NAME));
+ }
+
+ @Override
+ public Map<String, VersionScheme> getVersionSchemes() {
+ return Collections.unmodifiableMap(versionSchemes);
+ }
+}
diff --git
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/version/GenericVersionSchemeProvider.java
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/version/GenericVersionSchemeProvider.java
new file mode 100644
index 00000000..0839d66f
--- /dev/null
+++
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/version/GenericVersionSchemeProvider.java
@@ -0,0 +1,43 @@
+/*
+ * 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.internal.impl.version;
+
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import org.eclipse.aether.util.version.GenericVersionScheme;
+import org.eclipse.aether.version.VersionScheme;
+
+/**
+ * Provider of generic version scheme.
+ *
+ * @since 2.0.0
+ */
+@Singleton
+@Named(GenericVersionSchemeProvider.NAME)
+public final class GenericVersionSchemeProvider implements
Provider<VersionScheme> {
+ public static final String NAME = "generic";
+ private final GenericVersionScheme genericVersionScheme = new
GenericVersionScheme();
+
+ @Override
+ public VersionScheme get() {
+ return genericVersionScheme;
+ }
+}
diff --git
a/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/version/VersionSchemeSelector.java
b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/version/VersionSchemeSelector.java
new file mode 100644
index 00000000..c80e1904
--- /dev/null
+++
b/maven-resolver-spi/src/main/java/org/eclipse/aether/spi/version/VersionSchemeSelector.java
@@ -0,0 +1,59 @@
+/*
+ * 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.spi.version;
+
+import java.util.Map;
+
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.version.VersionScheme;
+
+/**
+ * Selects a version scheme from the installed version schemes.
+ *
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @noextend This interface is not intended to be extended by clients.
+ * @since 2.0.0
+ */
+public interface VersionSchemeSelector {
+ /**
+ * Tries to select a version scheme from the specified scheme name.
+ *
+ * @param schemeName The schemeName to select scheme for, must not be
{@code null}.
+ * @return The scheme selected, never {@code null}.
+ * @throws IllegalArgumentException if asked scheme name is not supported.
+ * @throws NullPointerException if passed in names is {@code null}.
+ */
+ VersionScheme selectVersionScheme(String schemeName);
+
+ /**
+ * Tries to select a version scheme from the specified scheme name.
+ *
+ * @param session The repository system session from which to configure
the scheme, must not be {@code null}.
+ * @return The scheme selected, never {@code null}.
+ * @throws IllegalArgumentException If none of the installed schemes
cannot be selected.
+ * @throws NullPointerException if passed in session is {@code null}.
+ */
+ VersionScheme selectVersionScheme(RepositorySystemSession session);
+
+ /**
+ * Returns immutable map of all supported version schemes (maps scheme
name to scheme instance). This represents
+ * ALL the schemes supported by Resolver, either provided out of the box,
or extension installed.
+ */
+ Map<String, VersionScheme> getVersionSchemes();
+}
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
index a30b14ce..2ef5379d 100644
---
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
@@ -100,6 +100,8 @@ 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.internal.impl.version.DefaultVersionSchemeSelector;
+import org.eclipse.aether.internal.impl.version.GenericVersionSchemeProvider;
import org.eclipse.aether.named.NamedLockFactory;
import org.eclipse.aether.named.providers.FileLockNamedLockFactory;
import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
@@ -120,6 +122,7 @@ 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.spi.version.VersionSchemeSelector;
import org.eclipse.aether.transport.apache.ApacheTransporterFactory;
import org.eclipse.aether.transport.file.FileTransporterFactory;
import org.eclipse.aether.util.version.GenericVersionScheme;
@@ -438,8 +441,14 @@ public class RepositorySystemSupplier implements
Supplier<RepositorySystem> {
remoteRepositoryFilterManager);
}
- protected VersionScheme getVersionScheme() {
- return new GenericVersionScheme();
+ protected Map<String, VersionScheme> getVersionSchemes() {
+ HashMap<String, VersionScheme> result = new HashMap<>();
+ result.put(GenericVersionSchemeProvider.NAME, new
GenericVersionScheme());
+ return result;
+ }
+
+ protected VersionSchemeSelector getVersionSchemeSelector(Map<String,
VersionScheme> versionSchemes) {
+ return new DefaultVersionSchemeSelector(versionSchemes);
}
// Maven provided
@@ -484,10 +493,14 @@ public class RepositorySystemSupplier implements
Supplier<RepositorySystem> {
MetadataResolver metadataResolver,
SyncContextFactory syncContextFactory,
RepositoryEventDispatcher repositoryEventDispatcher,
- VersionScheme versionScheme) {
+ VersionSchemeSelector versionSchemeSelector) {
// from maven-resolver-provider
+ // TODO: hack here, until maven bits does not pick this change
return new DefaultVersionRangeResolver(
- metadataResolver, syncContextFactory,
repositoryEventDispatcher, versionScheme);
+ metadataResolver,
+ syncContextFactory,
+ repositoryEventDispatcher,
+
versionSchemeSelector.selectVersionScheme(GenericVersionSchemeProvider.NAME));
}
protected ModelBuilder getModelBuilder() {
@@ -581,11 +594,12 @@ public class RepositorySystemSupplier implements
Supplier<RepositorySystem> {
offlineController,
remoteRepositoryFilterManager);
- VersionScheme versionScheme = getVersionScheme();
+ Map<String, VersionScheme> versionSchemes = getVersionSchemes();
+ VersionSchemeSelector versionSchemeSelector =
getVersionSchemeSelector(versionSchemes);
VersionResolver versionResolver =
getVersionResolver(metadataResolver, syncContextFactory,
repositoryEventDispatcher);
- VersionRangeResolver versionRangeResolver =
- getVersionRangeResolver(metadataResolver, syncContextFactory,
repositoryEventDispatcher, versionScheme);
+ VersionRangeResolver versionRangeResolver = getVersionRangeResolver(
+ metadataResolver, syncContextFactory,
repositoryEventDispatcher, versionSchemeSelector);
Map<String, ArtifactResolverPostProcessor>
artifactResolverPostProcessors =
getArtifactResolverPostProcessors(checksumAlgorithmFactorySelector,
trustedChecksumsSources);
diff --git a/src/site/markdown/configuration.md
b/src/site/markdown/configuration.md
index 34954dca..4a07d985 100644
--- a/src/site/markdown/configuration.md
+++ b/src/site/markdown/configuration.md
@@ -123,6 +123,7 @@ under the License.
| 96. | `"aether.trustedChecksumsSource.summaryFile.basedir"` |
`java.lang.String` | The basedir where checksums are. If relative, is resolved
from local repository root. | `".checksums"` | 1.9.0 | No | Session
Configuration |
| 97. | `"aether.trustedChecksumsSource.summaryFile.originAware"` |
`java.lang.Boolean` | Is source origin aware? | `true` | 1.9.0 | No |
Session Configuration |
| 98. | `"aether.updateCheckManager.sessionState"` | `java.lang.String` |
Manages the session state, i.e. influences if the same download requests to
artifacts/metadata will happen multiple times within the same
RepositorySystemSession. If "enabled" will enable the session state. If
"bypass" will enable bypassing (i.e. store all artifact ids/metadata ids which
have been updates but not evaluating those). All other values lead to disabling
the session state completely. | `"enabled"` | [...]
+| 99. | `"aether.versionScheme.name"` | `java.lang.String` | The name of the
version scheme to be used in session. | `"generic"` | 2.0.0 | No | Session
Configuration |
All properties which have `yes` in the column `Supports Repo ID Suffix` can be
optionally configured specifically for a repository id. In that case the
configuration property needs to be suffixed with a period followed by the
repository id of the repository to configure, e.g.
`aether.connector.http.headers.central` for repository with id `central`.