Skip to content

Commit

Permalink
8342576: [macos] AppContentTest still fails after JDK-8341443 for sam…
Browse files Browse the repository at this point in the history
…e reason on older macOS versions
  • Loading branch information
sashamatveev committed Oct 25, 2024
1 parent 7133d1b commit d964968
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
67 changes: 46 additions & 21 deletions test/jdk/tools/jpackage/share/AppContentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*/
Expand All @@ -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
*/
Expand Down Expand Up @@ -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<String> 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<String> paths = Arrays.asList(arg.split(","));
for (String p : paths) {
Path name = Path.of(p).getFileName();
TKit.assertPathExists(contentDir.resolve(name), true);
}
}
}
}

0 comments on commit d964968

Please sign in to comment.