From 49b17dd5c97bf967c01166542cfccf4b196cf8a9 Mon Sep 17 00:00:00 2001 From: Alexey Semenyuk Date: Fri, 17 Oct 2025 22:58:26 +0000 Subject: [PATCH] 8356575: Test order in which jpackage fills app image Reviewed-by: almatvee --- .../internal/ApplicationImageUtils.java | 4 +- .../jpackage/test/LauncherIconVerifier.java | 3 +- .../helpers/jdk/jpackage/test/TKit.java | 30 ++ .../jpackage/share/AppImageFillOrderTest.java | 359 ++++++++++++++++++ 4 files changed, 393 insertions(+), 3 deletions(-) create mode 100644 test/jdk/tools/jpackage/share/AppImageFillOrderTest.java diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/ApplicationImageUtils.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/ApplicationImageUtils.java index 7d3250ff7b9..cda5b6c79ef 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/ApplicationImageUtils.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/ApplicationImageUtils.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; +import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -148,6 +149,7 @@ final class ApplicationImageUtils { } } - FileUtils.copyRecursive(srcDir, dstDir.toAbsolutePath(), excludes, LinkOption.NOFOLLOW_LINKS); + FileUtils.copyRecursive(srcDir, dstDir.toAbsolutePath(), excludes, + LinkOption.NOFOLLOW_LINKS, StandardCopyOption.REPLACE_EXISTING); } } diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherIconVerifier.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherIconVerifier.java index 6285d9d93a0..278cd569bac 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherIconVerifier.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherIconVerifier.java @@ -24,7 +24,6 @@ package jdk.jpackage.test; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; public final class LauncherIconVerifier { @@ -77,7 +76,7 @@ public final class LauncherIconVerifier { } else { TKit.assertFileExists(iconPath); if (!verifyFileInAppImageOnly) { - TKit.assertTrue(-1 == Files.mismatch(expectedIcon, iconPath), + TKit.assertSameFileContent(expectedIcon, iconPath, String.format( "Check icon file [%s] of %s launcher is a copy of source icon file [%s]", iconPath, label, expectedIcon)); 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 b3f188bb371..ed9c727abcc 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java @@ -25,6 +25,7 @@ package jdk.jpackage.test; import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; import static java.util.stream.Collectors.toSet; +import static jdk.jpackage.internal.util.function.ThrowingBiFunction.toBiFunction; import static jdk.jpackage.internal.util.function.ThrowingSupplier.toSupplier; import java.io.Closeable; @@ -797,6 +798,35 @@ public final class TKit { } } + public static void assertMismatchFileContent(Path a, Path b) { + assertFilesMismatch(a, b, true, Optional.empty()); + } + + public static void assertMismatchFileContent(Path a, Path b, String msg) { + assertFilesMismatch(a, b, true, Optional.of(msg)); + } + + public static void assertSameFileContent(Path a, Path b) { + assertFilesMismatch(a, b, false, Optional.empty()); + } + + public static void assertSameFileContent(Path a, Path b, String msg) { + assertFilesMismatch(a, b, false, Optional.of(msg)); + } + + public static void assertFilesMismatch(Path a, Path b, boolean expectMismatch, Optional msg) { + var mismatch = toBiFunction(Files::mismatch).apply(a, b) != -1; + if (expectMismatch) { + assertTrue(mismatch, msg.orElseGet(() -> { + return String.format("Check the content of [%s] and [%s] files mismatch", a, b); + })); + } else { + assertTrue(!mismatch, msg.orElseGet(() -> { + return String.format("Check the content of [%s] and [%s] files is the same", a, b); + })); + } + } + public static void assertDirectoryNotEmpty(Path path) { assertDirectoryExists(path, Optional.of(false)); } diff --git a/test/jdk/tools/jpackage/share/AppImageFillOrderTest.java b/test/jdk/tools/jpackage/share/AppImageFillOrderTest.java new file mode 100644 index 00000000000..75c0ddfc16f --- /dev/null +++ b/test/jdk/tools/jpackage/share/AppImageFillOrderTest.java @@ -0,0 +1,359 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import static java.util.stream.Collectors.toMap; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.TreeMap; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.stream.Stream; +import jdk.jpackage.test.Annotations.Parameter; +import jdk.jpackage.test.Annotations.ParameterSupplier; +import jdk.jpackage.test.Annotations.Test; +import jdk.jpackage.test.AppImageFile; +import jdk.jpackage.test.ApplicationLayout; +import jdk.jpackage.test.JPackageCommand; +import jdk.jpackage.test.TKit; + +/* + * @test + * @summary test order in which jpackage fills app image + * @library /test/jdk/tools/jpackage/helpers + * @build jdk.jpackage.test.* + * @compile -Xlint:all -Werror AppImageFillOrderTest.java + * @run main/othervm/timeout=1440 -Xmx512m + * jdk.jpackage.test.Main + * --jpt-run=AppImageFillOrderTest + */ + +/** + * Test order in which overlapping items are added to the app image. jpackage + * defaults should go first to let user-provided content override them. + * + *

+ * Custom content comes from: + *