Skip to content

Commit e91deac

Browse files
committed
[Core] Warn when cucumber.options is used
In #1779 we deprecated and removed cucumber.options. Unfortunately there are a slew of outdated tutorials still in existence. And this outdated knowledge creates a slow trickle of questions on StackOverflow. It would be nice if we can stop this waste of everyone's time. Fixes: #2673
1 parent 35c71f0 commit e91deac

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

cucumber-core/src/main/java/io/cucumber/core/options/Constants.java

+7
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ public final class Constants {
118118
*/
119119
public static final String OBJECT_FACTORY_PROPERTY_NAME = "cucumber.object-factory";
120120

121+
/**
122+
* Property name formerly used to pass command line options to Cucumber:
123+
* {@value}
124+
* This property is no longer read by Cucumber. Please use any of the
125+
*/
126+
static final String OPTIONS_PROPERTY_NAME = "cucumber.options";
127+
121128
/**
122129
* Property name to enable plugins: {@value}
123130
* <p>

cucumber-core/src/main/java/io/cucumber/core/options/CucumberPropertiesParser.java

+23-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import io.cucumber.core.exception.CucumberException;
44
import io.cucumber.core.feature.FeatureWithLines;
55
import io.cucumber.core.feature.GluePath;
6+
import io.cucumber.core.logging.Logger;
7+
import io.cucumber.core.logging.LoggerFactory;
68
import io.cucumber.tagexpressions.TagExpressionParser;
79

810
import java.nio.file.Path;
@@ -24,6 +26,7 @@
2426
import static io.cucumber.core.options.Constants.FILTER_TAGS_PROPERTY_NAME;
2527
import static io.cucumber.core.options.Constants.GLUE_PROPERTY_NAME;
2628
import static io.cucumber.core.options.Constants.OBJECT_FACTORY_PROPERTY_NAME;
29+
import static io.cucumber.core.options.Constants.OPTIONS_PROPERTY_NAME;
2730
import static io.cucumber.core.options.Constants.PLUGIN_PROPERTY_NAME;
2831
import static io.cucumber.core.options.Constants.PLUGIN_PUBLISH_ENABLED_PROPERTY_NAME;
2932
import static io.cucumber.core.options.Constants.PLUGIN_PUBLISH_QUIET_PROPERTY_NAME;
@@ -32,10 +35,13 @@
3235
import static io.cucumber.core.options.Constants.WIP_PROPERTY_NAME;
3336
import static io.cucumber.core.options.OptionsFileParser.parseFeatureWithLinesFile;
3437
import static java.util.Arrays.stream;
38+
import static java.util.function.Function.identity;
3539
import static java.util.stream.Collectors.toList;
3640

3741
public final class CucumberPropertiesParser {
3842

43+
private static final Logger log = LoggerFactory.getLogger(CucumberPropertiesParser.class);
44+
3945
public RuntimeOptionsBuilder parse(Map<String, String> properties) {
4046
return parse(properties::get);
4147
}
@@ -96,14 +102,19 @@ public RuntimeOptionsBuilder parse(CucumberPropertiesProvider properties) {
96102
ObjectFactoryParser::parseObjectFactory,
97103
builder::setObjectFactoryClass);
98104

105+
parse(properties,
106+
OPTIONS_PROPERTY_NAME,
107+
identity(),
108+
warnWhenCucumberOptionsIsUsed());
109+
99110
parseAll(properties,
100111
PLUGIN_PROPERTY_NAME,
101-
splitAndMap(Function.identity()),
112+
splitAndMap(identity()),
102113
builder::addPluginName);
103114

104115
parse(properties,
105116
PLUGIN_PUBLISH_TOKEN_PROPERTY_NAME,
106-
s -> s, // No validation - validated on server
117+
identity(), // No validation - validated on server
107118
builder::setPublishToken);
108119

109120
parse(properties,
@@ -129,6 +140,16 @@ public RuntimeOptionsBuilder parse(CucumberPropertiesProvider properties) {
129140
return builder;
130141
}
131142

143+
private static Consumer<String> warnWhenCucumberOptionsIsUsed() {
144+
// Quite a few old blogs still recommend the use of cucumber.options
145+
// This should take care of recurring question involving this property.
146+
return commandLineOptions -> log.warn(() -> String.format("" +
147+
"Passing commandline options via the property '%s' is no longer supported. " +
148+
"Please use individual properties instead. " +
149+
"See the java doc on %s for details.",
150+
OPTIONS_PROPERTY_NAME, Constants.class.getName()));
151+
}
152+
132153
private <T> void parse(
133154
CucumberPropertiesProvider properties, String propertyName, Function<String, T> parser, Consumer<T> setter
134155
) {

cucumber-core/src/test/java/io/cucumber/core/options/CucumberPropertiesParserTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import io.cucumber.core.backend.ObjectFactory;
44
import io.cucumber.core.exception.CucumberException;
5+
import io.cucumber.core.logging.LogRecordListener;
6+
import io.cucumber.core.logging.WithLogRecordListener;
57
import io.cucumber.core.order.StandardPickleOrders;
68
import io.cucumber.core.snippets.SnippetType;
79
import io.cucumber.tagexpressions.TagExpressionParser;
@@ -30,6 +32,7 @@
3032
import static org.junit.jupiter.api.Assertions.assertAll;
3133
import static org.junit.jupiter.api.Assertions.assertThrows;
3234

35+
@WithLogRecordListener
3336
class CucumberPropertiesParserTest {
3437

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

144+
@Test
145+
void should_warn_about_cucumber_options(LogRecordListener logRecordListener) {
146+
properties.put(Constants.OPTIONS_PROPERTY_NAME, "--help");
147+
cucumberPropertiesParser.parse(properties).build();
148+
assertThat(logRecordListener.getLogRecords().get(0).getMessage(), equalTo("" +
149+
"Passing commandline options via the property 'cucumber.options' is no longer supported. " +
150+
"Please use individual properties instead. " +
151+
"See the java doc on io.cucumber.core.options.Constants for details."));
152+
}
153+
141154
@Test
142155
void should_parse_plugin() {
143156
properties.put(Constants.PLUGIN_PROPERTY_NAME, "message:target/cucumber.ndjson, html:target/cucumber.html");

0 commit comments

Comments
 (0)