From ac82a8f89c7066fb1d379b12bcfd68053cb39ba4 Mon Sep 17 00:00:00 2001 From: Alexey Semenyuk Date: Thu, 7 Nov 2024 12:32:34 +0000 Subject: [PATCH] 8343610: InOutPathTest jpackage test produces invalid app image on macOS Reviewed-by: almatvee --- .../jdk/jpackage/test/JPackageCommand.java | 5 ++-- .../helpers/jdk/jpackage/test/MacHelper.java | 24 +++++++++++++-- .../helpers/jdk/jpackage/test/TKit.java | 14 +++++++-- .../tools/jpackage/share/InOutPathTest.java | 29 +++++++++++++++---- 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java index d4219704934f8..9b25c9058d184 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java @@ -897,8 +897,9 @@ public JPackageCommand setAppLayoutAsserts(AppLayoutAssert ... asserts) { } public JPackageCommand excludeAppLayoutAsserts(AppLayoutAssert... asserts) { - return setAppLayoutAsserts(Stream.of(asserts).filter(Predicate.not( - appLayoutAsserts::contains)).toArray(AppLayoutAssert[]::new)); + var asSet = Set.of(asserts); + return setAppLayoutAsserts(appLayoutAsserts.stream().filter(Predicate.not( + asSet::contains)).toArray(AppLayoutAssert[]::new)); } JPackageCommand assertAppLayout() { diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MacHelper.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MacHelper.java index 8068e1d858f48..63afb6cf9f765 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MacHelper.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MacHelper.java @@ -259,7 +259,7 @@ static PackageHandlers createPkgPackageHandlers() { } static void verifyBundleStructure(JPackageCommand cmd) { - Path bundleRoot; + final Path bundleRoot; if (cmd.isImagePackageType()) { bundleRoot = cmd.outputBundle(); } else { @@ -268,8 +268,26 @@ static void verifyBundleStructure(JPackageCommand cmd) { } TKit.assertDirectoryContent(bundleRoot).match(Path.of("Contents")); - TKit.assertDirectoryContent(bundleRoot.resolve("Contents")).match( - cmd.isRuntime() ? RUNTIME_BUNDLE_CONTENTS : APP_BUNDLE_CONTENTS); + + final var contentsDir = bundleRoot.resolve("Contents"); + final var expectedContentsItems = cmd.isRuntime() ? RUNTIME_BUNDLE_CONTENTS : APP_BUNDLE_CONTENTS; + + var contentsVerifier = TKit.assertDirectoryContent(contentsDir); + if (!cmd.hasArgument("--app-content")) { + contentsVerifier.match(expectedContentsItems); + } else { + // Additional content added to the bundle. + // Verify there is no period (.) char in the names of additional directories if any. + contentsVerifier.contains(expectedContentsItems); + contentsVerifier = contentsVerifier.removeAll(expectedContentsItems); + contentsVerifier.match(contentsVerifier.items().stream().filter(path -> { + if (Files.isDirectory(contentsDir.resolve(path))) { + return !path.getFileName().toString().contains("."); + } else { + return true; + } + }).collect(toSet())); + } } static String getBundleName(JPackageCommand cmd) { diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java index ca1224aafd78c..e332480e35ae4 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java @@ -786,7 +786,7 @@ public void match(Set expected) { baseDir, format(comm.common), format(comm.unique1), format(comm.unique2))); } else if (!comm.unique1.isEmpty()) { error(String.format( - "assertDirectoryContentEquals%s: Expected %s. Unexpected %s", + "assertDirectoryContentEquals(%s): Expected %s. Unexpected %s", baseDir, format(comm.common), format(comm.unique1))); } else if (!comm.unique2.isEmpty()) { error(String.format( @@ -818,12 +818,20 @@ public void contains(Set expected) { } } - public DirectoryContentVerifier removeAll(Path ... paths) { + public DirectoryContentVerifier removeAll(Collection paths) { Set newContent = new HashSet<>(content); - newContent.removeAll(List.of(paths)); + newContent.removeAll(paths); return new DirectoryContentVerifier(baseDir, newContent); } + public DirectoryContentVerifier removeAll(Path ... paths) { + return removeAll(List.of(paths)); + } + + public Set items() { + return content; + } + private DirectoryContentVerifier(Path baseDir, Set contents) { this.baseDir = baseDir; this.content = contents; diff --git a/test/jdk/tools/jpackage/share/InOutPathTest.java b/test/jdk/tools/jpackage/share/InOutPathTest.java index 8ea70a0603451..f8cb983bd1657 100644 --- a/test/jdk/tools/jpackage/share/InOutPathTest.java +++ b/test/jdk/tools/jpackage/share/InOutPathTest.java @@ -72,11 +72,20 @@ public static Collection input() { data.addAll(additionalContentInput(packageTypes, "--app-content")); } - data.addAll(List.of(new Object[][]{ - {PackageType.IMAGE.toString(), wrap(cmd -> { - additionalContent(cmd, "--app-content", cmd.outputBundle()); - }, "--app-content same as output bundle")}, - })); + if (!TKit.isOSX()) { + data.addAll(List.of(new Object[][]{ + {PackageType.IMAGE.toString(), wrap(cmd -> { + additionalContent(cmd, "--app-content", cmd.outputBundle()); + }, "--app-content same as output bundle")}, + })); + } else { + var contentsFolder = "Contents/MacOS"; + data.addAll(List.of(new Object[][]{ + {PackageType.IMAGE.toString(), wrap(cmd -> { + additionalContent(cmd, "--app-content", cmd.outputBundle().resolve(contentsFolder)); + }, String.format("--app-content same as the \"%s\" folder in the output bundle", contentsFolder))}, + })); + } if (TKit.isOSX()) { data.addAll(additionalContentInput(PackageType.MAC_DMG.toString(), @@ -172,6 +181,16 @@ private static void runTest(Set packageTypes, if (isAppImageValid(cmd)) { verifyAppImage(cmd); } + + if (cmd.hasArgument("--app-content")) { + // `--app-content` can be set to the app image directory which + // should not exist before jpackage is executed: + // jpackage --name Foo --dest output --app-content output/Foo + // Verify the directory exists after jpackage execution. + // At least this will catch the case when the value of + // `--app-content` option refers to a path unrelated to jpackage I/O. + TKit.assertDirectoryExists(Path.of(cmd.getArgumentValue("--app-content"))); + } } else { new PackageTest() .forTypes(packageTypes)