From 9eaa4afc99b09f4704e4d641f95104be40b9ea66 Mon Sep 17 00:00:00 2001 From: Alexander Matveev Date: Fri, 21 May 2021 00:44:39 +0000 Subject: [PATCH] 8267056: tools/jpackage/share/RuntimePackageTest.java fails with NoSuchFileException Reviewed-by: asemenyuk, herrick --- .../jdk/jpackage/internal/MacPkgBundler.java | 24 +++++++++++-------- .../jpackage/share/RuntimePackageTest.java | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java index 88c340688e4..4a0dcd5337a 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java @@ -390,16 +390,20 @@ public class MacPkgBundler extends MacBaseInstallerBundler { Path rootDir = appLocation.getParent() == null ? Path.of(".") : appLocation.getParent(); - Path[] list = Files.list(rootDir).toArray(Path[]::new); - if (list != null) { // Should not happend - // We should only have app image and/or .DS_Store - if (list.length == 1) { - return rootDir.toString(); - } else if (list.length == 2) { - // Check case with app image and .DS_Store - if (list[0].toString().toLowerCase().endsWith(".ds_store") || - list[1].toString().toLowerCase().endsWith(".ds_store")) { - return rootDir.toString(); // Only app image and .DS_Store + // Not needed for runtime installer and it might break runtime installer + // if parent does not have any other files + if (!StandardBundlerParam.isRuntimeInstaller(params)) { + try (var fileList = Files.list(rootDir)) { + Path[] list = fileList.toArray(Path[]::new); + // We should only have app image and/or .DS_Store + if (list.length == 1) { + return rootDir.toString(); + } else if (list.length == 2) { + // Check case with app image and .DS_Store + if (list[0].toString().toLowerCase().endsWith(".ds_store") || + list[1].toString().toLowerCase().endsWith(".ds_store")) { + return rootDir.toString(); // Only app image and .DS_Store + } } } } diff --git a/test/jdk/tools/jpackage/share/RuntimePackageTest.java b/test/jdk/tools/jpackage/share/RuntimePackageTest.java index 020c78ec7ec..e3ebdd3327e 100644 --- a/test/jdk/tools/jpackage/share/RuntimePackageTest.java +++ b/test/jdk/tools/jpackage/share/RuntimePackageTest.java @@ -151,6 +151,7 @@ public class RuntimePackageTest { final Path prefsDir = Path.of(".systemPrefs"); return files.map(root::relativize) .filter(x -> !x.startsWith(prefsDir)) + .filter(x -> !x.endsWith(".DS_Store")) .collect(Collectors.toSet()); } }