Skip to content

Commit

Permalink
8277328: jdk/jshell/CommandCompletionTest.java failures on Windows
Browse files Browse the repository at this point in the history
Reviewed-by: vromero
  • Loading branch information
lahodaj committed Dec 7, 2021
1 parent 5a036ac commit 3955b03
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public int read() throws IOException {
Pattern.compile(OPTION_PRE_PATTERN.pattern() + "(?<dd>-??)(?<flag>-([a-z][a-z\\-]*)?)");
// match an option flag and a (possibly missing or incomplete) value
private static final Pattern OPTION_VALUE_PATTERN =
Pattern.compile(OPTION_PATTERN.pattern() + "\\s+(?<val>\\S*)");
Pattern.compile(OPTION_PATTERN.pattern() + "\\s+(?<val>(\\S|\\\\ )*)");

// Tool id (tid) mapping: the three name spaces
NameSpace mainNamespace;
Expand Down Expand Up @@ -1561,13 +1561,13 @@ private static CompletionProvider skipWordThenCompletion(CompletionProvider comp
private static CompletionProvider fileCompletions(Predicate<Path> accept) {
return (code, cursor, anchor) -> {
int lastSlash = code.lastIndexOf('/');
String path = code.substring(0, lastSlash + 1);
String prefix = lastSlash != (-1) ? code.substring(lastSlash + 1) : code;
String path = code.substring(0, lastSlash + 1).replace("\\ ", " ");
String prefix = (lastSlash != (-1) ? code.substring(lastSlash + 1) : code).replace("\\ ", " ");
Path current = toPathResolvingUserHome(path);
List<Suggestion> result = new ArrayList<>();
try (Stream<Path> dir = Files.list(current)) {
dir.filter(f -> accept.test(f) && f.getFileName().toString().startsWith(prefix))
.map(f -> new ArgSuggestion(f.getFileName() + (Files.isDirectory(f) ? "/" : "")))
.map(f -> new ArgSuggestion(f.getFileName().toString().replace(" ", "\\ ") + (Files.isDirectory(f) ? "/" : "")))
.forEach(result::add);
} catch (IOException ex) {
//ignore...
Expand Down
25 changes: 21 additions & 4 deletions test/langtools/jdk/jshell/CommandCompletionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/*
* @test
* @bug 8144095 8164825 8169818 8153402 8165405 8177079 8178013 8167554 8166232
* @bug 8144095 8164825 8169818 8153402 8165405 8177079 8178013 8167554 8166232 8277328
* @summary Test Command Completion
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
Expand Down Expand Up @@ -331,24 +331,41 @@ public void testClassPath() throws IOException {
);
}

@Test
public void testClassPathWithSpace() throws IOException {
Compiler compiler = new Compiler();
Path outDir = compiler.getPath("testClassPathWithSpace");
Path dirWithSpace = Files.createDirectories(outDir.resolve("dir with space"));
Files.createDirectories(dirWithSpace.resolve("nested with space"));
String[] pathArray = new String[] {"dir\\ with\\ space/"};
String[] pathArray2 = new String[] {"nested\\ with\\ space/"};
testNoStartUp(
a -> assertCompletion(a, "/env -class-path " + outDir + "/|", false, pathArray),
a -> assertCompletion(a, "/env -class-path " + outDir + "/dir|", false, pathArray),
a -> assertCompletion(a, "/env -class-path " + outDir + "/dir\\ with|", false, pathArray),
a -> assertCompletion(a, "/env -class-path " + outDir + "/dir\\ with\\ space/|", false, pathArray2)
);
}

@Test
public void testUserHome() throws IOException {
List<String> completions;
Path home = Paths.get(System.getProperty("user.home"));
String selectedFile;
try (Stream<Path> content = Files.list(home)) {
selectedFile = content.filter(CLASSPATH_FILTER)
.filter(file -> file.getFileName().toString().contains(" "))
.findAny()
.map(file -> file.getFileName().toString())
.map(file -> file.getFileName().toString().replace(" ", "\\ "))
.orElse(null);
}
if (selectedFile == null) {
throw new SkipException("No suitable file(s) found for this test in " + home);
}
try (Stream<Path> content = Files.list(home)) {
completions = content.filter(CLASSPATH_FILTER)
.filter(file -> file.getFileName().toString().startsWith(selectedFile))
.map(file -> file.getFileName().toString() + (Files.isDirectory(file) ? "/" : ""))
.filter(file -> file.getFileName().toString().startsWith(selectedFile.replace("\\ ", " ")))
.map(file -> file.getFileName().toString().replace(" ", "\\ ") + (Files.isDirectory(file) ? "/" : ""))
.sorted()
.collect(Collectors.toList());
}
Expand Down

5 comments on commit 3955b03

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 3955b03 Dec 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken the backport was successfully created on the branch MBaesken-backport-3955b037 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 3955b037 from the openjdk/jdk repository.

The commit being backported was authored by Jan Lahoda on 7 Dec 2021 and was reviewed by Vicente Romero.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev MBaesken-backport-3955b037:MBaesken-backport-3955b037
$ git checkout MBaesken-backport-3955b037
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev MBaesken-backport-3955b037

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 3955b03 Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 3955b03 Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch GoeLin-backport-3955b037 in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 3955b037 from the openjdk/jdk repository.

The commit being backported was authored by Jan Lahoda on 7 Dec 2021 and was reviewed by Vicente Romero.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev GoeLin-backport-3955b037:GoeLin-backport-3955b037
$ git checkout GoeLin-backport-3955b037
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev GoeLin-backport-3955b037

Please sign in to comment.