5
5
import cucumber .runtime .io .MultiLoader ;
6
6
import cucumber .runtime .io .Resource ;
7
7
import cucumber .runtime .io .ResourceLoader ;
8
- import cucumber .runtime .model .PathWithLines ;
9
- import cucumber .util .Encoding ;
8
+ import io .cucumber .core .model .FeatureWithLines ;
10
9
import cucumber .util .FixJava ;
11
10
import cucumber .util .Mapper ;
12
11
import gherkin .GherkinDialect ;
22
21
import java .io .IOException ;
23
22
import java .io .InputStreamReader ;
24
23
import java .io .Reader ;
24
+ import java .net .URI ;
25
25
import java .util .ArrayList ;
26
- import java .util .Collections ;
27
26
import java .util .HashMap ;
28
27
import java .util .List ;
29
28
import java .util .Map ;
30
29
import java .util .ResourceBundle ;
30
+ import java .util .Set ;
31
+ import java .util .TreeSet ;
31
32
import java .util .regex .Matcher ;
32
33
import java .util .regex .Pattern ;
33
34
@@ -58,8 +59,8 @@ public String map(String keyword) {
58
59
private final List <String > glue = new ArrayList <String >();
59
60
private final List <String > tagFilters = new ArrayList <String >();
60
61
private final List <Pattern > nameFilters = new ArrayList <Pattern >();
61
- private final Map <String , List < Long >> lineFilters = new HashMap <String , List < Long > >();
62
- private final List <String > featurePaths = new ArrayList <String >();
62
+ private final Map <URI , Set < Integer >> lineFilters = new HashMap <>();
63
+ private final List <URI > featurePaths = new ArrayList <>();
63
64
64
65
private final List <String > junitOptions = new ArrayList <String >();
65
66
private final ResourceLoader resourceLoader ;
@@ -137,8 +138,8 @@ public RuntimeOptions noSummaryPrinter() {
137
138
private void parse (List <String > args ) {
138
139
List <String > parsedTagFilters = new ArrayList <String >();
139
140
List <Pattern > parsedNameFilters = new ArrayList <Pattern >();
140
- Map <String , List < Long >> parsedLineFilters = new HashMap <String , List < Long > >();
141
- List <String > parsedFeaturePaths = new ArrayList <String >();
141
+ Map <URI , Set < Integer >> parsedLineFilters = new HashMap <>();
142
+ List <URI > parsedFeaturePaths = new ArrayList <>();
142
143
List <String > parsedGlue = new ArrayList <String >();
143
144
ParsedPluginData parsedPluginData = new ParsedPluginData ();
144
145
List <String > parsedJunitOptions = new ArrayList <String >();
@@ -188,29 +189,21 @@ private void parse(List<String> args) {
188
189
} else if (arg .startsWith ("-" )) {
189
190
printUsage ();
190
191
throw new CucumberException ("Unknown option: " + arg );
191
- } else {
192
- List <PathWithLines > paths ;
193
- if (arg .startsWith ("@" )) {
194
- paths = loadRerunFile (arg .substring (1 ));
195
- } else {
196
- paths = parsePathWithLines (arg );
197
- }
198
- for (PathWithLines pathWithLines : paths ) {
199
- parsedFeaturePaths .add (pathWithLines .path );
200
- if (!pathWithLines .lines .isEmpty ()) {
201
- String key = pathWithLines .path .replace ("classpath:" , "" );
202
- addLineFilters (parsedLineFilters , key , pathWithLines .lines );
203
- }
204
- }
192
+ } else if (arg .startsWith ("@" )) {
193
+ FeatureWithLines featureWithLines = parseFeatureWithLines (arg .substring (1 ));
194
+ processPathWitheLinesFromRerunFile (parsedLineFilters , parsedFeaturePaths , featureWithLines .uri ());
195
+ } else if (!arg .isEmpty ()){
196
+ FeatureWithLines featureWithLines = parseFeatureWithLines (arg );
197
+ processFeatureWithLines (parsedLineFilters , parsedFeaturePaths , featureWithLines );
205
198
}
206
199
}
207
- if (!parsedTagFilters .isEmpty () || !parsedNameFilters .isEmpty () || !parsedLineFilters .isEmpty () || haveLineFilters ( parsedFeaturePaths ) ) {
200
+ if (!parsedTagFilters .isEmpty () || !parsedNameFilters .isEmpty () || !parsedLineFilters .isEmpty ()) {
208
201
tagFilters .clear ();
209
202
tagFilters .addAll (parsedTagFilters );
210
203
nameFilters .clear ();
211
204
nameFilters .addAll (parsedNameFilters );
212
205
lineFilters .clear ();
213
- for (String path : parsedLineFilters .keySet ()) {
206
+ for (URI path : parsedLineFilters .keySet ()) {
214
207
lineFilters .put (path , parsedLineFilters .get (path ));
215
208
}
216
209
}
@@ -233,47 +226,50 @@ private void parse(List<String> args) {
233
226
parsedPluginData .updatePluginSummaryPrinterNames (pluginSummaryPrinterNames );
234
227
}
235
228
236
- private void addLineFilters (Map <String , List <Long >> parsedLineFilters , String key , List <Long > lines ) {
229
+ private FeatureWithLines parseFeatureWithLines (String pathWithLines ) {
230
+ return FeatureWithLines .parse (pathWithLines );
231
+ }
232
+
233
+ private void addLineFilters (Map <URI , Set <Integer >> parsedLineFilters , URI key , Set <Integer > lines ) {
234
+ if (lines .isEmpty ()){
235
+ return ;
236
+ }
237
237
if (parsedLineFilters .containsKey (key )) {
238
238
parsedLineFilters .get (key ).addAll (lines );
239
239
} else {
240
- parsedLineFilters .put (key , lines );
240
+ parsedLineFilters .put (key , new TreeSet <>( lines ) );
241
241
}
242
242
}
243
243
244
- private boolean haveLineFilters (List <String > parsedFeaturePaths ) {
245
- for (String pathName : parsedFeaturePaths ) {
246
- if (PathWithLines .hasLineFilters (pathName )) {
247
- return true ;
248
- }
244
+ private void processFeatureWithLines (Map <URI , Set <Integer >> parsedLineFilters , List <URI > parsedFeaturePaths , FeatureWithLines featureWithLines ) {
245
+ parsedFeaturePaths .add (featureWithLines .uri ());
246
+ addLineFilters (parsedLineFilters , featureWithLines .uri (), featureWithLines .lines ());
247
+ }
248
+
249
+ private void processPathWitheLinesFromRerunFile (Map <URI , Set <Integer >> parsedLineFilters , List <URI > parsedFeaturePaths , URI rerunPath ) {
250
+ for (FeatureWithLines featureWithLines : loadRerunFile (rerunPath )) {
251
+ processFeatureWithLines (parsedLineFilters , parsedFeaturePaths , featureWithLines );
249
252
}
250
- return false ;
251
253
}
252
254
253
- private List <PathWithLines > loadRerunFile (String rerunPath ) {
254
- List <PathWithLines > featurePaths = new ArrayList <>();
255
+ private List <FeatureWithLines > loadRerunFile (URI rerunPath ) {
256
+ List <FeatureWithLines > featurePaths = new ArrayList <>();
255
257
Iterable <Resource > resources = resourceLoader .resources (rerunPath , null );
256
258
for (Resource resource : resources ) {
257
259
String source = read (resource );
258
260
if (!source .isEmpty ()) {
259
261
Matcher matcher = RERUN_PATH_SPECIFICATION .matcher (source );
260
262
while (matcher .find ()) {
261
- featurePaths .addAll ( parsePathWithLines (matcher .group (1 )));
263
+ featurePaths .add ( parseFeatureWithLines (matcher .group (1 )));
262
264
}
263
265
}
264
266
}
265
267
return featurePaths ;
266
268
}
267
269
268
- private List <PathWithLines > parsePathWithLines (String pathWithLineFilter ) {
269
- String normalizedPath = convertFileSeparatorToForwardSlash (pathWithLineFilter );
270
- PathWithLines pathWithLines = new PathWithLines (normalizedPath );
271
- return Collections .singletonList (pathWithLines );
272
- }
273
-
274
270
private static String read (Resource resource ) {
275
271
try {
276
- return Encoding . readFile ( resource );
272
+ return FixJava . readReader ( new InputStreamReader ( resource . getInputStream ()) );
277
273
} catch (IOException e ) {
278
274
throw new CucumberException ("Failed to read resource:" + resource .getPath (), e );
279
275
}
@@ -380,7 +376,7 @@ public boolean isWip() {
380
376
}
381
377
382
378
@ Override
383
- public List <String > getFeaturePaths () {
379
+ public List <URI > getFeaturePaths () {
384
380
return featurePaths ;
385
381
}
386
382
@@ -395,7 +391,7 @@ public List<String> getTagFilters() {
395
391
}
396
392
397
393
@ Override
398
- public Map <String , List < Long >> getLineFilters () {
394
+ public Map <URI , Set < Integer >> getLineFilters () {
399
395
return lineFilters ;
400
396
}
401
397
0 commit comments