Skip to content
Permalink
Browse files
8246792: Mac signing tests failed (unsealed contents present in the b…
…undle root)

Reviewed-by: herrick, almatvee
  • Loading branch information
Alexey Semenyuk committed Jun 11, 2020
1 parent 03642a0 commit 95730995b6702d196de61035045e140b7179311e
Showing 8 changed files with 74 additions and 38 deletions.
@@ -310,6 +310,19 @@ private void copyRuntimeFiles(Map<String, ? super Object> params)
// generate java runtime info.plist
writeRuntimeInfoPlist(
runtimeDir.resolve("Contents/Info.plist").toFile(), params);

// copy library
Path runtimeMacOSDir = Files.createDirectories(
runtimeDir.resolve("Contents/MacOS"));

final Path jliName = Path.of("libjli.dylib");
try (Stream<Path> walk = Files.walk(runtimeRoot.resolve("lib"))) {
final Path jli = walk
.filter(file -> file.getFileName().equals(jliName))
.findFirst()
.get();
Files.copy(jli, runtimeMacOSDir.resolve(jliName));
}
}

private void sign(Map<String, ? super Object> params) throws IOException {
@@ -336,10 +336,6 @@ private File buildDMG( Map<String, ? super Object> params,
File mountedRoot = new File(imagesRoot.getAbsolutePath(),
APP_NAME.fetchFrom(params));
try {
Files.deleteIfExists(AppImageFile.getPathInAppImage(
mountedRoot.toPath().resolve(APP_NAME.fetchFrom(params)
+ ".app")));

// background image
File bgdir = new File(mountedRoot, BACKGROUND_IMAGE_FOLDER);
bgdir.mkdirs();
@@ -407,8 +407,6 @@ private File createPKG(Map<String, ? super Object> params,
root,
"--install-location",
getInstallDir(params),
"--filter",
AppImageFile.getPathInAppImage(Path.of("")).toString(),
"--analyze",
cpl.getAbsolutePath());

@@ -424,8 +422,6 @@ private File createPKG(Map<String, ? super Object> params,
root,
"--install-location",
getInstallDir(params),
"--filter",
AppImageFile.getPathInAppImage(Path.of("")).toString(),
"--component-plist",
cpl.getAbsolutePath(),
"--scripts",
@@ -95,7 +95,10 @@ void verifyCompatible() throws ConfigException {
* @param appImageDir - path to application image
*/
public static Path getPathInAppImage(Path appImageDir) {
return appImageDir.resolve(FILENAME);
return ApplicationLayout.platformAppImage()
.resolveAt(appImageDir)
.appDirectory()
.resolve(FILENAME);
}

/**
@@ -251,6 +251,7 @@ public static interface XmlConsumer {
public static void createXml(Path dstFile, XmlConsumer xmlConsumer) throws
IOException {
XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance();
Files.createDirectories(dstFile.getParent());
try (Writer w = Files.newBufferedWriter(dstFile)) {
// Wrap with pretty print proxy
XMLStreamWriter xml = (XMLStreamWriter) Proxy.newProxyInstance(
@@ -38,6 +38,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jdk.incubator.jpackage.internal.AppImageFile;
import jdk.incubator.jpackage.internal.ApplicationLayout;
import jdk.jpackage.test.Functional.ThrowingConsumer;
import jdk.jpackage.test.Functional.ThrowingFunction;
@@ -235,9 +236,7 @@ public JPackageCommand setFakeRuntime() {

Files.createDirectories(fakeRuntimeDir);

if (TKit.isWindows() || TKit.isLinux()) {
// Needed to make WindowsAppBundler happy as it copies MSVC dlls
// from `bin` directory.
if (TKit.isLinux()) {
// Need to make the code in rpm spec happy as it assumes there is
// always something in application image.
fakeRuntimeDir.resolve("bin").toFile().mkdir();
@@ -246,7 +245,7 @@ public JPackageCommand setFakeRuntime() {
if (TKit.isOSX()) {
// Make MacAppImageBuilder happy
createBulkFile.accept(fakeRuntimeDir.resolve(Path.of(
"Contents/Home/lib/jli/libjli.dylib")));
"lib/jli/libjli.dylib")));
}

// Mak sure fake runtime takes some disk space.
@@ -680,13 +679,56 @@ public Executor.Result executeAndAssertImageCreated() {

public JPackageCommand assertImageCreated() {
verifyIsOfType(PackageType.IMAGE);
assertAppLayout();
return this;
}

JPackageCommand assertAppLayout() {
if (isPackageUnpacked() || isImagePackageType()) {
final Path rootDir = isPackageUnpacked() ? pathToUnpackedPackageFile(
appInstallationDirectory()) : outputBundle();
final Path appImageFileName = AppImageFile.getPathInAppImage(
Path.of("")).getFileName();
try (Stream<Path> walk = ThrowingSupplier.toSupplier(
() -> Files.walk(rootDir)).get()) {
List<String> appImageFiles = walk
.filter(path -> path.getFileName().equals(appImageFileName))
.map(Path::toString)
.collect(Collectors.toList());
if (isImagePackageType() || TKit.isOSX()) {
List<String> expected = List.of(
AppImageFile.getPathInAppImage(rootDir).toString());
TKit.assertStringListEquals(expected, appImageFiles,
String.format(
"Check there is only one file with [%s] name in the package",
appImageFileName));
} else {
TKit.assertStringListEquals(List.of(), appImageFiles,
String.format(
"Check there are no files with [%s] name in the package",
appImageFileName));
}
}
} else if (TKit.isOSX()) {
TKit.assertFileExists(AppImageFile.getPathInAppImage(
appInstallationDirectory()));
} else {
TKit.assertPathExists(AppImageFile.getPathInAppImage(
appInstallationDirectory()), false);
}

TKit.assertDirectoryExists(appRuntimeDirectory());

if (!isRuntime()) {
TKit.assertExecutableFileExists(appLauncherPath());
TKit.assertFileExists(appLauncherCfgPath(null));
}

if (TKit.isOSX()) {
TKit.assertFileExists(appRuntimeDirectory().resolve(
"Contents/MacOS/libjli.dylib"));
}

return this;
}

@@ -785,14 +827,6 @@ public static String escapeAndJoin(List<String> args) {
}).collect(Collectors.joining(" "));
}

public static Path relativePathInRuntime(JavaTool tool) {
Path path = tool.relativePathInJavaHome();
if (TKit.isOSX()) {
path = Path.of("Contents/Home").resolve(path);
}
return path;
}

public static Stream<String> filterOutput(Stream<String> jpackageOutput) {
// Skip "WARNING: Using incubator ..." first line of output
return jpackageOutput.skip(1);
@@ -553,30 +553,14 @@ private void verifyPackageInstalled(JPackageCommand cmd) {
}
TKit.trace(String.format(formatString, cmd.getPrintableCommandLine()));

TKit.assertDirectoryExists(cmd.appRuntimeDirectory());
if (!cmd.isRuntime()) {
TKit.assertExecutableFileExists(cmd.appLauncherPath());

if (PackageType.WINDOWS.contains(cmd.packageType())
&& !cmd.isPackageUnpacked(
"Not verifying desktop integration")) {
new WindowsHelper.DesktopIntegrationVerifier(cmd);
}
}

if (cmd.isPackageUnpacked()) {
final Path appImageFile = AppImageFile.getPathInAppImage(
Path.of(""));
try (Stream<Path> walk = ThrowingSupplier.toSupplier(
() -> Files.walk(cmd.unpackedPackageDirectory())).get()) {
walk.filter(path -> path.getFileName().equals(appImageFile))
.findFirst()
.ifPresent(path -> TKit.assertPathExists(path, false));
}
} else {
TKit.assertPathExists(AppImageFile.getPathInAppImage(
cmd.appInstallationDirectory()), false);
}
cmd.assertAppLayout();

installVerifiers.forEach(v -> v.accept(cmd));
}
@@ -335,6 +335,15 @@ public void testJLinkRuntime(String javaAppDesc) throws IOException {
"--no-header-files",
"--no-man-pages");

TKit.trace("jlink output BEGIN");
try (Stream<Path> paths = Files.walk(runtimeDir)) {
paths.filter(Files::isRegularFile)
.map(runtimeDir::relativize)
.map(Path::toString)
.forEach(TKit::trace);
}
TKit.trace("jlink output END");

if (moduleName != null) {
jlink.addArguments("--add-modules", moduleName, "--module-path",
Path.of(cmd.getArgumentValue("--module-path")).resolve(

0 comments on commit 9573099

Please sign in to comment.