[MNG-6909] Convert to JSR330 in tests - maven-compat

This commit is contained in:
Sylwester Lachiewicz 2021-01-02 23:19:24 +01:00
parent b877445cb9
commit 0e34b35947
28 changed files with 250 additions and 155 deletions

View File

@ -29,6 +29,7 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport; import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
@ -54,6 +55,7 @@ import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector;
import org.eclipse.aether.util.graph.traverser.FatArtifactTraverser; import org.eclipse.aether.util.graph.traverser.FatArtifactTraverser;
import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy; import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
import javax.inject.Inject;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -62,6 +64,7 @@ import java.io.Writer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@ -70,10 +73,15 @@ import java.util.List;
public abstract class AbstractArtifactComponentTestCase public abstract class AbstractArtifactComponentTestCase
extends PlexusTestCase extends PlexusTestCase
{ {
@Inject
protected ArtifactFactory artifactFactory; protected ArtifactFactory artifactFactory;
@Inject
protected ArtifactRepositoryFactory artifactRepositoryFactory; protected ArtifactRepositoryFactory artifactRepositoryFactory;
@Inject
LegacySupport legacySupport;
@Override @Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{ {
@ -87,14 +95,15 @@ public abstract class AbstractArtifactComponentTestCase
throws Exception throws Exception
{ {
super.setUp(); super.setUp();
artifactFactory = lookup( ArtifactFactory.class );
artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class ); ((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
RepositorySystemSession repoSession = initRepoSession(); RepositorySystemSession repoSession = initRepoSession();
MavenSession session = new MavenSession( getContainer(), repoSession, new DefaultMavenExecutionRequest(), MavenSession session = new MavenSession( getContainer(), repoSession, new DefaultMavenExecutionRequest(),
new DefaultMavenExecutionResult() ); new DefaultMavenExecutionResult() );
LegacySupport legacySupport = lookup( LegacySupport.class );
legacySupport.setSession( session ); legacySupport.setSession( session );
} }

View File

@ -26,22 +26,17 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.FileUtils;
import javax.inject.Inject;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/ */
public class ArtifactDeployerTest public class ArtifactDeployerTest
extends AbstractArtifactComponentTestCase extends AbstractArtifactComponentTestCase
{ {
@Inject
private ArtifactDeployer artifactDeployer; private ArtifactDeployer artifactDeployer;
protected void setUp()
throws Exception
{
super.setUp();
artifactDeployer = (ArtifactDeployer) lookup( ArtifactDeployer.ROLE );
}
protected String component() protected String component()
{ {
return "deployer"; return "deployer";

View File

@ -31,34 +31,35 @@ import org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource;
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
import org.apache.maven.repository.legacy.metadata.ResolutionGroup; import org.apache.maven.repository.legacy.metadata.ResolutionGroup;
import javax.inject.Named;
import javax.inject.Singleton;
/** @author Jason van Zyl */ /** @author Jason van Zyl */
@Named( "classpath" )
@Singleton
public class SimpleArtifactMetadataSource public class SimpleArtifactMetadataSource
implements ArtifactMetadataSource implements ArtifactMetadataSource
{ {
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories ) List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{ {
throw new UnsupportedOperationException( "Cannot retrieve metadata in this test case" ); throw new UnsupportedOperationException( "Cannot retrieve metadata in this test case" );
} }
public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories ) List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{ {
return Collections.<ArtifactVersion>singletonList( new DefaultArtifactVersion( "10.1.3" ) ); return Collections.singletonList( new DefaultArtifactVersion( "10.1.3" ) );
} }
public List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, public List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact,
ArtifactRepository localRepository, ArtifactRepository localRepository,
ArtifactRepository remoteRepository ) ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{ {
return Collections.<ArtifactVersion>singletonList( new DefaultArtifactVersion( "10.1.3" ) ); return Collections.singletonList( new DefaultArtifactVersion( "10.1.3" ) );
} }
public ResolutionGroup retrieve( MetadataResolutionRequest request ) public ResolutionGroup retrieve( MetadataResolutionRequest request )
throws ArtifactMetadataRetrievalException
{ {
return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() ); return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
} }

View File

@ -21,14 +21,25 @@ package org.apache.maven.artifact.factory;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import org.eclipse.aether.RepositorySystemSession;
import javax.inject.Inject;
import java.util.Collections;
public class DefaultArtifactFactoryTest public class DefaultArtifactFactoryTest
extends PlexusTestCase extends PlexusTestCase
{ {
@Inject
ArtifactFactory factory;
@Override @Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{ {
@ -37,10 +48,19 @@ public class DefaultArtifactFactoryTest
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
} }
public void testPropagationOfSystemScopeRegardlessOfInheritedScope() throws Exception @Override
protected void setUp()
throws Exception
{ {
ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
public void testPropagationOfSystemScopeRegardlessOfInheritedScope()
{
Artifact artifact = factory.createDependencyArtifact( "test-grp", "test-artifact", VersionRange.createFromVersion("1.0"), "type", null, "system", "provided" ); Artifact artifact = factory.createDependencyArtifact( "test-grp", "test-artifact", VersionRange.createFromVersion("1.0"), "type", null, "system", "provided" );
Artifact artifact2 = factory.createDependencyArtifact( "test-grp", "test-artifact-2", VersionRange.createFromVersion("1.0"), "type", null, "system", "test" ); Artifact artifact2 = factory.createDependencyArtifact( "test-grp", "test-artifact-2", VersionRange.createFromVersion("1.0"), "type", null, "system", "test" );
Artifact artifact3 = factory.createDependencyArtifact( "test-grp", "test-artifact-3", VersionRange.createFromVersion("1.0"), "type", null, "system", "runtime" ); Artifact artifact3 = factory.createDependencyArtifact( "test-grp", "test-artifact-3", VersionRange.createFromVersion("1.0"), "type", null, "system", "runtime" );

View File

@ -24,22 +24,17 @@ import java.io.File;
import org.apache.maven.artifact.AbstractArtifactComponentTestCase; import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import javax.inject.Inject;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/ */
public class ArtifactInstallerTest public class ArtifactInstallerTest
extends AbstractArtifactComponentTestCase extends AbstractArtifactComponentTestCase
{ {
@Inject
private ArtifactInstaller artifactInstaller; private ArtifactInstaller artifactInstaller;
protected void setUp()
throws Exception
{
super.setUp();
artifactInstaller = (ArtifactInstaller) lookup( ArtifactInstaller.ROLE );
}
protected String component() protected String component()
{ {
return "installer"; return "installer";

View File

@ -28,14 +28,17 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@Component(role = ArtifactMetadataSource.class, hint="test") import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
@Named( "test" )
@Singleton
public class TestMetadataSource public class TestMetadataSource
implements ArtifactMetadataSource implements ArtifactMetadataSource
{ {
@Requirement @Inject
private ArtifactFactory factory; private ArtifactFactory factory;
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories ) public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )

View File

@ -36,6 +36,8 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
import javax.inject.Inject;
// It would be cool if there was a hook that i could use to setup a test environment. // It would be cool if there was a hook that i could use to setup a test environment.
// I want to setup a local/remote repositories for testing but i don't want to have // I want to setup a local/remote repositories for testing but i don't want to have
// to change them when i change the layout of the repositories. So i want to generate // to change them when i change the layout of the repositories. So i want to generate
@ -48,7 +50,8 @@ import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
public class ArtifactResolverTest public class ArtifactResolverTest
extends AbstractArtifactComponentTestCase extends AbstractArtifactComponentTestCase
{ {
private DefaultArtifactResolver artifactResolver; @Inject
private ArtifactResolver artifactResolver;
private Artifact projectArtifact; private Artifact projectArtifact;
@ -58,8 +61,6 @@ public class ArtifactResolverTest
{ {
super.setUp(); super.setUp();
artifactResolver = (DefaultArtifactResolver) lookup( ArtifactResolver.class );
projectArtifact = createLocalArtifact( "project", "3.0" ); projectArtifact = createLocalArtifact( "project", "3.0" );
} }
@ -67,7 +68,6 @@ public class ArtifactResolverTest
protected void tearDown() protected void tearDown()
throws Exception throws Exception
{ {
artifactFactory = null;
projectArtifact = null; projectArtifact = null;
super.tearDown(); super.tearDown();
} }
@ -193,7 +193,6 @@ public class ArtifactResolverTest
{ {
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories ) List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{ {
Set<Artifact> dependencies = new HashSet<>(); Set<Artifact> dependencies = new HashSet<>();
@ -203,7 +202,6 @@ public class ArtifactResolverTest
public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact,
ArtifactRepository localRepository, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories ) List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{ {
throw new UnsupportedOperationException( "Cannot get available versions in this test case" ); throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
} }
@ -212,19 +210,16 @@ public class ArtifactResolverTest
Artifact artifact, Artifact artifact,
ArtifactRepository localRepository, ArtifactRepository localRepository,
ArtifactRepository remoteRepository ) ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{ {
throw new UnsupportedOperationException( "Cannot get available versions in this test case" ); throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
} }
public ResolutionGroup retrieve( MetadataResolutionRequest request ) public ResolutionGroup retrieve( MetadataResolutionRequest request )
throws ArtifactMetadataRetrievalException
{ {
return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() ); return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
} }
public List<ArtifactVersion> retrieveAvailableVersions( MetadataResolutionRequest request ) public List<ArtifactVersion> retrieveAvailableVersions( MetadataResolutionRequest request )
throws ArtifactMetadataRetrievalException
{ {
return retrieveAvailableVersions( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() ); return retrieveAvailableVersions( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
} }

View File

@ -25,10 +25,13 @@ import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.DefaultArtifactResolver.DaemonThreadCreator; import org.apache.maven.artifact.resolver.DefaultArtifactResolver.DaemonThreadCreator;
import javax.inject.Inject;
public class DefaultArtifactResolverTest public class DefaultArtifactResolverTest
extends AbstractArtifactComponentTestCase extends AbstractArtifactComponentTestCase
{ {
private DefaultArtifactResolver artifactResolver; @Inject
private ArtifactResolver artifactResolver;
private Artifact projectArtifact; private Artifact projectArtifact;
@ -37,9 +40,6 @@ public class DefaultArtifactResolverTest
throws Exception throws Exception
{ {
super.setUp(); super.setUp();
artifactResolver = (DefaultArtifactResolver) lookup( ArtifactResolver.class );
projectArtifact = createLocalArtifact( "project", "3.0" ); projectArtifact = createLocalArtifact( "project", "3.0" );
} }
@ -47,7 +47,6 @@ public class DefaultArtifactResolverTest
protected void tearDown() protected void tearDown()
throws Exception throws Exception
{ {
artifactFactory = null;
projectArtifact = null; projectArtifact = null;
super.tearDown(); super.tearDown();
} }

View File

@ -15,20 +15,28 @@ package org.apache.maven.artifact.transform;
* the License. * the License.
*/ */
import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformation;
import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformationManager; import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformationManager;
import org.apache.maven.repository.legacy.resolver.transform.LatestArtifactTransformation; import org.apache.maven.repository.legacy.resolver.transform.LatestArtifactTransformation;
import org.apache.maven.repository.legacy.resolver.transform.ReleaseArtifactTransformation; import org.apache.maven.repository.legacy.resolver.transform.ReleaseArtifactTransformation;
import org.apache.maven.repository.legacy.resolver.transform.SnapshotTransformation; import org.apache.maven.repository.legacy.resolver.transform.SnapshotTransformation;
import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import javax.inject.Inject;
/** @author Jason van Zyl */ /** @author Jason van Zyl */
public class TransformationManagerTest public class TransformationManagerTest
extends PlexusTestCase extends PlexusTestCase
{ {
@Inject
ArtifactTransformationManager tm;
@Override @Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{ {
@ -37,12 +45,20 @@ public class TransformationManagerTest
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
} }
public void testTransformationManager() @Override
protected void setUp()
throws Exception throws Exception
{ {
ArtifactTransformationManager tm = lookup( ArtifactTransformationManager.class ); super.setUp();
List tms = tm.getArtifactTransformations(); ((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
public void testTransformationManager()
{
List<ArtifactTransformation> tms = tm.getArtifactTransformations();
assertEquals( 3, tms.size() ); assertEquals( 3, tms.size() );

View File

@ -19,28 +19,34 @@ package org.apache.maven.profiles.manager;
* under the License. * under the License.
*/ */
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Activation; import org.apache.maven.model.Activation;
import org.apache.maven.model.ActivationProperty; import org.apache.maven.model.ActivationProperty;
import org.apache.maven.model.Profile; import org.apache.maven.model.Profile;
import org.apache.maven.profiles.DefaultProfileManager; import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager; import org.apache.maven.profiles.ProfileManager;
import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import org.eclipse.aether.RepositorySystemSession;
public class DefaultProfileManagerTest public class DefaultProfileManagerTest
extends PlexusTestCase extends PlexusTestCase
{ {
@Override @Override
protected void customizeContainerConfiguration( ContainerConfiguration configuration ) protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{ {
super.customizeContainerConfiguration( configuration ); super.customizeContainerConfiguration( containerConfiguration );
configuration.setAutoWiring( true ); containerConfiguration.setAutoWiring( true );
configuration.setClassPathScanning( PlexusConstants.SCANNING_ON ); containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
} }
public void testShouldActivateDefaultProfile() public void testShouldActivateDefaultProfile()

View File

@ -21,17 +21,25 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.building.ModelBuildingException; import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.building.ModelProblem; import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import javax.inject.Inject;
/** /**
* @author Jason van Zyl * @author Jason van Zyl
@ -41,6 +49,7 @@ public abstract class AbstractMavenProjectTestCase
{ {
protected ProjectBuilder projectBuilder; protected ProjectBuilder projectBuilder;
@Inject
protected RepositorySystem repositorySystem; protected RepositorySystem repositorySystem;
@Override @Override
@ -51,11 +60,16 @@ public abstract class AbstractMavenProjectTestCase
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
} }
@Override
protected void setUp() protected void setUp()
throws Exception throws Exception
{ {
super.setUp(); super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) ) if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) )
{ {
projectBuilder = lookup( ProjectBuilder.class, "test" ); projectBuilder = lookup( ProjectBuilder.class, "test" );
@ -65,8 +79,6 @@ public abstract class AbstractMavenProjectTestCase
// default over to the main project builder... // default over to the main project builder...
projectBuilder = lookup( ProjectBuilder.class ); projectBuilder = lookup( ProjectBuilder.class );
} }
repositorySystem = lookup( RepositorySystem.class );
} }
@Override @Override

View File

@ -25,7 +25,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.codehaus.plexus.component.annotations.Component;
import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.impl.ArtifactResolver; import org.eclipse.aether.impl.ArtifactResolver;
@ -34,10 +33,14 @@ import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult; import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.aether.transfer.ArtifactNotFoundException; import org.eclipse.aether.transfer.ArtifactNotFoundException;
import javax.inject.Named;
import javax.inject.Singleton;
/** /**
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
@Component( role = ArtifactResolver.class, hint = "classpath" ) @Named( "classpath" )
@Singleton
public class ClasspathArtifactResolver public class ClasspathArtifactResolver
implements ArtifactResolver implements ArtifactResolver
{ {

View File

@ -20,12 +20,18 @@ package org.apache.maven.project;
*/ */
import java.io.File; import java.io.File;
import java.util.Collections;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader; import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader;
import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.impl.ArtifactDescriptorReader; import org.eclipse.aether.impl.ArtifactDescriptorReader;
import org.eclipse.aether.impl.ArtifactResolver; import org.eclipse.aether.impl.ArtifactResolver;
@ -42,16 +48,21 @@ public class ProjectClasspathTest
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
} }
public void setUp() @Override
protected void setUp()
throws Exception throws Exception
{ {
super.setUp();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
ArtifactResolver resolver = lookup( ArtifactResolver.class, "classpath" ); ArtifactResolver resolver = lookup( ArtifactResolver.class, "classpath" );
DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)lookup(ArtifactDescriptorReader.class); DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)lookup(ArtifactDescriptorReader.class);
pomReader.setArtifactResolver( resolver ); pomReader.setArtifactResolver( resolver );
projectBuilder = lookup( ProjectBuilder.class, "classpath" ); projectBuilder = lookup( ProjectBuilder.class, "classpath" );
repositorySystem = lookup( RepositorySystem.class );
} }
@Override @Override

View File

@ -16,15 +16,21 @@ package org.apache.maven.project;
*/ */
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.DefaultArtifactResolver; import org.apache.maven.artifact.resolver.DefaultArtifactResolver;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@Component(role=ArtifactResolver.class,hint="classpath") import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
@Named( "classpath" )
@Singleton
public class TestArtifactResolver public class TestArtifactResolver
extends DefaultArtifactResolver extends DefaultArtifactResolver
{ {
@Requirement(hint="classpath")
private ArtifactMetadataSource source; private ArtifactMetadataSource source;
@Inject
public TestArtifactResolver(final @Named( "classpath" ) ArtifactMetadataSource source) {
this.source = source;
}
} }

View File

@ -15,16 +15,20 @@ package org.apache.maven.project;
* the License. * the License.
*/ */
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.legacy.LegacyRepositorySystem; import org.apache.maven.repository.legacy.LegacyRepositorySystem;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@Component(role = RepositorySystem.class, hint = "classpath") import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.Map;
@Named( "classpath" )
@Singleton
public class TestMavenRepositorySystem public class TestMavenRepositorySystem
extends LegacyRepositorySystem extends LegacyRepositorySystem
{ {
@Requirement(hint="classpath") @Inject
private ArtifactResolver artifactResolver; private ArtifactResolver artifactResolver;
} }

View File

@ -19,9 +19,12 @@ import java.io.File;
import java.util.Collections; import java.util.Collections;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.component.annotations.Component;
@Component(role=ProjectBuilder.class,hint="classpath") import javax.inject.Named;
import javax.inject.Singleton;
@Named( "classpath" )
@Singleton
public class TestProjectBuilder public class TestProjectBuilder
extends DefaultProjectBuilder extends DefaultProjectBuilder
{ {

View File

@ -21,18 +21,17 @@ package org.apache.maven.repository;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.codehaus.plexus.PlexusTestCase; import org.junit.Test;
import static org.junit.Assert.assertFalse;
public class DefaultMirrorSelectorTest public class DefaultMirrorSelectorTest
extends PlexusTestCase
{ {
@Test
public void testMirrorWithMirrorOfPatternContainingANegationIsNotSelected() public void testMirrorWithMirrorOfPatternContainingANegationIsNotSelected()
{ {
ArtifactRepository repository = new DefaultArtifactRepository( "snapshots.repo", "http://whatever", null ); ArtifactRepository repository = new DefaultArtifactRepository( "snapshots.repo", "http://whatever", null );
String pattern = "external:*, !snapshots.repo"; String pattern = "external:*, !snapshots.repo";
boolean matches = DefaultMirrorSelector.matchPattern( repository, pattern ); assertFalse( DefaultMirrorSelector.matchPattern( repository, pattern ) );
System.out.println( matches );
assertFalse( matches );
} }
} }

View File

@ -17,6 +17,7 @@ package org.apache.maven.repository;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
@ -31,15 +32,19 @@ import org.apache.maven.model.Dependency;
import org.apache.maven.model.Repository; import org.apache.maven.model.Repository;
import org.apache.maven.model.RepositoryPolicy; import org.apache.maven.model.RepositoryPolicy;
import org.apache.maven.plugin.LegacySupport; import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.legacy.LegacyRepositorySystem; import org.apache.maven.repository.legacy.LegacyRepositorySystem;
import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepository;
import javax.inject.Inject;
/** /**
* Tests {@link LegacyRepositorySystem}. * Tests {@link LegacyRepositorySystem}.
* *
@ -48,8 +53,9 @@ import org.eclipse.aether.repository.LocalRepository;
public class LegacyRepositorySystemTest public class LegacyRepositorySystemTest
extends PlexusTestCase extends PlexusTestCase
{ {
@Inject
private RepositorySystem repositorySystem; private RepositorySystem repositorySystem;
@Inject
private ResolutionErrorHandler resolutionErrorHandler; private ResolutionErrorHandler resolutionErrorHandler;
@Override @Override
@ -65,17 +71,10 @@ public class LegacyRepositorySystemTest
throws Exception throws Exception
{ {
super.setUp(); super.setUp();
repositorySystem = lookup( RepositorySystem.class, "default" );
resolutionErrorHandler = lookup( ResolutionErrorHandler.class );
}
@Override ((DefaultPlexusContainer)getContainer())
protected void tearDown() .addPlexusInjector( Collections.emptyList(),
throws Exception binder -> binder.requestInjection( this ) );
{
repositorySystem = null;
resolutionErrorHandler = null;
super.tearDown();
} }
protected List<ArtifactRepository> getRemoteRepositories() protected List<ArtifactRepository> getRemoteRepositories()

View File

@ -20,35 +20,45 @@ package org.apache.maven.repository;
*/ */
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory; import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.settings.Mirror; import org.apache.maven.settings.Mirror;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import javax.inject.Inject;
public class MirrorProcessorTest public class MirrorProcessorTest
extends PlexusTestCase extends PlexusTestCase
{ {
@Inject
private DefaultMirrorSelector mirrorSelector; private DefaultMirrorSelector mirrorSelector;
@Inject
private ArtifactRepositoryFactory repositorySystem; private ArtifactRepositoryFactory repositorySystem;
protected void setUp() @Override
throws Exception protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{ {
mirrorSelector = (DefaultMirrorSelector) lookup( MirrorSelector.class ); super.customizeContainerConfiguration( containerConfiguration );
repositorySystem = lookup( ArtifactRepositoryFactory.class ); containerConfiguration.setAutoWiring( true );
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
} }
@Override @Override
protected void tearDown() protected void setUp()
throws Exception throws Exception
{ {
mirrorSelector = null; super.setUp();
repositorySystem = null;
super.tearDown(); ((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
} }
public void testExternalURL() public void testExternalURL()

View File

@ -22,6 +22,7 @@ package org.apache.maven.repository.legacy;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
@ -44,22 +45,28 @@ import org.apache.maven.wagon.events.TransferListener;
import org.apache.maven.wagon.observers.AbstractTransferListener; import org.apache.maven.wagon.observers.AbstractTransferListener;
import org.apache.maven.wagon.observers.Debug; import org.apache.maven.wagon.observers.Debug;
import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.FileUtils;
import javax.inject.Inject;
/** /**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
*/ */
public class DefaultWagonManagerTest public class DefaultWagonManagerTest
extends PlexusTestCase extends PlexusTestCase
{ {
private DefaultWagonManager wagonManager; @Inject
private WagonManager wagonManager;
private TransferListener transferListener = new Debug(); private final TransferListener transferListener = new Debug();
@Inject
private ArtifactFactory artifactFactory; private ArtifactFactory artifactFactory;
@Inject
private ArtifactRepositoryFactory artifactRepositoryFactory; private ArtifactRepositoryFactory artifactRepositoryFactory;
@Override @Override
@ -70,22 +77,15 @@ public class DefaultWagonManagerTest
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
} }
@Override
protected void setUp() protected void setUp()
throws Exception throws Exception
{ {
super.setUp(); super.setUp();
wagonManager = (DefaultWagonManager) lookup( WagonManager.class );
artifactFactory = lookup( ArtifactFactory.class );
artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class );
}
@Override ((DefaultPlexusContainer)getContainer())
protected void tearDown() .addPlexusInjector( Collections.emptyList(),
throws Exception binder -> binder.requestInjection( this ) );
{
wagonManager = null;
artifactFactory = null;
super.tearDown();
} }
public void testUnnecessaryRepositoryLookup() public void testUnnecessaryRepositoryLookup()
@ -164,8 +164,7 @@ public class DefaultWagonManagerTest
} }
public void testGetRemoteJar() public void testGetRemoteJar()
throws TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException, IOException, throws TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException, IOException
AuthorizationException
{ {
Artifact artifact = createTestArtifact( "target/test-data/get-remote-jar", "jar" ); Artifact artifact = createTestArtifact( "target/test-data/get-remote-jar", "jar" );

View File

@ -17,15 +17,19 @@ package org.apache.maven.repository.legacy;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.Authentication; import org.apache.maven.artifact.repository.Authentication;
import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Server; import org.apache.maven.settings.Server;
import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import javax.inject.Inject;
/** /**
* Tests {@link LegacyRepositorySystem}. * Tests {@link LegacyRepositorySystem}.
* *
@ -34,6 +38,7 @@ import org.codehaus.plexus.PlexusTestCase;
public class LegacyRepositorySystemTest public class LegacyRepositorySystemTest
extends PlexusTestCase extends PlexusTestCase
{ {
@Inject
private RepositorySystem repositorySystem; private RepositorySystem repositorySystem;
@Override @Override
@ -49,15 +54,10 @@ public class LegacyRepositorySystemTest
throws Exception throws Exception
{ {
super.setUp(); super.setUp();
repositorySystem = lookup( RepositorySystem.class, "default" );
}
@Override ((DefaultPlexusContainer)getContainer())
protected void tearDown() .addPlexusInjector( Collections.emptyList(),
throws Exception binder -> binder.requestInjection( this ) );
{
repositorySystem = null;
super.tearDown();
} }
public void testThatLocalRepositoryWithSpacesIsProperlyHandled() public void testThatLocalRepositoryWithSpacesIsProperlyHandled()
@ -69,7 +69,6 @@ public class LegacyRepositorySystemTest
} }
public void testAuthenticationHandling() public void testAuthenticationHandling()
throws Exception
{ {
Server server = new Server(); Server server = new Server();
server.setId( "repository" ); server.setId( "repository" );

View File

@ -20,12 +20,14 @@ package org.apache.maven.repository.legacy;
*/ */
import org.apache.maven.wagon.Wagon; import org.apache.maven.wagon.Wagon;
import org.codehaus.plexus.component.annotations.Component;
import javax.inject.Named;
import javax.inject.Singleton;
/** /**
* Wagon with per-lookup instantiation strategy. * Wagon with per-lookup instantiation strategy.
*/ */
@Component( role = Wagon.class, hint = "perlookup", instantiationStrategy = "per-lookup" ) @Named( "perlookup" )
public class PerLookupWagon public class PerLookupWagon
extends WagonMock extends WagonMock
{ {

View File

@ -31,13 +31,15 @@ import org.apache.maven.wagon.OutputData;
import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.StreamWagon; import org.apache.maven.wagon.StreamWagon;
import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.authentication.AuthenticationException; import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authorization.AuthorizationException; import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.resource.Resource; import org.apache.maven.wagon.resource.Resource;
import org.codehaus.plexus.component.annotations.Component;
@Component(role=Wagon.class,hint="string") import javax.inject.Named;
import javax.inject.Singleton;
@Named( "string" )
@Singleton
public class StringWagon public class StringWagon
extends StreamWagon extends StreamWagon
{ {

View File

@ -1,8 +1,4 @@
package org.apache.maven.repository.legacy; package org.apache.maven.repository.legacy;
import org.apache.maven.wagon.Wagon;
import org.codehaus.plexus.component.annotations.Component;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
@ -21,6 +17,8 @@ import org.codehaus.plexus.component.annotations.Component;
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
import javax.inject.Named;
import javax.inject.Singleton;
/** /**
* Wagon for testing, for protocol <code>a</code> * Wagon for testing, for protocol <code>a</code>
@ -28,7 +26,8 @@ import org.codehaus.plexus.component.annotations.Component;
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a> * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/ */
@Component(role=Wagon.class,hint="a") @Named( "a" )
@Singleton
public class WagonA public class WagonA
extends WagonMock extends WagonMock
{ {

View File

@ -1,8 +1,5 @@
package org.apache.maven.repository.legacy; package org.apache.maven.repository.legacy;
import org.apache.maven.wagon.Wagon;
import org.codehaus.plexus.component.annotations.Component;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
@ -22,13 +19,17 @@ import org.codehaus.plexus.component.annotations.Component;
* under the License. * under the License.
*/ */
import javax.inject.Named;
import javax.inject.Singleton;
/** /**
* Wagon for testing, for protocols <code>b1</code> and <code>b2</code> * Wagon for testing, for protocols <code>b1</code> and <code>b2</code>
* *
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a> * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/ */
@Component(role=Wagon.class,hint="b") @Named( "b" )
@Singleton
public class WagonB public class WagonB
extends WagonMock extends WagonMock
{ {

View File

@ -1,8 +1,5 @@
package org.apache.maven.repository.legacy; package org.apache.maven.repository.legacy;
import org.apache.maven.wagon.Wagon;
import org.codehaus.plexus.component.annotations.Component;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
@ -22,13 +19,17 @@ import org.codehaus.plexus.component.annotations.Component;
* under the License. * under the License.
*/ */
import javax.inject.Named;
import javax.inject.Singleton;
/** /**
* Wagon for testing, for protocol <code>c</code> * Wagon for testing, for protocol <code>c</code>
* *
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a> * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/ */
@Component(role=Wagon.class,hint="c") @Named( "c" )
@Singleton
public class WagonC public class WagonC
extends WagonMock extends WagonMock
{ {

View File

@ -27,9 +27,11 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.repository.legacy.resolver.conflict.ConflictResolver; import org.apache.maven.repository.legacy.resolver.conflict.ConflictResolver;
import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import javax.inject.Inject;
import java.util.Collections; import java.util.Collections;
/** /**
@ -54,6 +56,7 @@ public abstract class AbstractConflictResolverTest
private final String roleHint; private final String roleHint;
@Inject
private ArtifactFactory artifactFactory; private ArtifactFactory artifactFactory;
private ConflictResolver conflictResolver; private ConflictResolver conflictResolver;
@ -76,14 +79,16 @@ public abstract class AbstractConflictResolverTest
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
} }
/* @Override
* @see junit.framework.TestCase#setUp() protected void setUp()
*/ throws Exception
protected void setUp() throws Exception
{ {
super.setUp(); super.setUp();
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); ((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
conflictResolver = (ConflictResolver) lookup( ConflictResolver.ROLE, roleHint ); conflictResolver = (ConflictResolver) lookup( ConflictResolver.ROLE, roleHint );
a1 = createArtifact( "a", "1.0" ); a1 = createArtifact( "a", "1.0" );
@ -100,7 +105,6 @@ public abstract class AbstractConflictResolverTest
a2 = null; a2 = null;
b1 = null; b1 = null;
artifactFactory = null;
conflictResolver = null; conflictResolver = null;
super.tearDown(); super.tearDown();

View File

@ -27,18 +27,20 @@ import org.apache.maven.repository.legacy.metadata.ArtifactMetadataRetrievalExce
import org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource; import org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource;
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
import org.apache.maven.repository.legacy.metadata.ResolutionGroup; import org.apache.maven.repository.legacy.metadata.ResolutionGroup;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@Component(role = ArtifactMetadataSource.class) @Named
@Singleton
public class TestMetadataSource public class TestMetadataSource
implements ArtifactMetadataSource implements ArtifactMetadataSource
{ {
@Requirement @Inject
private ArtifactFactory factory; private ArtifactFactory factory;
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories ) public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )