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