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