Skip to content

Commit badbe44

Browse files
authored
Fix cucumber.publish.enabled=false (#2751)
Also disables the advertisement banner in light of https://mattwynne.net/new-beginning Fixes: #2747
1 parent 7b7328b commit badbe44

File tree

5 files changed

+60
-28
lines changed

5 files changed

+60
-28
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1010
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1111

1212
## [Unreleased]
13+
### Fixed
14+
- [Core] Fixed `cucumber.publish.enabled=false` ([#2747](https://github.com/cucumber/cucumber-jvm/pull/2747) M.P. Korstanje)
15+
- [JUnit Platform Engine] Fixed `cucumber.publish.enabled=false` ([#2747](https://github.com/cucumber/cucumber-jvm/pull/2747) M.P. Korstanje)
1316

1417
## [7.12.0] - 2023-04-29
1518
### Added

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.stream.Collectors;
2525

2626
import static io.cucumber.core.resource.ClasspathSupport.rootPackageUri;
27+
import static java.lang.Boolean.FALSE;
28+
import static java.lang.Boolean.TRUE;
2729
import static java.util.Collections.emptyList;
2830
import static java.util.Collections.singletonList;
2931
import static java.util.Collections.unmodifiableList;
@@ -52,7 +54,12 @@ public final class RuntimeOptions implements
5254
private Class<? extends ObjectFactory> objectFactoryClass;
5355
private Class<? extends UuidGenerator> uuidGeneratorClass;
5456
private String publishToken;
55-
private boolean publish;
57+
private Boolean publish;
58+
// Disable the banner advertising the hosted cucumber reports by default
59+
// until the uncertainty around the projects future is resolved. It would
60+
// not be proper to advertise a service that may be discontinued to new
61+
// users.
62+
// For context see: https://mattwynne.net/new-beginning
5663
private boolean publishQuiet = true;
5764
private boolean enablePublishPlugin;
5865

@@ -108,10 +115,11 @@ private List<Plugin> getPublishPlugin() {
108115
if (!enablePublishPlugin) {
109116
return emptyList();
110117
}
111-
if (publishToken != null) {
118+
// Implicitly enabled by the token if not explicitly disabled
119+
if (!FALSE.equals(publish) && publishToken != null) {
112120
return singletonList(PluginOption.forClass(PublishFormatter.class, publishToken));
113121
}
114-
if (publish) {
122+
if (TRUE.equals(publish)) {
115123
return singletonList(PluginOption.forClass(PublishFormatter.class));
116124
}
117125
if (publishQuiet) {
@@ -257,7 +265,7 @@ void setPublishToken(String token) {
257265
this.publishToken = token;
258266
}
259267

260-
void setPublish(boolean publish) {
268+
void setPublish(Boolean publish) {
261269
this.publish = publish;
262270
}
263271

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ void should_parse_plugin_publish_enabled() {
185185
assertThat(options.plugins().get(0).pluginString(), equalTo("io.cucumber.core.plugin.PublishFormatter"));
186186
}
187187

188+
@Test
189+
void should_parse_plugin_publish_disabled_and_publish_token() {
190+
properties.put(Constants.PLUGIN_PUBLISH_ENABLED_PROPERTY_NAME, "false");
191+
properties.put(Constants.PLUGIN_PUBLISH_TOKEN_PROPERTY_NAME, "some/value");
192+
RuntimeOptions options = cucumberPropertiesParser
193+
.parse(properties)
194+
.enablePublishPlugin()
195+
.build();
196+
assertThat(options.plugins(), empty());
197+
}
198+
188199
@Test
189200
void should_parse_plugin_publish_token() {
190201
properties.put(Constants.PLUGIN_PUBLISH_TOKEN_PROPERTY_NAME, "some/value");

cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/CucumberEngineOptions.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Optional;
2525
import java.util.regex.Pattern;
2626
import java.util.stream.Collectors;
27-
import java.util.stream.Stream;
2827

2928
import static io.cucumber.core.resource.ClasspathSupport.CLASSPATH_SCHEME_PREFIX;
3029
import static io.cucumber.junit.platform.engine.Constants.ANSI_COLORS_DISABLED_PROPERTY_NAME;
@@ -71,41 +70,39 @@ public List<Plugin> plugins() {
7170
}
7271

7372
private Optional<PluginOption> getPublishPlugin() {
74-
Optional<PluginOption> fromToken = getPublishTokenPlugin();
75-
Optional<PluginOption> fromEnabled = getPublishEnabledPlugin();
76-
77-
Optional<PluginOption> plugin = Stream.of(fromToken, fromEnabled)
78-
.flatMap(pluginOption -> pluginOption.map(Stream::of).orElseGet(Stream::empty))
79-
.findFirst();
80-
81-
// With higher java version use ifPresentOrElse in plugins()
82-
if (plugin.isPresent()) {
83-
return plugin;
73+
if (isPublishPluginEnabled()) {
74+
return createPublishPlugin();
8475
}
85-
return getPublishQuietPlugin();
76+
return createCucumberReportsAdvertisingPlugin();
8677
}
8778

88-
private Optional<PluginOption> getPublishQuietPlugin() {
79+
private Optional<PluginOption> createCucumberReportsAdvertisingPlugin() {
8980
Optional<PluginOption> noPublishOption = Optional.of(PluginOption.forClass(NoPublishFormatter.class));
9081
Optional<PluginOption> quiteOption = Optional.empty();
9182
return configurationParameters
9283
.getBoolean(PLUGIN_PUBLISH_QUIET_PROPERTY_NAME)
9384
.map(quite -> quite ? quiteOption : noPublishOption)
94-
.orElse(noPublishOption);
85+
// Disable the banner advertising the hosted cucumber reports
86+
// by default until the uncertainty around the projects future
87+
// is resolved. It would not be proper to advertise a service
88+
// that may be discontinued to new users.
89+
// For context see: https://mattwynne.net/new-beginning
90+
.orElse(quiteOption);
91+
9592
}
9693

97-
private Optional<PluginOption> getPublishTokenPlugin() {
98-
return configurationParameters
94+
private Optional<PluginOption> createPublishPlugin() {
95+
PluginOption publishPlugin = configurationParameters
9996
.get(PLUGIN_PUBLISH_TOKEN_PROPERTY_NAME)
100-
.map(token -> PluginOption.forClass(PublishFormatter.class, token));
97+
.map(token -> PluginOption.forClass(PublishFormatter.class, token))
98+
.orElse(PluginOption.forClass(PublishFormatter.class));
99+
return Optional.of(publishPlugin);
101100
}
102101

103-
private Optional<PluginOption> getPublishEnabledPlugin() {
104-
Optional<PluginOption> enabledOption = Optional.of(PluginOption.forClass(PublishFormatter.class));
105-
Optional<PluginOption> disabledOption = Optional.empty();
106-
return configurationParameters
107-
.getBoolean(PLUGIN_PUBLISH_ENABLED_PROPERTY_NAME)
108-
.flatMap(enabled -> enabled ? enabledOption : disabledOption);
102+
private boolean isPublishPluginEnabled() {
103+
return configurationParameters.getBoolean(PLUGIN_PUBLISH_ENABLED_PROPERTY_NAME)
104+
// Implicitly enabled by the token if not explicitly disabled
105+
.orElse(configurationParameters.get(PLUGIN_PUBLISH_TOKEN_PROPERTY_NAME).isPresent());
109106
}
110107

111108
@Override

cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/CucumberEngineOptionsTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.junit.platform.engine.ConfigurationParameters;
99

1010
import java.net.URI;
11+
import java.util.Map;
1112

1213
import static java.util.stream.Collectors.toList;
1314
import static org.hamcrest.CoreMatchers.is;
@@ -60,7 +61,7 @@ void getPluginNamesWithNothingEnabled() {
6061
assertThat(new CucumberEngineOptions(config).plugins().stream()
6162
.map(Options.Plugin::pluginString)
6263
.collect(toList()),
63-
hasItem("io.cucumber.core.plugin.NoPublishFormatter"));
64+
empty());
6465
}
6566

6667
@Test
@@ -85,6 +86,18 @@ void getPluginNamesWithPublishEnabled() {
8586
hasItem("io.cucumber.core.plugin.PublishFormatter"));
8687
}
8788

89+
@Test
90+
void getPluginNamesWithPublishDisabledAndPublishToken() {
91+
ConfigurationParameters config = new MapConfigurationParameters(Map.of(
92+
Constants.PLUGIN_PUBLISH_ENABLED_PROPERTY_NAME, "false",
93+
Constants.PLUGIN_PUBLISH_TOKEN_PROPERTY_NAME, "some/token"));
94+
95+
assertThat(new CucumberEngineOptions(config).plugins().stream()
96+
.map(Options.Plugin::pluginString)
97+
.collect(toList()),
98+
empty());
99+
}
100+
88101
@Test
89102
void isMonochrome() {
90103
MapConfigurationParameters ansiColors = new MapConfigurationParameters(

0 commit comments

Comments
 (0)