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 final Task task;
34  
35      private String indent = "";
36  
37      DependencyGraphLogger(Task task) {
38          this.task = task;
39      }
40  
41      @Override
42      public boolean visitEnter(DependencyNode node) {
43          StringBuilder buffer = new StringBuilder(128);
44          buffer.append(indent);
45          Dependency dep = node.getDependency();
46          if (dep != null) {
47              Artifact art = dep.getArtifact();
48  
49              buffer.append(art);
50              buffer.append(':').append(dep.getScope());
51  
52              String premanagedScope = DependencyManagerUtils.getPremanagedScope(node);
53              if (premanagedScope != null && !premanagedScope.equals(dep.getScope())) {
54                  buffer.append(" (scope managed from ").append(premanagedScope).append(")");
55              }
56  
57              String premanagedVersion = DependencyManagerUtils.getPremanagedVersion(node);
58              if (premanagedVersion != null && !premanagedVersion.equals(art.getVersion())) {
59                  buffer.append(" (version managed from ")
60                          .append(premanagedVersion)
61                          .append(")");
62              }
63          } else {
64              buffer.append("Resolved Dependency Graph:");
65          }
66  
67          task.log(buffer.toString(), Project.MSG_VERBOSE);
68          indent += "   ";
69          return true;
70      }
71  
72      @Override
73      public boolean visitLeave(DependencyNode node) {
74          indent = indent.substring(0, indent.length() - 3);
75          return true;
76      }
77  }