equal
deleted
inserted
replaced
41 import java.lang.module.ModuleFinder; |
41 import java.lang.module.ModuleFinder; |
42 import java.lang.module.ModuleReference; |
42 import java.lang.module.ModuleReference; |
43 import java.nio.charset.Charset; |
43 import java.nio.charset.Charset; |
44 import java.nio.file.FileSystems; |
44 import java.nio.file.FileSystems; |
45 import java.nio.file.Files; |
45 import java.nio.file.Files; |
|
46 import java.nio.file.InvalidPathException; |
46 import java.nio.file.Path; |
47 import java.nio.file.Path; |
47 import java.nio.file.Paths; |
48 import java.nio.file.Paths; |
48 import java.text.MessageFormat; |
49 import java.text.MessageFormat; |
49 import java.util.ArrayList; |
50 import java.util.ArrayList; |
50 import java.util.Arrays; |
51 import java.util.Arrays; |
385 // check that the supplied string represent valid class/module paths |
386 // check that the supplied string represent valid class/module paths |
386 // converting any ~/ to user home |
387 // converting any ~/ to user home |
387 private Collection<String> validPaths(Collection<String> vals, String context, boolean isModulePath) { |
388 private Collection<String> validPaths(Collection<String> vals, String context, boolean isModulePath) { |
388 Stream<String> result = vals.stream() |
389 Stream<String> result = vals.stream() |
389 .map(s -> Arrays.stream(s.split(File.pathSeparator)) |
390 .map(s -> Arrays.stream(s.split(File.pathSeparator)) |
390 .map(sp -> toPathResolvingUserHome(sp)) |
391 .flatMap(sp -> toPathImpl(sp, context)) |
391 .filter(p -> checkValidPathEntry(p, context, isModulePath)) |
392 .filter(p -> checkValidPathEntry(p, context, isModulePath)) |
392 .map(p -> p.toString()) |
393 .map(p -> p.toString()) |
393 .collect(Collectors.joining(File.pathSeparator))); |
394 .collect(Collectors.joining(File.pathSeparator))); |
394 if (failed) { |
395 if (failed) { |
395 return Collections.emptyList(); |
396 return Collections.emptyList(); |
423 } |
424 } |
424 } |
425 } |
425 msg("jshell.err.arg", context, p); |
426 msg("jshell.err.arg", context, p); |
426 failed = true; |
427 failed = true; |
427 return false; |
428 return false; |
|
429 } |
|
430 |
|
431 private Stream<Path> toPathImpl(String path, String context) { |
|
432 try { |
|
433 return Stream.of(toPathResolvingUserHome(path)); |
|
434 } catch (InvalidPathException ex) { |
|
435 msg("jshell.err.file.not.found", context, path); |
|
436 failed = true; |
|
437 return Stream.empty(); |
|
438 } |
428 } |
439 } |
429 |
440 |
430 Options parse(OptionSet options) { |
441 Options parse(OptionSet options) { |
431 addOptions(OptionKind.CLASS_PATH, |
442 addOptions(OptionKind.CLASS_PATH, |
432 validPaths(options.valuesOf(argClassPath), "--class-path", false)); |
443 validPaths(options.valuesOf(argClassPath), "--class-path", false)); |