Skip to content

Commit c53ddd7

Browse files
authored
Prefer URIs with authority (#3098)
There are two ways to obtain a URI of a file: * `File.toURI()` -> `file:/path/to/file.feature` * `Path.toUri()` -> `file:///path/to/file.feature` While both URIs are equal, their string representation is not. This poses some problems when comparing string based outputs. Currently, when using the Cucumber JUnit Platform Engine the latter variant is used. When using the CLI the former variant is used. The choice between the two is fairly arbitrary. But the latter seems to picked up by IDEA and turned into a clickable link. The former is not.
1 parent e189472 commit c53ddd7

File tree

7 files changed

+29
-22
lines changed

7 files changed

+29
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Changelog
1+
~~# Changelog
22

33
All notable changes to the current version this project will be documented in
44
this file. For previous versions see the [release-notes archive](release-notes).
@@ -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] Prefer URIs with authority ([#3098](https://github.com/cucumber/cucumber-jvm/pull/3098) M.P. Korstanje)
15+
1316
### Changed
1417
- [Core] Use a message based `TimeLineFormatter` ([#3095](https://github.com/cucumber/cucumber-jvm/pull/3095) M.P. Korstanje)
1518

@@ -576,4 +579,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
576579
[7.2.0]: https://github.com/cucumber/cucumber-jvm/compare/v7.1.0...v7.2.0
577580
[7.1.0]: https://github.com/cucumber/cucumber-jvm/compare/v7.0.0...v7.1.0
578581
[7.0.0]: https://github.com/cucumber/cucumber-jvm/compare/v7.0.0-RC1...v7.0.0
579-
[7.0.0-RC1]: https://github.com/cucumber/cucumber-jvm/compare/v6.11.0...v7.0.0-RC1
582+
[7.0.0-RC1]: https://github.com/cucumber/cucumber-jvm/compare/v6.11.0...v7.0.0-RC1~~

cucumber-core/src/main/java/io/cucumber/core/feature/FeaturePath.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.File;
44
import java.net.URI;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
57
import java.util.Locale;
68

79
import static io.cucumber.core.resource.ClasspathSupport.CLASSPATH_SCHEME_PREFIX;
@@ -69,8 +71,8 @@ private static String replaceNonStandardPathSeparator(String featureIdentifier)
6971
}
7072

7173
private static URI parseAssumeFileScheme(String featureIdentifier) {
72-
File featureFile = new File(featureIdentifier);
73-
return featureFile.toURI();
74+
Path featureFile = Paths.get(featureIdentifier);
75+
return featureFile.toUri();
7476
}
7577

7678
private static boolean isWindowsOS() {

cucumber-core/src/main/java/io/cucumber/core/plugin/JsonFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public final class JsonFormatter implements ConcurrentEventListener {
1717
private final MessagesToJsonWriter writer;
1818

1919
public JsonFormatter(OutputStream out) {
20-
URI cwdUri = new File("").toURI();
20+
URI cwdUri = new File("").toPath().toUri();
2121
this.writer = builder(Jackson.OBJECT_MAPPER::writeValue)
2222
.relativizeAgainst(cwdUri)
2323
.build(out);

cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public PrettyFormatter(OutputStream out) {
3232
}
3333

3434
private static MessagesToPrettyWriter.Builder createBuilder() {
35-
String cwdUri = new File("").toURI().toString();
35+
String cwdUri = new File("").toPath().toUri().toString();
3636
return MessagesToPrettyWriter.builder()
3737
.feature(INCLUDE_FEATURE_LINE, false)
3838
.feature(INCLUDE_RULE_LINE, false)

cucumber-core/src/test/java/io/cucumber/core/feature/FeaturePathTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void can_parse_root_package() {
2929
URI uri = FeaturePath.parse("classpath:/");
3030
assertAll(
3131
() -> assertThat(uri.getScheme(), is("classpath")),
32-
() -> assertThat(uri.getSchemeSpecificPart(), is("/")));
32+
() -> assertThat(uri.getPath(), is("/")));
3333
}
3434

3535
@Test
@@ -39,7 +39,7 @@ void can_parse_eclipse_plugin_default_glue() {
3939

4040
assertAll(
4141
() -> assertThat(uri.getScheme(), is("classpath")),
42-
() -> assertThat(uri.getSchemeSpecificPart(), is("/")));
42+
() -> assertThat(uri.getPath(), is("/")));
4343
}
4444

4545
@Test
@@ -48,7 +48,7 @@ void can_parse_classpath_form() {
4848

4949
assertAll(
5050
() -> assertThat(uri.getScheme(), is("classpath")),
51-
() -> assertThat(uri.getSchemeSpecificPart(), is("/path/to/file.feature")));
51+
() -> assertThat(uri.getPath(), is("/path/to/file.feature")));
5252
}
5353

5454
@Test
@@ -57,7 +57,7 @@ void can_parse_classpath_directory_form() {
5757

5858
assertAll(
5959
() -> assertThat(uri.getScheme(), is("classpath")),
60-
() -> assertThat(uri.getSchemeSpecificPart(), is("/path/to")));
60+
() -> assertThat(uri.getPath(), is("/path/to")));
6161
}
6262

6363
@Test
@@ -67,7 +67,7 @@ void can_parse_absolute_file_form() {
6767

6868
assertAll(
6969
() -> assertThat(uri.getScheme(), is("file")),
70-
() -> assertThat(uri.getSchemeSpecificPart(), is("/path/to/file.feature")));
70+
() -> assertThat(uri.getPath(), is("/path/to/file.feature")));
7171
}
7272

7373
@Test
@@ -77,7 +77,7 @@ void can_parse_absolute_directory_form() {
7777

7878
assertAll(
7979
() -> assertThat(uri.getScheme(), is("file")),
80-
() -> assertThat(uri.getSchemeSpecificPart(), is("/path/to")));
80+
() -> assertThat(uri.getPath(), is("/path/to")));
8181
}
8282

8383
@Test
@@ -86,7 +86,7 @@ void can_parse_relative_file_form() {
8686

8787
assertAll(
8888
() -> assertThat(uri.getScheme(), is("file")),
89-
() -> assertThat(uri.getSchemeSpecificPart(), endsWith("path/to/file.feature")));
89+
() -> assertThat(uri.getPath(), endsWith("path/to/file.feature")));
9090
}
9191

