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.resolver;
20  
21  import javax.inject.Named;
22  import javax.inject.Singleton;
23  
24  import java.util.ArrayList;
25  import java.util.Collection;
26  import java.util.List;
27  
28  /**
29   */
30  @Named
31  @Singleton
32  @Deprecated
33  public class DefaultResolutionErrorHandler implements ResolutionErrorHandler {
34  
35      public void throwErrors(ArtifactResolutionRequest request, ArtifactResolutionResult result)
36              throws ArtifactResolutionException {
37          // Metadata cannot be found
38  
39          if (result.hasMetadataResolutionExceptions()) {
40              throw result.getMetadataResolutionException(0);
41          }
42  
43          // Metadata cannot be retrieved
44  
45          // Cyclic Dependency Error
46  
47          if (result.hasCircularDependencyExceptions()) {
48              throw result.getCircularDependencyException(0);
49          }
50  
51          // Version Range Violation
52  
53          if (result.hasVersionRangeViolations()) {
54              throw result.getVersionRangeViolation(0);
55          }
56  
57          // Transfer Error
58  
59          if (result.hasErrorArtifactExceptions()) {
60              throw result.getErrorArtifactExceptions().get(0);
61          }
62  
63          if (result.hasMissingArtifacts()) {
64              throw new MultipleArtifactsNotFoundException(
65                      request.getArtifact(),
66                      toList(result.getArtifacts()),
67                      result.getMissingArtifacts(),
68                      request.getRemoteRepositories());
69          }
70  
71          // this should never happen since we checked all possible error sources before but better be sure
72          if (result.hasExceptions()) {
73              throw new ArtifactResolutionException(
74                      "Unknown error during artifact resolution, " + request + ", " + result.getExceptions(),
75                      request.getArtifact(),
76                      request.getRemoteRepositories());
77          }
78      }
79  
80      private static <T> List<T> toList(Collection<T> items) {
81          return (items != null) ? new ArrayList<>(items) : null;
82      }
83  }