8130424: if directory specified with --dest-dir does not exist, only .class files are dumped and .js files are not
Reviewed-by: attila, lagergren, hannesw
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/DumpBytecode.java Wed Jul 05 20:40:53 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/DumpBytecode.java Fri Jul 03 18:41:58 2015 +0530
@@ -88,7 +88,7 @@
}
- // should code be dumped to disk - only valid in compile_only mode?
+ // should code be dumped to disk
if (env._dest_dir != null) {
final String fileName = className.replace('.', File.separatorChar) + ".class";
final int index = fileName.lastIndexOf(File.separatorChar);
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java Wed Jul 05 20:40:53 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java Fri Jul 03 18:41:58 2015 +0530
@@ -995,7 +995,7 @@
return initLogger(Context.getContextTrusted());
}
- private File dumpFile(final String dir) {
+ private File dumpFile(final File dirFile) {
final URL u = getURL();
final StringBuilder buf = new StringBuilder();
// make it unique by prefixing current date & time
@@ -1010,11 +1010,17 @@
buf.append(getName());
}
- return new File(dir, buf.toString());
+ return new File(dirFile, buf.toString());
}
void dump(final String dir) {
- final File file = dumpFile(dir);
+ final File dirFile = new File(dir);
+ final File file = dumpFile(dirFile);
+ if (!dirFile.exists() && !dirFile.mkdirs()) {
+ debug("Skipping source dump for " + name);
+ return;
+ }
+
try (final FileOutputStream fos = new FileOutputStream(file)) {
final PrintWriter pw = new PrintWriter(fos);
pw.print(data.toString());