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 java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.IdentityHashMap;
24  import java.util.List;
25  import java.util.Map;
26  
27  import org.eclipse.aether.graph.Dependency;
28  import org.eclipse.aether.graph.DependencyNode;
29  
30  /**
31   * @author Benjamin Bentmann
32   */
33  class DefaultDependencyResolutionResult implements DependencyResolutionResult {
34  
35      private DependencyNode root;
36  
37      private List<Dependency> dependencies = new ArrayList<>();
38  
39      private List<Dependency> resolvedDependencies = new ArrayList<>();
40  
41      private List<Dependency> unresolvedDependencies = new ArrayList<>();
42  
43      private List<Exception> collectionErrors = new ArrayList<>();
44  
45      private Map<Dependency, List<Exception>> resolutionErrors = new IdentityHashMap<>();
46  
47      public DependencyNode getDependencyGraph() {
48          return root;
49      }
50  
51      public void setDependencyGraph(DependencyNode root) {
52          this.root = root;
53      }
54  
55      public List<Dependency> getDependencies() {
56          return dependencies;
57      }
58  
59      public List<Dependency> getResolvedDependencies() {
60          return resolvedDependencies;
61      }
62  
63      public void addResolvedDependency(Dependency dependency) {
64          dependencies.add(dependency);
65          resolvedDependencies.add(dependency);
66      }
67  
68      public List<Dependency> getUnresolvedDependencies() {
69          return unresolvedDependencies;
70      }
71  
72      public List<Exception> getCollectionErrors() {
73          return collectionErrors;
74      }
75  
76      public void setCollectionErrors(List<Exception> exceptions) {
77          if (exceptions != null) {
78              this.collectionErrors = exceptions;
79          } else {
80              this.collectionErrors = new ArrayList<>();
81          }
82      }
83  
84      public List<Exception> getResolutionErrors(Dependency dependency) {
85          List<Exception> errors = resolutionErrors.get(dependency);
86          return (errors != null) ? Collections.unmodifiableList(errors) : Collections.<Exception>emptyList();
87      }
88  
89      public void setResolutionErrors(Dependency dependency, List<Exception> errors) {
90          dependencies.add(dependency);
91          unresolvedDependencies.add(dependency);
92          resolutionErrors.put(dependency, errors);
93      }
94  }