@@ -279,6 +279,72 @@ else
279
279
end
280
280
end
281
281
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
+
282
348
# Handle `mvn findbugs:check` results
283
349
findbugs_report = 'target/findbugsXml.xml'
284
350
unless File . file? ( findbugs_report )
0 commit comments