@@ -329,6 +329,76 @@ else
329
329
end
330
330
end
331
331
332
+ # Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:compile` output
333
+ #
334
+ # Example:
335
+ # [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
336
+ # [INFO] Changes detected - recompiling the module!
337
+ # [INFO] Compiling 206 source files to /home/coder/mystamps/target/classes
338
+ # [INFO] -------------------------------------------------------------
339
+ # [ERROR] COMPILATION ERROR :
340
+ # [INFO] -------------------------------------------------------------
341
+ # [ERROR] /home/coder/mystamps/src/main/java/ru/mystamps/web/service/CollectionService.java:[31,32] cannot find symbol
342
+ # symbol: class Date
343
+ # location: interface ru.mystamps.web.service.CollectionService
344
+ # [INFO] 1 error
345
+ # [INFO] -------------------------------------------------------------
346
+ # [INFO] ------------------------------------------------------------------------
347
+ # [INFO] BUILD FAILURE
348
+ # [INFO] ------------------------------------------------------------------------
349
+ #
350
+ # We're parsing file with `mvn test` output because compilation occurs before executing tests.
351
+ test_output = 'test.log'
352
+ unless File . file? ( test_output )
353
+ warn ( "Couldn't find #{ test_output } . Result of running unit tests is unknown" )
354
+ else
355
+ errors = [ ]
356
+ plugin_output_started = false
357
+ errors_detected = false
358
+ File . readlines ( test_output ) . each do |line |
359
+ # We're interesting in everything between
360
+ # [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mystamps ---
361
+ # and
362
+ # [INFO] --- gmaven-plugin:1.4:compile (default) @ mystamps ---
363
+ # or
364
+ # [INFO] BUILD FAILURE
365
+
366
+ if line . start_with? '[INFO] --- maven-compiler-plugin:'
367
+ plugin_output_started = true
368
+ next
369
+ end
370
+
371
+ unless plugin_output_started
372
+ next
373
+ end
374
+
375
+ if line . start_with? '[INFO] Download'
376
+ next
377
+ end
378
+
379
+ # next plugin started its execution => no errors encountered, stop processing
380
+ if line . start_with? '[INFO] --- '
381
+ break
382
+ end
383
+
384
+ # build failed => error output was collected, stop processing
385
+ if line =~ /BUILD FAILURE/
386
+ break
387
+ end
388
+
389
+ errors << line . rstrip
390
+ end
391
+
392
+ unless errors . empty?
393
+ if errors . last . start_with? '[INFO] -----'
394
+ errors . pop # remove last useless line
395
+ end
396
+ error_msgs = errors . join ( "\n " )
397
+ fail ( "maven-compile-plugin has failed. Please, fix compilation errors. " \
398
+ "Here is its output:\n ```\n #{ error_msgs } \n ```" )
399
+ end
400
+ end
401
+
332
402
# Handle `mvn findbugs:check` results
333
403
#
334
404
# Example:
0 commit comments