Skip to content

Commit e791926

Browse files
committed
handle maven-compiler-plugin:testCompile goal
1 parent ef56019 commit e791926

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
@@ -280,6 +280,7 @@ else
280280
end
281281

282282
# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:compile` output
283+
# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:testCompile` output
283284
#
284285
# Example:
285286
# [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
@@ -298,13 +299,16 @@ end
298299
# [INFO] ------------------------------------------------------------------------
299300
#
300301
# 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.
301304
test_output = 'test.log'
302305
unless File.file?(test_output)
303306
warn("Couldn't find #{test_output}. Result of running unit tests is unknown")
304307
else
305308
errors = []
306309
plugin_output_started = false
307310
errors_detected = false
311+
goal = 'unknown'
308312
File.readlines(test_output).each do |line|
309313
# We're interesting in everything between
310314
# [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
@@ -315,6 +319,9 @@ else
315319

316320
if line.start_with? '[INFO] --- maven-compiler-plugin:'
317321
plugin_output_started = true
322+
parsed = line.match(/:[^:]+:(?<goal>[^ ]+)/)
323+
goal = parsed['goal']
324+
errors << line.rstrip
318325
next
319326
end
320327

@@ -326,9 +333,12 @@ else
326333
next
327334
end
328335

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
330338
if line.start_with? '[INFO] --- '
331-
break
339+
plugin_output_started = false
340+
errors.clear()
341+
next
332342
end
333343

334344
# build failed => error output was collected, stop processing
@@ -344,7 +354,7 @@ else
344354
errors.pop # remove last useless line
345355
end
346356
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. "\
348358
"Here is its output:\n```\n#{error_msgs}\n```")
349359
end
350360
end

0 commit comments

Comments
 (0)