1 package org.apache.maven.repository.metadata;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Set;
25
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.artifact.factory.ArtifactFactory;
28 import org.apache.maven.artifact.repository.ArtifactRepository;
29 import org.apache.maven.artifact.versioning.ArtifactVersion;
30 import org.apache.maven.repository.legacy.metadata.ArtifactMetadataRetrievalException;
31 import org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource;
32 import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
33 import org.apache.maven.repository.legacy.metadata.ResolutionGroup;
34 import org.codehaus.plexus.component.annotations.Component;
35 import org.codehaus.plexus.component.annotations.Requirement;
36
37 @Component(role = ArtifactMetadataSource.class)
38 public class TestMetadataSource
39 implements ArtifactMetadataSource
40 {
41 @Requirement
42 private ArtifactFactory factory;
43
44 public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
45 throws ArtifactMetadataRetrievalException
46 {
47 Set dependencies = new HashSet();
48
49 if ( "g".equals( artifact.getArtifactId() ) )
50 {
51 Artifact a = null;
52 try
53 {
54 a = factory.createBuildArtifact( "org.apache.maven", "h", "1.0", "jar" );
55 dependencies.add( a );
56 }
57 catch ( Exception e )
58 {
59 throw new ArtifactMetadataRetrievalException( "Error retrieving metadata", e, a );
60 }
61 }
62
63 if ( "i".equals( artifact.getArtifactId() ) )
64 {
65 Artifact a = null;
66 try
67 {
68 a = factory.createBuildArtifact( "org.apache.maven", "j", "1.0-SNAPSHOT", "jar" );
69 dependencies.add( a );
70 }
71 catch ( Exception e )
72 {
73 throw new ArtifactMetadataRetrievalException( "Error retrieving metadata", e, a );
74 }
75 }
76
77
78 return new ResolutionGroup( artifact, dependencies, remoteRepositories );
79 }
80
81 public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
82 throws ArtifactMetadataRetrievalException
83 {
84 throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
85 }
86
87 public List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository )
88 throws ArtifactMetadataRetrievalException
89 {
90 throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
91 }
92
93 public ResolutionGroup retrieve( MetadataResolutionRequest request )
94 throws ArtifactMetadataRetrievalException
95 {
96 return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
97 }
98
99 }