Skip to content

Commit fd95821

Browse files
committed
Dangerfile: handle maven-compiler-plugin:testCompile output.
1 parent 55fcde0 commit fd95821

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Dangerfile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ else
330330
end
331331

332332
# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:compile` output
333+
# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:testCompile` output
333334
#
334335
# Example:
335336
# [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
@@ -348,13 +349,16 @@ end
348349
# [INFO] ------------------------------------------------------------------------
349350
#
350351
# 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.
351354
test_output = 'test.log'
352355
unless File.file?(test_output)
353356
warn("Couldn't find #{test_output}. Result of running unit tests is unknown")
354357
else
355358
errors = []
356359
plugin_output_started = false
357360
errors_detected = false
361+
goal = 'unknown'
358362
File.readlines(test_output).each do |line|
359363
# We're interesting in everything between
360364
# [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
@@ -365,6 +369,9 @@ else
365369

366370
if line.start_with? '[INFO] --- maven-compiler-plugin:'
367371
plugin_output_started = true
372+
parsed = line.match(/:[^:]+:(?<goal>[^ ]+)/)
373+
goal = parsed['goal']
374+
errors << line.rstrip
368375
next
369376
end
370377

@@ -376,9 +383,12 @@ else
376383
next
377384
end
378385

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
380388
if line.start_with? '[INFO] --- '
381-
break
389+
plugin_output_started = false
390+
errors.clear()
391+
next
382392
end
383393

384394
# build failed => error output was collected, stop processing
@@ -394,7 +404,7 @@ else
394404
errors.pop # remove last useless line
395405
end
396406
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. "\
398408
"Here is its output:\n```\n#{error_msgs}\n```")
399409
end
400410
end

0 commit comments

Comments
 (0)