280
280
end
281
281
282
282
# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:compile` output
283
+ # Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:testCompile` output
283
284
#
284
285
# Example:
285
286
# [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
@@ -298,13 +299,16 @@ end
298
299
# [INFO] ------------------------------------------------------------------------
299
300
#
300
301
# We're parsing file with `mvn test` output because compilation occurs before executing tests.
302
+ # Also because goals are executing in order and the process stops if one of
303
+ # them failed, we're using the same array to collect errors from different goals.
301
304
test_output = 'test.log'
302
305
unless File . file? ( test_output )
303
306
warn ( "Couldn't find #{ test_output } . Result of running unit tests is unknown" )
304
307
else
305
308
errors = [ ]
306
309
plugin_output_started = false
307
310
errors_detected = false
311
+ goal = 'unknown'
308
312
File . readlines ( test_output ) . each do |line |
309
313
# We're interesting in everything between
310
314
# [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
315
319
316
320
if line . start_with? '[INFO] --- maven-compiler-plugin:'
317
321
plugin_output_started = true
322
+ parsed = line . match ( /:[^:]+:(?<goal>[^ ]+)/ )
323
+ goal = parsed [ 'goal' ]
324
+ errors << line . rstrip
318
325
next
319
326
end
320
327
@@ -326,9 +333,12 @@ else
326
333
next
327
334
end
328
335
329
- # next plugin started its execution => no errors encountered, stop processing
336
+ # next plugin started its execution =>
337
+ # no errors encountered, continue to find next compiler plugin invocation
330
338
if line . start_with? '[INFO] --- '
331
- break
339
+ plugin_output_started = false
340
+ errors . clear ( )
341
+ next
332
342
end
333
343
334
344
# build failed => error output was collected, stop processing
344
354
errors . pop # remove last useless line
345
355
end
346
356
error_msgs = errors . join ( "\n " )
347
- fail ( "maven-compile -plugin has failed. Please, fix compilation errors. " \
357
+ fail ( "maven-compiler -plugin: #{ goal } has failed. Please, fix compilation errors. " \
348
358
"Here is its output:\n ```\n #{ error_msgs } \n ```" )
349
359
end
350
360
end
0 commit comments