View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.artifact.metadata;
20  
21  import javax.inject.Inject;
22  import javax.inject.Named;
23  import javax.inject.Singleton;
24  
25  import java.util.HashSet;
26  import java.util.List;
27  import java.util.Set;
28  
29  import org.apache.maven.artifact.Artifact;
30  import org.apache.maven.artifact.factory.ArtifactFactory;
31  import org.apache.maven.artifact.repository.ArtifactRepository;
32  import org.apache.maven.artifact.versioning.ArtifactVersion;
33  import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
34  
35  @Named("test")
36  @Singleton
37  @Deprecated
38  public class TestMetadataSource implements ArtifactMetadataSource {
39      @Inject
40      private ArtifactFactory factory;
41  
42      public ResolutionGroup retrieve(
43              Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories)
44              throws ArtifactMetadataRetrievalException {
45          Set<Artifact> dependencies = new HashSet<>();
46  
47          if ("g".equals(artifact.getArtifactId())) {
48              Artifact a = null;
49              try {
50                  a = factory.createBuildArtifact("org.apache.maven", "h", "1.0", "jar");
51                  dependencies.add(a);
52              } catch (Exception e) {
53                  throw new ArtifactMetadataRetrievalException("Error retrieving metadata", e, a);
54              }
55          }
56  
57          if ("i".equals(artifact.getArtifactId())) {
58              Artifact a = null;
59              try {
60                  a = factory.createBuildArtifact("org.apache.maven", "j", "1.0-SNAPSHOT", "jar");
61                  dependencies.add(a);
62              } catch (Exception e) {
63                  throw new ArtifactMetadataRetrievalException("Error retrieving metadata", e, a);
64              }
65          }
66  
67          return new ResolutionGroup(artifact, dependencies, remoteRepositories);
68      }
69  
70      public List<ArtifactVersion> retrieveAvailableVersions(
71              Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories)
72              throws ArtifactMetadataRetrievalException {
73          throw new UnsupportedOperationException("Cannot get available versions in this test case");
74      }
75  
76      public List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository(
77              Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository)
78              throws ArtifactMetadataRetrievalException {
79          throw new UnsupportedOperationException("Cannot get available versions in this test case");
80      }
81  
82      public ResolutionGroup retrieve(MetadataResolutionRequest request) throws ArtifactMetadataRetrievalException {
83          return retrieve(request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories());
84      }
85  
86      public List<ArtifactVersion> retrieveAvailableVersions(MetadataResolutionRequest request)
87              throws ArtifactMetadataRetrievalException {
88          return retrieveAvailableVersions(
89                  request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories());
90      }
91  }