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