Skip to content

Commit 43a2fc7

Browse files
committed
Add list parting for features, glue and plugins
1 parent 789a521 commit 43a2fc7

File tree

3 files changed

+56
-34
lines changed

3 files changed

+56
-34
lines changed

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

+18-21
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,21 @@ public final class Constants {
7373
/**
7474
* Property name used to set feature location: {@value}
7575
* <p>
76-
* {@code path/to/dir} Load the files with the extension ".feature" for the
76+
* A comma separated list of:
77+
* <ul>
78+
* <li>{@code path/to/dir} - Load the files with the extension ".feature" for the
7779
* directory {@code path} and its sub directories.
78-
* <p>
79-
* {@code path/name.feature} Load the feature file {@code path/name.feature}
80-
* from the file system.
81-
* <p>
82-
* {@code classpath:path/name.feature} Load the feature file
83-
* {@code path/name.feature} from the classpath.
84-
* <p>
85-
* {@code path/name.feature:3:9} Load the scenarios on line 3 and line 9 in
86-
* the file {@code path/name.feature}.
87-
* <p>
88-
* {@code @path/file} Load {@code path/file} from the file system and parse
89-
* feature paths.
90-
* <p>
91-
* {@code @classpath:path/file} Load {@code path/file} from the classpath and
92-
* parse feature paths.
80+
* <li>{@code path/name.feature} - Load the feature file {@code path/name.feature}
81+
* from the file system.</li>
82+
* <li>{@code classpath:path/name.feature} - Load the feature file
83+
* {@code path/name.feature} from the classpath.</li>
84+
* <li>{@code path/name.feature:3:9} - Load the scenarios on line 3 and line 9 in
85+
* the file {@code path/name.feature}.</li>
86+
* <li>{@code @path/file} - Load {@code path/file} from the file system and parse
87+
* feature paths.</li>
88+
* <li>{@code @classpath:path/file} - Load {@code path/file} from the classpath and
89+
* parse feature paths.</li>
90+
* </ul>
9391
*
9492
* @see io.cucumber.core.feature.FeatureWithLines
9593
*/
@@ -127,7 +125,8 @@ public final class Constants {
127125
/**
128126
* Property name to set the glue path: {@value}
129127
* <p>
130-
* The glue path is a uri or package name e.g.: {@code com.example.app.steps}.
128+
* A comma separated list of a classpath uri or package name e.g.:
129+
* {@code com.example.app.steps}.
131130
*
132131
* @see io.cucumber.core.feature.GluePath
133132
*/
@@ -153,8 +152,8 @@ public final class Constants {
153152
/**
154153
* Property name to enable plugins: {@value}
155154
* <p>
156-
* Registers one or more plugins. Using the format
157-
* {@code [PLUGIN[:PATH_OR_URL]]} e.g: {@code json:target/cucumber.json}.
155+
* A comma separated list of {@code [PLUGIN[:PATH_OR_URL]]} e.g:
156+
* {@code json:target/cucumber.json}.
158157
* <p>
159158
* Built-in formatter PLUGIN types:
160159
* <ul>
@@ -171,8 +170,6 @@ public final class Constants {
171170
* <p>
172171
* {@code PLUGIN} can also be a fully qualified class name, allowing registration
173172
* of 3rd party plugins.
174-
* <p>
175-
* <p>
176173
*/
177174
public static final String PLUGIN_PROPERTY_NAME = "cucumber.plugin";
178175

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

+16-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import io.cucumber.core.feature.FeatureWithLines;
55
import io.cucumber.core.feature.GluePath;
66

7-
import java.net.URI;
87
import java.nio.file.Path;
98
import java.nio.file.Paths;
109
import java.util.Collection;
@@ -32,9 +31,19 @@
3231
import static io.cucumber.core.options.Constants.SNIPPET_TYPE_PROPERTY_NAME;
3332
import static io.cucumber.core.options.Constants.WIP_PROPERTY_NAME;
3433
import static io.cucumber.core.options.OptionsFileParser.parseFeatureWithLinesFile;
34+
import static java.util.Arrays.stream;
35+
import static java.util.stream.Collectors.toList;
3536

3637
public final class CucumberPropertiesParser {
3738

39+
private static <T> Function<String, Collection<T>> splitAndThen(Function<String, T> parse) {
40+
return combined -> stream(combined.split(","))
41+
.map(String::trim)
42+
.filter(part -> !part.isEmpty())
43+
.map(parse)
44+
.collect(toList());
45+
}
46+
3847
public RuntimeOptionsBuilder parse(Map<String, String> properties) {
3948
final RuntimeOptionsBuilder builder;
4049
String cucumberOptions = properties.get(OPTIONS_PROPERTY_NAME);
@@ -80,9 +89,9 @@ public RuntimeOptionsBuilder parse(Map<String, String> properties) {
8089
builder::setStrict
8190
);
8291

83-
parse(properties,
92+
parseAll(properties,
8493
FEATURES_PROPERTY_NAME,
85-
FeatureWithLines::parse,
94+
splitAndThen(FeatureWithLines::parse),
8695
builder::addFeature
8796
);
8897

@@ -104,9 +113,9 @@ public RuntimeOptionsBuilder parse(Map<String, String> properties) {
104113
builder::addTagFilter
105114
);
106115

107-
parse(properties,
116+
parseAll(properties,
108117
GLUE_PROPERTY_NAME,
109-
GluePath::parse,
118+
splitAndThen(GluePath::parse),
110119
builder::addGlue
111120
);
112121

@@ -116,9 +125,9 @@ public RuntimeOptionsBuilder parse(Map<String, String> properties) {
116125
builder::setObjectFactoryClass
117126
);
118127

119-
parse(properties,
128+
parseAll(properties,
120129
PLUGIN_PROPERTY_NAME,
121-
Function.identity(),
130+
splitAndThen(Function.identity()),
122131
plugin -> builder.addPluginName(plugin, true)
123132
);
124133

@@ -136,11 +145,6 @@ public RuntimeOptionsBuilder parse(Map<String, String> properties) {
136145
return builder;
137146
}
138147

139-
private Collection<URI> parseGlueFile(String property) {
140-
Path glueFile = Paths.get(property);
141-
return OptionsFileParser.parseGlueFile(glueFile);
142-
}
143-
144148
private Collection<FeatureWithLines> parseRerunFile(RuntimeOptionsBuilder builder, String property) {
145149
builder.setIsRerun(true);
146150
Path rerunFile = Paths.get(property);

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ void should_parse_features() {
8383
));
8484
}
8585

86+
@Test
87+
void should_parse_features_list() {
88+
properties.put(Constants.FEATURES_PROPERTY_NAME, "com/example/app.feature, com/example/other.feature");
89+
RuntimeOptions options = cucumberPropertiesParser.parse(properties).build();
90+
assertThat(options.getFeaturePaths(), contains(
91+
URI.create("file:com/example/app.feature"),
92+
URI.create("file:com/example/other.feature")
93+
));
94+
}
95+
8696
@Test
8797
void should_parse_filter_name() {
8898
properties.put(Constants.FILTER_NAME_PROPERTY_NAME, "Test.*");
@@ -110,6 +120,16 @@ void should_parse_glue() {
110120
));
111121
}
112122

123+
@Test
124+
void should_parse_glue_list() {
125+
properties.put(Constants.GLUE_PROPERTY_NAME, "com.example.app.steps, com.example.other.steps");
126+
RuntimeOptions options = cucumberPropertiesParser.parse(properties).build();
127+
assertThat(options.getGlue(), contains(
128+
URI.create("classpath:com/example/app/steps"),
129+
URI.create("classpath:com/example/other/steps")
130+
));
131+
}
132+
113133
@Test
114134
void should_parse_object_factory() {
115135
properties.put(Constants.OBJECT_FACTORY_PROPERTY_NAME, CustomObjectFactory.class.getName());
@@ -119,9 +139,10 @@ void should_parse_object_factory() {
119139

120140
@Test
121141
void should_parse_plugin() {
122-
properties.put(Constants.PLUGIN_PROPERTY_NAME, "json:target/cucumber.json");
142+
properties.put(Constants.PLUGIN_PROPERTY_NAME, "json:target/cucumber.json, html:target/cucumber.html");
123143
RuntimeOptions options = cucumberPropertiesParser.parse(properties).build();
124144
assertThat(options.plugins().get(0).pluginString(), equalTo("json:target/cucumber.json"));
145+
assertThat(options.plugins().get(1).pluginString(), equalTo("html:target/cucumber.html"));
125146
}
126147

127148
@Test

0 commit comments

Comments
 (0)