From 967d8fc19cbb8a78410ceed70bd91c2e628da813 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 15 Jun 2023 16:24:56 +0200 Subject: [PATCH] [MNG-7794][MNG-7809] Deprecate RepositorySystem and make maven-compat optional (#1150) * Move maven-compat to jsr330 * Remove more ties to RepositorySystem * Move more stuff to maven-compat * Move PluginManager and LocalRepositoryNotAccessibleException to maven-compat * Fix tests * Break circular dependency loop in components * Move unused deprecated classes --- maven-compat/pom.xml | 8 +- .../apache/maven/ArtifactFilterManager.java | 1 + .../maven/ArtifactFilterManagerDelegate.java | 1 + .../maven/DefaultArtifactFilterManager.java | 2 +- .../DefaultProjectDependenciesResolver.java | 2 +- .../maven/ProjectDependenciesResolver.java | 0 .../deployer/DefaultArtifactDeployer.java | 11 +- .../installer/DefaultArtifactInstaller.java | 13 +- .../artifact/manager/DefaultWagonManager.java | 19 +- .../metadata/AbstractArtifactMetadata.java | 0 .../ArtifactMetadataRetrievalException.java | 0 .../metadata/ArtifactMetadataSource.java | 0 .../artifact/metadata/ResolutionGroup.java | 0 .../DefaultArtifactRepositoryFactory.java | 26 +- .../LegacyLocalRepositoryManager.java | 4 + .../layout/FlatRepositoryLayout.java | 7 +- .../metadata/AbstractRepositoryMetadata.java | 0 .../metadata/ArtifactRepositoryMetadata.java | 0 .../DefaultRepositoryMetadataManager.java | 13 +- .../metadata/RepositoryMetadata.java | 0 ...RepositoryMetadataDeploymentException.java | 0 ...positoryMetadataInstallationException.java | 0 .../metadata/RepositoryMetadataManager.java | 0 ...RepositoryMetadataResolutionException.java | 0 .../resolver/ArtifactResolutionRequest.java | 0 .../resolver/ArtifactResolutionResult.java | 0 .../resolver/DefaultArtifactCollector.java | 6 +- .../resolver/DefaultArtifactResolver.java | 31 +- .../DefaultResolutionErrorHandler.java | 0 .../resolver/ResolutionErrorHandler.java | 0 .../artifact/resolver/ResolutionListener.java | 0 .../artifact/resolver/ResolutionNode.java | 0 .../execution/DefaultRuntimeInformation.java | 11 +- .../apache/maven/plugin/PluginManager.java | 0 .../plugin/internal/DefaultPluginManager.java | 0 .../maven/profiles/DefaultProfileManager.java | 7 +- .../project/DefaultMavenProjectBuilder.java | 15 +- .../artifact/ActiveProjectArtifact.java | 0 .../artifact/DefaultMavenMetadataCache.java | 1 + .../artifact/DefaultMetadataSource.java | 1 + .../project/artifact/MavenMetadataCache.java | 1 + .../project/artifact/MavenMetadataSource.java | 1 + .../artifact/ProjectArtifactMetadata.java | 1 + .../DefaultModelInheritanceAssembler.java | 7 +- .../AbstractStringBasedModelInterpolator.java | 5 +- .../StringSearchModelInterpolator.java | 7 +- .../project/path/DefaultPathTranslator.java | 7 +- .../maven/project/path/PathTranslator.java | 0 .../validation/DefaultModelValidator.java | 11 +- .../ArtifactDoesNotExistException.java | 1 + .../repository/ArtifactTransferEvent.java | 1 + .../ArtifactTransferFailedException.java | 1 + .../repository/ArtifactTransferListener.java | 1 + .../repository/ArtifactTransferResource.java | 1 + .../repository/DefaultMirrorSelector.java | 7 +- .../DelegatingLocalArtifactRepository.java | 0 .../repository/LocalArtifactRepository.java | 1 + ...LocalRepositoryNotAccessibleException.java | 1 + .../maven/repository/RepositorySystem.java | 9 +- .../legacy/DefaultUpdateCheckManager.java | 7 +- .../legacy/DefaultWagonManager.java | 17 +- .../legacy/LegacyRepositorySystem.java | 27 +- .../metadata/AbstractArtifactMetadata.java | 1 + .../ArtifactMetadataRetrievalException.java | 1 + .../metadata/ArtifactMetadataSource.java | 1 + .../DefaultMetadataResolutionRequest.java | 1 + .../metadata/MetadataResolutionRequest.java | 1 + .../legacy/metadata/ResolutionGroup.java | 1 + .../DefaultArtifactRepositoryFactory.java | 11 +- .../DefaultLegacyArtifactCollector.java | 16 +- .../conflict/DefaultConflictResolver.java | 6 +- .../DefaultConflictResolverFactory.java | 11 +- .../conflict/FarthestConflictResolver.java | 7 +- .../conflict/NearestConflictResolver.java | 7 +- .../conflict/NewestConflictResolver.java | 7 +- .../conflict/OldestConflictResolver.java | 7 +- .../AbstractVersionTransformation.java | 7 +- .../DefaultArtifactTransformationManager.java | 25 +- .../LatestArtifactTransformation.java | 7 +- .../ReleaseArtifactTransformation.java | 7 +- .../transform/SnapshotTransformation.java | 7 +- .../DefaultClasspathTransformation.java | 11 +- .../DefaultGraphConflictResolutionPolicy.java | 7 +- .../DefaultGraphConflictResolver.java | 11 +- .../settings/DefaultMavenSettingsBuilder.java | 0 .../maven/settings/MavenSettingsBuilder.java | 0 .../toolchain/DefaultToolchainsBuilder.java | 0 .../maven/toolchain/ToolchainsBuilder.java | 2 + .../AbstractCoreMavenComponentTestCase.java | 286 ++++++++++++++++++ .../ProjectDependenciesResolverTest.java | 0 .../metadata/SwitchableMetadataSource.java | 79 +++++ .../DefaultMavenMetadataCacheTest.java | 0 .../artifact/MavenMetadataSourceTest.java | 0 .../LegacyRepositorySystemTest.java | 17 +- .../maven/repository/TestArtifactHandler.java | 0 .../repository}/TestRepositorySystem.java | 15 +- .../legacy/LegacyRepositorySystemTest.java | 3 +- .../it0063/jdk/jre/placeholder.txt | 0 .../it0063/jdk/lib/tools.jar | Bin .../it0063/pom.xml | 0 .../project-with-exclusions/pom.xml | 0 maven-core/pom.xml | 15 + .../java/org/apache/maven/DefaultMaven.java | 8 +- .../org/apache/maven/RepositoryUtils.java | 28 ++ .../maven/bridge/MavenRepositorySystem.java | 35 ++- ...DefaultMavenExecutionRequestPopulator.java | 9 +- .../DefaultProjectArtifactFactory.java | 113 ++++++- .../maven/project/DefaultProjectBuilder.java | 4 +- .../project/DefaultProjectBuildingHelper.java | 8 +- .../apache/maven/project/MavenProject.java | 4 +- .../AbstractCoreMavenComponentTestCase.java | 6 +- ...ultRepositorySystemSessionFactoryTest.java | 5 +- .../stub/ProjectDependenciesResolverStub.java | 104 ------- ...luginParameterExpressionEvaluatorTest.java | 6 +- ...ginParameterExpressionEvaluatorV4Test.java | 6 +- .../project/AbstractMavenProjectTestCase.java | 5 +- .../maven/project/PomConstructionTest.java | 8 +- .../project/ProjectModelResolverTest.java | 3 +- .../maven/project/TestMetadataSource.java | 64 ---- .../repository/TestMavenRepositorySystem.java | 61 ++++ .../repository/TestRepositorySystem.java | 172 ----------- .../PomConstructionWithSettingsTest.java | 4 +- pom.xml | 19 -- 123 files changed, 966 insertions(+), 576 deletions(-) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/ArtifactFilterManager.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/ArtifactFilterManagerDelegate.java (98%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/DefaultArtifactFilterManager.java (98%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/ProjectDependenciesResolver.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataRetrievalException.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java (98%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/repository/metadata/ArtifactRepositoryMetadata.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadata.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataDeploymentException.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataInstallationException.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataResolutionException.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/resolver/DefaultResolutionErrorHandler.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/resolver/ResolutionErrorHandler.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/resolver/ResolutionListener.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/plugin/PluginManager.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/project/artifact/DefaultMetadataSource.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/project/path/PathTranslator.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/ArtifactDoesNotExistException.java (98%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/ArtifactTransferFailedException.java (98%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/ArtifactTransferListener.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/ArtifactTransferResource.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/DelegatingLocalArtifactRepository.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/LocalArtifactRepository.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/LocalRepositoryNotAccessibleException.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/RepositorySystem.java (94%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/legacy/metadata/AbstractArtifactMetadata.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataRetrievalException.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataSource.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/legacy/metadata/DefaultMetadataResolutionRequest.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/legacy/metadata/MetadataResolutionRequest.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/repository/legacy/metadata/ResolutionGroup.java (99%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java (100%) rename {maven-core => maven-compat}/src/main/java/org/apache/maven/toolchain/ToolchainsBuilder.java (94%) create mode 100644 maven-compat/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java rename {maven-core => maven-compat}/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java (100%) create mode 100644 maven-compat/src/test/java/org/apache/maven/artifact/metadata/SwitchableMetadataSource.java rename {maven-core => maven-compat}/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java (100%) rename {maven-core => maven-compat}/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java (100%) rename {maven-core => maven-compat}/src/test/java/org/apache/maven/repository/TestArtifactHandler.java (100%) rename {maven-core/src/test/java/org/apache/maven/internal/impl => maven-compat/src/test/java/org/apache/maven/repository}/TestRepositorySystem.java (97%) rename {maven-core => maven-compat}/src/test/projects/project-dependencies-resolver/it0063/jdk/jre/placeholder.txt (100%) rename {maven-core => maven-compat}/src/test/projects/project-dependencies-resolver/it0063/jdk/lib/tools.jar (100%) rename {maven-core => maven-compat}/src/test/projects/project-dependencies-resolver/it0063/pom.xml (100%) rename {maven-core => maven-compat}/src/test/projects/project-dependencies-resolver/project-with-exclusions/pom.xml (100%) delete mode 100644 maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/ProjectDependenciesResolverStub.java delete mode 100644 maven-core/src/test/java/org/apache/maven/project/TestMetadataSource.java create mode 100644 maven-core/src/test/java/org/apache/maven/repository/TestMavenRepositorySystem.java delete mode 100644 maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java diff --git a/maven-compat/pom.xml b/maven-compat/pom.xml index fa052f0c89..4d7217b41d 100644 --- a/maven-compat/pom.xml +++ b/maven-compat/pom.xml @@ -88,10 +88,6 @@ under the License. org.eclipse.sisu org.eclipse.sisu.plexus - - org.codehaus.plexus - plexus-component-annotations - org.apache.maven.wagon wagon-provider-api @@ -127,8 +123,8 @@ under the License. - org.codehaus.plexus - plexus-component-metadata + org.eclipse.sisu + sisu-maven-plugin org.codehaus.modello diff --git a/maven-core/src/main/java/org/apache/maven/ArtifactFilterManager.java b/maven-compat/src/main/java/org/apache/maven/ArtifactFilterManager.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/ArtifactFilterManager.java rename to maven-compat/src/main/java/org/apache/maven/ArtifactFilterManager.java index e2476cea55..e756a9ce4a 100644 --- a/maven-core/src/main/java/org/apache/maven/ArtifactFilterManager.java +++ b/maven-compat/src/main/java/org/apache/maven/ArtifactFilterManager.java @@ -25,6 +25,7 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter; /** * ArtifactFilterManager */ +@Deprecated public interface ArtifactFilterManager { /** * Returns a filter for core + extension artifacts. diff --git a/maven-core/src/main/java/org/apache/maven/ArtifactFilterManagerDelegate.java b/maven-compat/src/main/java/org/apache/maven/ArtifactFilterManagerDelegate.java similarity index 98% rename from maven-core/src/main/java/org/apache/maven/ArtifactFilterManagerDelegate.java rename to maven-compat/src/main/java/org/apache/maven/ArtifactFilterManagerDelegate.java index 7deb000afd..c9e752e453 100644 --- a/maven-core/src/main/java/org/apache/maven/ArtifactFilterManagerDelegate.java +++ b/maven-compat/src/main/java/org/apache/maven/ArtifactFilterManagerDelegate.java @@ -23,6 +23,7 @@ import java.util.Set; /** * @deprecated use {@code META-INF/maven/extension.xml} to define artifacts exported by Maven core extensions. */ +@Deprecated public interface ArtifactFilterManagerDelegate { void addExcludes(Set excludes); diff --git a/maven-core/src/main/java/org/apache/maven/DefaultArtifactFilterManager.java b/maven-compat/src/main/java/org/apache/maven/DefaultArtifactFilterManager.java similarity index 98% rename from maven-core/src/main/java/org/apache/maven/DefaultArtifactFilterManager.java rename to maven-compat/src/main/java/org/apache/maven/DefaultArtifactFilterManager.java index bf9ad700e5..c01f4112db 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultArtifactFilterManager.java +++ b/maven-compat/src/main/java/org/apache/maven/DefaultArtifactFilterManager.java @@ -35,7 +35,7 @@ import org.apache.maven.extension.internal.CoreExports; */ @Named @Singleton -@SuppressWarnings("deprecation") +@Deprecated public class DefaultArtifactFilterManager implements ArtifactFilterManager { // this is a live injected collection diff --git a/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java b/maven-compat/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java rename to maven-compat/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java index b2f705c743..ce24588292 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java @@ -48,9 +48,9 @@ import org.apache.maven.repository.RepositorySystem; * but should have been. * */ -@Deprecated @Named @Singleton +@Deprecated public class DefaultProjectDependenciesResolver implements ProjectDependenciesResolver { private final RepositorySystem repositorySystem; diff --git a/maven-core/src/main/java/org/apache/maven/ProjectDependenciesResolver.java b/maven-compat/src/main/java/org/apache/maven/ProjectDependenciesResolver.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/ProjectDependenciesResolver.java rename to maven-compat/src/main/java/org/apache/maven/ProjectDependenciesResolver.java diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java b/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java index e64df59334..1d04b089f5 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java @@ -18,6 +18,9 @@ */ package org.apache.maven.artifact.deployer; +import javax.inject.Inject; +import javax.inject.Named; + import java.io.File; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -33,8 +36,6 @@ import org.apache.maven.artifact.repository.metadata.MetadataBridge; import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; import org.apache.maven.plugin.LegacySupport; import org.apache.maven.project.artifact.ProjectArtifactMetadata; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; @@ -49,13 +50,13 @@ import org.eclipse.aether.util.artifact.SubArtifact; /** * DefaultArtifactDeployer */ -@Component(role = ArtifactDeployer.class, instantiationStrategy = "per-lookup") +@Named public class DefaultArtifactDeployer extends AbstractLogEnabled implements ArtifactDeployer { - @Requirement + @Inject private RepositorySystem repoSystem; - @Requirement + @Inject private LegacySupport legacySupport; private Map relatedMetadata = new ConcurrentHashMap<>(); diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java b/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java index 7101f71692..344a159b3e 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java @@ -18,6 +18,10 @@ */ package org.apache.maven.artifact.installer; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.io.File; import org.apache.maven.RepositoryUtils; @@ -32,8 +36,6 @@ import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryM import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.plugin.LegacySupport; import org.apache.maven.project.artifact.ProjectArtifactMetadata; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; @@ -45,13 +47,14 @@ import org.eclipse.aether.util.artifact.SubArtifact; /** * @author Jason van Zyl */ -@Component(role = ArtifactInstaller.class) +@Named +@Singleton public class DefaultArtifactInstaller extends AbstractLogEnabled implements ArtifactInstaller { - @Requirement + @Inject private RepositorySystem repoSystem; - @Requirement + @Inject private LegacySupport legacySupport; /** @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly. */ diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java b/maven-compat/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java index 4a61ba7608..f5f029f063 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java @@ -18,6 +18,10 @@ */ package org.apache.maven.artifact.manager; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.util.List; import org.apache.maven.artifact.Artifact; @@ -37,31 +41,30 @@ import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.authentication.AuthenticationInfo; import org.apache.maven.wagon.proxy.ProxyInfo; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; /** * Manages Wagon related operations in Maven. */ -@Component(role = WagonManager.class) +@Named +@Singleton public class DefaultWagonManager extends org.apache.maven.repository.legacy.DefaultWagonManager implements WagonManager { // NOTE: This must use a different field name than in the super class or IoC has no chance to inject the loggers - @Requirement + @Inject private Logger log; - @Requirement + @Inject private LegacySupport legacySupport; - @Requirement + @Inject private SettingsDecrypter settingsDecrypter; - @Requirement + @Inject private MirrorSelector mirrorSelector; - @Requirement + @Inject private ArtifactRepositoryFactory artifactRepositoryFactory; public AuthenticationInfo getAuthenticationInfo(String id) { diff --git a/maven-core/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java b/maven-compat/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java rename to maven-compat/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataRetrievalException.java b/maven-compat/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataRetrievalException.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataRetrievalException.java rename to maven-compat/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataRetrievalException.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java b/maven-compat/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java rename to maven-compat/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java b/maven-compat/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java rename to maven-compat/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java index f5ae8ea4fc..91d4585c21 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java @@ -18,6 +18,10 @@ */ package org.apache.maven.artifact.repository; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.util.Arrays; import java.util.List; @@ -25,24 +29,25 @@ import org.apache.maven.artifact.UnknownRepositoryLayoutException; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.plugin.LegacySupport; import org.apache.maven.repository.RepositorySystem; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.eclipse.aether.RepositorySystemSession; /** * @author jdcasey */ -@Component(role = ArtifactRepositoryFactory.class) +@Named +@Singleton public class DefaultArtifactRepositoryFactory implements ArtifactRepositoryFactory { - @Requirement + @Inject private org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory factory; - @Requirement + @Inject private LegacySupport legacySupport; - @Requirement - private RepositorySystem repositorySystem; + @Inject + private PlexusContainer container; public ArtifactRepositoryLayout getLayout(String layoutId) throws UnknownRepositoryLayoutException { return factory.getLayout(layoutId); @@ -92,6 +97,13 @@ public class DefaultArtifactRepositoryFactory implements ArtifactRepositoryFacto if (session != null && repository != null && !isLocalRepository(repository)) { List repositories = Arrays.asList(repository); + RepositorySystem repositorySystem; + try { + repositorySystem = container.lookup(RepositorySystem.class); + } catch (ComponentLookupException e) { + throw new IllegalStateException("Unable to lookup " + RepositorySystem.class.getName()); + } + if (mirrors) { repositorySystem.injectMirror(session, repositories); } diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java similarity index 98% rename from maven-core/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java rename to maven-compat/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java index cd76c79d78..6307213596 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java @@ -60,6 +60,10 @@ public class LegacyLocalRepositoryManager implements LocalRepositoryManager { public static RepositorySystemSession overlay( ArtifactRepository repository, RepositorySystemSession session, RepositorySystem system) { + return overlay(repository, session); + } + + public static RepositorySystemSession overlay(ArtifactRepository repository, RepositorySystemSession session) { if (repository == null || repository.getBasedir() == null) { return session; } diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/layout/FlatRepositoryLayout.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/layout/FlatRepositoryLayout.java index 6960d1a948..c787cf3211 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/layout/FlatRepositoryLayout.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/layout/FlatRepositoryLayout.java @@ -18,16 +18,19 @@ */ package org.apache.maven.artifact.repository.layout; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.codehaus.plexus.component.annotations.Component; /** * FlatRepositoryLayout */ -@Component(role = ArtifactRepositoryLayout.class, hint = "flat") +@Named("flat") +@Singleton public class FlatRepositoryLayout implements ArtifactRepositoryLayout { private static final char ARTIFACT_SEPARATOR = '-'; diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java rename to maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/ArtifactRepositoryMetadata.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/ArtifactRepositoryMetadata.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/ArtifactRepositoryMetadata.java rename to maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/ArtifactRepositoryMetadata.java diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java index 8741eca2c4..04b6f36354 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java @@ -18,6 +18,10 @@ */ package org.apache.maven.artifact.repository.metadata; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -40,20 +44,19 @@ import org.apache.maven.repository.legacy.UpdateCheckManager; import org.apache.maven.repository.legacy.WagonManager; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** * @author Jason van Zyl */ -@Component(role = RepositoryMetadataManager.class) +@Named +@Singleton public class DefaultRepositoryMetadataManager extends AbstractLogEnabled implements RepositoryMetadataManager { - @Requirement + @Inject private WagonManager wagonManager; - @Requirement + @Inject private UpdateCheckManager updateCheckManager; public void resolve( diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadata.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadata.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadata.java rename to maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadata.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataDeploymentException.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataDeploymentException.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataDeploymentException.java rename to maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataDeploymentException.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataInstallationException.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataInstallationException.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataInstallationException.java rename to maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataInstallationException.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java rename to maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataResolutionException.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataResolutionException.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataResolutionException.java rename to maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataResolutionException.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java rename to maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java rename to maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java index dde86482f9..0c0a235a9a 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java @@ -18,13 +18,15 @@ */ package org.apache.maven.artifact.resolver; -import org.codehaus.plexus.component.annotations.Component; +import javax.inject.Named; +import javax.inject.Singleton; /** * Artifact collector - takes a set of original artifacts and resolves all of the best versions to use * along with their metadata. No artifacts are downloaded. */ @Deprecated -@Component(role = ArtifactCollector.class) +@Named +@Singleton public class DefaultArtifactCollector extends org.apache.maven.repository.legacy.resolver.DefaultLegacyArtifactCollector implements ArtifactCollector {} diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index 952382a23b..f367e7f11a 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -18,6 +18,10 @@ */ package org.apache.maven.artifact.resolver; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.io.File; import java.util.ArrayList; import java.util.Collections; @@ -55,8 +59,6 @@ import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; import org.apache.maven.repository.legacy.resolver.conflict.ConflictResolver; import org.apache.maven.wagon.events.TransferListener; import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable; @@ -69,32 +71,30 @@ import org.eclipse.aether.resolution.ArtifactResult; /** * @author Jason van Zyl */ -@Component(role = ArtifactResolver.class) +@Named +@Singleton public class DefaultArtifactResolver implements ArtifactResolver, Disposable { - @Requirement + @Inject private Logger logger; - @Requirement + @Inject protected ArtifactFactory artifactFactory; - @Requirement + @Inject private ArtifactCollector artifactCollector; - @Requirement + @Inject private ResolutionErrorHandler resolutionErrorHandler; - @Requirement + @Inject private ArtifactMetadataSource source; - @Requirement + @Inject private PlexusContainer container; - @Requirement + @Inject private LegacySupport legacySupport; - @Requirement - private RepositorySystem repoSystem; - private final Executor executor; public DefaultArtifactResolver() { @@ -108,7 +108,7 @@ public class DefaultArtifactResolver implements ArtifactResolver, Disposable { } private RepositorySystemSession getSession(ArtifactRepository localRepository) { - return LegacyLocalRepositoryManager.overlay(localRepository, legacySupport.getRepositorySession(), repoSystem); + return LegacyLocalRepositoryManager.overlay(localRepository, legacySupport.getRepositorySession(), null); } private void injectSession1(RepositoryRequest request, MavenSession session) { @@ -185,7 +185,10 @@ public class DefaultArtifactResolver implements ArtifactResolver, Disposable { String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact()); artifact.setFile(new File(lrm.getRepository().getBasedir(), path)); + RepositorySystem repoSystem = container.lookup(RepositorySystem.class); result = repoSystem.resolveArtifact(session, artifactRequest); + } catch (ComponentLookupException e) { + throw new IllegalStateException("Unable to lookup " + RepositorySystem.class.getName()); } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) { if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) { throw new ArtifactNotFoundException(e.getMessage(), artifact, remoteRepositories, e); diff --git a/maven-core/src/main/java/org/apache/maven/artifact/resolver/DefaultResolutionErrorHandler.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultResolutionErrorHandler.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/resolver/DefaultResolutionErrorHandler.java rename to maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultResolutionErrorHandler.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/resolver/ResolutionErrorHandler.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionErrorHandler.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/resolver/ResolutionErrorHandler.java rename to maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionErrorHandler.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/resolver/ResolutionListener.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionListener.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/resolver/ResolutionListener.java rename to maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionListener.java diff --git a/maven-core/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java rename to maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java diff --git a/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java b/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java index 93697127ca..547b0aa301 100644 --- a/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java +++ b/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java @@ -18,10 +18,12 @@ */ package org.apache.maven.execution; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; @@ -31,10 +33,11 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExce * @author Brett Porter */ @Deprecated -@Component(role = RuntimeInformation.class) +@Named +@Singleton public class DefaultRuntimeInformation implements RuntimeInformation, Initializable { - @Requirement + @Inject private org.apache.maven.rtinfo.RuntimeInformation rtInfo; private ArtifactVersion applicationVersion; diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java b/maven-compat/src/main/java/org/apache/maven/plugin/PluginManager.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java rename to maven-compat/src/main/java/org/apache/maven/plugin/PluginManager.java diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java b/maven-compat/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java rename to maven-compat/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java diff --git a/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java b/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java index a682218aad..6727261059 100644 --- a/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java +++ b/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java @@ -18,6 +18,8 @@ */ package org.apache.maven.profiles; +import javax.inject.Inject; + import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -32,7 +34,6 @@ import org.apache.maven.model.profile.ProfileSelector; import org.apache.maven.profiles.activation.ProfileActivationException; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; @@ -42,10 +43,10 @@ import org.codehaus.plexus.logging.Logger; @Deprecated public class DefaultProfileManager implements ProfileManager { - @Requirement + @Inject private Logger logger; - @Requirement + @Inject private ProfileSelector profileSelector; private List activatedIds = new ArrayList<>(); diff --git a/maven-compat/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-compat/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 85a28e32dc..e2d6928edb 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-compat/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -18,6 +18,10 @@ */ package org.apache.maven.project; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -41,22 +45,21 @@ import org.apache.maven.profiles.ProfileManager; import org.apache.maven.properties.internal.EnvironmentUtils; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.wagon.events.TransferListener; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; /** */ -@Component(role = MavenProjectBuilder.class) @Deprecated +@Named +@Singleton public class DefaultMavenProjectBuilder implements MavenProjectBuilder { - @Requirement + @Inject private ProjectBuilder projectBuilder; - @Requirement + @Inject private RepositorySystem repositorySystem; - @Requirement + @Inject private LegacySupport legacySupport; // ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java b/maven-compat/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java rename to maven-compat/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java b/maven-compat/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java rename to maven-compat/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java index 8141cc1492..48c889cd98 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java +++ b/maven-compat/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java @@ -43,6 +43,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; */ @Named @Singleton +@Deprecated public class DefaultMavenMetadataCache implements MavenMetadataCache { protected final Map cache = new ConcurrentHashMap<>(); diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMetadataSource.java b/maven-compat/src/main/java/org/apache/maven/project/artifact/DefaultMetadataSource.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMetadataSource.java rename to maven-compat/src/main/java/org/apache/maven/project/artifact/DefaultMetadataSource.java index 42c30aee27..2b04d081c8 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMetadataSource.java +++ b/maven-compat/src/main/java/org/apache/maven/project/artifact/DefaultMetadataSource.java @@ -37,6 +37,7 @@ import org.apache.maven.project.ProjectBuilder; */ @Named @Singleton +@Deprecated public class DefaultMetadataSource extends MavenMetadataSource { @Inject public DefaultMetadataSource( diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java b/maven-compat/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java rename to maven-compat/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java index 8b759dbcbe..bafc22cb89 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java +++ b/maven-compat/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java @@ -27,6 +27,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; /** * MavenMetadataCache */ +@Deprecated public interface MavenMetadataCache { ResolutionGroup get( diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-compat/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java rename to maven-compat/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 41af279853..b606ee5b73 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-compat/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -92,6 +92,7 @@ import org.slf4j.LoggerFactory; */ @Named("maven") @Singleton +@Deprecated public class MavenMetadataSource implements ArtifactMetadataSource { private final Logger logger = LoggerFactory.getLogger(getClass()); private final RepositoryMetadataManager repositoryMetadataManager; diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java b/maven-compat/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java rename to maven-compat/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java index 4a349330ea..673714adfa 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java +++ b/maven-compat/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java @@ -33,6 +33,7 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreExce * * @author Brett Porter */ +@Deprecated public class ProjectArtifactMetadata extends AbstractArtifactMetadata { private final File file; diff --git a/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java b/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java index 215f6ae6cf..c872258889 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java +++ b/maven-compat/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java @@ -18,14 +18,17 @@ */ package org.apache.maven.project.inheritance; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.model.Build; import org.apache.maven.model.Model; -import org.codehaus.plexus.component.annotations.Component; /** * DefaultModelInheritanceAssembler */ -@Component(role = ModelInheritanceAssembler.class) +@Named +@Singleton public class DefaultModelInheritanceAssembler implements ModelInheritanceAssembler { @Override public void assembleModelInheritance(Model child, Model parent, String childPathAdjustment) { diff --git a/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java b/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java index 87e46e85c5..3745157e03 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java +++ b/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java @@ -18,6 +18,8 @@ */ package org.apache.maven.project.interpolation; +import javax.inject.Inject; + import java.io.File; import java.io.IOException; import java.io.StringReader; @@ -35,7 +37,6 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.project.DefaultProjectBuilderConfiguration; import org.apache.maven.project.ProjectBuilderConfiguration; import org.apache.maven.project.path.PathTranslator; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.interpolation.AbstractValueSource; import org.codehaus.plexus.interpolation.InterpolationException; import org.codehaus.plexus.interpolation.InterpolationPostProcessor; @@ -86,7 +87,7 @@ public abstract class AbstractStringBasedModelInterpolator extends AbstractLogEn TRANSLATED_PATH_EXPRESSIONS = translatedPrefixes; } - @Requirement + @Inject private PathTranslator pathTranslator; private Interpolator interpolator; diff --git a/maven-compat/src/main/java/org/apache/maven/project/interpolation/StringSearchModelInterpolator.java b/maven-compat/src/main/java/org/apache/maven/project/interpolation/StringSearchModelInterpolator.java index 259208e45a..d63cbec5c1 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/interpolation/StringSearchModelInterpolator.java +++ b/maven-compat/src/main/java/org/apache/maven/project/interpolation/StringSearchModelInterpolator.java @@ -18,6 +18,9 @@ */ package org.apache.maven.project.interpolation; +import javax.inject.Named; +import javax.inject.Singleton; + import java.io.File; import java.lang.reflect.Array; import java.lang.reflect.Field; @@ -33,7 +36,6 @@ import java.util.WeakHashMap; import org.apache.maven.model.Model; import org.apache.maven.project.ProjectBuilderConfiguration; import org.apache.maven.project.path.PathTranslator; -import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.interpolation.InterpolationPostProcessor; import org.codehaus.plexus.interpolation.Interpolator; import org.codehaus.plexus.interpolation.StringSearchInterpolator; @@ -44,7 +46,8 @@ import org.codehaus.plexus.logging.Logger; * StringSearchModelInterpolator */ @Deprecated -@Component(role = ModelInterpolator.class) +@Named +@Singleton public class StringSearchModelInterpolator extends AbstractStringBasedModelInterpolator { private static final Map, Field[]> FIELDS_BY_CLASS = new WeakHashMap<>(); diff --git a/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java b/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java index 6c9083fb45..9a6bc49c37 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java +++ b/maven-compat/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java @@ -18,6 +18,9 @@ */ package org.apache.maven.project.path; +import javax.inject.Named; +import javax.inject.Singleton; + import java.io.File; import java.util.ArrayList; import java.util.List; @@ -26,13 +29,13 @@ import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.model.Reporting; import org.apache.maven.model.Resource; -import org.codehaus.plexus.component.annotations.Component; /** * DefaultPathTranslator */ @Deprecated -@Component(role = PathTranslator.class) +@Named +@Singleton public class DefaultPathTranslator implements PathTranslator { private static final String[] BASEDIR_EXPRESSIONS = {"${basedir}", "${pom.basedir}", "${project.basedir}"}; diff --git a/maven-core/src/main/java/org/apache/maven/project/path/PathTranslator.java b/maven-compat/src/main/java/org/apache/maven/project/path/PathTranslator.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/project/path/PathTranslator.java rename to maven-compat/src/main/java/org/apache/maven/project/path/PathTranslator.java diff --git a/maven-compat/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java b/maven-compat/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java index 87cf801b56..2edbe701a6 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java +++ b/maven-compat/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java @@ -18,23 +18,26 @@ */ package org.apache.maven.project.validation; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.model.Model; import org.apache.maven.model.building.DefaultModelBuildingRequest; import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.model.building.ModelProblem; import org.apache.maven.model.building.ModelProblemCollector; import org.apache.maven.model.building.ModelProblemCollectorRequest; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; /** * @author Trygve Laugstøl */ -@Component(role = ModelValidator.class) @Deprecated +@Named +@Singleton public class DefaultModelValidator implements ModelValidator { - @Requirement + @Inject private org.apache.maven.model.validation.ModelValidator modelValidator; public ModelValidationResult validate(Model model) { diff --git a/maven-core/src/main/java/org/apache/maven/repository/ArtifactDoesNotExistException.java b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactDoesNotExistException.java similarity index 98% rename from maven-core/src/main/java/org/apache/maven/repository/ArtifactDoesNotExistException.java rename to maven-compat/src/main/java/org/apache/maven/repository/ArtifactDoesNotExistException.java index 98918468c7..5624e1d99d 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/ArtifactDoesNotExistException.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactDoesNotExistException.java @@ -21,6 +21,7 @@ package org.apache.maven.repository; /** * ArtifactDoesNotExistException */ +@Deprecated public class ArtifactDoesNotExistException extends Exception { public ArtifactDoesNotExistException(final String message) { super(message); diff --git a/maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java rename to maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java index 55720cea9c..53e36e2adc 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferEvent.java @@ -27,6 +27,7 @@ import java.util.EventObject; * * @author Michal Maczka */ +@Deprecated public class ArtifactTransferEvent extends EventObject { /** * A transfer was attempted, but has not yet commenced. diff --git a/maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferFailedException.java b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferFailedException.java similarity index 98% rename from maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferFailedException.java rename to maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferFailedException.java index e041f7c472..530ec343a9 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferFailedException.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferFailedException.java @@ -21,6 +21,7 @@ package org.apache.maven.repository; /** * ArtifactTransferFailedException */ +@Deprecated public class ArtifactTransferFailedException extends Exception { public ArtifactTransferFailedException(final String message) { super(message); diff --git a/maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferListener.java b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferListener.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferListener.java rename to maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferListener.java index 77525cf618..c286881582 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferListener.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferListener.java @@ -21,6 +21,7 @@ package org.apache.maven.repository; /** * ArtifactTransferListener */ +@Deprecated public interface ArtifactTransferListener { boolean isShowChecksumEvents(); diff --git a/maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferResource.java b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferResource.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferResource.java rename to maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferResource.java index 90f678afa7..3db1df3e00 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/ArtifactTransferResource.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/ArtifactTransferResource.java @@ -23,6 +23,7 @@ package org.apache.maven.repository; * * @author Benjamin Bentmann */ +@Deprecated public interface ArtifactTransferResource { /** diff --git a/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java b/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java index f3e524a89b..fc8361c993 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java @@ -18,6 +18,9 @@ */ package org.apache.maven.repository; +import javax.inject.Named; +import javax.inject.Singleton; + import java.net.MalformedURLException; import java.net.URL; import java.util.List; @@ -25,12 +28,12 @@ import java.util.List; import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.settings.Mirror; -import org.codehaus.plexus.component.annotations.Component; /** * DefaultMirrorSelector */ -@Component(role = MirrorSelector.class) +@Named +@Singleton public class DefaultMirrorSelector implements MirrorSelector { private static final String WILDCARD = "*"; diff --git a/maven-core/src/main/java/org/apache/maven/repository/DelegatingLocalArtifactRepository.java b/maven-compat/src/main/java/org/apache/maven/repository/DelegatingLocalArtifactRepository.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/repository/DelegatingLocalArtifactRepository.java rename to maven-compat/src/main/java/org/apache/maven/repository/DelegatingLocalArtifactRepository.java diff --git a/maven-core/src/main/java/org/apache/maven/repository/LocalArtifactRepository.java b/maven-compat/src/main/java/org/apache/maven/repository/LocalArtifactRepository.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/repository/LocalArtifactRepository.java rename to maven-compat/src/main/java/org/apache/maven/repository/LocalArtifactRepository.java index ce66c112fd..3577c316ad 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/LocalArtifactRepository.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/LocalArtifactRepository.java @@ -24,6 +24,7 @@ import org.apache.maven.artifact.repository.MavenArtifactRepository; /** * LocalArtifactRepository */ +@Deprecated public abstract class LocalArtifactRepository extends MavenArtifactRepository { public static final String IDE_WORKSPACE = "ide-workspace"; diff --git a/maven-core/src/main/java/org/apache/maven/repository/LocalRepositoryNotAccessibleException.java b/maven-compat/src/main/java/org/apache/maven/repository/LocalRepositoryNotAccessibleException.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/repository/LocalRepositoryNotAccessibleException.java rename to maven-compat/src/main/java/org/apache/maven/repository/LocalRepositoryNotAccessibleException.java index 4058db5151..ebfb6a8cef 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/LocalRepositoryNotAccessibleException.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/LocalRepositoryNotAccessibleException.java @@ -25,6 +25,7 @@ import java.io.IOException; * * @author Benjamin Bentmann */ +@Deprecated public class LocalRepositoryNotAccessibleException extends IOException { public LocalRepositoryNotAccessibleException(String message, Throwable cause) { diff --git a/maven-core/src/main/java/org/apache/maven/repository/RepositorySystem.java b/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java similarity index 94% rename from maven-core/src/main/java/org/apache/maven/repository/RepositorySystem.java rename to maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java index ede7f869c4..dae35585ad 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/RepositorySystem.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java @@ -28,6 +28,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.model.Repository; @@ -38,9 +39,11 @@ import org.eclipse.aether.RepositorySystemSession; /** * @author Jason van Zyl * @since 3.0-alpha + * @deprecated Use {@link MavenRepositorySystem} if needed, or maven-resolver directly, until maven 4.x api is out */ +@Deprecated public interface RepositorySystem { - String DEFAULT_LOCAL_REPO_ID = "local"; + String DEFAULT_LOCAL_REPO_ID = MavenRepositorySystem.DEFAULT_LOCAL_REPO_ID; @SuppressWarnings("checkstyle:constantname") String userHome = System.getProperty("user.home"); @@ -51,9 +54,9 @@ public interface RepositorySystem { @SuppressWarnings("checkstyle:constantname") File defaultUserLocalRepository = new File(userMavenConfigurationHome, "repository"); - String DEFAULT_REMOTE_REPO_ID = "central"; + String DEFAULT_REMOTE_REPO_ID = MavenRepositorySystem.DEFAULT_REMOTE_REPO_ID; - String DEFAULT_REMOTE_REPO_URL = "https://repo.maven.apache.org/maven2"; + String DEFAULT_REMOTE_REPO_URL = MavenRepositorySystem.DEFAULT_REMOTE_REPO_ID; Artifact createArtifact(String groupId, String artifactId, String version, String packaging); diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java index 6e2633cc10..f975742cf9 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java @@ -18,6 +18,9 @@ */ package org.apache.maven.repository.legacy; +import javax.inject.Named; +import javax.inject.Singleton; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -34,14 +37,14 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.Authentication; import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; import org.apache.maven.repository.Proxy; -import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; /** * DefaultUpdateCheckManager */ -@Component(role = UpdateCheckManager.class) +@Named +@Singleton public class DefaultUpdateCheckManager extends AbstractLogEnabled implements UpdateCheckManager { private static final String ERROR_KEY_SUFFIX = ".error"; diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java index 3ffc399ed2..963b9377e7 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultWagonManager.java @@ -18,6 +18,10 @@ */ package org.apache.maven.repository.legacy; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.io.File; import java.io.IOException; import java.lang.reflect.Method; @@ -46,8 +50,6 @@ import org.apache.maven.wagon.observers.ChecksumObserver; import org.apache.maven.wagon.proxy.ProxyInfo; import org.apache.maven.wagon.repository.Repository; import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; @@ -62,7 +64,8 @@ import org.eclipse.aether.util.ConfigUtils; /** * Manages Wagon related operations in Maven. */ -@Component(role = WagonManager.class) +@Named +@Singleton public class DefaultWagonManager implements WagonManager { private static final String[] CHECKSUM_IDS = {"md5", "sha1"}; @@ -72,16 +75,16 @@ public class DefaultWagonManager implements WagonManager { */ private static final String[] CHECKSUM_ALGORITHMS = {"MD5", "SHA-1"}; - @Requirement + @Inject private Logger logger; - @Requirement + @Inject private PlexusContainer container; - @Requirement + @Inject private UpdateCheckManager updateCheckManager; - @Requirement + @Inject private LegacySupport legacySupport; // diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java index a9d30d4e1a..5a77e9b030 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java @@ -18,6 +18,10 @@ */ package org.apache.maven.repository.legacy; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -67,8 +71,6 @@ import org.apache.maven.settings.crypto.SettingsDecryptionResult; import org.apache.maven.wagon.proxy.ProxyInfo; import org.apache.maven.wagon.proxy.ProxyUtils; import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; @@ -81,34 +83,35 @@ import org.eclipse.aether.repository.RemoteRepository; /** * @author Jason van Zyl */ -@Component(role = RepositorySystem.class, hint = "default") +@Named("default") +@Singleton public class LegacyRepositorySystem implements RepositorySystem { - @Requirement + @Inject private Logger logger; - @Requirement + @Inject private ArtifactFactory artifactFactory; - @Requirement + @Inject private ArtifactResolver artifactResolver; - @Requirement + @Inject private ArtifactRepositoryFactory artifactRepositoryFactory; - @Requirement(role = ArtifactRepositoryLayout.class) + @Inject private Map layouts; - @Requirement + @Inject private WagonManager wagonManager; - @Requirement + @Inject private PlexusContainer plexus; - @Requirement + @Inject private MirrorSelector mirrorSelector; - @Requirement + @Inject private SettingsDecrypter settingsDecrypter; public Artifact createArtifact(String groupId, String artifactId, String version, String scope, String type) { diff --git a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/AbstractArtifactMetadata.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/AbstractArtifactMetadata.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/AbstractArtifactMetadata.java rename to maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/AbstractArtifactMetadata.java index 65a2e98533..c6846766c8 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/AbstractArtifactMetadata.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/AbstractArtifactMetadata.java @@ -25,6 +25,7 @@ import org.apache.maven.artifact.Artifact; * * @author Brett Porter */ +@Deprecated public abstract class AbstractArtifactMetadata implements ArtifactMetadata { private static final String LS = System.lineSeparator(); diff --git a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataRetrievalException.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataRetrievalException.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataRetrievalException.java rename to maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataRetrievalException.java index 616a6e5464..57c9b2a538 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataRetrievalException.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataRetrievalException.java @@ -25,6 +25,7 @@ import org.apache.maven.artifact.Artifact; * * @author Jason van Zyl */ +@Deprecated public class ArtifactMetadataRetrievalException extends Exception { private Artifact artifact; diff --git a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataSource.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataSource.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataSource.java rename to maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataSource.java index be6db47d9e..64ebdd9a43 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataSource.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadataSource.java @@ -30,6 +30,7 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; * * @author Jason van Zyl */ +@Deprecated public interface ArtifactMetadataSource { ResolutionGroup retrieve(MetadataResolutionRequest request) throws ArtifactMetadataRetrievalException; diff --git a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/DefaultMetadataResolutionRequest.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/DefaultMetadataResolutionRequest.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/DefaultMetadataResolutionRequest.java rename to maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/DefaultMetadataResolutionRequest.java index 58921df5cd..c08e9cd638 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/DefaultMetadataResolutionRequest.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/DefaultMetadataResolutionRequest.java @@ -31,6 +31,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; * * @author Benjamin Bentmann */ +@Deprecated public class DefaultMetadataResolutionRequest implements MetadataResolutionRequest { private Artifact artifact; diff --git a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/MetadataResolutionRequest.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/MetadataResolutionRequest.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/MetadataResolutionRequest.java rename to maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/MetadataResolutionRequest.java index bb4c8705e6..452436ac29 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/MetadataResolutionRequest.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/MetadataResolutionRequest.java @@ -29,6 +29,7 @@ import org.apache.maven.artifact.repository.RepositoryRequest; * * @author Benjamin Bentmann */ +@Deprecated public interface MetadataResolutionRequest extends RepositoryRequest { /** diff --git a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/ResolutionGroup.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/ResolutionGroup.java similarity index 99% rename from maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/ResolutionGroup.java rename to maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/ResolutionGroup.java index 5e4290535c..1bb1c9c735 100644 --- a/maven-core/src/main/java/org/apache/maven/repository/legacy/metadata/ResolutionGroup.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/metadata/ResolutionGroup.java @@ -28,6 +28,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; /** * ResolutionGroup */ +@Deprecated public class ResolutionGroup { private final Set artifacts; diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/repository/DefaultArtifactRepositoryFactory.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/repository/DefaultArtifactRepositoryFactory.java index 3c3de65877..ef0ce7f9bd 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/repository/DefaultArtifactRepositoryFactory.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/repository/DefaultArtifactRepositoryFactory.java @@ -18,6 +18,10 @@ */ package org.apache.maven.repository.legacy.repository; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.util.Map; import org.apache.maven.artifact.UnknownRepositoryLayoutException; @@ -26,20 +30,19 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.MavenArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout2; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; /** * @author jdcasey */ -@Component(role = ArtifactRepositoryFactory.class) +@Named +@Singleton public class DefaultArtifactRepositoryFactory implements ArtifactRepositoryFactory { // TODO use settings? private String globalUpdatePolicy; private String globalChecksumPolicy; - @Requirement(role = ArtifactRepositoryLayout.class) + @Inject private Map repositoryLayouts; public ArtifactRepositoryLayout getLayout(String layoutId) throws UnknownRepositoryLayoutException { diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java index e03a0e5d1a..6d949af5b9 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java @@ -18,6 +18,10 @@ */ package org.apache.maven.repository.legacy.resolver; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -50,24 +54,24 @@ import org.apache.maven.repository.legacy.metadata.ArtifactMetadataRetrievalExce import org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest; import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; import org.apache.maven.repository.legacy.resolver.conflict.ConflictResolver; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; /** * @author Brett Porter * @author Jason van Zyl */ -@Component(role = LegacyArtifactCollector.class) +@Named +@Singleton public class DefaultLegacyArtifactCollector implements LegacyArtifactCollector { - @Requirement(hint = "nearest") + @Inject + @Named("nearest") private ConflictResolver defaultConflictResolver; - @Requirement + @Inject private Logger logger; - @Requirement + @Inject private LegacySupport legacySupport; private void injectSession(ArtifactResolutionRequest request) { diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/DefaultConflictResolver.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/DefaultConflictResolver.java index d99798986c..3587a2611f 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/DefaultConflictResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/DefaultConflictResolver.java @@ -18,7 +18,8 @@ */ package org.apache.maven.repository.legacy.resolver.conflict; -import org.codehaus.plexus.component.annotations.Component; +import javax.inject.Named; +import javax.inject.Singleton; /** * The default conflict resolver that delegates to the nearest strategy. @@ -28,5 +29,6 @@ import org.codehaus.plexus.component.annotations.Component; * @deprecated As of 3.0, use a specific implementation instead, e.g. {@link NearestConflictResolver} */ @Deprecated -@Component(role = ConflictResolver.class) +@Named +@Singleton public class DefaultConflictResolver extends NearestConflictResolver {} diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/DefaultConflictResolverFactory.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/DefaultConflictResolverFactory.java index 5a6dffb0d6..4b397467d3 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/DefaultConflictResolverFactory.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/DefaultConflictResolverFactory.java @@ -18,10 +18,12 @@ */ package org.apache.maven.repository.legacy.resolver.conflict; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; @@ -34,14 +36,15 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; * TODO you don't need the container in here with the active maps (jvz). * @since 3.0 */ -@Component(role = ConflictResolverFactory.class) +@Named +@Singleton public class DefaultConflictResolverFactory implements ConflictResolverFactory, Contextualizable { // fields ----------------------------------------------------------------- /** * The plexus container used to obtain instances from. */ - @Requirement + @Inject private PlexusContainer container; // ConflictResolverFactory methods ---------------------------------------- diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/FarthestConflictResolver.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/FarthestConflictResolver.java index 89d32c90bb..7da3bcbcfb 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/FarthestConflictResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/FarthestConflictResolver.java @@ -18,8 +18,10 @@ */ package org.apache.maven.repository.legacy.resolver.conflict; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.artifact.resolver.ResolutionNode; -import org.codehaus.plexus.component.annotations.Component; /** * Resolves conflicting artifacts by always selecting the farthest declaration. Farthest is defined as the @@ -28,7 +30,8 @@ import org.codehaus.plexus.component.annotations.Component; * @author Mark Hobson * @since 3.0 */ -@Component(role = ConflictResolver.class, hint = "farthest") +@Named("farthest") +@Singleton public class FarthestConflictResolver implements ConflictResolver { // ConflictResolver methods ----------------------------------------------- diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/NearestConflictResolver.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/NearestConflictResolver.java index a265835eee..2424ac9a82 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/NearestConflictResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/NearestConflictResolver.java @@ -18,8 +18,10 @@ */ package org.apache.maven.repository.legacy.resolver.conflict; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.artifact.resolver.ResolutionNode; -import org.codehaus.plexus.component.annotations.Component; /** * Resolves conflicting artifacts by always selecting the nearest declaration. Nearest is defined as the @@ -29,7 +31,8 @@ import org.codehaus.plexus.component.annotations.Component; * @author Mark Hobson * @since 3.0 */ -@Component(role = ConflictResolver.class, hint = "nearest") +@Named("nearest") +@Singleton public class NearestConflictResolver implements ConflictResolver { // ConflictResolver methods ----------------------------------------------- diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/NewestConflictResolver.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/NewestConflictResolver.java index cd4fac8221..a3e8d486ab 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/NewestConflictResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/NewestConflictResolver.java @@ -18,10 +18,12 @@ */ package org.apache.maven.repository.legacy.resolver.conflict; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.artifact.resolver.ResolutionNode; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.OverConstrainedVersionException; -import org.codehaus.plexus.component.annotations.Component; /** * Resolves conflicting artifacts by always selecting the newest declaration. Newest is defined as the @@ -31,7 +33,8 @@ import org.codehaus.plexus.component.annotations.Component; * @see ArtifactVersion#compareTo * @since 3.0 */ -@Component(role = ConflictResolver.class, hint = "newest") +@Named("newest") +@Singleton public class NewestConflictResolver implements ConflictResolver { // ConflictResolver methods ----------------------------------------------- diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/OldestConflictResolver.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/OldestConflictResolver.java index eee4bde2bd..5a2f30e735 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/OldestConflictResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/OldestConflictResolver.java @@ -18,10 +18,12 @@ */ package org.apache.maven.repository.legacy.resolver.conflict; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.artifact.resolver.ResolutionNode; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.OverConstrainedVersionException; -import org.codehaus.plexus.component.annotations.Component; /** * Resolves conflicting artifacts by always selecting the oldest declaration. Oldest is defined as the @@ -31,7 +33,8 @@ import org.codehaus.plexus.component.annotations.Component; * @see ArtifactVersion#compareTo * @since 3.0 */ -@Component(role = ConflictResolver.class, hint = "oldest") +@Named("oldest") +@Singleton public class OldestConflictResolver implements ConflictResolver { // ConflictResolver methods ----------------------------------------------- diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/AbstractVersionTransformation.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/AbstractVersionTransformation.java index 5d37d4d3e0..66c1920015 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/AbstractVersionTransformation.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/AbstractVersionTransformation.java @@ -18,6 +18,8 @@ */ package org.apache.maven.repository.legacy.resolver.transform; +import javax.inject.Inject; + import java.util.List; import org.apache.maven.artifact.Artifact; @@ -34,7 +36,6 @@ import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.repository.legacy.WagonManager; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; /** @@ -44,10 +45,10 @@ import org.codehaus.plexus.logging.AbstractLogEnabled; * TODO try and refactor to remove abstract methods - not particular happy about current design */ public abstract class AbstractVersionTransformation extends AbstractLogEnabled implements ArtifactTransformation { - @Requirement + @Inject protected RepositoryMetadataManager repositoryMetadataManager; - @Requirement + @Inject protected WagonManager wagonManager; public void transformForResolve( diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/DefaultArtifactTransformationManager.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/DefaultArtifactTransformationManager.java index ca53d0672b..1f2a74e832 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/DefaultArtifactTransformationManager.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/DefaultArtifactTransformationManager.java @@ -18,7 +18,15 @@ */ package org.apache.maven.repository.legacy.resolver.transform; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.deployer.ArtifactDeploymentException; @@ -27,19 +35,24 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.RepositoryRequest; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; /** * @author Jason van Zyl */ -@Component(role = ArtifactTransformationManager.class) +@Named +@Singleton public class DefaultArtifactTransformationManager implements ArtifactTransformationManager { - @Requirement( - role = ArtifactTransformation.class, - hints = {"release", "latest", "snapshot"}) + private List artifactTransformations; + @Inject + public DefaultArtifactTransformationManager(Map artifactTransformations) { + this.artifactTransformations = Stream.of("release", "latest", "snapshot") + .map(artifactTransformations::get) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + public void transformForResolve(Artifact artifact, RepositoryRequest request) throws ArtifactResolutionException, ArtifactNotFoundException { for (ArtifactTransformation transform : artifactTransformations) { diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/LatestArtifactTransformation.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/LatestArtifactTransformation.java index 2821a833fc..437e936c79 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/LatestArtifactTransformation.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/LatestArtifactTransformation.java @@ -18,6 +18,9 @@ */ package org.apache.maven.repository.legacy.resolver.transform; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.RepositoryRequest; @@ -25,12 +28,12 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutio import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.codehaus.plexus.component.annotations.Component; /** * Describes a version transformation during artifact resolution - "latest" type */ -@Component(role = ArtifactTransformation.class, hint = "latest") +@Named("latest") +@Singleton public class LatestArtifactTransformation extends AbstractVersionTransformation { public void transformForResolve(Artifact artifact, RepositoryRequest request) diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/ReleaseArtifactTransformation.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/ReleaseArtifactTransformation.java index 81a6e072de..97ba40e0e1 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/ReleaseArtifactTransformation.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/ReleaseArtifactTransformation.java @@ -18,6 +18,9 @@ */ package org.apache.maven.repository.legacy.resolver.transform; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -27,14 +30,14 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutio import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.codehaus.plexus.component.annotations.Component; /** * Change the version RELEASE to the appropriate release version from the remote repository. * * @author Brett Porter */ -@Component(role = ArtifactTransformation.class, hint = "release") +@Named("release") +@Singleton public class ReleaseArtifactTransformation extends AbstractVersionTransformation { public void transformForResolve(Artifact artifact, RepositoryRequest request) diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/SnapshotTransformation.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/SnapshotTransformation.java index b06add804c..8840d94ead 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/SnapshotTransformation.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/SnapshotTransformation.java @@ -18,6 +18,9 @@ */ package org.apache.maven.repository.legacy.resolver.transform; +import javax.inject.Named; +import javax.inject.Singleton; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -35,14 +38,14 @@ import org.apache.maven.artifact.repository.metadata.Snapshot; import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.StringUtils; /** * @author Brett Porter * @author Michal Maczka */ -@Component(role = ArtifactTransformation.class, hint = "snapshot") +@Named("snapshot") +@Singleton public class SnapshotTransformation extends AbstractVersionTransformation { private static final String DEFAULT_SNAPSHOT_TIMESTAMP_FORMAT = "yyyyMMdd.HHmmss"; diff --git a/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java b/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java index b7c3425fb9..d14c24ee37 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java @@ -18,13 +18,15 @@ */ package org.apache.maven.repository.metadata; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.maven.artifact.ArtifactScopeEnum; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; /** * default implementation of the metadata classpath transformer @@ -32,9 +34,10 @@ import org.codehaus.plexus.component.annotations.Requirement; * @author Oleg Gusakov * */ -@Component(role = ClasspathTransformation.class) +@Named +@Singleton public class DefaultClasspathTransformation implements ClasspathTransformation { - @Requirement + @Inject GraphConflictResolver conflictResolver; // ---------------------------------------------------------------------------------------------------- diff --git a/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicy.java b/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicy.java index c897c0f7d8..ad066520d9 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicy.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicy.java @@ -18,16 +18,19 @@ */ package org.apache.maven.repository.metadata; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; -import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Configuration; /** * @author Oleg Gusakov * */ -@Component(role = GraphConflictResolutionPolicy.class) +@Named +@Singleton public class DefaultGraphConflictResolutionPolicy implements GraphConflictResolutionPolicy { /** * artifact, closer to the entry point, is selected diff --git a/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolver.java b/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolver.java index 3bb1bd00b9..6673bf93d3 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolver.java @@ -18,25 +18,28 @@ */ package org.apache.maven.repository.metadata; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.util.ArrayList; import java.util.List; import java.util.TreeSet; import org.apache.maven.artifact.ArtifactScopeEnum; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; /** * Default conflict resolver.Implements closer newer first policy by default, but could be configured via plexus * * @author Oleg Gusakov */ -@Component(role = GraphConflictResolver.class) +@Named +@Singleton public class DefaultGraphConflictResolver implements GraphConflictResolver { /** * artifact, closer to the entry point, is selected */ - @Requirement(role = GraphConflictResolutionPolicy.class) + @Inject protected GraphConflictResolutionPolicy policy; // ------------------------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java b/maven-compat/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java rename to maven-compat/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java diff --git a/maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java b/maven-compat/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java rename to maven-compat/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java b/maven-compat/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java similarity index 100% rename from maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java rename to maven-compat/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/ToolchainsBuilder.java b/maven-compat/src/main/java/org/apache/maven/toolchain/ToolchainsBuilder.java similarity index 94% rename from maven-core/src/main/java/org/apache/maven/toolchain/ToolchainsBuilder.java rename to maven-compat/src/main/java/org/apache/maven/toolchain/ToolchainsBuilder.java index 43adef4d24..2517e8b780 100644 --- a/maven-core/src/main/java/org/apache/maven/toolchain/ToolchainsBuilder.java +++ b/maven-compat/src/main/java/org/apache/maven/toolchain/ToolchainsBuilder.java @@ -27,7 +27,9 @@ import org.apache.maven.toolchain.model.PersistedToolchains; * Note: This is an internal component whose interface can change without prior notice. * * @author Benjamin Bentmann + * @deprecated use {@link org.apache.maven.toolchain.building.ToolchainsBuilder} instead */ +@Deprecated public interface ToolchainsBuilder { /** diff --git a/maven-compat/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-compat/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java new file mode 100644 index 0000000000..733026c4f0 --- /dev/null +++ b/maven-compat/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java @@ -0,0 +1,286 @@ +/* + * 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.apache.maven; + +import javax.inject.Inject; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.InvalidRepositoryException; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.bridge.MavenRepositorySystem; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.DefaultMavenExecutionResult; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.internal.impl.DefaultSession; +import org.apache.maven.model.Build; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Exclusion; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.Repository; +import org.apache.maven.model.RepositoryPolicy; +import org.apache.maven.project.DefaultProjectBuildingRequest; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.repository.RepositorySystem; +import org.apache.maven.repository.internal.MavenRepositorySystemUtils; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.testing.PlexusTest; +import org.codehaus.plexus.util.FileUtils; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.internal.impl.DefaultRepositorySystem; +import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; +import org.eclipse.aether.repository.LocalRepository; + +import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; + +@PlexusTest +public abstract class AbstractCoreMavenComponentTestCase { + + @Inject + protected PlexusContainer container; + + @Inject + protected RepositorySystem repositorySystem; + + @Inject + protected org.apache.maven.project.ProjectBuilder projectBuilder; + + protected abstract String getProjectsDirectory(); + + protected PlexusContainer getContainer() { + return container; + } + + protected File getProject(String name) throws Exception { + File source = new File(new File(getBasedir(), getProjectsDirectory()), name); + File target = new File(new File(getBasedir(), "target"), name); + FileUtils.copyDirectoryStructureIfModified(source, target); + return new File(target, "pom.xml"); + } + + protected MavenExecutionRequest createMavenExecutionRequest(File pom) throws Exception { + MavenExecutionRequest request = new DefaultMavenExecutionRequest() + .setPom(pom) + .setProjectPresent(true) + .setShowErrors(true) + .setPluginGroups(Arrays.asList("org.apache.maven.plugins")) + .setLocalRepository(getLocalRepository()) + .setRemoteRepositories(getRemoteRepositories()) + .setPluginArtifactRepositories(getPluginArtifactRepositories()) + .setGoals(Arrays.asList("package")); + + if (pom != null) { + request.setMultiModuleProjectDirectory(pom.getParentFile()); + } + + return request; + } + + // layer the creation of a project builder configuration with a request, but this will need to be + // a Maven subclass because we don't want to couple maven to the project builder which we need to + // separate. + protected MavenSession createMavenSession(File pom) throws Exception { + return createMavenSession(pom, new Properties()); + } + + protected MavenSession createMavenSession(File pom, Properties executionProperties) throws Exception { + return createMavenSession(pom, executionProperties, false); + } + + protected MavenSession createMavenSession(File pom, Properties executionProperties, boolean includeModules) + throws Exception { + MavenExecutionRequest request = createMavenExecutionRequest(pom); + + ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest() + .setLocalRepository(request.getLocalRepository()) + .setRemoteRepositories(request.getRemoteRepositories()) + .setPluginArtifactRepositories(request.getPluginArtifactRepositories()) + .setSystemProperties(executionProperties) + .setUserProperties(new Properties()); + + List projects = new ArrayList<>(); + + if (pom != null) { + MavenProject project = projectBuilder.build(pom, configuration).getProject(); + + projects.add(project); + if (includeModules) { + for (String module : project.getModules()) { + File modulePom = new File(pom.getParentFile(), module); + if (modulePom.isDirectory()) { + modulePom = new File(modulePom, "pom.xml"); + } + projects.add(projectBuilder.build(modulePom, configuration).getProject()); + } + } + } else { + MavenProject project = createStubMavenProject(); + project.setRemoteArtifactRepositories(request.getRemoteRepositories()); + project.setPluginArtifactRepositories(request.getPluginArtifactRepositories()); + projects.add(project); + } + + initRepoSession(configuration); + + MavenSession session = new MavenSession( + getContainer(), configuration.getRepositorySession(), request, new DefaultMavenExecutionResult()); + session.setProjects(projects); + session.setAllProjects(session.getProjects()); + session.setSession(new DefaultSession(session, new DefaultRepositorySystem(), null, null, null, null)); + + return session; + } + + protected void initRepoSession(ProjectBuildingRequest request) throws Exception { + File localRepoDir = new File(request.getLocalRepository().getBasedir()); + LocalRepository localRepo = new LocalRepository(localRepoDir); + DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); + session.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(session, localRepo)); + request.setRepositorySession(session); + } + + protected MavenProject createStubMavenProject() { + Model model = new Model(); + model.setGroupId("org.apache.maven.test"); + model.setArtifactId("maven-test"); + model.setVersion("1.0"); + return new MavenProject(model); + } + + protected List getRemoteRepositories() throws InvalidRepositoryException { + File repoDir = new File(getBasedir(), "src/test/remote-repo").getAbsoluteFile(); + + RepositoryPolicy policy = new RepositoryPolicy(); + policy.setEnabled(true); + policy.setChecksumPolicy("ignore"); + policy.setUpdatePolicy("always"); + + Repository repository = new Repository(); + repository.setId(MavenRepositorySystem.DEFAULT_REMOTE_REPO_ID); + repository.setUrl("file://" + repoDir.toURI().getPath()); + repository.setReleases(policy); + repository.setSnapshots(policy); + + return Arrays.asList(repositorySystem.buildArtifactRepository(repository)); + } + + protected List getPluginArtifactRepositories() throws InvalidRepositoryException { + return getRemoteRepositories(); + } + + protected ArtifactRepository getLocalRepository() throws InvalidRepositoryException { + File repoDir = new File(getBasedir(), "target/local-repo").getAbsoluteFile(); + + return repositorySystem.createLocalRepository(repoDir); + } + + protected class ProjectBuilder { + private MavenProject project; + + public ProjectBuilder(MavenProject project) { + this.project = project; + } + + public ProjectBuilder(String groupId, String artifactId, String version) { + Model model = new Model(); + model.setModelVersion("4.0.0"); + model.setGroupId(groupId); + model.setArtifactId(artifactId); + model.setVersion(version); + model.setBuild(new Build()); + project = new MavenProject(model); + } + + public ProjectBuilder setGroupId(String groupId) { + project.setGroupId(groupId); + return this; + } + + public ProjectBuilder setArtifactId(String artifactId) { + project.setArtifactId(artifactId); + return this; + } + + public ProjectBuilder setVersion(String version) { + project.setVersion(version); + return this; + } + + // Dependencies + // + public ProjectBuilder addDependency(String groupId, String artifactId, String version, String scope) { + return addDependency(groupId, artifactId, version, scope, (Exclusion) null); + } + + public ProjectBuilder addDependency( + String groupId, String artifactId, String version, String scope, Exclusion exclusion) { + return addDependency(groupId, artifactId, version, scope, null, exclusion); + } + + public ProjectBuilder addDependency( + String groupId, String artifactId, String version, String scope, String systemPath) { + return addDependency(groupId, artifactId, version, scope, systemPath, null); + } + + public ProjectBuilder addDependency( + String groupId, + String artifactId, + String version, + String scope, + String systemPath, + Exclusion exclusion) { + Dependency d = new Dependency(); + d.setGroupId(groupId); + d.setArtifactId(artifactId); + d.setVersion(version); + d.setScope(scope); + + if (systemPath != null && scope.equals(Artifact.SCOPE_SYSTEM)) { + d.setSystemPath(systemPath); + } + + if (exclusion != null) { + d.addExclusion(exclusion); + } + + project.getDependencies().add(d); + + return this; + } + + // Plugins + // + public ProjectBuilder addPlugin(Plugin plugin) { + project.getBuildPlugins().add(plugin); + return this; + } + + public MavenProject get() { + return project; + } + } +} diff --git a/maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java b/maven-compat/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java similarity index 100% rename from maven-core/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java rename to maven-compat/src/test/java/org/apache/maven/ProjectDependenciesResolverTest.java diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/metadata/SwitchableMetadataSource.java b/maven-compat/src/test/java/org/apache/maven/artifact/metadata/SwitchableMetadataSource.java new file mode 100644 index 0000000000..a06fb8b461 --- /dev/null +++ b/maven-compat/src/test/java/org/apache/maven/artifact/metadata/SwitchableMetadataSource.java @@ -0,0 +1,79 @@ +/* + * 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.apache.maven.artifact.metadata; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; +import org.eclipse.sisu.Priority; + +@Singleton +@Priority(10) +@Named +public class SwitchableMetadataSource implements ArtifactMetadataSource { + private ArtifactMetadataSource delegate; + + @Inject + public SwitchableMetadataSource(@Named("test") ArtifactMetadataSource delegate) { + this.delegate = delegate; + } + + public void setDelegate(ArtifactMetadataSource delegate) { + this.delegate = delegate; + } + + @Override + public ResolutionGroup retrieve(MetadataResolutionRequest request) throws ArtifactMetadataRetrievalException { + return delegate.retrieve(request); + } + + @Override + public ResolutionGroup retrieve( + Artifact artifact, ArtifactRepository localRepository, List remoteRepositories) + throws ArtifactMetadataRetrievalException { + return delegate.retrieve(artifact, localRepository, remoteRepositories); + } + + @Override + public List retrieveAvailableVersions(MetadataResolutionRequest request) + throws ArtifactMetadataRetrievalException { + return delegate.retrieveAvailableVersions(request); + } + + @Override + public List retrieveAvailableVersions( + Artifact artifact, ArtifactRepository localRepository, List remoteRepositories) + throws ArtifactMetadataRetrievalException { + return delegate.retrieveAvailableVersions(artifact, localRepository, remoteRepositories); + } + + @Override + public List retrieveAvailableVersionsFromDeploymentRepository( + Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository) + throws ArtifactMetadataRetrievalException { + return delegate.retrieveAvailableVersionsFromDeploymentRepository(artifact, localRepository, remoteRepository); + } +} diff --git a/maven-core/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java b/maven-compat/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java similarity index 100% rename from maven-core/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java rename to maven-compat/src/test/java/org/apache/maven/project/artifact/DefaultMavenMetadataCacheTest.java diff --git a/maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java b/maven-compat/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java similarity index 100% rename from maven-core/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java rename to maven-compat/src/test/java/org/apache/maven/project/artifact/MavenMetadataSourceTest.java diff --git a/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java b/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java index 2eda1b281e..b8db7d99b1 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/LegacyRepositorySystemTest.java @@ -25,6 +25,7 @@ import java.util.Arrays; import java.util.List; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.SwitchableMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; @@ -36,12 +37,15 @@ import org.apache.maven.model.Dependency; import org.apache.maven.model.Repository; import org.apache.maven.model.RepositoryPolicy; import org.apache.maven.plugin.LegacySupport; +import org.apache.maven.project.artifact.DefaultMetadataSource; import org.apache.maven.repository.legacy.LegacyRepositorySystem; import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException; import org.codehaus.plexus.testing.PlexusTest; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.codehaus.plexus.testing.PlexusExtension.getBasedir; @@ -57,7 +61,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @PlexusTest class LegacyRepositorySystemTest { @Inject - private RepositorySystem repositorySystem; + private LegacyRepositorySystem repositorySystem; @Inject private ResolutionErrorHandler resolutionErrorHandler; @@ -184,4 +188,15 @@ class LegacyRepositorySystemTest { assertEquals(localRepoDir.getPath(), basedir); } + + @Inject + DefaultMetadataSource defaultMetadataSource; + + @Inject + SwitchableMetadataSource switchableMetadataSource; + + @BeforeEach + void setup() throws CycleDetectedInComponentGraphException { + switchableMetadataSource.setDelegate(defaultMetadataSource); + } } diff --git a/maven-core/src/test/java/org/apache/maven/repository/TestArtifactHandler.java b/maven-compat/src/test/java/org/apache/maven/repository/TestArtifactHandler.java similarity index 100% rename from maven-core/src/test/java/org/apache/maven/repository/TestArtifactHandler.java rename to maven-compat/src/test/java/org/apache/maven/repository/TestArtifactHandler.java diff --git a/maven-core/src/test/java/org/apache/maven/internal/impl/TestRepositorySystem.java b/maven-compat/src/test/java/org/apache/maven/repository/TestRepositorySystem.java similarity index 97% rename from maven-core/src/test/java/org/apache/maven/internal/impl/TestRepositorySystem.java rename to maven-compat/src/test/java/org/apache/maven/repository/TestRepositorySystem.java index a23293796c..cc57f3d975 100644 --- a/maven-core/src/test/java/org/apache/maven/internal/impl/TestRepositorySystem.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/TestRepositorySystem.java @@ -16,8 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.internal.impl; +package org.apache.maven.repository; +import javax.annotation.Priority; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @@ -44,15 +45,12 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.model.Repository; import org.apache.maven.model.io.ModelReader; import org.apache.maven.project.artifact.ArtifactWithDependencies; -import org.apache.maven.repository.ArtifactDoesNotExistException; -import org.apache.maven.repository.ArtifactTransferFailedException; -import org.apache.maven.repository.ArtifactTransferListener; -import org.apache.maven.repository.RepositorySystem; import org.apache.maven.settings.Mirror; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Server; @@ -63,12 +61,17 @@ import org.eclipse.aether.RepositorySystemSession; */ @Named @Singleton +@Priority(10) public class TestRepositorySystem implements RepositorySystem { private final ModelReader modelReader; private final ArtifactFactory artifactFactory; + public TestRepositorySystem() { + this(null, null); + } + @Inject public TestRepositorySystem(ModelReader modelReader, ArtifactFactory artifactFactory) { this.modelReader = modelReader; @@ -144,7 +147,7 @@ public class TestRepositorySystem implements RepositorySystem { public ArtifactRepository createLocalRepository(File localRepository) throws InvalidRepositoryException { return new MavenArtifactRepository( - DEFAULT_LOCAL_REPO_ID, + MavenRepositorySystem.DEFAULT_LOCAL_REPO_ID, "file://" + localRepository.toURI().getPath(), new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java index 6019dca7e5..821e321c8e 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java @@ -25,7 +25,6 @@ import java.util.Arrays; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.Authentication; -import org.apache.maven.repository.RepositorySystem; import org.apache.maven.settings.Server; import org.codehaus.plexus.testing.PlexusTest; import org.junit.jupiter.api.Test; @@ -41,7 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; @PlexusTest class LegacyRepositorySystemTest { @Inject - private RepositorySystem repositorySystem; + private LegacyRepositorySystem repositorySystem; @Test void testThatLocalRepositoryWithSpacesIsProperlyHandled() throws Exception { diff --git a/maven-core/src/test/projects/project-dependencies-resolver/it0063/jdk/jre/placeholder.txt b/maven-compat/src/test/projects/project-dependencies-resolver/it0063/jdk/jre/placeholder.txt similarity index 100% rename from maven-core/src/test/projects/project-dependencies-resolver/it0063/jdk/jre/placeholder.txt rename to maven-compat/src/test/projects/project-dependencies-resolver/it0063/jdk/jre/placeholder.txt diff --git a/maven-core/src/test/projects/project-dependencies-resolver/it0063/jdk/lib/tools.jar b/maven-compat/src/test/projects/project-dependencies-resolver/it0063/jdk/lib/tools.jar similarity index 100% rename from maven-core/src/test/projects/project-dependencies-resolver/it0063/jdk/lib/tools.jar rename to maven-compat/src/test/projects/project-dependencies-resolver/it0063/jdk/lib/tools.jar diff --git a/maven-core/src/test/projects/project-dependencies-resolver/it0063/pom.xml b/maven-compat/src/test/projects/project-dependencies-resolver/it0063/pom.xml similarity index 100% rename from maven-core/src/test/projects/project-dependencies-resolver/it0063/pom.xml rename to maven-compat/src/test/projects/project-dependencies-resolver/it0063/pom.xml diff --git a/maven-core/src/test/projects/project-dependencies-resolver/project-with-exclusions/pom.xml b/maven-compat/src/test/projects/project-dependencies-resolver/project-with-exclusions/pom.xml similarity index 100% rename from maven-core/src/test/projects/project-dependencies-resolver/project-with-exclusions/pom.xml rename to maven-compat/src/test/projects/project-dependencies-resolver/project-with-exclusions/pom.xml diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 1aed356c02..83ad8ff157 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -329,6 +329,21 @@ under the License. org.apache.maven.toolchain.DefaultToolchain#DefaultToolchain(org.apache.maven.toolchain.model.ToolchainModel,org.codehaus.plexus.logging.Logger):CONSTRUCTOR_REMOVED org.apache.maven.toolchain.DefaultToolchain#DefaultToolchain(org.apache.maven.toolchain.model.ToolchainModel,java.lang.String,org.codehaus.plexus.logging.Logger):CONSTRUCTOR_REMOVED org.apache.maven.toolchain.DefaultToolchainManager#logger + + org.apache.maven.plugin.PluginManager + org.apache.maven.repository.ArtifactDoesNotExistException + org.apache.maven.repository.ArtifactTransferEvent + org.apache.maven.repository.ArtifactTransferFailedException + org.apache.maven.repository.ArtifactTransferListener + org.apache.maven.repository.ArtifactTransferResource + org.apache.maven.repository.DelegatingLocalArtifactRepository + org.apache.maven.repository.LocalArtifactRepository + org.apache.maven.repository.LocalRepositoryNotAccessibleException + org.apache.maven.repository.RepositorySystem + org.apache.maven.settings.DefaultMavenSettingsBuilder + org.apache.maven.settings.MavenSettingsBuilder + org.apache.maven.toolchain.DefaultToolchainsBuilder + org.apache.maven.toolchain.ToolchainsBuilder diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index d1312fe0d4..e060f56af6 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -23,6 +23,7 @@ import javax.inject.Named; import javax.inject.Singleton; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -68,7 +69,6 @@ import org.apache.maven.model.superpom.SuperPomProvider; import org.apache.maven.plugin.LegacySupport; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuilder; -import org.apache.maven.repository.LocalRepositoryNotAccessibleException; import org.apache.maven.session.scope.internal.SessionScope; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; @@ -204,7 +204,7 @@ public class DefaultMaven implements Maven { try { validateLocalRepository(request); - } catch (LocalRepositoryNotAccessibleException e) { + } catch (IOException e) { return addExceptionToResult(result, e); } @@ -408,7 +408,7 @@ public class DefaultMaven implements Maven { return repositorySessionFactory.newRepositorySession(request); } - private void validateLocalRepository(MavenExecutionRequest request) throws LocalRepositoryNotAccessibleException { + private void validateLocalRepository(MavenExecutionRequest request) throws IOException { File localRepoDir = request.getLocalRepositoryPath(); logger.debug("Using local repository at " + localRepoDir); @@ -416,7 +416,7 @@ public class DefaultMaven implements Maven { localRepoDir.mkdirs(); if (!localRepoDir.isDirectory()) { - throw new LocalRepositoryNotAccessibleException("Could not create local repository at " + localRepoDir); + throw new IOException("Could not create local repository at " + localRepoDir); } } diff --git a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java index 3754de834a..cbbfe3ea35 100644 --- a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java +++ b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java @@ -18,6 +18,7 @@ */ package org.apache.maven; +import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -33,6 +34,8 @@ import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.ArtifactProperties; @@ -45,6 +48,8 @@ import org.eclipse.aether.graph.DependencyFilter; import org.eclipse.aether.graph.DependencyNode; import org.eclipse.aether.graph.Exclusion; import org.eclipse.aether.repository.Authentication; +import org.eclipse.aether.repository.LocalRepository; +import org.eclipse.aether.repository.LocalRepositoryManager; import org.eclipse.aether.repository.Proxy; import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.repository.RepositoryPolicy; @@ -351,6 +356,29 @@ public class RepositoryUtils { return result; } + public static RepositorySystemSession overlay( + ArtifactRepository repository, RepositorySystemSession session, RepositorySystem system) { + if (repository == null || repository.getBasedir() == null) { + return session; + } + + DefaultRepositorySystemSession newSession; + if (session != null) { + LocalRepositoryManager lrm = session.getLocalRepositoryManager(); + if (lrm != null && lrm.getRepository().getBasedir().equals(new File(repository.getBasedir()))) { + return session; + } + newSession = new DefaultRepositorySystemSession(session); + } else { + newSession = new DefaultRepositorySystemSession(); + } + + final LocalRepositoryManager llrm = + system.newLocalRepositoryManager(newSession, new LocalRepository(repository.getBasedir())); + newSession.setLocalRepositoryManager(llrm); + return newSession; + } + private static int repositoryHashCode(RemoteRepository repository) { int result = 17; Object obj = repository.getUrl(); diff --git a/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java b/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java index eb54b31f8e..7d3301d90c 100644 --- a/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java +++ b/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java @@ -54,7 +54,6 @@ import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.repository.Proxy; -import org.apache.maven.repository.RepositorySystem; import org.apache.maven.settings.Mirror; import org.codehaus.plexus.util.StringUtils; import org.eclipse.aether.RepositorySystemSession; @@ -69,6 +68,13 @@ import org.eclipse.aether.repository.RemoteRepository; @Named("default") @Singleton public class MavenRepositorySystem { + + public static final String DEFAULT_REMOTE_REPO_ID = "central"; + + public static final String DEFAULT_REMOTE_REPO_URL = "https://repo.maven.apache.org/maven2"; + + public static final String DEFAULT_LOCAL_REPO_ID = "local"; + private final ArtifactHandlerManager artifactHandlerManager; private final Map layouts; @@ -373,7 +379,7 @@ public class MavenRepositorySystem { String layoutId, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases) - throws Exception { + throws InvalidRepositoryException { ArtifactRepositoryLayout layout = layouts.get(layoutId); checkLayout(id, layoutId, layout); @@ -381,10 +387,12 @@ public class MavenRepositorySystem { return createArtifactRepository(id, url, layout, snapshots, releases); } - private void checkLayout(String repositoryId, String layoutId, ArtifactRepositoryLayout layout) throws Exception { + private void checkLayout(String repositoryId, String layoutId, ArtifactRepositoryLayout layout) + throws InvalidRepositoryException { if (layout == null) { - throw new Exception( - String.format("Cannot find ArtifactRepositoryLayout instance for: %s %s", layoutId, repositoryId)); + throw new InvalidRepositoryException( + String.format("Cannot find ArtifactRepositoryLayout instance for: %s %s", layoutId, repositoryId), + repositoryId); } } @@ -518,11 +526,14 @@ public class MavenRepositorySystem { // // Code taken from LegacyRepositorySystem // + public ArtifactRepository createDefaultRemoteRepository() throws Exception { + return createDefaultRemoteRepository(null); + } public ArtifactRepository createDefaultRemoteRepository(MavenExecutionRequest request) throws Exception { return createRepository( - RepositorySystem.DEFAULT_REMOTE_REPO_URL, - RepositorySystem.DEFAULT_REMOTE_REPO_ID, + MavenRepositorySystem.DEFAULT_REMOTE_REPO_URL, + MavenRepositorySystem.DEFAULT_REMOTE_REPO_ID, true, ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, false, @@ -538,7 +549,7 @@ public class MavenRepositorySystem { boolean snapshots, String snapshotUpdates, String checksumPolicy) - throws Exception { + throws InvalidRepositoryException { ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy(snapshots, snapshotUpdates, checksumPolicy); @@ -638,10 +649,14 @@ public class MavenRepositorySystem { } public ArtifactRepository createLocalRepository(MavenExecutionRequest request, File localRepository) - throws Exception { + throws InvalidRepositoryException { + return createLocalRepository(localRepository); + } + + public ArtifactRepository createLocalRepository(File localRepository) throws InvalidRepositoryException { return createRepository( "file://" + localRepository.toURI().getRawPath(), - RepositorySystem.DEFAULT_LOCAL_REPO_ID, + MavenRepositorySystem.DEFAULT_LOCAL_REPO_ID, true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, true, diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java index aee374816a..e2204e4023 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java @@ -32,7 +32,6 @@ import java.util.Set; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.bridge.MavenRepositorySystem; -import org.apache.maven.repository.RepositorySystem; import org.apache.maven.settings.Mirror; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Repository; @@ -104,7 +103,7 @@ public class DefaultMavenExecutionRequestPopulator implements MavenExecutionRequ throws MavenExecutionRequestPopulationException { Set definedRepositories = repositorySystem.getRepoIds(request.getRemoteRepositories()); - if (!definedRepositories.contains(RepositorySystem.DEFAULT_REMOTE_REPO_ID)) { + if (!definedRepositories.contains(MavenRepositorySystem.DEFAULT_REMOTE_REPO_ID)) { try { request.addRemoteRepository(repositorySystem.createDefaultRemoteRepository(request)); } catch (Exception e) { @@ -117,7 +116,7 @@ public class DefaultMavenExecutionRequestPopulator implements MavenExecutionRequ throws MavenExecutionRequestPopulationException { Set definedRepositories = repositorySystem.getRepoIds(request.getPluginArtifactRepositories()); - if (!definedRepositories.contains(RepositorySystem.DEFAULT_REMOTE_REPO_ID)) { + if (!definedRepositories.contains(MavenRepositorySystem.DEFAULT_REMOTE_REPO_ID)) { try { request.addPluginArtifactRepository(repositorySystem.createDefaultRemoteRepository(request)); } catch (Exception e) { @@ -157,11 +156,11 @@ public class DefaultMavenExecutionRequestPopulator implements MavenExecutionRequ } if (localRepositoryPath == null || localRepositoryPath.isEmpty()) { - localRepositoryPath = RepositorySystem.defaultUserLocalRepository.getAbsolutePath(); + localRepositoryPath = new File(System.getProperty("user.home"), ".m2/repository").getAbsolutePath(); } try { - return repositorySystem.createLocalRepository(request, new File(localRepositoryPath)); + return repositorySystem.createLocalRepository(new File(localRepositoryPath)); } catch (Exception e) { throw new MavenExecutionRequestPopulationException("Cannot create local repository.", e); } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultProjectArtifactFactory.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultProjectArtifactFactory.java index ede5b4e09e..6ae029efde 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultProjectArtifactFactory.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultProjectArtifactFactory.java @@ -21,13 +21,22 @@ package org.apache.maven.lifecycle.internal; import javax.inject.Inject; import javax.inject.Named; +import java.io.File; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.resolver.filter.ExclusionArtifactFilter; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.InvalidDependencyVersionException; -import org.apache.maven.project.artifact.MavenMetadataSource; /** * Default component responsible for creation of MavenProject#dependencyArtifacts instances. @@ -44,6 +53,106 @@ public class DefaultProjectArtifactFactory implements ProjectArtifactFactory { @Override public Set createArtifacts(MavenProject project) throws InvalidDependencyVersionException { - return MavenMetadataSource.createArtifacts(artifactFactory, project.getDependencies(), null, null, project); + return createArtifacts(artifactFactory, project.getDependencies(), null, null, project); + } + + public static Set createArtifacts( + ArtifactFactory artifactFactory, + List dependencies, + String inheritedScope, + ArtifactFilter dependencyFilter, + MavenProject project) + throws InvalidDependencyVersionException { + Set artifacts = new LinkedHashSet<>(); + + for (Dependency d : dependencies) { + Artifact dependencyArtifact; + try { + dependencyArtifact = createDependencyArtifact(artifactFactory, d, inheritedScope, dependencyFilter); + } catch (InvalidVersionSpecificationException e) { + throw new InvalidDependencyVersionException(project.getId(), d, project.getFile(), e); + } + + if (dependencyArtifact != null) { + artifacts.add(dependencyArtifact); + } + } + + return artifacts; + } + + private static Artifact createDependencyArtifact( + ArtifactFactory factory, Dependency dependency, String inheritedScope, ArtifactFilter inheritedFilter) + throws InvalidVersionSpecificationException { + String effectiveScope = getEffectiveScope(dependency.getScope(), inheritedScope); + + if (effectiveScope == null) { + return null; + } + + VersionRange versionRange = VersionRange.createFromVersionSpec(dependency.getVersion()); + + Artifact dependencyArtifact = factory.createDependencyArtifact( + dependency.getGroupId(), + dependency.getArtifactId(), + versionRange, + dependency.getType(), + dependency.getClassifier(), + effectiveScope, + dependency.isOptional()); + + if (inheritedFilter != null && !inheritedFilter.include(dependencyArtifact)) { + return null; + } + + if (Artifact.SCOPE_SYSTEM.equals(effectiveScope)) { + dependencyArtifact.setFile(new File(dependency.getSystemPath())); + } + + dependencyArtifact.setDependencyFilter(createDependencyFilter(dependency, inheritedFilter)); + + return dependencyArtifact; + } + + private static String getEffectiveScope(String originalScope, String inheritedScope) { + String effectiveScope = Artifact.SCOPE_RUNTIME; + + if (originalScope == null) { + originalScope = Artifact.SCOPE_COMPILE; + } + + if (inheritedScope == null) { + // direct dependency retains its scope + effectiveScope = originalScope; + } else if (Artifact.SCOPE_TEST.equals(originalScope) || Artifact.SCOPE_PROVIDED.equals(originalScope)) { + // test and provided are not transitive, so exclude them + effectiveScope = null; + } else if (Artifact.SCOPE_SYSTEM.equals(originalScope)) { + // system scope come through unchanged... + effectiveScope = Artifact.SCOPE_SYSTEM; + } else if (Artifact.SCOPE_COMPILE.equals(originalScope) && Artifact.SCOPE_COMPILE.equals(inheritedScope)) { + // added to retain compile scope. Remove if you want compile inherited as runtime + effectiveScope = Artifact.SCOPE_COMPILE; + } else if (Artifact.SCOPE_TEST.equals(inheritedScope)) { + effectiveScope = Artifact.SCOPE_TEST; + } else if (Artifact.SCOPE_PROVIDED.equals(inheritedScope)) { + effectiveScope = Artifact.SCOPE_PROVIDED; + } + + return effectiveScope; + } + + private static ArtifactFilter createDependencyFilter(Dependency dependency, ArtifactFilter inheritedFilter) { + ArtifactFilter effectiveFilter = inheritedFilter; + + if (!dependency.getExclusions().isEmpty()) { + effectiveFilter = new ExclusionArtifactFilter(dependency.getExclusions()); + + if (inheritedFilter != null) { + effectiveFilter = new AndArtifactFilter(Arrays.asList(inheritedFilter, effectiveFilter)); + } + } + + return effectiveFilter; } } 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 7ec9992431..1ec21e2981 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 @@ -42,7 +42,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.InvalidArtifactRTException; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.LegacyLocalRepositoryManager; import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.feature.Features; import org.apache.maven.model.Build; @@ -971,8 +970,7 @@ public class DefaultProjectBuilder implements ProjectBuilder { this.modelPool = modelPool; this.transformerContextBuilder = transformerContextBuilder; - session = LegacyLocalRepositoryManager.overlay( - request.getLocalRepository(), request.getRepositorySession(), repoSystem); + session = RepositoryUtils.overlay(request.getLocalRepository(), request.getRepositorySession(), repoSystem); repositories = RepositoryUtils.toRepos(request.getRemoteRepositories()); } } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java index 92cbd259f2..9908778618 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java @@ -36,6 +36,7 @@ import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.classrealm.ClassRealmManager; import org.apache.maven.model.Build; import org.apache.maven.model.Extension; @@ -47,7 +48,6 @@ import org.apache.maven.plugin.MavenPluginManager; import org.apache.maven.plugin.PluginManagerException; import org.apache.maven.plugin.PluginResolutionException; import org.apache.maven.plugin.version.PluginVersionResolutionException; -import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.eclipse.aether.graph.DependencyFilter; @@ -69,7 +69,7 @@ public class DefaultProjectBuildingHelper implements ProjectBuildingHelper { private final PlexusContainer container; // TODO not used? Then remove private final ClassRealmManager classRealmManager; private final ProjectRealmCache projectRealmCache; - private final RepositorySystem repositorySystem; + private final MavenRepositorySystem repositorySystem; private final MavenPluginManager pluginManager; @Inject @@ -77,7 +77,7 @@ public class DefaultProjectBuildingHelper implements ProjectBuildingHelper { PlexusContainer container, ClassRealmManager classRealmManager, ProjectRealmCache projectRealmCache, - RepositorySystem repositorySystem, + MavenRepositorySystem repositorySystem, MavenPluginManager pluginManager) { this.container = container; this.classRealmManager = classRealmManager; @@ -94,7 +94,7 @@ public class DefaultProjectBuildingHelper implements ProjectBuildingHelper { List internalRepositories = new ArrayList<>(); for (Repository repository : pomRepositories) { - internalRepositories.add(repositorySystem.buildArtifactRepository(repository)); + internalRepositories.add(MavenRepositorySystem.buildArtifactRepository(repository)); } repositorySystem.injectMirror(request.getRepositorySession(), internalRepositories); diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index 84a4090b23..0e165e04cb 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -40,6 +40,7 @@ import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.lifecycle.internal.DefaultProjectArtifactFactory; import org.apache.maven.model.Build; import org.apache.maven.model.CiManagement; import org.apache.maven.model.Contributor; @@ -67,7 +68,6 @@ import org.apache.maven.model.Scm; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.model.root.RootLocator; import org.apache.maven.project.artifact.InvalidDependencyVersionException; -import org.apache.maven.project.artifact.MavenMetadataSource; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.eclipse.aether.graph.DependencyFilter; @@ -1313,7 +1313,7 @@ public class MavenProject implements Cloneable { @Deprecated public Set createArtifacts(ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter filter) throws InvalidDependencyVersionException { - return MavenMetadataSource.createArtifacts( + return DefaultProjectArtifactFactory.createArtifacts( artifactFactory, getModel().getDependencies(), inheritedScope, filter, this); } diff --git a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java index 720729582f..c406898f06 100644 --- a/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/AbstractCoreMavenComponentTestCase.java @@ -29,6 +29,7 @@ import java.util.Properties; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.execution.DefaultMavenExecutionRequest; import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.MavenExecutionRequest; @@ -44,7 +45,6 @@ import org.apache.maven.model.RepositoryPolicy; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingRequest; -import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.testing.PlexusTest; @@ -63,7 +63,7 @@ public abstract class AbstractCoreMavenComponentTestCase { protected PlexusContainer container; @Inject - protected RepositorySystem repositorySystem; + protected MavenRepositorySystem repositorySystem; @Inject protected org.apache.maven.project.ProjectBuilder projectBuilder; @@ -179,7 +179,7 @@ public abstract class AbstractCoreMavenComponentTestCase { policy.setUpdatePolicy("always"); Repository repository = new Repository(); - repository.setId(RepositorySystem.DEFAULT_REMOTE_REPO_ID); + repository.setId(MavenRepositorySystem.DEFAULT_REMOTE_REPO_ID); repository.setUrl("file://" + repoDir.toURI().getPath()); repository.setReleases(policy); repository.setSnapshots(policy); diff --git a/maven-core/src/test/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactoryTest.java b/maven-core/src/test/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactoryTest.java index 20ee58e56e..fe2bbe8b44 100644 --- a/maven-core/src/test/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactoryTest.java +++ b/maven-core/src/test/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactoryTest.java @@ -55,9 +55,6 @@ import static org.junit.jupiter.api.Assertions.assertThrowsExactly; @PlexusTest public class DefaultRepositorySystemSessionFactoryTest { - @Inject - protected org.apache.maven.repository.RepositorySystem repositorySystem; - @Inject protected MavenRepositorySystem mavenRepositorySystem; @@ -398,6 +395,6 @@ public class DefaultRepositorySystemSessionFactoryTest { protected ArtifactRepository getLocalRepository() throws InvalidRepositoryException { File repoDir = new File(getBasedir(), "target/local-repo").getAbsoluteFile(); - return repositorySystem.createLocalRepository(repoDir); + return mavenRepositorySystem.createLocalRepository(repoDir); } } diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/ProjectDependenciesResolverStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/ProjectDependenciesResolverStub.java deleted file mode 100644 index 773b432be7..0000000000 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/ProjectDependenciesResolverStub.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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.apache.maven.lifecycle.internal.stub; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.maven.ProjectDependenciesResolver; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.DependencyResolutionException; -import org.apache.maven.project.DependencyResolutionRequest; -import org.apache.maven.project.DependencyResolutionResult; -import org.apache.maven.project.MavenProject; -import org.eclipse.aether.graph.DefaultDependencyNode; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.graph.DependencyNode; - -/** - * @author Kristian Rosenvold - */ -public class ProjectDependenciesResolverStub - implements ProjectDependenciesResolver, org.apache.maven.project.ProjectDependenciesResolver { - public Set resolve(MavenProject project, Collection scopesToResolve, MavenSession session) - throws ArtifactResolutionException, ArtifactNotFoundException { - return new HashSet<>(); - } - - public Set resolve( - MavenProject project, - Collection scopesToCollect, - Collection scopesToResolve, - MavenSession session) - throws ArtifactResolutionException, ArtifactNotFoundException { - return new HashSet<>(); - } - - public Set resolve( - Collection projects, Collection scopes, MavenSession session) - throws ArtifactResolutionException, ArtifactNotFoundException { - return new HashSet<>(); - } - - public Set resolve( - MavenProject project, - Collection scopesToCollect, - Collection scopesToResolve, - MavenSession session, - Set ignorableArtifacts) - throws ArtifactResolutionException, ArtifactNotFoundException { - return new HashSet<>(); - } - - public DependencyResolutionResult resolve(DependencyResolutionRequest request) - throws DependencyResolutionException { - return new DependencyResolutionResult() { - - public List getUnresolvedDependencies() { - return Collections.emptyList(); - } - - public List getResolvedDependencies() { - return Collections.emptyList(); - } - - public List getResolutionErrors(Dependency dependency) { - return Collections.emptyList(); - } - - public DependencyNode getDependencyGraph() { - return new DefaultDependencyNode((Dependency) null); - } - - public List getDependencies() { - return Collections.emptyList(); - } - - public List getCollectionErrors() { - return Collections.emptyList(); - } - }; - } -} diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index c01c6f56c3..8759d8e5f3 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -34,6 +34,7 @@ import org.apache.maven.AbstractCoreMavenComponentTestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.execution.DefaultMavenExecutionRequest; import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.MavenExecutionRequest; @@ -46,7 +47,6 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.DuplicateProjectException; import org.apache.maven.project.MavenProject; -import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; @@ -69,7 +69,7 @@ class PluginParameterExpressionEvaluatorTest extends AbstractCoreMavenComponentT private static final String FS = File.separator; @Inject - private RepositorySystem factory; + private MavenRepositorySystem factory; private Path rootDirectory; @@ -394,7 +394,7 @@ class PluginParameterExpressionEvaluatorTest extends AbstractCoreMavenComponentT private ExpressionEvaluator createExpressionEvaluator( MavenProject project, PluginDescriptor pluginDescriptor, Properties executionProperties) throws Exception { - ArtifactRepository repo = factory.createDefaultLocalRepository(); + ArtifactRepository repo = getLocalRepository(); MutablePlexusContainer container = (MutablePlexusContainer) getContainer(); MavenSession session = createSession(container, repo, executionProperties); diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4Test.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4Test.java index aee3309830..db3eb2a82a 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4Test.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4Test.java @@ -35,6 +35,7 @@ import org.apache.maven.api.Session; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.execution.DefaultMavenExecutionRequest; import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.MavenExecutionRequest; @@ -49,7 +50,6 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.DuplicateProjectException; import org.apache.maven.project.MavenProject; -import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.MutablePlexusContainer; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; @@ -77,7 +77,7 @@ public class PluginParameterExpressionEvaluatorV4Test extends AbstractCoreMavenC private static final String FS = File.separator; @Inject - private RepositorySystem factory; + private MavenRepositorySystem factory; private Path rootDirectory; @@ -407,7 +407,7 @@ public class PluginParameterExpressionEvaluatorV4Test extends AbstractCoreMavenC private ExpressionEvaluator createExpressionEvaluator( MavenProject project, PluginDescriptor pluginDescriptor, Properties executionProperties) throws Exception { - ArtifactRepository repo = factory.createDefaultLocalRepository(); + ArtifactRepository repo = getLocalRepository(); MutablePlexusContainer container = (MutablePlexusContainer) getContainer(); MavenSession mavenSession = createSession(container, repo, executionProperties); diff --git a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java index ced6976574..36ecf072d2 100644 --- a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -27,9 +27,9 @@ import java.net.URL; import java.util.Arrays; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.model.building.ModelBuildingException; import org.apache.maven.model.building.ModelProblem; -import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.testing.PlexusTest; @@ -45,7 +45,7 @@ public abstract class AbstractMavenProjectTestCase { protected ProjectBuilder projectBuilder; @Inject - protected RepositorySystem repositorySystem; + protected MavenRepositorySystem repositorySystem; @Inject protected PlexusContainer container; @@ -139,6 +139,7 @@ public abstract class AbstractMavenProjectTestCase { protected ProjectBuildingRequest newBuildingRequest() throws Exception { ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest(); configuration.setLocalRepository(getLocalRepository()); + configuration.setRemoteRepositories(Arrays.asList(this.repositorySystem.createDefaultRemoteRepository())); initRepoSession(configuration); return configuration; } diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java index 9f850f3ce7..7b172ea803 100644 --- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Properties; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; @@ -36,7 +37,6 @@ import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.ReportSet; import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.project.harness.PomTestWrapper; -import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.codehaus.plexus.testing.PlexusTest; import org.eclipse.aether.DefaultRepositorySystemSession; @@ -71,7 +71,7 @@ class PomConstructionTest { private DefaultProjectBuilder projectBuilder; @Inject - private RepositorySystem repositorySystem; + private MavenRepositorySystem repositorySystem; private File testDirectory; @@ -1375,8 +1375,8 @@ class PomConstructionTest { assertEquals("project-remote-repo", pom.getValue("repositories[1]/id")); assertEquals("https://project.url/remote", pom.getValue("repositories[1]/url")); assertEquals("repo", pom.getValue("repositories[1]/name")); - assertEquals(RepositorySystem.DEFAULT_REMOTE_REPO_ID, pom.getValue("repositories[2]/id")); - assertEquals(RepositorySystem.DEFAULT_REMOTE_REPO_URL, pom.getValue("repositories[2]/url")); + assertEquals(MavenRepositorySystem.DEFAULT_REMOTE_REPO_ID, pom.getValue("repositories[2]/id")); + assertEquals(MavenRepositorySystem.DEFAULT_REMOTE_REPO_URL, pom.getValue("repositories[2]/url")); assertEquals("test", pom.getValue("build/defaultGoal")); assertEquals("coreit", pom.getValue("build/finalName")); diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java index b7352b9306..41fa488fd8 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicReference; import org.apache.maven.artifact.InvalidRepositoryException; +import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.model.Dependency; import org.apache.maven.model.Parent; import org.apache.maven.model.resolution.ModelResolver; @@ -207,7 +208,7 @@ class ProjectModelResolverTest extends AbstractMavenProjectTestCase { private List getRemoteRepositories() throws InvalidRepositoryException { final File repoDir = new File(getBasedir(), "src/test/remote-repo").getAbsoluteFile(); final RemoteRepository remoteRepository = new RemoteRepository.Builder( - org.apache.maven.repository.RepositorySystem.DEFAULT_REMOTE_REPO_ID, + MavenRepositorySystem.DEFAULT_REMOTE_REPO_ID, "default", repoDir.toURI().toASCIIString()) .build(); diff --git a/maven-core/src/test/java/org/apache/maven/project/TestMetadataSource.java b/maven-core/src/test/java/org/apache/maven/project/TestMetadataSource.java deleted file mode 100644 index 6648da8427..0000000000 --- a/maven-core/src/test/java/org/apache/maven/project/TestMetadataSource.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.apache.maven.project; - -import javax.inject.Named; -import javax.inject.Singleton; - -import java.util.List; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ResolutionGroup; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager; -import org.apache.maven.bridge.MavenRepositorySystem; -import org.apache.maven.plugin.LegacySupport; -import org.apache.maven.project.artifact.MavenMetadataCache; -import org.apache.maven.project.artifact.MavenMetadataSource; - -@SuppressWarnings("deprecation") -@Named("classpath") -@Singleton -public class TestMetadataSource extends MavenMetadataSource { - - public TestMetadataSource( - RepositoryMetadataManager repositoryMetadataManager, - ArtifactFactory repositorySystem, - ProjectBuilder projectBuilder, - MavenMetadataCache cache, - LegacySupport legacySupport, - MavenRepositorySystem mavenRepositorySystem) { - super(repositoryMetadataManager, repositorySystem, projectBuilder, cache, legacySupport, mavenRepositorySystem); - } - - @Override - public ResolutionGroup retrieve( - Artifact artifact, ArtifactRepository localRepository, List remoteRepositories) - throws ArtifactMetadataRetrievalException { - ResolutionGroup rg = super.retrieve(artifact, localRepository, remoteRepositories); - - for (Artifact a : rg.getArtifacts()) { - a.setResolved(true); - } - - return rg; - } -} diff --git a/maven-core/src/test/java/org/apache/maven/repository/TestMavenRepositorySystem.java b/maven-core/src/test/java/org/apache/maven/repository/TestMavenRepositorySystem.java new file mode 100644 index 0000000000..1f1e33e1c6 --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/repository/TestMavenRepositorySystem.java @@ -0,0 +1,61 @@ +/* + * 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.apache.maven.repository; + +import javax.annotation.Priority; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import java.io.File; +import java.util.Map; + +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.MavenArtifactRepository; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.bridge.MavenRepositorySystem; + +@Named +@Priority(10) +@Singleton +public class TestMavenRepositorySystem extends MavenRepositorySystem { + + @Inject + public TestMavenRepositorySystem( + ArtifactHandlerManager artifactHandlerManager, Map layouts) { + super(artifactHandlerManager, layouts); + } + + @Override + public ArtifactRepository createDefaultRemoteRepository() throws Exception { + return new MavenArtifactRepository( + DEFAULT_REMOTE_REPO_ID, + "file://" + + new File(System.getProperty("basedir", "."), "src/test/remote-repo") + .getAbsoluteFile() + .toURI() + .getPath(), + new DefaultRepositoryLayout(), + new ArtifactRepositoryPolicy(), + new ArtifactRepositoryPolicy()); + } +} diff --git a/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java b/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java deleted file mode 100644 index c8cbd97f73..0000000000 --- a/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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.apache.maven.repository; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import java.io.File; -import java.util.List; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.InvalidRepositoryException; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; -import org.apache.maven.artifact.repository.MavenArtifactRepository; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; -import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; -import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.Repository; -import org.apache.maven.settings.Mirror; -import org.apache.maven.settings.Proxy; -import org.apache.maven.settings.Server; -import org.eclipse.aether.RepositorySystemSession; - -/** - * @author Benjamin Bentmann - */ -@Named -@Singleton -public class TestRepositorySystem implements RepositorySystem { - - @Inject - public TestRepositorySystem() {} - - public ArtifactRepository buildArtifactRepository(Repository repository) throws InvalidRepositoryException { - return new MavenArtifactRepository( - repository.getId(), - repository.getUrl(), - new DefaultRepositoryLayout(), - new ArtifactRepositoryPolicy(), - new ArtifactRepositoryPolicy()); - } - - public Artifact createArtifact(String groupId, String artifactId, String version, String packaging) { - return createArtifact(groupId, artifactId, version, null, packaging); - } - - public Artifact createArtifact(String groupId, String artifactId, String version, String scope, String type) { - return new DefaultArtifact(groupId, artifactId, version, scope, type, null, new TestArtifactHandler(type)); - } - - public ArtifactRepository createArtifactRepository( - String id, - String url, - ArtifactRepositoryLayout repositoryLayout, - ArtifactRepositoryPolicy snapshots, - ArtifactRepositoryPolicy releases) { - return new MavenArtifactRepository(id, url, repositoryLayout, snapshots, releases); - } - - public Artifact createArtifactWithClassifier( - String groupId, String artifactId, String version, String type, String classifier) { - return new DefaultArtifact(groupId, artifactId, version, null, type, classifier, new TestArtifactHandler(type)); - } - - public ArtifactRepository createDefaultLocalRepository() throws InvalidRepositoryException { - return createLocalRepository( - new File(System.getProperty("basedir", "."), "target/local-repo").getAbsoluteFile()); - } - - public ArtifactRepository createDefaultRemoteRepository() throws InvalidRepositoryException { - return new MavenArtifactRepository( - DEFAULT_REMOTE_REPO_ID, - "file://" - + new File(System.getProperty("basedir", "."), "src/test/remote-repo") - .getAbsoluteFile() - .toURI() - .getPath(), - new DefaultRepositoryLayout(), - new ArtifactRepositoryPolicy(), - new ArtifactRepositoryPolicy()); - } - - public Artifact createDependencyArtifact(Dependency dependency) { - Artifact artifact = new DefaultArtifact( - dependency.getGroupId(), - dependency.getArtifactId(), - dependency.getVersion(), - dependency.getScope(), - dependency.getType(), - dependency.getClassifier(), - new TestArtifactHandler(dependency.getType())); - - if (Artifact.SCOPE_SYSTEM.equals(dependency.getScope())) { - artifact.setFile(new File(dependency.getSystemPath())); - artifact.setResolved(true); - } - - return artifact; - } - - public ArtifactRepository createLocalRepository(File localRepository) throws InvalidRepositoryException { - return new MavenArtifactRepository( - DEFAULT_LOCAL_REPO_ID, - "file://" + localRepository.toURI().getPath(), - new DefaultRepositoryLayout(), - new ArtifactRepositoryPolicy(), - new ArtifactRepositoryPolicy()); - } - - public Artifact createPluginArtifact(Plugin plugin) { - throw new UnsupportedOperationException(); - } - - public Artifact createProjectArtifact(String groupId, String artifactId, String version) { - return createArtifact(groupId, artifactId, version, "pom"); - } - - public List getEffectiveRepositories(List repositories) { - return repositories; - } - - public Mirror getMirror(ArtifactRepository repository, List mirrors) { - return null; - } - - public void injectAuthentication(List repositories, List servers) {} - - public void injectMirror(List repositories, List mirrors) {} - - public void injectProxy(List repositories, List proxies) {} - - public void publish( - ArtifactRepository repository, File source, String remotePath, ArtifactTransferListener transferListener) {} - - public ArtifactResolutionResult resolve(ArtifactResolutionRequest request) { - throw new UnsupportedOperationException(); - } - - public void retrieve( - ArtifactRepository repository, - File destination, - String remotePath, - ArtifactTransferListener transferListener) {} - - public void injectMirror(RepositorySystemSession session, List repositories) {} - - public void injectProxy(RepositorySystemSession session, List repositories) {} - - public void injectAuthentication(RepositorySystemSession session, List repositories) {} -} diff --git a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java index eb6c21f0f6..aa9798c13f 100644 --- a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java +++ b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java @@ -25,12 +25,12 @@ import java.io.IOException; import java.io.Reader; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.model.Profile; import org.apache.maven.project.DefaultProjectBuilder; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.project.harness.PomTestWrapper; -import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; import org.codehaus.plexus.testing.PlexusTest; @@ -55,7 +55,7 @@ class PomConstructionWithSettingsTest { private DefaultProjectBuilder projectBuilder; @Inject - private RepositorySystem repositorySystem; + private MavenRepositorySystem repositorySystem; private File testDirectory; diff --git a/pom.xml b/pom.xml index 0b6733cc53..ae4ce0a908 100644 --- a/pom.xml +++ b/pom.xml @@ -154,7 +154,6 @@ under the License. 3.12.0 5.9.1 4.11.0 - 2.1.0 1.26 4.0.0 4.0.0 @@ -290,11 +289,6 @@ under the License. javax.annotation-api 1.3.2 - - org.codehaus.plexus - plexus-component-annotations - ${plexusVersion} - org.codehaus.plexus plexus-classworlds @@ -494,19 +488,6 @@ under the License. - - org.codehaus.plexus - plexus-component-metadata - ${plexusVersion} - - - - generate-metadata - generate-test-metadata - - - - org.apache.maven.plugins maven-release-plugin