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