29
29
import org .apache .maven .artifact .handler .DefaultArtifactHandler ;
30
30
import org .apache .maven .artifact .test .ArtifactTestCase ;
31
31
import org .apache .maven .artifact .versioning .VersionRange ;
32
-
32
+ import org . codehaus . plexus . compiler . CompilerMessage . Kind ;
33
33
import org .codehaus .plexus .util .FileUtils ;
34
34
import org .codehaus .plexus .util .StringUtils ;
35
35
36
- import javax .print .DocFlavor ;
37
36
import java .io .File ;
38
37
import java .util .ArrayList ;
39
38
import java .util .Collection ;
@@ -91,6 +90,22 @@ protected void configureCompilerConfig( CompilerConfiguration compilerConfig )
91
90
92
91
}
93
92
93
+
94
+ /**
95
+ * Called once per compile iteration to allow configuration customization for
96
+ * tests.
97
+ *
98
+ * @param compilerConfig
99
+ * configuration used for this compile iteration.
100
+ * @param filename
101
+ * file about to be compiled this iteration.
102
+ * @since 2.8.6
103
+ */
104
+ protected void configureCompilerConfig (CompilerConfiguration compilerConfig , String filename )
105
+ {
106
+ configureCompilerConfig ( compilerConfig );
107
+ }
108
+
94
109
public void testCompilingSources ()
95
110
throws Exception
96
111
{
@@ -113,7 +128,9 @@ public void testCompilingSources()
113
128
114
129
int numCompilerErrors = compilerErrorCount ( messages );
115
130
116
- int numCompilerWarnings = messages .size () - numCompilerErrors ;
131
+ int numCompilerWarnings = compilerWarningCount ( messages );
132
+
133
+ int numCompilerNotes = compilerNoteCount ( messages );
117
134
118
135
int expectedErrors = expectedErrors ();
119
136
@@ -123,7 +140,7 @@ public void testCompilingSources()
123
140
List <String > errors = new ArrayList <>();
124
141
for ( CompilerMessage error : messages )
125
142
{
126
- if ( ! error .isError () )
143
+ if ( error .getKind () != Kind . ERROR )
127
144
{
128
145
continue ;
129
146
}
@@ -146,7 +163,7 @@ public void testCompilingSources()
146
163
System .out .println ( numCompilerWarnings + " warning(s) found:" );
147
164
for ( CompilerMessage error : messages )
148
165
{
149
- if ( error .isError () )
166
+ if ( error .getKind () == Kind . ERROR || error . getKind () == Kind . NOTE )
150
167
{
151
168
continue ;
152
169
}
@@ -162,6 +179,25 @@ public void testCompilingSources()
162
179
expectedWarnings , numCompilerWarnings );
163
180
}
164
181
182
+ if ( expectedNotes () != numCompilerNotes )
183
+ {
184
+ System .out .println ( numCompilerWarnings + " notes(s) found:" );
185
+ for (CompilerMessage error : messages )
186
+ {
187
+ if ( error .getKind () != Kind .NOTE )
188
+ {
189
+ continue ;
190
+ }
191
+
192
+ System .out .println ( "----" );
193
+ System .out .println ( error .getFile () );
194
+ System .out .println ( error .getMessage () );
195
+ System .out .println ( "----" );
196
+ }
197
+
198
+ assertEquals ( "Wrong number of compilation notes." , expectedNotes (), numCompilerNotes );
199
+ }
200
+
165
201
assertEquals ( new TreeSet <>( normalizePaths ( expectedOutputFiles () ) ), files );
166
202
}
167
203
@@ -199,7 +235,7 @@ private List<CompilerConfiguration> getCompilerConfigurations()
199
235
200
236
compilerConfig .setForceJavacCompilerUse ( this .forceJavacCompilerUse );
201
237
202
- configureCompilerConfig ( compilerConfig );
238
+ configureCompilerConfig ( compilerConfig , filename );
203
239
204
240
String target = getTargetVersion ();
205
241
if ( StringUtils .isNotEmpty ( target ) )
@@ -241,16 +277,32 @@ private List<String> normalizePaths( Collection<String> relativePaths )
241
277
return normalizedPaths ;
242
278
}
243
279
244
- protected int compilerErrorCount ( List <CompilerMessage > messages )
280
+ private int compilerErrorCount (List <CompilerMessage > messages )
281
+ {
282
+ return countKind ( messages , Kind .ERROR );
283
+ }
284
+
285
+ private int compilerWarningCount (List <CompilerMessage > messages )
245
286
{
246
- int count = 0 ;
287
+ return messages .size () - (compilerErrorCount ( messages ) + compilerNoteCount ( messages ));
288
+ }
289
+
290
+ private int compilerNoteCount (List <CompilerMessage > messages )
291
+ {
292
+ return countKind ( messages , Kind .NOTE );
293
+ }
247
294
248
- for ( CompilerMessage message : messages )
295
+ private int countKind (List <CompilerMessage > messages , Kind kind )
296
+ {
297
+ int c = 0 ;
298
+ for (CompilerMessage message : messages )
249
299
{
250
- count += message .isError () ? 1 : 0 ;
300
+ if ( message .getKind () == kind )
301
+ {
302
+ c ++;
303
+ }
251
304
}
252
-
253
- return count ;
305
+ return c ;
254
306
}
255
307
256
308
protected int expectedErrors ()
@@ -263,6 +315,17 @@ protected int expectedWarnings()
263
315
return 0 ;
264
316
}
265
317
318
+ /**
319
+ * Count of output generated at the {@link Kind#NOTE} level.
320
+ *
321
+ * @return count
322
+ * @since 2.8.6
323
+ */
324
+ protected int expectedNotes ()
325
+ {
326
+ return 0 ;
327
+ }
328
+
266
329
protected Collection <String > expectedOutputFiles ()
267
330
{
268
331
return Collections .emptyList ();
0 commit comments