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