1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.dependency.graph.internal;
20
21 import java.util.List;
22
23 import org.apache.maven.artifact.Artifact;
24 import org.apache.maven.model.Exclusion;
25 import org.apache.maven.shared.dependency.graph.DependencyNode;
26
27 class VerboseDependencyNode extends DefaultDependencyNode {
28
29 private final ConflictData data;
30
31 VerboseDependencyNode(
32 DependencyNode parent,
33 Artifact artifact,
34 String premanagedVersion,
35 String premanagedScope,
36 String versionConstraint,
37 Boolean optional,
38 List<Exclusion> exclusions,
39 ConflictData data) {
40 super(parent, artifact, premanagedVersion, premanagedScope, versionConstraint, optional, exclusions);
41
42 this.data = data;
43 }
44
45 @Override
46 public String toNodeString() {
47 StringBuilder buffer = new StringBuilder();
48
49 boolean included = (data.getWinnerVersion() == null);
50
51 if (!included) {
52 buffer.append('(');
53 }
54
55 buffer.append(getArtifact());
56
57 ItemAppender appender = new ItemAppender(buffer, included ? " (" : " - ", "; ", included ? ")" : "");
58
59 if (getPremanagedVersion() != null) {
60 appender.append("version managed from ", getPremanagedVersion());
61 }
62
63 if (getPremanagedScope() != null) {
64 appender.append("scope managed from ", getPremanagedScope());
65 }
66
67 if (data.getOriginalScope() != null) {
68 appender.append("scope updated from ", data.getOriginalScope());
69 }
70
71 if (data.getIgnoredScope() != null) {
72 appender.append("scope not updated to ", data.getIgnoredScope());
73 }
74
75
76
77
78
79
80
81 if (!included) {
82 String winnerVersion = data.getWinnerVersion();
83 if (winnerVersion.equals(getArtifact().getVersion())) {
84 appender.append("omitted for duplicate");
85 } else {
86 appender.append("omitted for conflict with ", winnerVersion);
87 }
88 }
89
90 appender.flush();
91
92 if (!included) {
93 buffer.append(')');
94 }
95
96 return buffer.toString();
97 }
98
99
100
101
102 private static class ItemAppender {
103 private StringBuilder buffer;
104
105 private String startToken;
106
107 private String separatorToken;
108
109 private String endToken;
110
111 private boolean appended;
112
113 ItemAppender(StringBuilder buffer, String startToken, String separatorToken, String endToken) {
114 this.buffer = buffer;
115 this.startToken = startToken;
116 this.separatorToken = separatorToken;
117 this.endToken = endToken;
118
119 appended = false;
120 }
121
122 public ItemAppender append(String item1) {
123 appendToken();
124
125 buffer.append(item1);
126
127 return this;
128 }
129
130 public ItemAppender append(String item1, String item2) {
131 appendToken();
132
133 buffer.append(item1).append(item2);
134
135 return this;
136 }
137
138 public void flush() {
139 if (appended) {
140 buffer.append(endToken);
141
142 appended = false;
143 }
144 }
145
146 private void appendToken() {
147 buffer.append(appended ? separatorToken : startToken);
148
149 appended = true;
150 }
151 }
152 }