changeset 10733:31c7f9661f09

8186642: Assertion error if output application already exists Reviewed-by: kcr
author vdrozdov
date Thu, 07 Dec 2017 18:00:39 -0800
parents ca3b3494dccb
children f5594a98ead9
files modules/jdk.packager/src/main/java/com/oracle/tools/packager/AbstractBundler.java modules/jdk.packager/src/main/java/com/oracle/tools/packager/IOUtils.java modules/jdk.packager/src/main/java/com/oracle/tools/packager/linux/LinuxDebBundler.java modules/jdk.packager/src/main/java/com/oracle/tools/packager/linux/LinuxRpmBundler.java modules/jdk.packager/src/main/java/com/oracle/tools/packager/mac/MacAppStoreBundler.java modules/jdk.packager/src/main/java/com/oracle/tools/packager/mac/MacDmgBundler.java modules/jdk.packager/src/main/java/com/oracle/tools/packager/mac/MacPkgBundler.java modules/jdk.packager/src/main/java/com/oracle/tools/packager/windows/WinExeBundler.java modules/jdk.packager/src/main/java/com/oracle/tools/packager/windows/WinMsiBundler.java
diffstat 9 files changed, 50 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/modules/jdk.packager/src/main/java/com/oracle/tools/packager/AbstractBundler.java	Thu Dec 07 13:13:58 2017 -0800
+++ b/modules/jdk.packager/src/main/java/com/oracle/tools/packager/AbstractBundler.java	Thu Dec 07 18:00:39 2017 -0800
@@ -152,7 +152,9 @@
         if (!StandardBundlerParam.VERBOSE.fetchFrom(params)) {
             try {
                 IOUtils.deleteRecursive(StandardBundlerParam.BUILD_ROOT.fetchFrom(params));
-            } catch (FileNotFoundException ignored) {}
+            } catch (IOException e) {
+                Log.debug(e.getMessage());
+            }
         }
     }
 }
--- a/modules/jdk.packager/src/main/java/com/oracle/tools/packager/IOUtils.java	Thu Dec 07 13:13:58 2017 -0800
+++ b/modules/jdk.packager/src/main/java/com/oracle/tools/packager/IOUtils.java	Thu Dec 07 18:00:39 2017 -0800
@@ -25,28 +25,50 @@
 
 package com.oracle.tools.packager;
 
-import com.oracle.tools.packager.Log;
 import java.io.*;
 import java.net.URL;
+import java.util.Arrays;
 import java.nio.channels.FileChannel;
-import java.util.Arrays;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
 
 public class IOUtils {
 
-    public static boolean deleteRecursive(File path) throws FileNotFoundException {
-        boolean ret = true;
-        if (!path.exists()) { //nothing to do
-            return true;
+    public static void deleteRecursive(File path) throws IOException {
+        if (!path.exists()) {
+            return;
         }
-        if (path.isDirectory()) {
-            File[] children = path.listFiles();
-            if (children != null) {
-                for (File f : children) {
-                    ret = ret && deleteRecursive(f);
+        Path directory = path.toPath();
+        Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
+            @Override
+            public FileVisitResult visitFile(Path file,
+                            BasicFileAttributes attr) throws IOException {
+                if (Platform.getPlatform() == Platform.WINDOWS) {
+                    Files.setAttribute(file, "dos:readonly", false);
                 }
+                Files.delete(file);
+                return FileVisitResult.CONTINUE;
             }
-        }
-        return ret && path.delete();
+
+            @Override
+            public FileVisitResult preVisitDirectory(Path dir,
+                            BasicFileAttributes attr) throws IOException {
+                if (Platform.getPlatform() == Platform.WINDOWS) {
+                    Files.setAttribute(dir, "dos:readonly", false);
+                }
+                return FileVisitResult.CONTINUE;
+            }
+
+            @Override
+            public FileVisitResult postVisitDirectory(Path dir, IOException e)
+                            throws IOException {
+                Files.delete(dir);
+                return FileVisitResult.CONTINUE;
+            }
+        });
     }
 
     public static void copyFromURL(URL location, File file) throws IOException {
--- a/modules/jdk.packager/src/main/java/com/oracle/tools/packager/linux/LinuxDebBundler.java	Thu Dec 07 13:13:58 2017 -0800
+++ b/modules/jdk.packager/src/main/java/com/oracle/tools/packager/linux/LinuxDebBundler.java	Thu Dec 07 18:00:39 2017 -0800
@@ -376,8 +376,9 @@
                 } else if (imageDir != null) {
                     Log.info(MessageFormat.format(I18N.getString("message.debug-working-directory"), imageDir.getAbsolutePath()));
                 }
-            } catch (FileNotFoundException ex) {
+            } catch (IOException ex) {
                 //noinspection ReturnInsideFinallyBlock
+                Log.debug(ex.getMessage());
                 return null;
             }
         }
--- a/modules/jdk.packager/src/main/java/com/oracle/tools/packager/linux/LinuxRpmBundler.java	Thu Dec 07 13:13:58 2017 -0800
+++ b/modules/jdk.packager/src/main/java/com/oracle/tools/packager/linux/LinuxRpmBundler.java	Thu Dec 07 18:00:39 2017 -0800
@@ -292,8 +292,9 @@
                 } else if (imageDir != null) {
                     Log.info(MessageFormat.format(I18N.getString("message.debug-working-directory"), imageDir.getAbsolutePath()));
                 }
