[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
This commit is contained in:
Guillaume Nodet 2023-06-15 16:24:56 +02:00 committed by GitHub
parent 00d350eaca
commit 967d8fc19c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
123 changed files with 966 additions and 576 deletions

View File

@ -88,10 +88,6 @@ under the License.
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
@ -127,8 +123,8 @@ under the License.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.modello</groupId>

View File

@ -25,6 +25,7 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
/**
* ArtifactFilterManager
*/
@Deprecated
public interface ArtifactFilterManager {
/**
* Returns a filter for core + extension artifacts.

View File

@ -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<String> excludes);

View File

@ -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

View File

@ -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;

View File

@ -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<Object, MergeableMetadata> relatedMetadata = new ConcurrentHashMap<>();

View File

@ -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. */

View File

@ -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 <a href="https://maven.apache.org/wagon">Wagon</a> 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) {

View File

@ -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<ArtifactRepository> 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);
}

View File

@ -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;
}

View File

@ -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 = '-';

View File

@ -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(

View File

@ -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 {}

View File

@ -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);

View File

@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
*/
@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;

View File

@ -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<String> activatedIds = new ArrayList<>();

View File

@ -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;
// ----------------------------------------------------------------------

View File

@ -43,6 +43,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
*/
@Named
@Singleton
@Deprecated
public class DefaultMavenMetadataCache implements MavenMetadataCache {
protected final Map<CacheKey, CacheRecord> cache = new ConcurrentHashMap<>();

View File

@ -37,6 +37,7 @@ import org.apache.maven.project.ProjectBuilder;
*/
@Named
@Singleton
@Deprecated
public class DefaultMetadataSource extends MavenMetadataSource {
@Inject
public DefaultMetadataSource(

View File

@ -27,6 +27,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* MavenMetadataCache
*/
@Deprecated
public interface MavenMetadataCache {
ResolutionGroup get(

View File

@ -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;

View File

@ -33,6 +33,7 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreExce
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
@Deprecated
public class ProjectArtifactMetadata extends AbstractArtifactMetadata {
private final File file;

View File

@ -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) {

View File

@ -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;

View File

@ -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<Class<?>, Field[]> FIELDS_BY_CLASS = new WeakHashMap<>();

View File

@ -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}"};

View File

@ -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 <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
*/
@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) {

View File

@ -21,6 +21,7 @@ package org.apache.maven.repository;
/**
* ArtifactDoesNotExistException
*/
@Deprecated
public class ArtifactDoesNotExistException extends Exception {
public ArtifactDoesNotExistException(final String message) {
super(message);

View File

@ -27,6 +27,7 @@ import java.util.EventObject;
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
*/
@Deprecated
public class ArtifactTransferEvent extends EventObject {
/**
* A transfer was attempted, but has not yet commenced.

View File

@ -21,6 +21,7 @@ package org.apache.maven.repository;
/**
* ArtifactTransferFailedException
*/
@Deprecated
public class ArtifactTransferFailedException extends Exception {
public ArtifactTransferFailedException(final String message) {
super(message);

View File

@ -21,6 +21,7 @@ package org.apache.maven.repository;
/**
* ArtifactTransferListener
*/
@Deprecated
public interface ArtifactTransferListener {
boolean isShowChecksumEvents();

View File

@ -23,6 +23,7 @@ package org.apache.maven.repository;
*
* @author Benjamin Bentmann
*/
@Deprecated
public interface ArtifactTransferResource {
/**

View File

@ -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 = "*";

View File

@ -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";

View File

@ -25,6 +25,7 @@ import java.io.IOException;
*
* @author Benjamin Bentmann
*/
@Deprecated
public class LocalRepositoryNotAccessibleException extends IOException {
public LocalRepositoryNotAccessibleException(String message, Throwable cause) {

View File

@ -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);

View File

@ -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";

View File

@ -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 <a href="https://maven.apache.org/wagon">Wagon</a> 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;
//

View File

@ -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<String, ArtifactRepositoryLayout> 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) {

View File

@ -25,6 +25,7 @@ import org.apache.maven.artifact.Artifact;
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
@Deprecated
public abstract class AbstractArtifactMetadata implements ArtifactMetadata {
private static final String LS = System.lineSeparator();

View File

@ -25,6 +25,7 @@ import org.apache.maven.artifact.Artifact;
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/
@Deprecated
public class ArtifactMetadataRetrievalException extends Exception {
private Artifact artifact;

View File

@ -30,6 +30,7 @@ import org.apache.maven.artifact.versioning.ArtifactVersion;
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
*/
@Deprecated
public interface ArtifactMetadataSource {
ResolutionGroup retrieve(MetadataResolutionRequest request) throws ArtifactMetadataRetrievalException;

View File

@ -31,6 +31,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
*
* @author Benjamin Bentmann
*/
@Deprecated
public class DefaultMetadataResolutionRequest implements MetadataResolutionRequest {
private Artifact artifact;

View File

@ -29,6 +29,7 @@ import org.apache.maven.artifact.repository.RepositoryRequest;
*
* @author Benjamin Bentmann
*/
@Deprecated
public interface MetadataResolutionRequest extends RepositoryRequest {
/**

View File

@ -28,6 +28,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* ResolutionGroup
*/
@Deprecated
public class ResolutionGroup {
private final Set<Artifact> artifacts;

View File

@ -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<String, ArtifactRepositoryLayout> repositoryLayouts;
public ArtifactRepositoryLayout getLayout(String layoutId) throws UnknownRepositoryLayoutException {

View File

@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
* @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) {

View File

@ -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 {}

View File

@ -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 ----------------------------------------

View File

@ -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 <em>farthest</em> declaration. Farthest is defined as the
@ -28,7 +30,8 @@ import org.codehaus.plexus.component.annotations.Component;
* @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
* @since 3.0
*/
@Component(role = ConflictResolver.class, hint = "farthest")
@Named("farthest")
@Singleton
public class FarthestConflictResolver implements ConflictResolver {
// ConflictResolver methods -----------------------------------------------

View File

@ -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 <em>nearest</em> declaration. Nearest is defined as the
@ -29,7 +31,8 @@ import org.codehaus.plexus.component.annotations.Component;
* @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
* @since 3.0
*/
@Component(role = ConflictResolver.class, hint = "nearest")
@Named("nearest")
@Singleton
public class NearestConflictResolver implements ConflictResolver {
// ConflictResolver methods -----------------------------------------------

View File

@ -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 <em>newest</em> 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 -----------------------------------------------

View File

@ -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 <em>oldest</em> 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 -----------------------------------------------

View File

@ -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(

View File

@ -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<ArtifactTransformation> artifactTransformations;
@Inject
public DefaultArtifactTransformationManager(Map<String, ArtifactTransformation> 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) {

View File

@ -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)

View File

@ -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 <code>RELEASE</code> to the appropriate release version from the remote repository.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
@Component(role = ArtifactTransformation.class, hint = "release")
@Named("release")
@Singleton
public class ReleaseArtifactTransformation extends AbstractVersionTransformation {
public void transformForResolve(Artifact artifact, RepositoryRequest request)

View File

@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
* @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a>
*/
@Component(role = ArtifactTransformation.class, hint = "snapshot")
@Named("snapshot")
@Singleton
public class SnapshotTransformation extends AbstractVersionTransformation {
private static final String DEFAULT_SNAPSHOT_TIMESTAMP_FORMAT = "yyyyMMdd.HHmmss";

View File

@ -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 <a href="oleg@codehaus.org">Oleg Gusakov</a>
*
*/
@Component(role = ClasspathTransformation.class)
@Named
@Singleton
public class DefaultClasspathTransformation implements ClasspathTransformation {
@Requirement
@Inject
GraphConflictResolver conflictResolver;
// ----------------------------------------------------------------------------------------------------

View File

@ -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 <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
*
*/
@Component(role = GraphConflictResolutionPolicy.class)
@Named
@Singleton
public class DefaultGraphConflictResolutionPolicy implements GraphConflictResolutionPolicy {
/**
* artifact, closer to the entry point, is selected

View File

@ -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 <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
*/
@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;
// -------------------------------------------------------------------------------------

View File

@ -27,7 +27,9 @@ import org.apache.maven.toolchain.model.PersistedToolchains;
* <strong>Note:</strong> 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 {
/**

View File

@ -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<MavenProject> 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<ArtifactRepository> 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<ArtifactRepository> 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;
}
}
}

View File

@ -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<ArtifactRepository> remoteRepositories)
throws ArtifactMetadataRetrievalException {
return delegate.retrieve(artifact, localRepository, remoteRepositories);
}
@Override
public List<ArtifactVersion> retrieveAvailableVersions(MetadataResolutionRequest request)
throws ArtifactMetadataRetrievalException {
return delegate.retrieveAvailableVersions(request);
}
@Override
public List<ArtifactVersion> retrieveAvailableVersions(
Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories)
throws ArtifactMetadataRetrievalException {
return delegate.retrieveAvailableVersions(artifact, localRepository, remoteRepositories);
}
@Override
public List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository(
Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository)
throws ArtifactMetadataRetrievalException {
return delegate.retrieveAvailableVersionsFromDeploymentRepository(artifact, localRepository, remoteRepository);
}
}

View File

@ -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);
}
}

View File

@ -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(),

View File

@ -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 {

Some files were not shown because too many files have changed in this diff Show More