From 99b6a8e981e23c15a13223237c3c2aa549236b89 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 24 Apr 2024 13:32:14 +0200 Subject: [PATCH 1/2] Use the new resolver provider --- ...eProvider.java => MavenVersionScheme.java} | 25 ++- .../internal/impl/standalone/ApiRunner.java | 4 +- .../maven/project/TestProjectBuilder.java | 3 - ...DefaultRepositorySystemSessionFactory.java | 2 +- .../internal/impl/DefaultTypeRegistry.java | 2 +- .../internal/impl/SisuDiBridgeModule.java | 163 ++++-------------- .../internal/DefaultMavenPluginManager.java | 4 +- .../internal/PluginDependenciesResolver.java | 9 + .../maven/project/DefaultProjectBuilder.java | 4 - .../maven/project/ProjectModelResolver.java | 6 +- .../maven/org.apache.maven.api.di.Inject | 69 ++++++++ .../apache/maven/internal/impl/TestApi.java | 10 ++ .../apache/maven/di/impl/InjectorImpl.java | 4 + maven-resolver-provider/pom.xml | 4 - .../META-INF/sisu/javax.inject.Named | 12 ++ 15 files changed, 171 insertions(+), 150 deletions(-) rename maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/{DefaultVersionSchemeProvider.java => MavenVersionScheme.java} (57%) create mode 100644 maven-core/src/main/resources/META-INF/maven/org.apache.maven.api.di.Inject create mode 100644 maven-resolver-provider/src/test/resources/META-INF/sisu/javax.inject.Named diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultVersionSchemeProvider.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenVersionScheme.java similarity index 57% rename from maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultVersionSchemeProvider.java rename to maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenVersionScheme.java index 08ef64703eb7..c146905892bf 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultVersionSchemeProvider.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/MavenVersionScheme.java @@ -19,9 +19,12 @@ 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; /** @@ -29,10 +32,22 @@ */ @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); } } diff --git a/maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/ApiRunner.java b/maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/ApiRunner.java index 08c80cef4c0a..147970d5642e 100644 --- a/maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/ApiRunner.java +++ b/maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/ApiRunner.java @@ -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; @@ -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); diff --git a/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java b/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java index 1907d53f283e..cfda6e1caccf 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java +++ b/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java @@ -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; @@ -47,7 +46,6 @@ public TestProjectBuilder( RepositorySystem repoSystem, RemoteRepositoryManager repositoryManager, ProjectDependenciesResolver dependencyResolver, - ModelCacheFactory modelCacheFactory, RootLocator rootLocator) { super( modelBuilder, @@ -57,7 +55,6 @@ public TestProjectBuilder( repoSystem, repositoryManager, dependencyResolver, - modelCacheFactory, rootLocator); } diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java index bd4c074e0afa..8b9f1bcbeb36 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java @@ -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; diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultTypeRegistry.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultTypeRegistry.java index edc8c3010325..fa5aa9d461a9 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultTypeRegistry.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultTypeRegistry.java @@ -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; diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java b/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java index 2a5482ffdbfd..bc31f3c1f33d 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java @@ -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; @@ -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 { @@ -86,7 +56,7 @@ class SisuDiBridgeModule extends AbstractModule { protected void configure() { Provider containerProvider = getProvider(PlexusContainer.class); - Injector injector = new InjectorImpl() { + InjectorImpl injector = new InjectorImpl() { @Override public Supplier getCompiledBinding(Key key) { Set> res = getBindings(key); @@ -163,23 +133,21 @@ public Supplier getCompiledBinding(Key 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 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 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(); } } } @@ -187,78 +155,23 @@ public Supplier getCompiledBinding(Key key) { } 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 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 itf = (clazz.isInterface() + ? null + : clazz.getInterfaces().length > 0 ? (Class) clazz.getInterfaces()[0] : null); if (itf != null) { - bind(itf).toProvider(() -> injector.getInstance(clazz)); + AnnotatedBindingBuilder 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)); } }); } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java index ec476eb8f8d0..5c250082a1b9 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java @@ -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; @@ -153,7 +153,7 @@ public DefaultMavenPluginManager( ClassRealmManager classRealmManager, PluginDescriptorCache pluginDescriptorCache, PluginRealmCache pluginRealmCache, - DefaultPluginDependenciesResolver pluginDependenciesResolver, + PluginDependenciesResolver pluginDependenciesResolver, ExtensionRealmCache extensionRealmCache, PluginVersionResolver pluginVersionResolver, PluginArtifactsCache pluginArtifactsCache, diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependenciesResolver.java index 4506ebea919f..deadde6a43b7 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependenciesResolver.java @@ -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. Warning: This is an internal utility interface @@ -68,4 +69,12 @@ DependencyNode resolve( List repositories, RepositorySystemSession session) throws PluginResolutionException; + + DependencyResult resolvePlugin( + Plugin plugin, + Artifact artifact, + DependencyFilter dependencyFilter, + List remotePluginRepositories, + RepositorySystemSession repositorySession) + throws PluginResolutionException; } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index eff08333f01b..4e04415085c2 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -69,7 +69,6 @@ import org.apache.maven.model.resolution.UnresolvableModelException; import org.apache.maven.model.root.RootLocator; import org.apache.maven.repository.internal.ArtifactDescriptorUtils; -import org.apache.maven.repository.internal.ModelCacheFactory; import org.apache.maven.utils.Os; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; @@ -100,7 +99,6 @@ public class DefaultProjectBuilder implements ProjectBuilder { private final org.eclipse.aether.RepositorySystem repoSystem; private final RemoteRepositoryManager repositoryManager; private final ProjectDependenciesResolver dependencyResolver; - private final ModelCacheFactory modelCacheFactory; private final RootLocator rootLocator; @@ -114,7 +112,6 @@ public DefaultProjectBuilder( RepositorySystem repoSystem, RemoteRepositoryManager repositoryManager, ProjectDependenciesResolver dependencyResolver, - ModelCacheFactory modelCacheFactory, RootLocator rootLocator) { this.modelBuilder = modelBuilder; this.modelProcessor = modelProcessor; @@ -123,7 +120,6 @@ public DefaultProjectBuilder( this.repoSystem = repoSystem; this.repositoryManager = repositoryManager; this.dependencyResolver = dependencyResolver; - this.modelCacheFactory = modelCacheFactory; this.rootLocator = rootLocator; } // ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java b/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java index 0629a537cf57..69156e0e602d 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java @@ -35,13 +35,13 @@ import org.apache.maven.api.model.Model; import org.apache.maven.api.model.Parent; import org.apache.maven.api.model.Repository; +import org.apache.maven.internal.impl.resolver.ArtifactDescriptorUtils; import org.apache.maven.model.building.ArtifactModelSource; import org.apache.maven.model.building.FileModelSource; import org.apache.maven.model.building.ModelSource; import org.apache.maven.model.resolution.InvalidRepositoryException; import org.apache.maven.model.resolution.ModelResolver; import org.apache.maven.model.resolution.UnresolvableModelException; -import org.apache.maven.repository.internal.ArtifactDescriptorUtils; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RequestTrace; @@ -141,8 +141,8 @@ public void addRepository(final Repository repository, boolean replace) throws I removeMatchingRepository(pomRepositories, repository.getId()); } - List newRepositories = Collections.singletonList( - ArtifactDescriptorUtils.toRemoteRepository(new org.apache.maven.model.Repository(repository))); + List newRepositories = + Collections.singletonList(ArtifactDescriptorUtils.toRemoteRepository(repository)); if (ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT.equals(repositoryMerging)) { repositories = remoteRepositoryManager.aggregateRepositories(session, repositories, newRepositories, true); diff --git a/maven-core/src/main/resources/META-INF/maven/org.apache.maven.api.di.Inject b/maven-core/src/main/resources/META-INF/maven/org.apache.maven.api.di.Inject new file mode 100644 index 000000000000..07598c76643a --- /dev/null +++ b/maven-core/src/main/resources/META-INF/maven/org.apache.maven.api.di.Inject @@ -0,0 +1,69 @@ +org.apache.maven.api.services.model.ProfileActivator +org.apache.maven.api.spi.LanguageProvider +org.apache.maven.api.spi.LifecycleProvider +org.apache.maven.api.spi.ModelParser +org.apache.maven.api.spi.PackagingProvider +org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory +org.apache.maven.internal.aether.LegacyRepositorySystemSessionExtender +org.apache.maven.internal.impl.DefaultArtifactCoordinateFactory +org.apache.maven.internal.impl.DefaultArtifactDeployer +org.apache.maven.internal.impl.DefaultArtifactFactory +org.apache.maven.internal.impl.DefaultArtifactInstaller +org.apache.maven.internal.impl.DefaultArtifactResolver +org.apache.maven.internal.impl.DefaultChecksumAlgorithmService +org.apache.maven.internal.impl.DefaultDependencyCollector +org.apache.maven.internal.impl.DefaultDependencyCoordinateFactory +org.apache.maven.internal.impl.DefaultLocalRepositoryManager +org.apache.maven.internal.impl.DefaultMessageBuilderFactory +org.apache.maven.internal.impl.DefaultModelXmlFactory +org.apache.maven.internal.impl.DefaultRepositoryFactory +org.apache.maven.internal.impl.DefaultSettingsBuilder +org.apache.maven.internal.impl.DefaultSettingsXmlFactory +org.apache.maven.internal.impl.DefaultToolchainsBuilder +org.apache.maven.internal.impl.DefaultToolchainsXmlFactory +org.apache.maven.internal.impl.DefaultTransportProvider +org.apache.maven.internal.impl.DefaultVersionParser +org.apache.maven.internal.impl.DefaultVersionRangeResolver +org.apache.maven.internal.impl.DefaultVersionResolver +org.apache.maven.internal.impl.DefaultModelVersionParser +org.apache.maven.internal.impl.DefaultUrlNormalizer +org.apache.maven.internal.impl.DefaultModelUrlNormalizer +org.apache.maven.internal.impl.DefaultSuperPomProvider +org.apache.maven.internal.impl.DefaultPluginConfigurationExpander +org.apache.maven.internal.impl.ExtensibleEnumRegistries$DefaultLanguageRegistry +org.apache.maven.internal.impl.ExtensibleEnumRegistries$DefaultPathScopeRegistry +org.apache.maven.internal.impl.ExtensibleEnumRegistries$DefaultProjectScopeRegistry +org.apache.maven.internal.impl.model.DefaultModelBuilder +org.apache.maven.internal.impl.model.DefaultModelProcessor +org.apache.maven.internal.impl.model.DefaultModelValidator +org.apache.maven.internal.impl.model.DefaultModelVersionProcessor +org.apache.maven.internal.impl.model.DefaultModelNormalizer +org.apache.maven.internal.impl.model.DefaultModelInterpolator +org.apache.maven.internal.impl.model.DefaultPathTranslator +org.apache.maven.internal.impl.model.DefaultRootLocator +org.apache.maven.internal.impl.model.DefaultModelPathTranslator +org.apache.maven.internal.impl.model.DefaultInheritanceAssembler +org.apache.maven.internal.impl.model.DefaultProfileSelector +org.apache.maven.internal.impl.model.DefaultProfileInjector +org.apache.maven.internal.impl.model.DefaultPluginManagementInjector +org.apache.maven.internal.impl.model.DefaultDependencyManagementInjector +org.apache.maven.internal.impl.model.DefaultDependencyManagementImporter +org.apache.maven.internal.impl.model.DefaultLifecycleBindingsInjector +org.apache.maven.internal.impl.model.ProfileActivationFilePathInterpolator +org.apache.maven.internal.impl.model.BuildModelTransformer +org.apache.maven.internal.impl.model.profile.FileProfileActivator +org.apache.maven.internal.impl.model.profile.JdkVersionProfileActivator +org.apache.maven.internal.impl.model.profile.OperatingSystemProfileActivator +org.apache.maven.internal.impl.model.profile.PackagingProfileActivator +org.apache.maven.internal.impl.model.profile.PropertyProfileActivator +org.apache.maven.internal.impl.resolver.PluginsMetadataGeneratorFactory +org.apache.maven.internal.impl.resolver.SnapshotMetadataGeneratorFactory +org.apache.maven.internal.impl.resolver.VersionsMetadataGeneratorFactory +org.apache.maven.internal.impl.resolver.DefaultVersionResolver +org.apache.maven.internal.impl.resolver.DefaultVersionRangeResolver +org.apache.maven.internal.impl.resolver.DefaultArtifactDescriptorReader +org.apache.maven.internal.impl.resolver.DefaultArtifactDescriptorReader +org.apache.maven.internal.impl.resolver.MavenVersionScheme +org.apache.maven.internal.impl.resolver.relocation.DistributionManagementArtifactRelocationSource +org.apache.maven.internal.impl.resolver.relocation.UserPropertiesArtifactRelocationSource +org.apache.maven.internal.impl.resolver.type.DefaultTypeProvider \ No newline at end of file diff --git a/maven-core/src/test/java/org/apache/maven/internal/impl/TestApi.java b/maven-core/src/test/java/org/apache/maven/internal/impl/TestApi.java index 434d75846688..cd71428fdb6b 100644 --- a/maven-core/src/test/java/org/apache/maven/internal/impl/TestApi.java +++ b/maven-core/src/test/java/org/apache/maven/internal/impl/TestApi.java @@ -49,9 +49,11 @@ import org.apache.maven.toolchain.DefaultToolchainManagerPrivate; import org.apache.maven.toolchain.building.ToolchainsBuilder; import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.testing.PlexusTest; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.impl.MetadataGeneratorFactory; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.RemoteRepository; import org.junit.jupiter.api.BeforeEach; @@ -209,6 +211,14 @@ void testResolveArtifactCoordinateDependencies() { assertEquals("plexus-1.0.11.pom", unresolved.get(0).getFileName().toString()); } + @Test + void testMetadataGeneratorFactory() throws ComponentLookupException { + List factories = plexusContainer.lookupList(MetadataGeneratorFactory.class); + assertNotNull(factories); + factories.forEach(f -> System.out.println(f.getClass().getName())); + assertEquals(3, factories.size()); + } + @Test void testProjectDependencies() { Artifact pom = session.createArtifact("org.codehaus.plexus", "plexus-container-default", "1.0-alpha-32", "pom"); diff --git a/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java b/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java index 6ee277da1cd8..142d2bae9687 100644 --- a/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java +++ b/maven-di/src/main/java/org/apache/maven/di/impl/InjectorImpl.java @@ -145,6 +145,10 @@ protected Set> getBoundKeys() { return bindings.keySet(); } + public Map, Set>> getBindings() { + return bindings; + } + public Supplier getCompiledBinding(Key key) { Set> res = getBindings(key); if (res != null && !res.isEmpty()) { diff --git a/maven-resolver-provider/pom.xml b/maven-resolver-provider/pom.xml index 3b0176d9ac11..a933dc66fe29 100644 --- a/maven-resolver-provider/pom.xml +++ b/maven-resolver-provider/pom.xml @@ -155,10 +155,6 @@ under the License. - - org.eclipse.sisu - sisu-maven-plugin - org.apache.maven.plugins maven-compiler-plugin diff --git a/maven-resolver-provider/src/test/resources/META-INF/sisu/javax.inject.Named b/maven-resolver-provider/src/test/resources/META-INF/sisu/javax.inject.Named new file mode 100644 index 000000000000..5ecb52e02e90 --- /dev/null +++ b/maven-resolver-provider/src/test/resources/META-INF/sisu/javax.inject.Named @@ -0,0 +1,12 @@ +org.apache.maven.repository.internal.DefaultArtifactDescriptorReader +org.apache.maven.repository.internal.DefaultModelCacheFactory +org.apache.maven.repository.internal.DefaultModelVersionParser +org.apache.maven.repository.internal.DefaultVersionRangeResolver +org.apache.maven.repository.internal.DefaultVersionResolver +org.apache.maven.repository.internal.DefaultVersionSchemeProvider +org.apache.maven.repository.internal.PluginsMetadataGeneratorFactory +org.apache.maven.repository.internal.SnapshotMetadataGeneratorFactory +org.apache.maven.repository.internal.VersionsMetadataGeneratorFactory +org.apache.maven.repository.internal.relocation.DistributionManagementArtifactRelocationSource +org.apache.maven.repository.internal.relocation.UserPropertiesArtifactRelocationSource +org.apache.maven.repository.internal.type.DefaultTypeProvider From c09dcea01b0fc539189d87b8bce3d00fabccff51 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 25 Apr 2024 13:44:52 +0200 Subject: [PATCH 2/2] Fix ConsumerPomBuilder --- .../org/apache/maven/internal/impl/SisuDiBridgeModule.java | 2 +- .../transformation/impl/DefaultConsumerPomBuilder.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java b/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java index bc31f3c1f33d..ed569ba420d2 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java @@ -163,7 +163,7 @@ public Supplier getCompiledBinding(Key key) { Class clazz = key.getRawType(); Class itf = (clazz.isInterface() ? null - : clazz.getInterfaces().length > 0 ? (Class) clazz.getInterfaces()[0] : null); + : (Class) (clazz.getInterfaces().length > 0 ? clazz.getInterfaces()[0] : clazz)); if (itf != null) { AnnotatedBindingBuilder binder = bind(itf); if (key.getQualifier() instanceof String s) { diff --git a/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java b/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java index 0fb21459cf36..c551dc4ae1eb 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java @@ -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; @@ -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(); @@ -180,7 +184,7 @@ public List getActiveProfiles( dependencyManagementImporter, lifecycleBindingsInjector, pluginConfigurationExpander, - null, + profileActivationFilePathInterpolator, modelTransformer, versionParser, remoteRepositoryManager);