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.project;
20  
21  import javax.inject.Named;
22  import javax.inject.Singleton;
23  
24  import java.io.FileNotFoundException;
25  import java.net.URISyntaxException;
26  import java.util.ArrayList;
27  import java.util.Collection;
28  import java.util.Collections;
29  import java.util.List;
30  
31  import org.eclipse.aether.RepositorySystemSession;
32  import org.eclipse.aether.artifact.Artifact;
33  import org.eclipse.aether.impl.ArtifactResolver;
34  import org.eclipse.aether.repository.RemoteRepository;
35  import org.eclipse.aether.resolution.ArtifactRequest;
36  import org.eclipse.aether.resolution.ArtifactResolutionException;
37  import org.eclipse.aether.resolution.ArtifactResult;
38  import org.eclipse.aether.transfer.ArtifactNotFoundException;
39  
40  /**
41   */
42  @Named("classpath")
43  @Singleton
44  @Deprecated
45  public class ClasspathArtifactResolver implements ArtifactResolver {
46  
47      public List<ArtifactResult> resolveArtifacts(
48              RepositorySystemSession session, Collection<? extends ArtifactRequest> requests)
49              throws ArtifactResolutionException {
50          List<ArtifactResult> results = new ArrayList<>();
51  
52          for (ArtifactRequest request : requests) {
53              ArtifactResult result = new ArtifactResult(request);
54              results.add(result);
55  
56              Artifact artifact = request.getArtifact();
57              if ("maven-test".equals(artifact.getGroupId())) {
58                  String scope = artifact.getArtifactId().substring("scope-".length());
59  
60                  try {
61                      artifact = artifact.setFile(ProjectClasspathTestType.getFileForClasspathResource(
62                              ProjectClasspathTestType.dir + "transitive-" + scope + "-dep.xml"));
63                      result.setArtifact(artifact);
64                  } catch (FileNotFoundException | URISyntaxException e) {
65                      throw new IllegalStateException("Missing test POM for " + artifact, e);
66                  }
67              } else {
68                  result.addException(new ArtifactNotFoundException(artifact, (RemoteRepository) null));
69                  throw new ArtifactResolutionException(results);
70              }
71          }
72  
73          return results;
74      }
75  
76      public ArtifactResult resolveArtifact(RepositorySystemSession session, ArtifactRequest request)
77              throws ArtifactResolutionException {
78          return resolveArtifacts(session, Collections.singleton(request)).get(0);
79      }
80  }