Skip to content

Commit 7f4f543

Browse files
committed
Resolve merge conflict. Closes #744
2 parents 35438bf + e073420 commit 7f4f543

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [1.2.0-SNAPSHOT (Git master)](https://github.com/cucumber/cucumber-jvm/compare/v1.1.8...master) (Not released)
22

3+
* [Core] Improve error message for multiple formatters using STDOUT ([#744](https://github.com/cucumber/cucumber-jvm/pull/744) Björn Rasmusson)
34
* [Core] Better error messages when loading features from rerun file ([#749](https://github.com/cucumber/cucumber-jvm/pull/749) Björn Rasmusson)
45
* [Core] Handle "" properly in ListConverter. ([#756](https://github.com/cucumber/cucumber-jvm/pull/756) Clément MATHIEU)
56
* [Guice] Update links and fix formatting in Cucumber Guice docs ([#763](https://github.com/cucumber/cucumber-jvm/pull/763) Jake Collins)

core/src/main/java/cucumber/runtime/formatter/PluginFactory.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public class PluginFactory {
5454
put("rerun", RerunFormatter.class);
5555
}};
5656
private static final Pattern PLUGIN_WITH_FILE_PATTERN = Pattern.compile("([^:]+):(.*)");
57+
private String defaultOutFormatter = null;
58+
5759
private Appendable defaultOut = new PrintStream(System.out) {
5860
@Override
5961
public void close() {
@@ -85,7 +87,7 @@ private <T> T instantiate(String pluginString, Class<T> pluginClass, String path
8587
for (Class ctorArgClass : CTOR_ARGS) {
8688
Constructor<T> constructor = findConstructor(pluginClass, ctorArgClass);
8789
if (constructor != null) {
88-
Object ctorArg = convertOrNull(pathOrUrl, ctorArgClass);
90+
Object ctorArg = convertOrNull(pathOrUrl, ctorArgClass, pluginString);
8991
try {
9092
if (ctorArgClass == null) {
9193
return constructor.newInstance();
@@ -107,7 +109,7 @@ private <T> T instantiate(String pluginString, Class<T> pluginClass, String path
107109
throw new CucumberException(String.format("%s must have a constructor that is either empty or a single arg of one of: %s", pluginClass, asList(CTOR_ARGS)));
108110
}
109111

110-
private Object convertOrNull(String pathOrUrl, Class ctorArgClass) throws IOException, URISyntaxException {
112+
private Object convertOrNull(String pathOrUrl, Class ctorArgClass, String formatterString) throws IOException, URISyntaxException {
111113
if (ctorArgClass == null) {
112114
return null;
113115
}
@@ -130,7 +132,7 @@ private Object convertOrNull(String pathOrUrl, Class ctorArgClass) throws IOExce
130132
if (pathOrUrl != null) {
131133
return new UTF8OutputStreamWriter(new URLOutputStream(toURL(pathOrUrl)));
132134
} else {
133-
return defaultOutOrFailIfAlreadyUsed();
135+
return defaultOutOrFailIfAlreadyUsed(formatterString);
134136
}
135137
}
136138
return null;
@@ -165,12 +167,15 @@ private <T> Class<T> loadClass(String className) {
165167
}
166168
}
167169

168-
private Appendable defaultOutOrFailIfAlreadyUsed() {
170+
private Appendable defaultOutOrFailIfAlreadyUsed(String formatterString) {
169171
try {
170172
if (defaultOut != null) {
173+
defaultOutFormatter = formatterString;
171174
return defaultOut;
172175
} else {
173-
throw new CucumberException("Only one plugin can use STDOUT. If you use more than one plugin you must specify output path with FORMAT:PATH_OR_URL");
176+
throw new CucumberException("Only one formatter can use STDOUT, now both " +
177+
defaultOutFormatter + " and " + formatterString + " use it. " +
178+
"If you use more than one formatter you must specify output path with PLUGIN:PATH_OR_URL");
174179
}
175180
} finally {
176181
defaultOut = null;

core/src/test/java/cucumber/runtime/formatter/PluginFactoryTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ public void instantiates_single_custom_appendable_plugin_with_stdout() {
106106
fc.create("cucumber.runtime.formatter.PluginFactoryTest$WantsAppendable");
107107
fail();
108108
} catch (CucumberException expected) {
109-
assertEquals("Only one plugin can use STDOUT. If you use more than one plugin you must specify output path with FORMAT:PATH_OR_URL", expected.getMessage());
109+
assertEquals("Only one formatter can use STDOUT, now both cucumber.runtime.formatter.PluginFactoryTest$WantsAppendable " +
110+
"and cucumber.runtime.formatter.PluginFactoryTest$WantsAppendable use it. " +
111+
"If you use more than one formatter you must specify output path with PLUGIN:PATH_OR_URL", expected.getMessage());
110112
}
111113
}
112114

0 commit comments

Comments
 (0)