-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
5 changed files
with
208 additions
and
7 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
.../src/main/java/org/eclipse/aether/internal/impl/version/DefaultVersionSchemeSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../src/main/java/org/eclipse/aether/internal/impl/version/GenericVersionSchemeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/version/VersionSchemeSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters