8130424: if directory specified with --dest-dir does not exist, only .class files are dumped and .js files are not
authorsundar
Fri, 03 Jul 2015 18:41:58 +0530
changeset 31546 c1ae3f297a28
parent 31509 61d2d0629b6d
child 31547 cdacdb10154e
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
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/DumpBytecode.java
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java
--- 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());