Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Warn when cucumber.options is used #2685

Merged
merged 1 commit into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- [Core] Warn when `cucumber.options` is used ([#2685](https://github.com/cucumber/cucumber-jvm/pull/2685) M.P. Korstanje)

## [7.11.0] - 2023-01-12
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ public final class Constants {
*/
public static final String OBJECT_FACTORY_PROPERTY_NAME = "cucumber.object-factory";

/**
* Property name formerly used to pass command line options to Cucumber:
* {@value} This property is no longer read by Cucumber. Please use any of
* the
*/
static final String OPTIONS_PROPERTY_NAME = "cucumber.options";

/**
* Property name to enable plugins: {@value}
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.cucumber.core.exception.CucumberException;
import io.cucumber.core.feature.FeatureWithLines;
import io.cucumber.core.feature.GluePath;
import io.cucumber.core.logging.Logger;
import io.cucumber.core.logging.LoggerFactory;
import io.cucumber.tagexpressions.TagExpressionParser;

import java.nio.file.Path;
Expand All @@ -24,6 +26,7 @@
import static io.cucumber.core.options.Constants.FILTER_TAGS_PROPERTY_NAME;
import static io.cucumber.core.options.Constants.GLUE_PROPERTY_NAME;
import static io.cucumber.core.options.Constants.OBJECT_FACTORY_PROPERTY_NAME;
import static io.cucumber.core.options.Constants.OPTIONS_PROPERTY_NAME;
import static io.cucumber.core.options.Constants.PLUGIN_PROPERTY_NAME;
import static io.cucumber.core.options.Constants.PLUGIN_PUBLISH_ENABLED_PROPERTY_NAME;
import static io.cucumber.core.options.Constants.PLUGIN_PUBLISH_QUIET_PROPERTY_NAME;
Expand All @@ -32,10 +35,13 @@
import static io.cucumber.core.options.Constants.WIP_PROPERTY_NAME;
import static io.cucumber.core.options.OptionsFileParser.parseFeatureWithLinesFile;
import static java.util.Arrays.stream;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toList;

public final class CucumberPropertiesParser {

private static final Logger log = LoggerFactory.getLogger(CucumberPropertiesParser.class);

public RuntimeOptionsBuilder parse(Map<String, String> properties) {
return parse(properties::get);
}
Expand Down Expand Up @@ -96,14 +102,19 @@ public RuntimeOptionsBuilder parse(CucumberPropertiesProvider properties) {
ObjectFactoryParser::parseObjectFactory,
builder::setObjectFactoryClass);

parse(properties,
OPTIONS_PROPERTY_NAME,
identity(),
warnWhenCucumberOptionsIsUsed());

parseAll(properties,
PLUGIN_PROPERTY_NAME,
splitAndMap(Function.identity()),
splitAndMap(identity()),
builder::addPluginName);

parse(properties,
PLUGIN_PUBLISH_TOKEN_PROPERTY_NAME,
s -> s, // No validation - validated on server
identity(), // No validation - validated on server
builder::setPublishToken);

parse(properties,
Expand All @@ -129,6 +140,16 @@ public RuntimeOptionsBuilder parse(CucumberPropertiesProvider properties) {
return builder;
}

private static Consumer<String> warnWhenCucumberOptionsIsUsed() {
// Quite a few old blogs still recommend the use of cucumber.options
// This should take care of recurring question involving this property.
return commandLineOptions -> log.warn(() -> String.format("" +
"Passing commandline options via the property '%s' is no longer supported. " +
"Please use individual properties instead. " +
"See the java doc on %s for details.",
OPTIONS_PROPERTY_NAME, Constants.class.getName()));
}

private <T> void parse(
CucumberPropertiesProvider properties, String propertyName, Function<String, T> parser, Consumer<T> setter
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.cucumber.core.backend.ObjectFactory;
import io.cucumber.core.exception.CucumberException;
import io.cucumber.core.logging.LogRecordListener;
import io.cucumber.core.logging.WithLogRecordListener;
import io.cucumber.core.order.StandardPickleOrders;
import io.cucumber.core.snippets.SnippetType;
import io.cucumber.tagexpressions.TagExpressionParser;
Expand Down Expand Up @@ -30,6 +32,7 @@
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertThrows;

@WithLogRecordListener
class CucumberPropertiesParserTest {

private final CucumberPropertiesParser cucumberPropertiesParser = new CucumberPropertiesParser();
Expand Down Expand Up @@ -138,6 +141,16 @@ void should_parse_object_factory() {
assertThat(options.getObjectFactoryClass(), equalTo(CustomObjectFactory.class));
}

@Test
void should_warn_about_cucumber_options(LogRecordListener logRecordListener) {
properties.put(Constants.OPTIONS_PROPERTY_NAME, "--help");
cucumberPropertiesParser.parse(properties).build();
assertThat(logRecordListener.getLogRecords().get(0).getMessage(), equalTo("" +
"Passing commandline options via the property 'cucumber.options' is no longer supported. " +
"Please use individual properties instead. " +
"See the java doc on io.cucumber.core.options.Constants for details."));
}

@Test
void should_parse_plugin() {
properties.put(Constants.PLUGIN_PROPERTY_NAME, "message:target/cucumber.ndjson, html:target/cucumber.html");
Expand Down