Skip to content

Commit

Permalink
[MRESOLVER-446] Introduce version scheme selector (#384)
Browse files Browse the repository at this point in the history
Open the gates to support multiple version schemes (currently per session).

---

https://issues.apache.org/jira/browse/MRESOLVER-446
  • Loading branch information
cstamas authored Dec 4, 2023
1 parent a2a0e17 commit ddf5534
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
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;
Expand All @@ -120,6 +122,7 @@
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;
Expand Down Expand Up @@ -438,8 +441,14 @@ protected MetadataResolver getMetadataResolver(
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
Expand Down Expand Up @@ -484,10 +493,14 @@ protected VersionRangeResolver getVersionRangeResolver(
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() {
Expand Down Expand Up @@ -581,11 +594,12 @@ public RepositorySystem get() {
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);
Expand Down
1 change: 1 addition & 0 deletions src/site/markdown/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"` | | No | Session Configuration |
| 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`.
Expand Down

0 comments on commit ddf5534

Please sign in to comment.