From 3ec487cdbfddbade6395f66d6b2a7d7debd831c8 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Tue, 19 May 2009 23:39:21 +0000 Subject: [PATCH] o creating a test metadata source for the legacy system, getting rid of anonymous instances in tests. git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@776498 13f79535-47bb-0310-9956-ffa450edef68 --- .../artifact/metadata/TestMetadataSource.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 maven-compat/src/test/java/org/apache/maven/artifact/metadata/TestMetadataSource.java diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/metadata/TestMetadataSource.java b/maven-compat/src/test/java/org/apache/maven/artifact/metadata/TestMetadataSource.java new file mode 100644 index 0000000000..71d7c221f7 --- /dev/null +++ b/maven-compat/src/test/java/org/apache/maven/artifact/metadata/TestMetadataSource.java @@ -0,0 +1,75 @@ +package org.apache.maven.artifact.metadata; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; + +@Component(role = ArtifactMetadataSource.class) +public class TestMetadataSource + implements ArtifactMetadataSource +{ + @Requirement + private ArtifactFactory factory; + + public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + throws ArtifactMetadataRetrievalException + { + Set dependencies = new HashSet(); + + if ( "g".equals( artifact.getArtifactId() ) ) + { + Artifact a = null; + try + { + a = factory.createBuildArtifact( "org.apache.maven", "h", "1.0", "jar" ); + dependencies.add( a ); + } + catch ( Exception e ) + { + throw new ArtifactMetadataRetrievalException( "Error retrieving metadata", e, a ); + } + } + + if ( "i".equals( artifact.getArtifactId() ) ) + { + Artifact a = null; + try + { + a = factory.createBuildArtifact( "org.apache.maven", "j", "1.0-SNAPSHOT", "jar" ); + dependencies.add( a ); + } + catch ( Exception e ) + { + throw new ArtifactMetadataRetrievalException( "Error retrieving metadata", e, a ); + } + } + + + return new ResolutionGroup( artifact, dependencies, remoteRepositories ); + } + + public List retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + throws ArtifactMetadataRetrievalException + { + throw new UnsupportedOperationException( "Cannot get available versions in this test case" ); + } + + public List retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository ) + throws ArtifactMetadataRetrievalException + { + throw new UnsupportedOperationException( "Cannot get available versions in this test case" ); + } + + public Artifact retrieveRelocatedArtifact( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + throws ArtifactMetadataRetrievalException + { + return artifact; + } +}