From bb6d23a72e708efd94e64b227d266829ed638c1f Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Mon, 1 Apr 2019 15:35:37 +1100 Subject: [PATCH] Exit command with a non-zero exit code if the externs contain an error --- .../generator/closure/ClosureJsInteropGenerator.java | 3 +++ .../generator/closure/GeneratorFailedException.java | 6 ++++++ java/jsinterop/generator/closure/Runner.java | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 java/jsinterop/generator/closure/GeneratorFailedException.java diff --git a/java/jsinterop/generator/closure/ClosureJsInteropGenerator.java b/java/jsinterop/generator/closure/ClosureJsInteropGenerator.java index 7cf8cec..12fdb54 100644 --- a/java/jsinterop/generator/closure/ClosureJsInteropGenerator.java +++ b/java/jsinterop/generator/closure/ClosureJsInteropGenerator.java @@ -121,6 +121,9 @@ private Program generateJavaProgram() { .build(); compiler.compile(new ArrayList<>(), allSources, createCompilerOptions()); + if (compiler.getErrorCount() > 0) { + throw new GeneratorFailedException(); + } GenerationContext ctx = GenerationContext.builder() diff --git a/java/jsinterop/generator/closure/GeneratorFailedException.java b/java/jsinterop/generator/closure/GeneratorFailedException.java new file mode 100644 index 0000000..f8b853f --- /dev/null +++ b/java/jsinterop/generator/closure/GeneratorFailedException.java @@ -0,0 +1,6 @@ +package jsinterop.generator.closure; + +public class GeneratorFailedException + extends RuntimeException +{ +} diff --git a/java/jsinterop/generator/closure/Runner.java b/java/jsinterop/generator/closure/Runner.java index 0c6793b..6522742 100644 --- a/java/jsinterop/generator/closure/Runner.java +++ b/java/jsinterop/generator/closure/Runner.java @@ -123,6 +123,10 @@ public static void main(String[] args) throws CmdLineException { Runner runner = new Runner(); CmdLineParser parser = new CmdLineParser(runner); parser.parseArgument(args); - runner.run(); + try { + runner.run(); + } catch (GeneratorFailedException ignored) { + System.exit(1); + } } }