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

View File

@ -26,22 +26,17 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.util.FileUtils;
import javax.inject.Inject;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/
public class ArtifactDeployerTest
extends AbstractArtifactComponentTestCase
{
@Inject
private ArtifactDeployer artifactDeployer;
protected void setUp()
throws Exception
{
super.setUp();
artifactDeployer = (ArtifactDeployer) lookup( ArtifactDeployer.ROLE );
}
protected String component()
{
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.ResolutionGroup;
import javax.inject.Named;
import javax.inject.Singleton;
/** @author Jason van Zyl */
@Named( "classpath" )
@Singleton
public class SimpleArtifactMetadataSource
implements ArtifactMetadataSource
{
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
throw new UnsupportedOperationException( "Cannot retrieve metadata in this test case" );
}
public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository,
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,
ArtifactRepository localRepository,
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 )
throws ArtifactMetadataRetrievalException
{
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.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.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.eclipse.aether.RepositorySystemSession;
import javax.inject.Inject;
import java.util.Collections;
public class DefaultArtifactFactoryTest
extends PlexusTestCase
{
@Inject
ArtifactFactory factory;
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
@ -37,10 +48,19 @@ public class DefaultArtifactFactoryTest
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 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" );

View File

@ -24,22 +24,17 @@ import java.io.File;
import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact;
import javax.inject.Inject;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/
public class ArtifactInstallerTest
extends AbstractArtifactComponentTestCase
{
@Inject
private ArtifactInstaller artifactInstaller;
protected void setUp()
throws Exception
{
super.setUp();
artifactInstaller = (ArtifactInstaller) lookup( ArtifactInstaller.ROLE );
}
protected String component()
{
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.versioning.ArtifactVersion;
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
implements ArtifactMetadataSource
{
@Requirement
@Inject
private ArtifactFactory factory;
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.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.
// 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
@ -48,7 +50,8 @@ import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
public class ArtifactResolverTest
extends AbstractArtifactComponentTestCase
{
private DefaultArtifactResolver artifactResolver;
@Inject
private ArtifactResolver artifactResolver;
private Artifact projectArtifact;
@ -58,8 +61,6 @@ public class ArtifactResolverTest
{
super.setUp();
artifactResolver = (DefaultArtifactResolver) lookup( ArtifactResolver.class );
projectArtifact = createLocalArtifact( "project", "3.0" );
}
@ -67,7 +68,6 @@ public class ArtifactResolverTest
protected void tearDown()
throws Exception
{
artifactFactory = null;
projectArtifact = null;
super.tearDown();
}
@ -193,7 +193,6 @@ public class ArtifactResolverTest
{
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
Set<Artifact> dependencies = new HashSet<>();
@ -203,7 +202,6 @@ public class ArtifactResolverTest
public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
}
@ -212,19 +210,16 @@ public class ArtifactResolverTest
Artifact artifact,
ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
}
public ResolutionGroup retrieve( MetadataResolutionRequest request )
throws ArtifactMetadataRetrievalException
{
return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
}
public List<ArtifactVersion> retrieveAvailableVersions( MetadataResolutionRequest request )
throws ArtifactMetadataRetrievalException
{
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.resolver.DefaultArtifactResolver.DaemonThreadCreator;
import javax.inject.Inject;
public class DefaultArtifactResolverTest
extends AbstractArtifactComponentTestCase
{
private DefaultArtifactResolver artifactResolver;
@Inject
private ArtifactResolver artifactResolver;
private Artifact projectArtifact;
@ -37,9 +40,6 @@ public class DefaultArtifactResolverTest
throws Exception
{
super.setUp();
artifactResolver = (DefaultArtifactResolver) lookup( ArtifactResolver.class );
projectArtifact = createLocalArtifact( "project", "3.0" );
}
@ -47,7 +47,6 @@ public class DefaultArtifactResolverTest
protected void tearDown()
throws Exception
{
artifactFactory = null;
projectArtifact = null;
super.tearDown();
}

View File

@ -15,20 +15,28 @@ package org.apache.maven.artifact.transform;
* the License.
*/
import java.util.Collections;
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.LatestArtifactTransformation;
import org.apache.maven.repository.legacy.resolver.transform.ReleaseArtifactTransformation;
import org.apache.maven.repository.legacy.resolver.transform.SnapshotTransformation;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import javax.inject.Inject;
/** @author Jason van Zyl */
public class TransformationManagerTest
extends PlexusTestCase
{
@Inject
ArtifactTransformationManager tm;
@Override
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
@ -37,12 +45,20 @@ public class TransformationManagerTest
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
public void testTransformationManager()
@Override
protected void setUp()
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() );

View File

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

View File

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

View File

@ -25,7 +25,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.codehaus.plexus.component.annotations.Component;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
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.transfer.ArtifactNotFoundException;
import javax.inject.Named;
import javax.inject.Singleton;
/**
* @author Benjamin Bentmann
*/
@Component( role = ArtifactResolver.class, hint = "classpath" )
@Named( "classpath" )
@Singleton
public class ClasspathArtifactResolver
implements ArtifactResolver
{

View File

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

View File

@ -16,15 +16,21 @@ package org.apache.maven.project;
*/
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.resolver.ArtifactResolver;
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
extends DefaultArtifactResolver
{
@Requirement(hint="classpath")
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.
*/
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.repository.RepositorySystem;
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
extends LegacyRepositorySystem
{
@Requirement(hint="classpath")
@Inject
private ArtifactResolver artifactResolver;
}

View File

@ -19,9 +19,12 @@ import java.io.File;
import java.util.Collections;
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
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.DefaultArtifactRepository;
import org.codehaus.plexus.PlexusTestCase;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
public class DefaultMirrorSelectorTest
extends PlexusTestCase
{
@Test
public void testMirrorWithMirrorOfPatternContainingANegationIsNotSelected()
{
ArtifactRepository repository = new DefaultArtifactRepository( "snapshots.repo", "http://whatever", null );
String pattern = "external:*, !snapshots.repo";
boolean matches = DefaultMirrorSelector.matchPattern( repository, pattern );
System.out.println( matches );
assertFalse( matches );
assertFalse( DefaultMirrorSelector.matchPattern( repository, pattern ) );
}
}

View File

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

View File

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

View File

@ -22,6 +22,7 @@ package org.apache.maven.repository.legacy;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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.Debug;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import javax.inject.Inject;
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
*/
public class DefaultWagonManagerTest
extends PlexusTestCase
{
private DefaultWagonManager wagonManager;
@Inject
private WagonManager wagonManager;
private TransferListener transferListener = new Debug();
private final TransferListener transferListener = new Debug();
@Inject
private ArtifactFactory artifactFactory;
@Inject
private ArtifactRepositoryFactory artifactRepositoryFactory;
@Override
@ -70,22 +77,15 @@ public class DefaultWagonManagerTest
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
@Override
protected void setUp()
throws Exception
{
super.setUp();
wagonManager = (DefaultWagonManager) lookup( WagonManager.class );
artifactFactory = lookup( ArtifactFactory.class );
artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class );
}
@Override
protected void tearDown()
throws Exception
{
wagonManager = null;
artifactFactory = null;
super.tearDown();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
public void testUnnecessaryRepositoryLookup()
@ -164,8 +164,7 @@ public class DefaultWagonManagerTest
}
public void testGetRemoteJar()
throws TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException, IOException,
AuthorizationException
throws TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException, IOException
{
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.util.Arrays;
import java.util.Collections;
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.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import javax.inject.Inject;
/**
* Tests {@link LegacyRepositorySystem}.
*
@ -34,6 +38,7 @@ import org.codehaus.plexus.PlexusTestCase;
public class LegacyRepositorySystemTest
extends PlexusTestCase
{
@Inject
private RepositorySystem repositorySystem;
@Override
@ -49,15 +54,10 @@ public class LegacyRepositorySystemTest
throws Exception
{
super.setUp();
repositorySystem = lookup( RepositorySystem.class, "default" );
}
@Override
protected void tearDown()
throws Exception
{
repositorySystem = null;
super.tearDown();
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
}
public void testThatLocalRepositoryWithSpacesIsProperlyHandled()
@ -69,7 +69,6 @@ public class LegacyRepositorySystemTest
}
public void testAuthenticationHandling()
throws Exception
{
Server server = new Server();
server.setId( "repository" );

View File

@ -20,12 +20,14 @@ package org.apache.maven.repository.legacy;
*/
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.
*/
@Component( role = Wagon.class, hint = "perlookup", instantiationStrategy = "per-lookup" )
@Named( "perlookup" )
public class PerLookupWagon
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.StreamWagon;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authorization.AuthorizationException;
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
extends StreamWagon
{

View File

@ -1,8 +1,4 @@
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
* 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
* under the License.
*/
import javax.inject.Named;
import javax.inject.Singleton;
/**
* 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:jason@maven.org">Jason van Zyl</a>
*/
@Component(role=Wagon.class,hint="a")
@Named( "a" )
@Singleton
public class WagonA
extends WagonMock
{

View File

@ -1,8 +1,5 @@
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
* or more contributor license agreements. See the NOTICE file
@ -22,13 +19,17 @@ import org.codehaus.plexus.component.annotations.Component;
* under the License.
*/
import javax.inject.Named;
import javax.inject.Singleton;
/**
* 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:jason@maven.org">Jason van Zyl</a>
*/
@Component(role=Wagon.class,hint="b")
@Named( "b" )
@Singleton
public class WagonB
extends WagonMock
{

View File

@ -1,8 +1,5 @@
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
* or more contributor license agreements. See the NOTICE file
@ -22,13 +19,17 @@ import org.codehaus.plexus.component.annotations.Component;
* under the License.
*/
import javax.inject.Named;
import javax.inject.Singleton;
/**
* Wagon for testing, for protocol <code>c</code>
*
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/
@Component(role=Wagon.class,hint="c")
@Named( "c" )
@Singleton
public class WagonC
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.repository.legacy.resolver.conflict.ConflictResolver;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
import javax.inject.Inject;
import java.util.Collections;
/**
@ -54,6 +56,7 @@ public abstract class AbstractConflictResolverTest
private final String roleHint;
@Inject
private ArtifactFactory artifactFactory;
private ConflictResolver conflictResolver;
@ -76,14 +79,16 @@ public abstract class AbstractConflictResolverTest
containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
}
/*
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception
@Override
protected void setUp()
throws Exception
{
super.setUp();
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
((DefaultPlexusContainer)getContainer())
.addPlexusInjector( Collections.emptyList(),
binder -> binder.requestInjection( this ) );
conflictResolver = (ConflictResolver) lookup( ConflictResolver.ROLE, roleHint );
a1 = createArtifact( "a", "1.0" );
@ -100,7 +105,6 @@ public abstract class AbstractConflictResolverTest
a2 = null;
b1 = null;
artifactFactory = null;
conflictResolver = null;
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.MetadataResolutionRequest;
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.List;
import java.util.Set;
@Component(role = ArtifactMetadataSource.class)
@Named
@Singleton
public class TestMetadataSource
implements ArtifactMetadataSource
{
@Requirement
@Inject
private ArtifactFactory factory;
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )