3
3
import cucumber .api .SnippetType ;
4
4
import cucumber .runtime .formatter .PluginFactory ;
5
5
import cucumber .runtime .io .MultiLoader ;
6
- import cucumber .runtime .io .Resource ;
7
6
import cucumber .runtime .io .ResourceLoader ;
7
+ import io .cucumber .core .model .FeaturePath ;
8
8
import io .cucumber .core .model .FeatureWithLines ;
9
9
import cucumber .util .FixJava ;
10
10
import cucumber .util .Mapper ;
11
11
import gherkin .GherkinDialect ;
12
12
import gherkin .GherkinDialectProvider ;
13
13
import gherkin .IGherkinDialectProvider ;
14
+ import io .cucumber .core .model .RerunLoader ;
14
15
import io .cucumber .core .options .FeatureOptions ;
15
16
import io .cucumber .core .options .FilterOptions ;
16
17
import io .cucumber .core .options .PluginOptions ;
17
18
import io .cucumber .core .options .RunnerOptions ;
18
19
import io .cucumber .datatable .DataTable ;
19
20
20
21
import java .io .File ;
21
- import java .io .IOException ;
22
22
import java .io .InputStreamReader ;
23
23
import java .io .Reader ;
24
24
import java .net .URI ;
29
29
import java .util .ResourceBundle ;
30
30
import java .util .Set ;
31
31
import java .util .TreeSet ;
32
- import java .util .regex .Matcher ;
33
32
import java .util .regex .Pattern ;
34
33
35
34
import static cucumber .util .FixJava .join ;
@@ -55,16 +54,15 @@ public String map(String keyword) {
55
54
return keyword .replaceAll ("[\\ s',!]" , "" );
56
55
}
57
56
};
58
- private static final Pattern RERUN_PATH_SPECIFICATION = Pattern .compile ("(?m:^| |)(.*?\\ .feature(?:(?::\\ d+)*))" );
59
57
private final List <String > glue = new ArrayList <String >();
60
58
private final List <String > tagFilters = new ArrayList <String >();
61
59
private final List <Pattern > nameFilters = new ArrayList <Pattern >();
62
60
private final Map <URI , Set <Integer >> lineFilters = new HashMap <>();
63
61
private final List <URI > featurePaths = new ArrayList <>();
64
62
65
63
private final List <String > junitOptions = new ArrayList <String >();
66
- private final ResourceLoader resourceLoader ;
67
64
private final char fileSeparatorChar ;
65
+ private final RerunLoader rerunLoader ;
68
66
private boolean dryRun ;
69
67
private boolean strict = false ;
70
68
private boolean monochrome = false ;
@@ -109,7 +107,7 @@ public RuntimeOptions(ResourceLoader resourceLoader, Env env, List<String> argv)
109
107
110
108
RuntimeOptions (char fileSeparatorChar , ResourceLoader resourceLoader , Env env , List <String > argv ) {
111
109
this .fileSeparatorChar = fileSeparatorChar ;
112
- this .resourceLoader = resourceLoader ;
110
+ this .rerunLoader = new RerunLoader ( resourceLoader ) ;
113
111
argv = new ArrayList <>(argv ); // in case the one passed in is unmodifiable.
114
112
parse (argv );
115
113
@@ -190,10 +188,10 @@ private void parse(List<String> args) {
190
188
printUsage ();
191
189
throw new CucumberException ("Unknown option: " + arg );
192
190
} else if (arg .startsWith ("@" )) {
193
- FeatureWithLines featureWithLines = parseFeatureWithLines (arg .substring (1 ));
194
- processPathWitheLinesFromRerunFile (parsedLineFilters , parsedFeaturePaths , featureWithLines . uri () );
191
+ URI rerunFile = FeaturePath . parse (arg .substring (1 ));
192
+ processPathWitheLinesFromRerunFile (parsedLineFilters , parsedFeaturePaths , rerunFile );
195
193
} else if (!arg .isEmpty ()){
196
- FeatureWithLines featureWithLines = parseFeatureWithLines (arg );
194
+ FeatureWithLines featureWithLines = FeatureWithLines . parse (arg );
197
195
processFeatureWithLines (parsedLineFilters , parsedFeaturePaths , featureWithLines );
198
196
}
199
197
}
@@ -226,10 +224,6 @@ private void parse(List<String> args) {
226
224
parsedPluginData .updatePluginSummaryPrinterNames (pluginSummaryPrinterNames );
227
225
}
228
226
229
- private FeatureWithLines parseFeatureWithLines (String pathWithLines ) {
230
- return FeatureWithLines .parse (pathWithLines );
231
- }
232
-
233
227
private void addLineFilters (Map <URI , Set <Integer >> parsedLineFilters , URI key , Set <Integer > lines ) {
234
228
if (lines .isEmpty ()){
235
229
return ;
@@ -247,33 +241,12 @@ private void processFeatureWithLines(Map<URI, Set<Integer>> parsedLineFilters, L
247
241
}
248
242
249
243
private void processPathWitheLinesFromRerunFile (Map <URI , Set <Integer >> parsedLineFilters , List <URI > parsedFeaturePaths , URI rerunPath ) {
250
- for (FeatureWithLines featureWithLines : loadRerunFile (rerunPath )) {
244
+ for (FeatureWithLines featureWithLines : rerunLoader . load (rerunPath )) {
251
245
processFeatureWithLines (parsedLineFilters , parsedFeaturePaths , featureWithLines );
252
246
}
253
247
}
254
248
255
- private List <FeatureWithLines > loadRerunFile (URI rerunPath ) {
256
- List <FeatureWithLines > featurePaths = new ArrayList <>();
257
- Iterable <Resource > resources = resourceLoader .resources (rerunPath , null );
258
- for (Resource resource : resources ) {
259
- String source = read (resource );
260
- if (!source .isEmpty ()) {
261
- Matcher matcher = RERUN_PATH_SPECIFICATION .matcher (source );
262
- while (matcher .find ()) {
263
- featurePaths .add (parseFeatureWithLines (matcher .group (1 )));
264
- }
265
- }
266
- }
267
- return featurePaths ;
268
- }
269
249
270
- private static String read (Resource resource ) {
271
- try {
272
- return FixJava .readReader (new InputStreamReader (resource .getInputStream ()));
273
- } catch (IOException e ) {
274
- throw new CucumberException ("Failed to read resource:" + resource .getPath (), e );
275
- }
276
- }
277
250
278
251
private String parseGlue (String gluePath ) {
279
252
return convertFileSeparatorToForwardSlash (gluePath );
0 commit comments