Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-7974] Update Resolver 2.0.0-alpha-5 #1337

Merged
merged 25 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d61677f
[MNG-7950][MNG-7951] Use VersionSchemeSelector from Resolver 2.0
cstamas Dec 7, 2023
8d2ee8e
Merge remote-tracking branch 'origin/master' into version-scheme-sele…
cstamas Dec 11, 2023
964cf0d
Merge remote-tracking branch 'origin/master' into version-scheme-sele…
cstamas Dec 14, 2023
3c34dfc
Use alpha-5
cstamas Dec 14, 2023
9f32f8a
Merge remote-tracking branch 'origin/master' into version-scheme-sele…
cstamas Dec 15, 2023
da737af
Sort out new API
cstamas Dec 15, 2023
6df760d
Update
cstamas Dec 15, 2023
cd5f2ab
Set up proper parser
cstamas Dec 15, 2023
affbef2
Drop use of plexus container
cstamas Dec 15, 2023
4d3f40d
Move nullchecks to their proper place
cstamas Dec 15, 2023
2c58486
Use service directly
cstamas Dec 15, 2023
a6db4ca
Do not use selector
cstamas Dec 15, 2023
38d5b9e
Make it per session
cstamas Dec 15, 2023
9fe8fe0
Use proper nonnull
cstamas Dec 15, 2023
b438cfa
Merge remote-tracking branch 'origin/master' into version-scheme-sele…
cstamas Dec 16, 2023
2a51421
Move off selector
cstamas Dec 16, 2023
b0a9e56
Move off session as well
cstamas Dec 16, 2023
eed8263
Simplify even more
cstamas Dec 16, 2023
701c247
Undo unneeded changes
cstamas Dec 16, 2023
530cfeb
Resolver 2.0.0-alpha-5 is released.
cstamas Dec 17, 2023
49cec29
Do not use Provider<X> on the injection side when not really required
gnodet Dec 18, 2023
5ce5279
Remove usage of Provider<VersionScheme>
gnodet Dec 18, 2023
88bc6f2
Fix code
gnodet Dec 18, 2023
6ca4861
DefaultConsumerPomBuilder should not be in session scope
gnodet Dec 18, 2023
9199b93
Undo this change
cstamas Dec 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,42 @@
*/
package org.apache.maven.internal.impl;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import java.util.Objects;
import java.util.regex.Pattern;

import org.apache.maven.api.Version;
import org.apache.maven.api.VersionRange;
import org.apache.maven.api.services.VersionParser;
import org.apache.maven.api.services.VersionParserException;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;

import static org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec;
import static org.apache.maven.internal.impl.Utils.nonNull;

