Skip to content

Commit eed8c7e

Browse files
committed
handle compilation failure
1 parent b24a2e4 commit eed8c7e

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

Dangerfile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,72 @@ else
279279
end
280280
end
281281

282+
# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:compile` output
283+
#
284+
# Example:
285+
# [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
286+
# [INFO] Changes detected - recompiling the module!
287+
# [INFO] Compiling 206 source files to /home/coder/mystamps.git/target/classes
288+
# [INFO] -------------------------------------------------------------
289+
# [ERROR] COMPILATION ERROR :
290+
# [INFO] -------------------------------------------------------------
291+
# [ERROR] /home/coder/mystamps.git/src/main/java/ru/mystamps/web/service/CollectionService.java:[31,32] cannot find symbol
292+
# symbol: class Date
293+
# location: interface ru.mystamps.web.service.CollectionService
294+
# [INFO] 1 error
295+
# [INFO] -------------------------------------------------------------
296+
# [INFO] ------------------------------------------------------------------------
297+
# [INFO] BUILD FAILURE
298+
# [INFO] ------------------------------------------------------------------------
299+
#
300+
# We're parsing file with `mvn test` output because compilation occurs before executing tests.
301+
test_output = 'test.log'
302+
unless File.file?(test_output)
303+
warn("Couldn't find #{test_output}. Result of running unit tests is unknown")
304+
else
305+
errors = []
306+
plugin_output_started = false
307+
errors_detected = false
308+
File.readlines(test_output).each do |line|
309+
# We're interesting in everything between
310+
# [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
311+
# and
312+
# [INFO] --- gmaven-plugin:1.4:compile (default) @ mystamps ---
313+
# or
314+
# [INFO] BUILD FAILURE
315+
316+
if line.start_with? '[INFO] --- maven-compiler-plugin:'
317+
plugin_output_started = true
318+
next
319+
end
320+
321+
unless plugin_output_started
322+
next
323+
end
324+
325+
# next plugin started its execution => no errors encountered, stop processing
326+
if line.start_with? '[INFO] --- '
327+
break
328+
end
329+
330+
# build failed => error output was collected, stop processing
331+
if line =~ /BUILD FAILURE/
332+
break
333+
end
334+
335+
errors << line.rstrip
336+
end
337+
338+
unless errors.empty?
339+
if errors.last.start_with? '[INFO] -----'
340+
errors.pop # remove last useless line
341+
end
342+
error_msgs = errors.join("\n")
343+
fail("maven-compile-plugin has failed. Please, fix compilation errors. "\
344+
"Here is its output:\n```#{error_msgs}\n```")
345+
end
346+
end
347+
282348
# Handle `mvn findbugs:check` results
283349
findbugs_report = 'target/findbugsXml.xml'
284350
unless File.file?(findbugs_report)

0 commit comments

Comments
 (0)