1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.impl.model;
20
21 import org.apache.maven.api.model.Model;
22 import org.apache.maven.api.services.ModelProblem;
23
24
25
26
27
28
29
30 public class DefaultModelProblem implements ModelProblem {
31
32 private final String source;
33
34 private final int lineNumber;
35
36 private final int columnNumber;
37
38 private final String modelId;
39
40 private final String message;
41
42 private final Exception exception;
43
44 private final Severity severity;
45
46 private final Version version;
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public DefaultModelProblem(
61 String message,
62 Severity severity,
63 Version version,
64 Model source,
65 int lineNumber,
66 int columnNumber,
67 Exception exception) {
68 this(
69 message,
70 severity,
71 version,
72 ModelProblemUtils.toPath(source),
73 lineNumber,
74 columnNumber,
75 ModelProblemUtils.toId(source),
76 exception);
77 }
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 @SuppressWarnings("checkstyle:parameternumber")
94 public DefaultModelProblem(
95 String message,
96 Severity severity,
97 Version version,
98 String source,
99 int lineNumber,
100 int columnNumber,
101 String modelId,
102 Exception exception) {
103 this.message = message;
104 this.severity = (severity != null) ? severity : Severity.ERROR;
105 this.source = (source != null) ? source : "";
106 this.lineNumber = lineNumber;
107 this.columnNumber = columnNumber;
108 this.modelId = (modelId != null) ? modelId : "";
109 this.exception = exception;
110 this.version = version != null ? version : Version.BASE;
111 }
112
113 @Override
114 public String getSource() {
115 return source;
116 }
117
118 @Override
119 public int getLineNumber() {
120 return lineNumber;
121 }
122
123 @Override
124 public int getColumnNumber() {
125 return columnNumber;
126 }
127
128 public String getModelId() {
129 return modelId;
130 }
131
132 @Override
133 public Exception getException() {
134 return exception;
135 }
136
137 @Override
138 public String getLocation() {
139 return "";
140 }
141
142 @Override
143 public String getMessage() {
144 String msg = null;
145
146 if (message != null && !message.isEmpty()) {
147 msg = message;
148 } else if (exception != null) {
149 msg = exception.getMessage();
150 }
151
152 if (msg == null) {
153 msg = "";
154 }
155
156 return msg;
157 }
158
159 @Override
160 public Severity getSeverity() {
161 return severity;
162 }
163
164 public Version getVersion() {
165 return version;
166 }
167
168 @Override
169 public String toString() {
170 StringBuilder buffer = new StringBuilder(128);
171
172 buffer.append('[').append(getSeverity()).append("] ");
173 buffer.append(getMessage());
174 String location = ModelProblemUtils.formatLocation(this, null);
175 if (!location.isEmpty()) {
176 buffer.append(" @ ");
177 buffer.append(location);
178 }
179
180 return buffer.toString();
181 }
182 }