/**
* A wrapper class around a resolver version that works as model version parser as well.
*/
@Named
@Singleton
public class DefaultVersionParser implements VersionParser {
private static final String SNAPSHOT = "SNAPSHOT";
private static final Pattern SNAPSHOT_TIMESTAMP = Pattern.compile("^(.*-)?([0-9]{8}\\.[0-9]{6}-[0-9]+)$");

private final org.apache.maven.model.version.VersionParser modelVersionParser;

@Inject
public DefaultVersionParser(org.apache.maven.model.version.VersionParser modelVersionParser) {
this.modelVersionParser = nonNull(modelVersionParser, "modelVersionParser");
}

@Override
public Version parseVersion(String version) {
return new DefaultVersion(new DefaultArtifactVersion(nonNull(version, "version")));
return modelVersionParser.parseVersion(version);
}

@Override
public VersionRange parseVersionRange(String range) {
try {
return new DefaultVersionRange(createFromVersionSpec(nonNull(range, "version")));
} catch (InvalidVersionSpecificationException e) {
throw new VersionParserException("Unable to parse version range: " + range, e);
}
return modelVersionParser.parseVersionRange(range);
}

@Override
Expand All @@ -63,75 +64,4 @@ public boolean isSnapshot(String version) {
static boolean checkSnapshot(String version) {
return version.endsWith(SNAPSHOT) || SNAPSHOT_TIMESTAMP.matcher(version).matches();
}

static class DefaultVersion implements Version {
private final ArtifactVersion delegate;

DefaultVersion(ArtifactVersion delegate) {
this.delegate = delegate;
}

@Override
public int compareTo(Version o) {
if (o instanceof DefaultVersion) {
return delegate.compareTo(((DefaultVersion) o).delegate);
} else {
return delegate.compareTo(new DefaultArtifactVersion(o.toString()));
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DefaultVersion that = (DefaultVersion) o;
return delegate.equals(that.delegate);
}

@Override
public int hashCode() {
return Objects.hash(delegate);
}

@Override
public String asString() {
return delegate.toString();
}

@Override
public String toString() {
return asString();
}
}

static class DefaultVersionRange implements VersionRange {
private final org.apache.maven.artifact.versioning.VersionRange delegate;

DefaultVersionRange(org.apache.maven.artifact.versioning.VersionRange delegate) {
this.delegate = delegate;
}

@Override
public boolean contains(Version version) {
if (version instanceof DefaultVersion) {
return delegate.containsVersion(((DefaultVersion) version).delegate);
} else {
return delegate.containsVersion(new DefaultArtifactVersion(version.toString()));
}
}

@Override
public String asString() {
return delegate.toString();
}

@Override
public String toString() {
return asString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -62,35 +63,82 @@
import org.apache.maven.model.superpom.SuperPomProvider;
import org.apache.maven.model.v4.MavenModelVersion;
import org.apache.maven.model.validation.ModelValidator;
import org.apache.maven.model.version.VersionParser;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.ProjectModelResolver;
import org.apache.maven.repository.internal.ModelCacheFactory;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.RequestTrace;
import org.eclipse.aether.impl.RemoteRepositoryManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Named
class DefaultConsumerPomBuilder implements ConsumerPomBuilder {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultConsumerPomBuilder.class);

private static final String BOM_PACKAGING = "bom";

public static final String POM_PACKAGING = "pom";

@Inject
PlexusContainer container;
private ModelCacheFactory modelCacheFactory;

@Inject
private ProfileInjector profileInjector;

@Inject
private InheritanceAssembler inheritanceAssembler;

@Inject
private DependencyManagementImporter dependencyManagementImporter;

@Inject
private DependencyManagementInjector dependencyManagementInjector;

@Inject
private LifecycleBindingsInjector lifecycleBindingsInjector;

@Inject
private ModelInterpolator modelInterpolator;

@Inject
private ModelNormalizer modelNormalizer;

@Inject
private ModelPathTranslator modelPathTranslator;

@Inject
private ModelProcessor modelProcessor;

@Inject
ModelCacheFactory modelCacheFactory;
private ModelUrlNormalizer modelUrlNormalizer;

public Model build(RepositorySystemSession session, MavenProject project, Path src)
throws ModelBuildingException, ComponentLookupException {
@Inject
private ModelValidator modelValidator;

@Inject
private PluginConfigurationExpander pluginConfigurationExpander;

@Inject
private PluginManagementInjector pluginManagementInjector;

@Inject
private ReportConfigurationExpander reportConfigurationExpander;

@Inject
private SuperPomProvider superPomProvider;

@Inject
private VersionParser versionParser;

// To break circular dependency
@Inject
private Provider<RepositorySystem> repositorySystem;

@Inject
private RemoteRepositoryManager remoteRepositoryManager;

@Override
public Model build(RepositorySystemSession session, MavenProject project, Path src) throws ModelBuildingException {
Model model = project.getModel().getDelegate();
String packaging = model.getPackaging();
String originalPackaging = project.getOriginalModel().getPackaging();
Expand All @@ -102,21 +150,21 @@ public Model build(RepositorySystemSession session, MavenProject project, Path s
}

protected Model buildPom(RepositorySystemSession session, MavenProject project, Path src)
throws ModelBuildingException, ComponentLookupException {
throws ModelBuildingException {
ModelBuildingResult result = buildModel(session, project, src);
Model model = result.getRawModel().getDelegate();
return transform(model, project);
}

protected Model buildNonPom(RepositorySystemSession session, MavenProject project, Path src)
throws ModelBuildingException, ComponentLookupException {
throws ModelBuildingException {
ModelBuildingResult result = buildModel(session, project, src);
Model model = result.getEffectiveModel().getDelegate();
return transform(model, project);
}

private ModelBuildingResult buildModel(RepositorySystemSession session, MavenProject project, Path src)
throws ModelBuildingException, ComponentLookupException {
throws ModelBuildingException {
ProfileSelector customSelector = new DefaultProfileSelector() {
@Override
public List<Profile> getActiveProfilesV4(
Expand All @@ -127,21 +175,22 @@ public List<Profile> getActiveProfilesV4(
DefaultModelBuilder modelBuilder = new DefaultModelBuilderFactory()
.setProfileSelector(customSelector)
// apply currently active ModelProcessor etc. to support extensions like jgitver
.setProfileInjector(lookup(ProfileInjector.class))
.setInheritanceAssembler(lookup(InheritanceAssembler.class))
.setDependencyManagementImporter(lookup(DependencyManagementImporter.class))
.setDependencyManagementInjector(lookup(DependencyManagementInjector.class))
.setLifecycleBindingsInjector(lookup(LifecycleBindingsInjector.class))
.setModelInterpolator(lookup(ModelInterpolator.class))
.setModelNormalizer(lookup(ModelNormalizer.class))
.setModelPathTranslator(lookup(ModelPathTranslator.class))
.setModelProcessor(lookup(ModelProcessor.class))
.setModelUrlNormalizer(lookup(ModelUrlNormalizer.class))
.setModelValidator(lookup(ModelValidator.class))
.setPluginConfigurationExpander(lookup(PluginConfigurationExpander.class))
.setPluginManagementInjector(lookup(PluginManagementInjector.class))
.setReportConfigurationExpander(lookup(ReportConfigurationExpander.class))
.setSuperPomProvider(lookup(SuperPomProvider.class))
.setProfileInjector(profileInjector)
.setInheritanceAssembler(inheritanceAssembler)
.setDependencyManagementImporter(dependencyManagementImporter)
.setDependencyManagementInjector(dependencyManagementInjector)
.setLifecycleBindingsInjector(lifecycleBindingsInjector)
.setModelInterpolator(modelInterpolator)
.setModelNormalizer(modelNormalizer)
.setModelPathTranslator(modelPathTranslator)
.setModelProcessor(modelProcessor)
.setModelUrlNormalizer(modelUrlNormalizer)
.setModelValidator(modelValidator)
.setPluginConfigurationExpander(pluginConfigurationExpander)
.setPluginManagementInjector(pluginManagementInjector)
.setReportConfigurationExpander(reportConfigurationExpander)
.setSuperPomProvider(superPomProvider)
.setModelVersionParser(versionParser)
.newInstance();
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
try {
Expand All @@ -155,8 +204,8 @@ public List<Profile> getActiveProfilesV4(
request.setModelResolver(new ProjectModelResolver(
session,
new RequestTrace(null),
lookup(RepositorySystem.class),
lookup(RemoteRepositoryManager.class),
repositorySystem.get(),
remoteRepositoryManager,
project.getRemoteProjectRepositories(),
ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT,
null));
Expand All @@ -173,10 +222,6 @@ private Properties toProperties(Map<String, String> map) {
return props;
}

private <T> T lookup(Class<T> clazz) throws ComponentLookupException {
return container.lookup(clazz);
}

static Model transform(Model model, MavenProject project) {
String packaging = model.getPackaging();
if (POM_PACKAGING.equals(packaging)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
import org.apache.maven.project.ExtensionDescriptor;
import org.apache.maven.project.ExtensionDescriptorBuilder;
import org.apache.maven.project.MavenProject;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.apache.maven.session.scope.internal.SessionScopeModule;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusContainer;
Expand Down Expand Up @@ -134,19 +133,18 @@ public class DefaultMavenPluginManager implements MavenPluginManager {

private final Logger logger = LoggerFactory.getLogger(getClass());

private PlexusContainer container;
private ClassRealmManager classRealmManager;
private PluginDescriptorCache pluginDescriptorCache;
private PluginRealmCache pluginRealmCache;
private DefaultPluginDependenciesResolver pluginDependenciesResolver;
private RuntimeInformation runtimeInformation;
private ExtensionRealmCache extensionRealmCache;
private PluginVersionResolver pluginVersionResolver;
private PluginArtifactsCache pluginArtifactsCache;
private MavenPluginValidator pluginValidator;
private List<MavenPluginConfigurationValidator> configurationValidators;
private PluginValidationManager pluginValidationManager;
private List<MavenPluginPrerequisitesChecker> prerequisitesCheckers;
private final PlexusContainer container;
private final ClassRealmManager classRealmManager;
private final PluginDescriptorCache pluginDescriptorCache;
private final PluginRealmCache pluginRealmCache;
private final DefaultPluginDependenciesResolver pluginDependenciesResolver;
private final ExtensionRealmCache extensionRealmCache;
private final PluginVersionResolver pluginVersionResolver;
private final PluginArtifactsCache pluginArtifactsCache;
private final MavenPluginValidator pluginValidator;
private final List<MavenPluginConfigurationValidator> configurationValidators;
private final PluginValidationManager pluginValidationManager;
private final List<MavenPluginPrerequisitesChecker> prerequisitesCheckers;
private final ExtensionDescriptorBuilder extensionDescriptorBuilder = new ExtensionDescriptorBuilder();
private final PluginDescriptorBuilder builder = new PluginDescriptorBuilder();

Expand All @@ -158,7 +156,6 @@ public DefaultMavenPluginManager(
PluginDescriptorCache pluginDescriptorCache,
PluginRealmCache pluginRealmCache,
DefaultPluginDependenciesResolver pluginDependenciesResolver,
RuntimeInformation runtimeInformation,
ExtensionRealmCache extensionRealmCache,
PluginVersionResolver pluginVersionResolver,
PluginArtifactsCache pluginArtifactsCache,
Expand All @@ -171,7 +168,6 @@ public DefaultMavenPluginManager(
this.pluginDescriptorCache = pluginDescriptorCache;
this.pluginRealmCache = pluginRealmCache;
this.pluginDependenciesResolver = pluginDependenciesResolver;
this.runtimeInformation = runtimeInformation;
this.extensionRealmCache = extensionRealmCache;
this.pluginVersionResolver = pluginVersionResolver;
this.pluginArtifactsCache = pluginArtifactsCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Service responsible for validating plugin configuration.
*
*/
interface MavenPluginConfigurationValidator {
public interface MavenPluginConfigurationValidator {
/**
* Checks mojo configuration issues.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@
@Named
@Singleton
public class MavenPluginJavaPrerequisiteChecker implements MavenPluginPrerequisitesChecker {

private final VersionScheme versionScheme;

@Inject
public MavenPluginJavaPrerequisiteChecker(final VersionScheme versionScheme) {
public MavenPluginJavaPrerequisiteChecker(VersionScheme versionScheme) {
this.versionScheme = versionScheme;
}

Expand Down
Loading
Loading