1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.model.building;
20
21 import java.io.File;
22
23 import org.apache.maven.model.Model;
24
25
26
27
28
29
30 public class ModelProblemUtils {
31
32
33
34
35
36
37
38 static String toSourceHint(Model model) {
39 if (model == null) {
40 return "";
41 }
42
43 StringBuilder buffer = new StringBuilder(128);
44
45 buffer.append(toId(model));
46
47 File pomFile = model.getPomFile();
48 if (pomFile != null) {
49 buffer.append(" (").append(pomFile).append(')');
50 }
51
52 return buffer.toString();
53 }
54
55 static String toPath(Model model) {
56 String path = "";
57
58 if (model != null) {
59 File pomFile = model.getPomFile();
60
61 if (pomFile != null) {
62 path = pomFile.getAbsolutePath();
63 }
64 }
65
66 return path;
67 }
68
69 static String toId(Model model) {
70 if (model == null) {
71 return "";
72 }
73
74 String groupId = model.getGroupId();
75 if (groupId == null && model.getParent() != null) {
76 groupId = model.getParent().getGroupId();
77 }
78
79 String artifactId = model.getArtifactId();
80
81 String version = model.getVersion();
82 if (version == null && model.getParent() != null) {
83 version = model.getParent().getVersion();
84 }
85 if (version == null) {
86 version = "[unknown-version]";
87 }
88
89 return toId(groupId, artifactId, version);
90 }
91
92
93
94
95
96
97
98
99
100 static String toId(String groupId, String artifactId, String version) {
101 StringBuilder buffer = new StringBuilder(128);
102
103 buffer.append((groupId != null && groupId.length() > 0) ? groupId : "[unknown-group-id]");
104 buffer.append(':');
105 buffer.append((artifactId != null && artifactId.length() > 0) ? artifactId : "[unknown-artifact-id]");
106 buffer.append(':');
107 buffer.append((version != null && version.length() > 0) ? version : "[unknown-version]");
108
109 return buffer.toString();
110 }
111
112
113
114
115
116
117
118
119
120
121
122 public static String formatLocation(ModelProblem problem, String projectId) {
123 StringBuilder buffer = new StringBuilder(256);
124
125 if (!problem.getModelId().equals(projectId)) {
126 buffer.append(problem.getModelId());
127
128 if (problem.getSource().length() > 0) {
129 if (buffer.length() > 0) {
130 buffer.append(", ");
131 }
132 buffer.append(problem.getSource());
133 }
134 }
135
136 if (problem.getLineNumber() > 0) {
137 if (buffer.length() > 0) {
138 buffer.append(", ");
139 }
140 buffer.append("line ").append(problem.getLineNumber());
141 }
142
143 if (problem.getColumnNumber() > 0) {
144 if (buffer.length() > 0) {
145 buffer.append(", ");
146 }
147 buffer.append("column ").append(problem.getColumnNumber());
148 }
149
150 return buffer.toString();
151 }
152 }