From 6d743c9e6b9776e0358bb1d54f397e3728186a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Mon, 21 Apr 2014 08:19:57 +0100 Subject: [PATCH] no longer calls --- History.md | 4 ++++ core/src/main/java/cucumber/api/cli/Main.java | 15 ++++++++++++--- .../java/cucumber/runtime/RuntimeOptions.java | 2 +- .../cucumber/{runtime => api/cli}/USAGE.txt | 0 4 files changed, 17 insertions(+), 4 deletions(-) rename core/src/main/resources/cucumber/{runtime => api/cli}/USAGE.txt (100%) diff --git a/History.md b/History.md index b08d9166bb..d7f739151c 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,7 @@ +## [1.1.7](https://github.com/cucumber/cucumber-jvm/compare/v1.1.6...master) (Git master) + +* [Core] `cucumber.api.cli.Main.run` no longer calls `System.exit`, allowing embedding in other tools (Aslak Hellesøy) + ## [1.1.6](https://github.com/cucumber/cucumber-jvm/compare/v1.1.5...v1.1.6) (2014-03-24) * [Guice] Add hookpoints in Cucumber and GuiceFactory ([#634](https://github.com/cucumber/cucumber-jvm/pull/634) Wouter Coekaerts) diff --git a/core/src/main/java/cucumber/api/cli/Main.java b/core/src/main/java/cucumber/api/cli/Main.java index 1d8564acd0..1801e84b85 100644 --- a/core/src/main/java/cucumber/api/cli/Main.java +++ b/core/src/main/java/cucumber/api/cli/Main.java @@ -15,16 +15,25 @@ public class Main { public static void main(String[] argv) throws Throwable { - run(argv, Thread.currentThread().getContextClassLoader()); + byte exitstatus = run(argv, Thread.currentThread().getContextClassLoader()); + System.exit(exitstatus); } - public static void run(String[] argv, ClassLoader classLoader) throws IOException { + /** + * Launches the Cucumber-JVM command line. + * + * @param argv runtime options. See details in the {@code cucumber.api.cli.Usage.txt} resource. + * @param classLoader classloader used to load the runtime + * @return 0 if execution was successful, 1 if it was not (test failures) + * @throws IOException if resources couldn't be loaded during the run. + */ + public static byte run(String[] argv, ClassLoader classLoader) throws IOException { RuntimeOptions runtimeOptions = new RuntimeOptions(new ArrayList(asList(argv))); ResourceLoader resourceLoader = new MultiLoader(classLoader); ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader); Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions); runtime.run(); - System.exit(runtime.exitStatus()); + return runtime.exitStatus(); } } diff --git a/core/src/main/java/cucumber/runtime/RuntimeOptions.java b/core/src/main/java/cucumber/runtime/RuntimeOptions.java index beb9c377e5..54a5acabad 100644 --- a/core/src/main/java/cucumber/runtime/RuntimeOptions.java +++ b/core/src/main/java/cucumber/runtime/RuntimeOptions.java @@ -24,7 +24,7 @@ // IMPORTANT! Make sure USAGE.txt is always uptodate if this class changes. public class RuntimeOptions { public static final String VERSION = ResourceBundle.getBundle("cucumber.version").getString("cucumber-jvm.version"); - public static final String USAGE = FixJava.readResource("/cucumber/runtime/USAGE.txt"); + public static final String USAGE = FixJava.readResource("/cucumber/api/cli/USAGE.txt"); private final List glue = new ArrayList(); private final List filters = new ArrayList(); diff --git a/core/src/main/resources/cucumber/runtime/USAGE.txt b/core/src/main/resources/cucumber/api/cli/USAGE.txt similarity index 100% rename from core/src/main/resources/cucumber/runtime/USAGE.txt rename to core/src/main/resources/cucumber/api/cli/USAGE.txt