All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.cucumber.core.cli.Main Maven / Gradle / Ivy

There is a newer version: 7.20.1
Show newest version
package io.cucumber.core.cli;

import io.cucumber.core.options.CommandlineOptionsParser;
import io.cucumber.core.options.Constants;
import io.cucumber.core.options.CucumberProperties;
import io.cucumber.core.options.CucumberPropertiesParser;
import io.cucumber.core.options.RuntimeOptions;
import io.cucumber.core.runtime.Runtime;
import org.apiguardian.api.API;

import java.util.Optional;

/**
 * Cucumber Main. Runs Cucumber as a CLI.
 * 

* Options can be provided in by (order of precedence): *

    *
  1. Command line arguments
  2. *
  3. Properties from {@link System#getProperties()}
  4. *
  5. Properties from in {@link System#getenv()}
  6. *
  7. Properties from {@value Constants#CUCUMBER_PROPERTIES_FILE_NAME}
  8. *
* For available properties see {@link Constants}. For Command line options * {@link CommandlineOptions}. */ @API(status = API.Status.STABLE) public class Main { public static void main(String... argv) { byte exitStatus = run(argv, Thread.currentThread().getContextClassLoader()); System.exit(exitStatus); } /** * Launches the Cucumber-JVM command line. * * @param argv runtime options. See details in the * {@code cucumber.api.cli.Usage.txt} resource. * @return 0 if execution was successful, 1 if it was not (test * failures) */ public static byte run(String... argv) { return run(argv, Thread.currentThread().getContextClassLoader()); } /** * 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) */ public static byte run(String[] argv, ClassLoader classLoader) { RuntimeOptions propertiesFileOptions = new CucumberPropertiesParser() .parse(CucumberProperties.fromPropertiesFile()) .build(); RuntimeOptions environmentOptions = new CucumberPropertiesParser() .parse(CucumberProperties.fromEnvironment()) .build(propertiesFileOptions); RuntimeOptions systemOptions = new CucumberPropertiesParser() .parse(CucumberProperties.fromSystemProperties()) .build(environmentOptions); CommandlineOptionsParser commandlineOptionsParser = new CommandlineOptionsParser(System.out); RuntimeOptions runtimeOptions = commandlineOptionsParser .parse(argv) .addDefaultGlueIfAbsent() .addDefaultFeaturePathIfAbsent() .addDefaultSummaryPrinterIfNotDisabled() .enablePublishPlugin() .build(systemOptions); Optional exitStatus = commandlineOptionsParser.exitStatus(); if (exitStatus.isPresent()) { return exitStatus.get(); } final Runtime runtime = Runtime.builder() .withRuntimeOptions(runtimeOptions) .withClassLoader(() -> classLoader) .build(); runtime.run(); return runtime.exitStatus(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy