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.resolver.internal.ant.tasks;
20  
21  import org.apache.tools.ant.Project;
22  import org.apache.tools.ant.Task;
23  import org.eclipse.aether.artifact.Artifact;
24  import org.eclipse.aether.graph.Dependency;
25  import org.eclipse.aether.graph.DependencyNode;
26  import org.eclipse.aether.graph.DependencyVisitor;
27  import org.eclipse.aether.util.graph.manager.DependencyManagerUtils;
28  
29  /**
30   */
31  class DependencyGraphLogger implements DependencyVisitor {
32  
33      private Task task;
34  
35      private String indent = "";
36  
37      DependencyGraphLogger(Task task) {
38          this.task = task;
39      }
40  
41      public boolean visitEnter(DependencyNode node) {
42          StringBuilder buffer = new StringBuilder(128);
43          buffer.append(indent);
44          Dependency dep = node.getDependency();
45          if (dep != null) {
46              Artifact art = dep.getArtifact();
47  
48              buffer.append(art);
49              buffer.append(':').append(dep.getScope());
50  
51              String premanagedScope = DependencyManagerUtils.getPremanagedScope(node);
52              if (premanagedScope != null && !premanagedScope.equals(dep.getScope())) {
53                  buffer.append(" (scope managed from ").append(premanagedScope).append(")");
54              }
55  
56              String premanagedVersion = DependencyManagerUtils.getPremanagedVersion(node);
57              if (premanagedVersion != null && !premanagedVersion.equals(art.getVersion())) {
58                  buffer.append(" (version managed from ")
59                          .append(premanagedVersion)
60                          .append(")");
61              }
62          } else {
63              buffer.append("Resolved Dependency Graph:");
64          }
65  
66          task.log(buffer.toString(), Project.MSG_VERBOSE);
67          indent += "   ";
68          return true;
69      }
70  
71      public boolean visitLeave(DependencyNode node) {
72          indent = indent.substring(0, indent.length() - 3);
73          return true;
74      }
75  }