1   package org.apache.maven.repository.metadata;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }