330
330
end
331
331
332
332
# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:compile` output
333
+ # Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:testCompile` output
333
334
#
334
335
# Example:
335
336
# [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
@@ -348,13 +349,16 @@ end
348
349
# [INFO] ------------------------------------------------------------------------
349
350
#
350
351
# We're parsing file with `mvn test` output because compilation occurs before executing tests.
352
+ # Also because goals are executing in order and the process stops if one of
353
+ # them failed, we're using the same array to collect errors from different goals.
351
354
test_output = 'test.log'
352
355
unless File . file? ( test_output )
353
356
warn ( "Couldn't find #{ test_output } . Result of running unit tests is unknown" )
354
357
else
355
358
errors = [ ]
356
359
plugin_output_started = false
357
360
errors_detected = false
361
+ goal = 'unknown'
358
362
File . readlines ( test_output ) . each do |line |
359
363
# We're interesting in everything between
360
364
# [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
365
369
366
370
if line . start_with? '[INFO] --- maven-compiler-plugin:'
367
371
plugin_output_started = true
372
+ parsed = line . match ( /:[^:]+:(?<goal>[^ ]+)/ )
373
+ goal = parsed [ 'goal' ]
374
+ errors << line . rstrip
368
375
next
369
376
end
370
377
@@ -376,9 +383,12 @@ else
376
383
next
377
384
end
378
385
379
- # next plugin started its execution => no errors encountered, stop processing
386
+ # next plugin started its execution =>
387
+ # no errors encountered, continue to find next compiler plugin invocation
380
388
if line . start_with? '[INFO] --- '
381
- break
389
+ plugin_output_started = false
390
+ errors . clear ( )
391
+ next
382
392
end
383
393
384
394
# build failed => error output was collected, stop processing
394
404
errors . pop # remove last useless line
395
405
end
396
406
error_msgs = errors . join ( "\n " )
397
- fail ( "maven-compile -plugin has failed. Please, fix compilation errors. " \
407
+ fail ( "maven-compiler -plugin: #{ goal } has failed. Please, fix compilation errors. " \
398
408
"Here is its output:\n ```\n #{ error_msgs } \n ```" )
399
409
end
400
410
end
0 commit comments