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