Skip to content

Commit

Permalink
Use the new resolver provider (#1483)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet authored Apr 25, 2024
1 parent 8d6bf5f commit 6fddd97
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,35 @@
package org.apache.maven.internal.impl.resolver;

import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Provides;
import org.apache.maven.api.di.Singleton;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version;
import org.eclipse.aether.version.VersionConstraint;
import org.eclipse.aether.version.VersionRange;
import org.eclipse.aether.version.VersionScheme;

/**
* Default version scheme provider: provides singleton {@link GenericVersionScheme} instance.
*/
@Singleton
@Named
public final class DefaultVersionSchemeProvider {
public class MavenVersionScheme implements VersionScheme {

@Provides
static VersionScheme getVersionScheme() {
return new GenericVersionScheme();
private final VersionScheme delegate = new GenericVersionScheme();

@Override
public Version parseVersion(String version) throws InvalidVersionSpecificationException {
return delegate.parseVersion(version);
}

@Override
public VersionRange parseVersionRange(String range) throws InvalidVersionSpecificationException {
return delegate.parseVersionRange(range);
}

@Override
public VersionConstraint parseVersionConstraint(String constraint) throws InvalidVersionSpecificationException {
return delegate.parseVersionConstraint(constraint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import org.apache.maven.internal.impl.model.*;
import org.apache.maven.internal.impl.resolver.DefaultVersionRangeResolver;
import org.apache.maven.internal.impl.resolver.DefaultVersionResolver;
import org.apache.maven.internal.impl.resolver.DefaultVersionSchemeProvider;
import org.apache.maven.internal.impl.resolver.MavenVersionScheme;
import org.apache.maven.internal.impl.resolver.type.DefaultTypeProvider;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
Expand Down Expand Up @@ -104,7 +104,7 @@ public static Session createSession() {
injector.bindImplicit(ExtensibleEnumRegistries.class);
injector.bindImplicit(DefaultTypeProvider.class);

injector.bindImplicit(DefaultVersionSchemeProvider.class);
injector.bindImplicit(MavenVersionScheme.class);
injector.bindImplicit(BuildModelTransformer.class);
injector.bindImplicit(DefaultDependencyManagementImporter.class);
injector.bindImplicit(DefaultDependencyManagementInjector.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.bridge.MavenRepositorySystem;
import org.apache.maven.model.root.RootLocator;
import org.apache.maven.repository.internal.ModelCacheFactory;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.impl.RemoteRepositoryManager;

Expand All @@ -47,7 +46,6 @@ public TestProjectBuilder(
RepositorySystem repoSystem,
RemoteRepositoryManager repositoryManager,
ProjectDependenciesResolver dependencyResolver,
ModelCacheFactory modelCacheFactory,
RootLocator rootLocator) {
super(
modelBuilder,
Expand All @@ -57,7 +55,6 @@ public TestProjectBuilder(
repoSystem,
repositoryManager,
dependencyResolver,
modelCacheFactory,
rootLocator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
import org.apache.maven.api.xml.XmlNode;
import org.apache.maven.eventspy.internal.EventSpyDispatcher;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.internal.impl.resolver.MavenSessionBuilderSupplier;
import org.apache.maven.internal.xml.XmlNodeImpl;
import org.apache.maven.internal.xml.XmlPlexusConfiguration;
import org.apache.maven.model.ModelBase;
import org.apache.maven.repository.internal.MavenSessionBuilderSupplier;
import org.apache.maven.resolver.RepositorySystemSessionFactory;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.apache.maven.settings.Mirror;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.apache.maven.artifact.handler.manager.LegacyArtifactHandlerManager;
import org.apache.maven.eventspy.AbstractEventSpy;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.repository.internal.type.DefaultType;
import org.apache.maven.internal.impl.resolver.type.DefaultType;

import static java.util.function.Function.identity;
import static org.apache.maven.internal.impl.Utils.nonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
import javax.inject.Named;
import javax.inject.Provider;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.annotation.Annotation;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
Expand All @@ -33,51 +37,17 @@
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.google.inject.AbstractModule;
import com.google.inject.binder.AnnotatedBindingBuilder;
import com.google.inject.name.Names;
import org.apache.maven.api.services.MavenException;
import org.apache.maven.api.services.model.ProfileActivator;
import org.apache.maven.api.spi.LanguageProvider;
import org.apache.maven.api.spi.LifecycleProvider;
import org.apache.maven.api.spi.ModelParser;
import org.apache.maven.api.spi.PackagingProvider;
import org.apache.maven.di.Injector;
import org.apache.maven.di.Key;
import org.apache.maven.di.impl.Binding;
import org.apache.maven.di.impl.DIException;
import org.apache.maven.di.impl.InjectorImpl;
import org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory;
import org.apache.maven.internal.aether.LegacyRepositorySystemSessionExtender;
import org.apache.maven.internal.impl.model.BuildModelTransformer;
import org.apache.maven.internal.impl.model.DefaultDependencyManagementImporter;
import org.apache.maven.internal.impl.model.DefaultDependencyManagementInjector;
import org.apache.maven.internal.impl.model.DefaultInheritanceAssembler;
import org.apache.maven.internal.impl.model.DefaultLifecycleBindingsInjector;
import org.apache.maven.internal.impl.model.DefaultModelBuilder;
import org.apache.maven.internal.impl.model.DefaultModelInterpolator;
import org.apache.maven.internal.impl.model.DefaultModelNormalizer;
import org.apache.maven.internal.impl.model.DefaultModelPathTranslator;
import org.apache.maven.internal.impl.model.DefaultModelProcessor;
import org.apache.maven.internal.impl.model.DefaultModelValidator;
import org.apache.maven.internal.impl.model.DefaultModelVersionProcessor;
import org.apache.maven.internal.impl.model.DefaultPathTranslator;
import org.apache.maven.internal.impl.model.DefaultPluginManagementInjector;
import org.apache.maven.internal.impl.model.DefaultProfileInjector;
import org.apache.maven.internal.impl.model.DefaultProfileSelector;
import org.apache.maven.internal.impl.model.DefaultRootLocator;
import org.apache.maven.internal.impl.model.ProfileActivationFilePathInterpolator;
import org.apache.maven.internal.impl.model.profile.FileProfileActivator;
import org.apache.maven.internal.impl.model.profile.JdkVersionProfileActivator;
import org.apache.maven.internal.impl.model.profile.OperatingSystemProfileActivator;
import org.apache.maven.internal.impl.model.profile.PackagingProfileActivator;
import org.apache.maven.internal.impl.model.profile.PropertyProfileActivator;
import org.apache.maven.internal.impl.resolver.DefaultArtifactDescriptorReader;
import org.apache.maven.internal.impl.resolver.DefaultVersionSchemeProvider;
import org.apache.maven.internal.impl.resolver.relocation.DistributionManagementArtifactRelocationSource;
import org.apache.maven.internal.impl.resolver.relocation.UserPropertiesArtifactRelocationSource;
import org.codehaus.plexus.PlexusContainer;
import org.eclipse.aether.version.VersionScheme;

@Named
class SisuDiBridgeModule extends AbstractModule {
Expand All @@ -86,7 +56,7 @@ class SisuDiBridgeModule extends AbstractModule {
protected void configure() {
Provider<PlexusContainer> containerProvider = getProvider(PlexusContainer.class);

Injector injector = new InjectorImpl() {
InjectorImpl injector = new InjectorImpl() {
@Override
public <Q> Supplier<Q> getCompiledBinding(Key<Q> key) {
Set<Binding<Q>> res = getBindings(key);
Expand Down Expand Up @@ -163,102 +133,45 @@ public <Q> Supplier<Q> getCompiledBinding(Key<Q> key) {
.asIterator();
it.hasNext(); ) {
URL url = it.next();
try (InputStream is = url.openStream()) {
String[] lines = new String(is.readAllBytes()).split("\n");
for (String className : lines) {
try {
Class<?> clazz = classLoader.loadClass(className);
injector.bindImplicit(clazz);
Class<Object> itf = (Class)
(clazz.isInterface()
? clazz
: clazz.getInterfaces().length > 0 ? clazz.getInterfaces()[0] : null);
if (itf != null) {
bind(itf).toProvider(() -> injector.getInstance(clazz));
}
} catch (ClassNotFoundException e) {
// ignore
e.printStackTrace();
}
List<String> lines;
try (InputStream is = url.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
lines = reader.lines()
.map(String::trim)
.filter(s -> !s.isEmpty() && !s.startsWith("#"))
.toList();
}
for (String className : lines) {
try {
Class<?> clazz = classLoader.loadClass(className);
injector.bindImplicit(clazz);
} catch (ClassNotFoundException e) {
// ignore
e.printStackTrace();
}
}
}

} catch (IOException e) {
throw new MavenException(e);
}
Stream.of(
LanguageProvider.class,
LifecycleProvider.class,
PackagingProvider.class,
DefaultArtifactCoordinateFactory.class,
DefaultArtifactDeployer.class,
DefaultArtifactFactory.class,
DefaultArtifactInstaller.class,
DefaultArtifactResolver.class,
DefaultChecksumAlgorithmService.class,
DefaultDependencyCollector.class,
DefaultDependencyCoordinateFactory.class,
DefaultLocalRepositoryManager.class,
DefaultMessageBuilderFactory.class,
DefaultModelXmlFactory.class,
DefaultRepositoryFactory.class,
DefaultSettingsBuilder.class,
DefaultSettingsXmlFactory.class,
DefaultToolchainsBuilder.class,
DefaultToolchainsXmlFactory.class,
DefaultTransportProvider.class,
DefaultVersionParser.class,
DefaultVersionRangeResolver.class,
DefaultVersionResolver.class,
DefaultVersionSchemeProvider.class,
VersionScheme.class,
DefaultModelVersionParser.class,
DefaultRepositorySystemSessionFactory.class,
LegacyRepositorySystemSessionExtender.class,
ExtensibleEnumRegistries.DefaultLanguageRegistry.class,
ExtensibleEnumRegistries.DefaultPathScopeRegistry.class,
ExtensibleEnumRegistries.DefaultProjectScopeRegistry.class,
DefaultModelBuilder.class,
DefaultModelProcessor.class,
ModelParser.class,
DefaultModelValidator.class,
DefaultModelVersionProcessor.class,
DefaultModelNormalizer.class,
DefaultModelInterpolator.class,
DefaultPathTranslator.class,
DefaultUrlNormalizer.class,
DefaultRootLocator.class,
DefaultModelPathTranslator.class,
DefaultModelUrlNormalizer.class,
DefaultSuperPomProvider.class,
DefaultInheritanceAssembler.class,
DefaultProfileSelector.class,
ProfileActivator.class,
DefaultProfileInjector.class,
DefaultPluginManagementInjector.class,
DefaultDependencyManagementInjector.class,
DefaultDependencyManagementImporter.class,
DefaultLifecycleBindingsInjector.class,
DefaultPluginConfigurationExpander.class,
ProfileActivationFilePathInterpolator.class,
BuildModelTransformer.class,
DefaultArtifactDescriptorReader.class,
DistributionManagementArtifactRelocationSource.class,
UserPropertiesArtifactRelocationSource.class,
FileProfileActivator.class,
JdkVersionProfileActivator.class,
OperatingSystemProfileActivator.class,
PackagingProfileActivator.class,
PropertyProfileActivator.class)
.forEach((Class<?> clazz) -> {
injector.bindImplicit(clazz);
Class<Object> itf = (Class)
(clazz.isInterface()
? null
: clazz.getInterfaces().length > 0 ? clazz.getInterfaces()[0] : null);
injector.getBindings().keySet().stream()
.filter(k -> k.getQualifier() != null)
.sorted(Comparator.comparing(k -> k.getRawType().getName()))
.distinct()
.forEach(key -> {
Class<?> clazz = key.getRawType();
Class<Object> itf = (clazz.isInterface()
? null
: (Class<Object>) (clazz.getInterfaces().length > 0 ? clazz.getInterfaces()[0] : clazz));
if (itf != null) {
bind(itf).toProvider(() -> injector.getInstance(clazz));
AnnotatedBindingBuilder<Object> binder = bind(itf);
if (key.getQualifier() instanceof String s) {
binder.annotatedWith(Names.named(s));
} else if (key.getQualifier() instanceof Annotation a) {
binder.annotatedWith(a);
}
binder.toProvider(() -> injector.getInstance(clazz));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.apache.maven.internal.impl.InternalSession;
import org.apache.maven.internal.impl.model.DefaultModelBuilder;
import org.apache.maven.internal.impl.model.DefaultProfileSelector;
import org.apache.maven.internal.impl.model.ProfileActivationFilePathInterpolator;
import org.apache.maven.internal.impl.resolver.DefaultModelResolver;
import org.apache.maven.model.v4.MavenModelVersion;
import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -129,6 +130,9 @@ class DefaultConsumerPomBuilder implements ConsumerPomBuilder {
@Inject
private RemoteRepositoryManager remoteRepositoryManager;

@Inject
private ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator;

@Override
public Model build(RepositorySystemSession session, MavenProject project, Path src) throws ModelBuilderException {
Model model = project.getModel().getDelegate();
Expand Down Expand Up @@ -180,7 +184,7 @@ public List<Profile> getActiveProfiles(
dependencyManagementImporter,
lifecycleBindingsInjector,
pluginConfigurationExpander,
null,
profileActivationFilePathInterpolator,
modelTransformer,
versionParser,
remoteRepositoryManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public class DefaultMavenPluginManager implements MavenPluginManager {
private final ClassRealmManager classRealmManager;
private final PluginDescriptorCache pluginDescriptorCache;
private final PluginRealmCache pluginRealmCache;
private final DefaultPluginDependenciesResolver pluginDependenciesResolver;
private final PluginDependenciesResolver pluginDependenciesResolver;
private final ExtensionRealmCache extensionRealmCache;
private final PluginVersionResolver pluginVersionResolver;
private final PluginArtifactsCache pluginArtifactsCache;
Expand All @@ -153,7 +153,7 @@ public DefaultMavenPluginManager(
ClassRealmManager classRealmManager,
PluginDescriptorCache pluginDescriptorCache,
PluginRealmCache pluginRealmCache,
DefaultPluginDependenciesResolver pluginDependenciesResolver,
PluginDependenciesResolver pluginDependenciesResolver,
ExtensionRealmCache extensionRealmCache,
PluginVersionResolver pluginVersionResolver,
PluginArtifactsCache pluginArtifactsCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.aether.graph.DependencyFilter;
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.DependencyResult;

/**
* Assists in resolving the dependencies of a plugin. <strong>Warning:</strong> This is an internal utility interface
Expand Down Expand Up @@ -68,4 +69,12 @@ DependencyNode resolve(
List<RemoteRepository> repositories,
RepositorySystemSession session)
throws PluginResolutionException;

DependencyResult resolvePlugin(
Plugin plugin,
Artifact artifact,
DependencyFilter dependencyFilter,
List<RemoteRepository> remotePluginRepositories,
RepositorySystemSession repositorySession)
throws PluginResolutionException;
}
Loading

0 comments on commit 6fddd97

Please sign in to comment.