From d964968c7aa19fbaa635685749fe36c4a51bc916 Mon Sep 17 00:00:00 2001 From: alexander_matveev Date: Thu, 24 Oct 2024 18:35:40 -0700 Subject: [PATCH] 8342576: [macos] AppContentTest still fails after JDK-8341443 for same reason on older macOS versions --- .../jdk/jpackage/test/JPackageCommand.java | 25 +++++-- .../tools/jpackage/share/AppContentTest.java | 67 +++++++++++++------ 2 files changed, 66 insertions(+), 26 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 fd62d6c7d8820..de593f38826f8 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -715,6 +715,12 @@ public JPackageCommand ignoreDefaultVerbose(boolean v) { return this; } + public JPackageCommand setExecuteWithoutExitCodeCheck(boolean v) { + verifyMutable(); + executeWithoutExitCodeCheck = v; + return this; + } + public boolean isWithToolProvider() { return Optional.ofNullable(withToolProvider).orElse( defaultWithToolProvider); @@ -786,10 +792,18 @@ public Executor.Result execute(int expectedExitCode) { } } - Executor.Result result = new JPackageCommand(this) - .adjustArgumentsBeforeExecution() - .createExecutor() - .execute(expectedExitCode); + Executor.Result result; + if (executeWithoutExitCodeCheck) { + result = new JPackageCommand(this) + .adjustArgumentsBeforeExecution() + .createExecutor() + .executeWithoutExitCodeCheck(); + } else { + result = new JPackageCommand(this) + .adjustArgumentsBeforeExecution() + .createExecutor() + .execute(expectedExitCode); + } if (result.exitCode == 0) { executeVerifyActions(); @@ -1108,6 +1122,7 @@ public void run() { private boolean suppressOutput; private boolean ignoreDefaultRuntime; private boolean ignoreDefaultVerbose; + private boolean executeWithoutExitCodeCheck; private boolean immutable; private final Actions prerequisiteActions; private final Actions verifyActions; diff --git a/test/jdk/tools/jpackage/share/AppContentTest.java b/test/jdk/tools/jpackage/share/AppContentTest.java index a343e20d8a748..8f24acce2da80 100644 --- a/test/jdk/tools/jpackage/share/AppContentTest.java +++ b/test/jdk/tools/jpackage/share/AppContentTest.java @@ -24,6 +24,7 @@ import java.nio.file.Path; import java.nio.file.Files; import jdk.jpackage.internal.ApplicationLayout; +import jdk.jpackage.test.JPackageCommand; import jdk.jpackage.test.PackageTest; import jdk.jpackage.test.PackageType; import jdk.jpackage.test.TKit; @@ -34,8 +35,6 @@ import java.util.Collection; import java.util.List; -import jdk.internal.util.OSVersion; - /** * Tests generation of packages with input folder containing empty folders. */ @@ -49,7 +48,6 @@ * @build jdk.jpackage.test.* * @build AppContentTest * @modules jdk.jpackage/jdk.jpackage.internal - * @modules java.base/jdk.internal.util * @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main * --jpt-run=AppContentTest */ @@ -82,37 +80,64 @@ public AppContentTest(String... testPathArgs) { @Test public void test() throws Exception { - - // On macOS signing may or may not work for modified app bundles. - // It works on macOS 15 and up, but fails on macOS below 15. + // On macOS signing may or may not work for modified app bundles, so + // generating package might fail. We still want to test if app image + // with addtional content was generated correctly, so on macOS we + // only generating app image and ignoring jpackage exit code. final int expectedJPackageExitCode; - final boolean isMacOS15 = (OSVersion.current().compareTo( - new OSVersion(15, 0, 0)) > 0); - if (testPathArgs.contains(TEST_BAD) || (TKit.isOSX() && !isMacOS15)) { + if (testPathArgs.contains(TEST_BAD)) { expectedJPackageExitCode = 1; } else { expectedJPackageExitCode = 0; } + if (TKit.isOSX()) { + testOSX(expectedJPackageExitCode); + } else { + testWindowsOrLinux(expectedJPackageExitCode); + } + } + + private void testOSX(int expectedJPackageExitCode) throws Exception { + JPackageCommand cmd = JPackageCommand.helloAppImage(); + for (String arg : testPathArgs) { + cmd.addArguments("--app-content", arg); + } + if (expectedJPackageExitCode == 0) { + // If expected code is 0, jpackage might still fail when doing + // signing. Which is expected on some macOS versions due to + // additional content. + cmd.setExecuteWithoutExitCodeCheck(true); + } + + cmd.execute(expectedJPackageExitCode); + + if (expectedJPackageExitCode == 0) { + verify(cmd); + } + } + + private void testWindowsOrLinux(int expectedJPackageExitCode) throws Exception { new PackageTest().configureHelloApp() .addInitializer(cmd -> { for (String arg : testPathArgs) { cmd.addArguments("--app-content", arg); } }) - .addInstallVerifier(cmd -> { - ApplicationLayout appLayout = cmd.appLayout(); - Path contentDir = appLayout.contentDirectory(); - for (String arg : testPathArgs) { - List paths = Arrays.asList(arg.split(",")); - for (String p : paths) { - Path name = Path.of(p).getFileName(); - TKit.assertPathExists(contentDir.resolve(name), true); - } - } - - }) + .addInstallVerifier(cmd -> { verify(cmd); }) .setExpectedExitCode(expectedJPackageExitCode) .run(); + } + + protected void verify(JPackageCommand cmd) { + ApplicationLayout appLayout = cmd.appLayout(); + Path contentDir = appLayout.contentDirectory(); + for (String arg : testPathArgs) { + List paths = Arrays.asList(arg.split(",")); + for (String p : paths) { + Path name = Path.of(p).getFileName(); + TKit.assertPathExists(contentDir.resolve(name), true); + } } + } }