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.nio.file.Path;
22
23 import org.apache.maven.model.Model;
24
25
26
27
28
29
30 @Deprecated(since = "4.0.0")
31 public class ModelProblemUtils {
32
33
34
35
36
37
38
39 static String toSourceHint(Model model) {
40 if (model == null) {
41 return "";
42 }
43
44 StringBuilder buffer = new StringBuilder(128);
45
46 buffer.append(toId(model));
47
48 Path pomPath = model.getPomPath();
49 if (pomPath != null) {
50 buffer.append(" (").append(pomPath).append(')');
51 }
52
53 return buffer.toString();
54 }
55
56 static String toPath(Model model) {
57 String path = "";
58
59 if (model != null) {
60 Path pomPath = model.getPomPath();
61
62 if (pomPath != null) {
63 path = pomPath.toAbsolutePath().toString();
64 }
65 }
66
67 return path;
68 }
69
70 static String toId(Model model) {
71 if (model == null) {
72 return "";
73 }
74 return toId(model.getDelegate());
75 }
76
77 static String toId(org.apache.maven.api.model.Model model) {
78 String groupId = model.getGroupId();
79 if (groupId == null && model.getParent() != null) {
80 groupId = model.getParent().getGroupId();
81 }
82
83 String artifactId = model.getArtifactId();
84
85 String version = model.getVersion();
86 if (version == null && model.getParent() != null) {
87 version = model.getParent().getVersion();
88 }
89 if (version == null) {
90 version = "[unknown-version]";
91 }
92
93 return toId(groupId, artifactId, version);
94 }
95
96
97
98
99
100
101
102
103
104 static String toId(String groupId, String artifactId, String version) {
105 StringBuilder buffer = new StringBuilder(128);
106
107 buffer.append((groupId != null && !groupId.isEmpty()) ? groupId : "[unknown-group-id]");
108 buffer.append(':');
109 buffer.append((artifactId != null && !artifactId.isEmpty()) ? artifactId : "[unknown-artifact-id]");
110 buffer.append(':');
111 buffer.append((version != null && !version.isEmpty()) ? version : "[unknown-version]");
112
113 return buffer.toString();
114 }
115
116
117
118
119
120
121
122
123
124
125
126 public static String formatLocation(ModelProblem problem, String projectId) {
127 StringBuilder buffer = new StringBuilder(256);
128
129 if (!problem.getModelId().equals(projectId)) {
130 buffer.append(problem.getModelId());
131
132 if (!problem.getSource().isEmpty()) {
133 if (buffer.length() > 0) {
134 buffer.append(", ");
135 }
136 buffer.append(problem.getSource());
137 }
138 }
139
140 if (problem.getLineNumber() > 0) {
141 if (buffer.length() > 0) {
142 buffer.append(", ");
143 }
144 buffer.append("line ").append(problem.getLineNumber());
145 }
146
147 if (problem.getColumnNumber() > 0) {
148 if (buffer.length() > 0) {
149 buffer.append(", ");
150 }
151 buffer.append("column ").append(problem.getColumnNumber());
152 }
153
154 return buffer.toString();
155 }
156 }