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