Skip to content

Commit b7f3322

Browse files
committed
handle gmaven-plugin error
1 parent e791926 commit b7f3322

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

Dangerfile

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ end
281281

282282
# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:compile` output
283283
# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:testCompile` output
284+
# Handle `mvn org.codehaus.gmaven:gmaven-plugin:testCompile` output
284285
#
285-
# Example:
286+
# Example for maven-compiler-plugin:
286287
# [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
287288
# [INFO] Changes detected - recompiling the module!
288289
# [INFO] Compiling 206 source files to /home/coder/mystamps.git/target/classes
@@ -298,6 +299,27 @@ end
298299
# [INFO] BUILD FAILURE
299300
# [INFO] ------------------------------------------------------------------------
300301
#
302+
# Example for gmaven-plugin:testCompile:
303+
# [INFO] --- gmaven-plugin:1.4:testCompile (default-cli) @ mystamps ---
304+
# [INFO] ------------------------------------------------------------------------
305+
# [INFO] BUILD FAILURE
306+
# [INFO] ------------------------------------------------------------------------
307+
# [INFO] Total time: 2.006 s
308+
# [INFO] Finished at: 2017-03-01T22:25:47+01:00
309+
# [INFO] Final Memory: 24M/322M
310+
# [INFO] ------------------------------------------------------------------------
311+
# [ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.4:testCompile (default-cli) on project mystamps: startup failed:
312+
# [ERROR] /home/coder/mystamps/src/test/groovy/ru/mystamps/web/service/SiteServiceImplTest.groovy: 27: unable to resolve class Specification
313+
# [ERROR] @ line 27, column 1.
314+
# [ERROR] @SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
315+
# [ERROR] ^
316+
# [ERROR]
317+
# [ERROR] 1 error
318+
# [ERROR] -> [Help 1]
319+
# [ERROR]
320+
# [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
321+
# [ERROR] Re-run Maven using the -X switch to enable full debug logging.
322+
#
301323
# We're parsing file with `mvn test` output because compilation occurs before executing tests.
302324
# Also because goals are executing in order and the process stops if one of
303325
# them failed, we're using the same array to collect errors from different goals.
@@ -308,19 +330,28 @@ else
308330
errors = []
309331
plugin_output_started = false
310332
errors_detected = false
311-
goal = 'unknown'
333+
plugin = 'unknown'
312334
File.readlines(test_output).each do |line|
313-
# We're interesting in everything between
335+
# For maven-compiler-plugin we're interesting in everything between
314336
# [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
315337
# and
316338
# [INFO] --- gmaven-plugin:1.4:compile (default) @ mystamps ---
317339
# or
318340
# [INFO] BUILD FAILURE
319-
320341
if line.start_with? '[INFO] --- maven-compiler-plugin:'
342+
plugin = 'maven-compiler-plugin'
343+
plugin_output_started = true
344+
errors << line.rstrip
345+
next
346+
end
347+
348+
# For maven-compiler-plugin we're interesting in everything between
349+
# [ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.4:testCompile (default-cli) on project mystamps: startup failed:
350+
# and
351+
# [ERROR] -> [Help 1]
352+
if line.start_with? '[ERROR] Failed to execute goal org.codehaus.gmaven:'
353+
plugin = 'gmaven-plugin'
321354
plugin_output_started = true
322-
parsed = line.match(/:[^:]+:(?<goal>[^ ]+)/)
323-
goal = parsed['goal']
324355
errors << line.rstrip
325356
next
326357
end
@@ -341,8 +372,18 @@ else
341372
next
342373
end
343374

344-
# build failed => error output was collected, stop processing
345375
if line =~ /BUILD FAILURE/
376+
if errors.empty?
377+
# when gmaven plugin fails we need to collect errors after this message
378+
next
379+
else
380+
# build failed => error output is collected, stop processing
381+
break
382+
end
383+
end
384+
385+
# stop collecting error message for the gmaven-plugin
386+
if line.start_with? '[ERROR] -> [Help'
346387
break
347388
end
348389

@@ -354,7 +395,7 @@ else
354395
errors.pop # remove last useless line
355396
end
356397
error_msgs = errors.join("\n")
357-
fail("maven-compiler-plugin:#{goal} has failed. Please, fix compilation errors. "\
398+
fail("#{plugin} has failed. Please, fix compilation errors. "\
358399
"Here is its output:\n```\n#{error_msgs}\n```")
359400
end
360401
end

0 commit comments

Comments
 (0)