-            } catch (FileNotFoundException ex) {
+            } catch (IOException ex) {
                 //noinspection ReturnInsideFinallyBlock
+                Log.debug(ex.getMessage());
                 return null;
             }
         }
--- a/modules/jdk.packager/src/main/java/com/oracle/tools/packager/mac/MacAppStoreBundler.java	Thu Dec 07 13:13:58 2017 -0800
+++ b/modules/jdk.packager/src/main/java/com/oracle/tools/packager/mac/MacAppStoreBundler.java	Thu Dec 07 18:00:39 2017 -0800
@@ -204,8 +204,9 @@
                 } else {
                     Log.info(MessageFormat.format(I18N.getString("message.config-save-location"), CONFIG_ROOT.fetchFrom(p).getAbsolutePath()));
                 }
-            } catch (FileNotFoundException ex) {
+            } catch (IOException ex) {
                 //noinspection ReturnInsideFinallyBlock
+                Log.debug(ex.getMessage());
                 return null;
             }
         }
--- a/modules/jdk.packager/src/main/java/com/oracle/tools/packager/mac/MacDmgBundler.java	Thu Dec 07 13:13:58 2017 -0800
+++ b/modules/jdk.packager/src/main/java/com/oracle/tools/packager/mac/MacDmgBundler.java	Thu Dec 07 18:00:39 2017 -0800
@@ -108,7 +108,7 @@
                 } else {
                     Log.info(MessageFormat.format(I18N.getString("message.config-save-location"), CONFIG_ROOT.fetchFrom(params).getAbsolutePath()));
                 }
-            } catch (FileNotFoundException ex) {
+            } catch (IOException ex) {
                 Log.debug(ex);
                 //noinspection ReturnInsideFinallyBlock
                 return null;
--- a/modules/jdk.packager/src/main/java/com/oracle/tools/packager/mac/MacPkgBundler.java	Thu Dec 07 13:13:58 2017 -0800
+++ b/modules/jdk.packager/src/main/java/com/oracle/tools/packager/mac/MacPkgBundler.java	Thu Dec 07 18:00:39 2017 -0800
@@ -175,7 +175,7 @@
                 } else {
                     Log.info(MessageFormat.format(I18N.getString("message.config-save-location"), CONFIG_ROOT.fetchFrom(params).getAbsolutePath()));
                 }
-            } catch (FileNotFoundException ex) {
+            } catch (IOException ex) {
                 Log.debug(ex);
                 //noinspection ReturnInsideFinallyBlock
                 return null;
--- a/modules/jdk.packager/src/main/java/com/oracle/tools/packager/windows/WinExeBundler.java	Thu Dec 07 13:13:58 2017 -0800
+++ b/modules/jdk.packager/src/main/java/com/oracle/tools/packager/windows/WinExeBundler.java	Thu Dec 07 18:00:39 2017 -0800
@@ -385,8 +385,9 @@
                 } else if (imageDir != null) {
                     Log.info(MessageFormat.format(I18N.getString("message.debug-working-directory"), imageDir.getAbsolutePath()));
                 }
-            } catch (FileNotFoundException ex) {
+            } catch (IOException ex) {
                 //noinspection ReturnInsideFinallyBlock
+                Log.debug(ex.getMessage());
                 return null;
             }
         }
--- a/modules/jdk.packager/src/main/java/com/oracle/tools/packager/windows/WinMsiBundler.java	Thu Dec 07 13:13:58 2017 -0800
+++ b/modules/jdk.packager/src/main/java/com/oracle/tools/packager/windows/WinMsiBundler.java	Thu Dec 07 18:00:39 2017 -0800
@@ -525,8 +525,9 @@
                 } else {
                     cleanupConfigFiles(p);
                 }
-            } catch (FileNotFoundException ex) {
+            } catch (IOException ex) {
                 //noinspection ReturnInsideFinallyBlock
+                Log.debug(ex.getMessage());
                 return null;
             }
         }