8172414: jshell not working in exploded JDK build
Summary: Using Class.getResourceAsStream instead of a direct reference to JRT.
Reviewed-by: rfield, sundar
--- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Tue Jan 10 10:17:47 2017 +0100
+++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Tue Jan 10 13:53:44 2017 +0100
@@ -218,7 +218,7 @@
static final String DEFAULT_STARTUP_NAME = "DEFAULT";
static final Pattern BUILTIN_FILE_PATTERN = Pattern.compile("\\w+");
- static final String BUILTIN_FILE_PATH_FORMAT = "jrt:/jdk.jshell/jdk/jshell/tool/resources/%s.jsh";
+ static final String BUILTIN_FILE_PATH_FORMAT = "/jdk/jshell/tool/resources/%s.jsh";
// match anything followed by whitespace
private static final Pattern OPTION_PRE_PATTERN =
@@ -2426,9 +2426,11 @@
String readResource(String name) throws IOException {
// Attempt to find the file as a resource
String spec = String.format(BUILTIN_FILE_PATH_FORMAT, name);
- URL url = new URL(spec);
- BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
- return reader.lines().collect(Collectors.joining("\n"));
+
+ try (InputStream in = JShellTool.class.getResourceAsStream(spec);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
+ return reader.lines().collect(Collectors.joining("\n"));
+ }
}
// retrieve the default startup string