View Javadoc
1   package org.apache.maven.artifact.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.MetadataResolutionRequest;
31  import org.codehaus.plexus.component.annotations.Component;
32  import org.codehaus.plexus.component.annotations.Requirement;
33  
34  @Component(role = ArtifactMetadataSource.class, hint="test")
35  public class TestMetadataSource
36      implements ArtifactMetadataSource
37  {
38      @Requirement
39      private ArtifactFactory factory;
40  
41      public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
42          throws ArtifactMetadataRetrievalException
43      {
44          Set<Artifact> dependencies = new HashSet<>();
45  
46          if ( "g".equals( artifact.getArtifactId() ) )
47          {
48              Artifact a = null;
49              try
50              {
51                  a = factory.createBuildArtifact( "org.apache.maven", "h", "1.0", "jar" );
52                  dependencies.add( a );
53              }
54              catch ( Exception e )
55              {
56                  throw new ArtifactMetadataRetrievalException( "Error retrieving metadata", e, a );
57              }
58          }
59  
60          if ( "i".equals( artifact.getArtifactId() ) )
61          {
62              Artifact a = null;
63              try
64              {
65                  a = factory.createBuildArtifact( "org.apache.maven", "j", "1.0-SNAPSHOT", "jar" );
66                  dependencies.add( a );
67              }
68              catch ( Exception e )
69              {
70                  throw new ArtifactMetadataRetrievalException( "Error retrieving metadata", e, a );
71              }
72          }
73  
74  
75          return new ResolutionGroup( artifact, dependencies, remoteRepositories );
76      }
77  
78      public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
79          throws ArtifactMetadataRetrievalException
80      {
81          throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
82      }
83  
84      public List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository )
85          throws ArtifactMetadataRetrievalException
86      {
87          throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
88      }
89  
90      public ResolutionGroup retrieve( MetadataResolutionRequest request )
91          throws ArtifactMetadataRetrievalException
92      {
93          return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
94      }
95  
96      public List<ArtifactVersion> retrieveAvailableVersions( MetadataResolutionRequest request )
97          throws ArtifactMetadataRetrievalException
98      {
99          return retrieveAvailableVersions( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
100     }
101 
102 }