1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.building;
20
21
22
23
24
25
26
27 class DefaultProblem implements Problem {
28
29 private final String source;
30
31 private final int lineNumber;
32
33 private final int columnNumber;
34
35 private final String message;
36
37 private final Exception exception;
38
39 private final Severity severity;
40
41
42
43
44
45
46
47
48
49
50
51
52
53 DefaultProblem(
54 String message, Severity severity, String source, int lineNumber, int columnNumber, Exception exception) {
55 this.message = message;
56 this.severity = (severity != null) ? severity : Severity.ERROR;
57 this.source = (source != null) ? source : "";
58 this.lineNumber = lineNumber;
59 this.columnNumber = columnNumber;
60 this.exception = exception;
61 }
62
63 public String getSource() {
64 return source;
65 }
66
67 public int getLineNumber() {
68 return lineNumber;
69 }
70
71 public int getColumnNumber() {
72 return columnNumber;
73 }
74
75 public String getLocation() {
76 StringBuilder buffer = new StringBuilder(256);
77
78 if (!getSource().isEmpty()) {
79 if (buffer.length() > 0) {
80 buffer.append(", ");
81 }
82 buffer.append(getSource());
83 }
84
85 if (getLineNumber() > 0) {
86 if (buffer.length() > 0) {
87 buffer.append(", ");
88 }
89 buffer.append("line ").append(getLineNumber());
90 }
91
92 if (getColumnNumber() > 0) {
93 if (buffer.length() > 0) {
94 buffer.append(", ");
95 }
96 buffer.append("column ").append(getColumnNumber());
97 }
98
99 return buffer.toString();
100 }
101
102 public Exception getException() {
103 return exception;
104 }
105
106 public String getMessage() {
107 String msg;
108
109 if (message != null && !message.isEmpty()) {
110 msg = message;
111 } else {
112 msg = exception.getMessage();
113
114 if (msg == null) {
115 msg = "";
116 }
117 }
118
119 return msg;
120 }
121
122 public Severity getSeverity() {
123 return severity;
124 }
125
126 @Override
127 public String toString() {
128 StringBuilder buffer = new StringBuilder(128);
129
130 buffer.append('[').append(getSeverity()).append("] ");
131 buffer.append(getMessage());
132 String location = getLocation();
133 if (!location.isEmpty()) {
134 buffer.append(" @ ");
135 buffer.append(location);
136 }
137
138 return buffer.toString();
139 }
140 }