From abb52f281a5a9856ae618894e9c26b70eace82fc Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" <erik@thauvin.net> Date: Mon, 24 Jun 2024 20:57:45 -0700 Subject: [PATCH] Ensure execution stops on failure --- .../rife/bld/extension/Antlr4Operation.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/rife/bld/extension/Antlr4Operation.java b/src/main/java/rife/bld/extension/Antlr4Operation.java index 620bc21..a06e3ea 100644 --- a/src/main/java/rife/bld/extension/Antlr4Operation.java +++ b/src/main/java/rife/bld/extension/Antlr4Operation.java @@ -6,6 +6,7 @@ import org.antlr.v4.Tool; import rife.bld.operations.AbstractOperation; +import rife.bld.operations.exceptions.ExitStatusException; import java.io.File; import java.util.*; @@ -51,7 +52,10 @@ public void execute() } if (sources.isEmpty()) { - throw new IllegalArgumentException("ERROR: no ANTLR grammars found"); + if (!silent()) { + System.out.println("ERROR: no ANTLR grammars found."); + } + throw new ExitStatusException(1); } var arguments = new ArrayList<>(arguments_); @@ -83,9 +87,14 @@ public void execute() var argument_array = new String[arguments.size()]; arguments.toArray(argument_array); - new Tool(argument_array).processGrammarsOnCommandLine(); - if (!silent()) { - System.out.println("ANTLR4 grammar processed successfully."); + var tool = new Tool(argument_array); + tool.processGrammarsOnCommandLine(); + if (tool.getNumErrors() == 0) { + if (!silent()) { + System.out.println("ANTLR4 grammar processed successfully."); + } + } else { + throw new ExitStatusException(1); } }