9292
@Test
@@ -95,7 +95,7 @@ void can_parse_absolute_path_form() {
9595
assertThat(uri.getScheme(), is(is("file")));
9696
// Use File to work out the drive letter on windows.
9797
File file = new File("/path/to/file.feature");
98-
assertThat(uri.getSchemeSpecificPart(), is(file.toURI().getSchemeSpecificPart()));
98+
assertThat(uri.getPath(), is(file.toURI().getPath()));
9999
}
100100

101101
@Test
@@ -104,7 +104,7 @@ void can_parse_relative_path_form() {
104104

105105
assertAll(
106106
() -> assertThat(uri.getScheme(), is("file")),
107-
() -> assertThat(uri.getSchemeSpecificPart(), endsWith("path/to/file.feature")));
107+
() -> assertThat(uri.getPath(), endsWith("path/to/file.feature")));
108108
}
109109

110110
@Test
@@ -114,7 +114,7 @@ void can_parse_windows_path_form() {
114114

115115
assertAll(
116116
() -> assertThat(uri.getScheme(), is("file")),
117-
() -> assertThat(uri.getSchemeSpecificPart(), endsWith("path/to/file.feature")));
117+
() -> assertThat(uri.getPath(), endsWith("path/to/file.feature")));
118118
}
119119

120120
@Test
@@ -124,7 +124,7 @@ void can_parse_windows_absolute_path_form() {
124124

125125
assertAll(
126126
() -> assertThat(uri.getScheme(), is(is("file"))),
127-
() -> assertThat(uri.getSchemeSpecificPart(), is("/C:/path/to/file.feature")));
127+
() -> assertThat(uri.getPath(), is("/C:/path/to/file.feature")));
128128
}
129129

130130
@Test
@@ -133,7 +133,7 @@ void can_parse_whitespace_in_path() {
133133

134134
assertAll(
135135
() -> assertThat(uri.getScheme(), is(is("file"))),
136-
() -> assertThat(uri.getSchemeSpecificPart(), endsWith("path/to the/file.feature")));
136+
() -> assertThat(uri.getPath(), endsWith("path/to the/file.feature")));
137137
}
138138

139139
@Test
@@ -143,7 +143,7 @@ void can_parse_windows_file_path_with_standard_file_separator() {
143143

144144
assertAll(
145145
() -> assertThat(uri.getScheme(), is("file")),
146-
() -> assertThat(uri.getSchemeSpecificPart(), is("/C:/path/to/file.feature")));
146+
() -> assertThat(uri.getPath(), is("/C:/path/to/file.feature")));
147147
}
148148

149149
}

cucumber-core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void writes_teamcity_report() {
5151
.build()
5252
.run();
5353

54-
String featureFile = new File("").toURI() + "path/test.feature";
54+
String featureFile = new File("").toPath().toUri() + "path/test.feature";
5555
assertThat(out, bytes(equalCompressingLineSeparators(("" +
5656
"##teamcity[enteredTheMatrix timestamp = '1970-01-01T12:00:00.000+0000']\n" +
5757
"##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' name = 'Cucumber']\n" +

cucumber-core/src/test/java/io/cucumber/core/runner/TestCaseStateTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ void provides_the_uri_and_scenario_line_as_unique_id() {
8282

8383
TestCaseState state = createTestCaseState(feature);
8484

85-
assertThat(state.getUri() + ":" + state.getLine(), is(new File("path/file.feature:2").toURI().toString()));
85+
assertThat(state.getUri() + ":" + state.getLine(),
86+
is(new File("path/file.feature").toPath().toUri() + ":2"));
8687
}
8788

8889
@Test
@@ -96,7 +97,8 @@ void provides_the_uri_and_example_row_line_as_unique_id_for_scenarios_from_scena
9697
" | cuke | \n");
9798
TestCaseState state = createTestCaseState(feature);
9899

99-
assertThat(state.getUri() + ":" + state.getLine(), is(new File("path/file.feature:6").toURI().toString()));
100+
assertThat(state.getUri() + ":" + state.getLine(),
101+
is(new File("path/file.feature").toPath().toUri() + ":6"));
100102
}
101103

102104
@Test

0 commit comments

Comments
 (0)