1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/*
* Copyright (c) 2020, 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
* 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 java.nio.file.Path;
import java.util.List;
import java.util.Map;
import static java.util.Map.entry;
import jdk.jpackage.test.JPackageCommand;
import jdk.jpackage.test.TKit;
import jdk.jpackage.test.MacHelper;
import jdk.jpackage.test.MacHelper.PListWrapper;
import jdk.jpackage.test.Annotations.Test;
/**
* Tests generation of app image with --file-associations and mac additional file
* association arguments. Test will verify that arguments correctly propagated to
* Info.plist.
*/
/*
* @test
* @summary jpackage with --file-associations and mac specific file association args
* @library /test/jdk/tools/jpackage/helpers
* @build jdk.jpackage.test.*
* @build MacFileAssociationsTest
* @requires (os.family == "mac")
* @run main/othervm -Xmx512m jdk.jpackage.test.Main
* --jpt-run=MacFileAssociationsTest
*/
public class MacFileAssociationsTest {
@Test
public static void test() throws Exception {
final Path propFile = TKit.workDir().resolve("fa.properties");
Map<String, String> map = Map.ofEntries(
entry("mime-type", "application/x-jpackage-foo"),
entry("extension", "foo"),
entry("description", "bar"),
entry("mac.CFBundleTypeRole", "Viewer"),
entry("mac.LSHandlerRank", "Default"),
entry("mac.NSDocumentClass", "SomeClass"),
entry("mac.LSTypeIsPackage", "true"),
entry("mac.LSSupportsOpeningDocumentsInPlace", "false"),
entry("mac.UISupportsDocumentBrowser", "false"),
entry("mac.NSExportableTypes", "public.png, public.jpg"),
entry("mac.UTTypeConformsTo", "public.image, public.data"));
TKit.createPropertiesFile(propFile, map);
JPackageCommand cmd = JPackageCommand.helloAppImage();
cmd.addArguments("--file-associations", propFile);
cmd.executeAndAssertHelloAppImageCreated();
Path appImage = cmd.outputBundle();
verifyPList(appImage);
}
private static void checkStringValue(PListWrapper plist, String key, String value) {
String result = plist.queryValue(key);
TKit.assertEquals(value, result, String.format(
"Check value of %s plist key", key));
}
private static void checkBoolValue(PListWrapper plist, String key, Boolean value) {
Boolean result = plist.queryBoolValue(key);
TKit.assertEquals(value.toString(), result.toString(), String.format(
"Check value of %s plist key", key));
}
private static void checkArrayValue(PListWrapper plist, String key,
List<String> values) {
List<String> result = plist.queryArrayValue(key);
TKit.assertStringListEquals(values, result, String.format(
"Check value of %s plist key", key));
}
private static void verifyPList(Path appImage) throws Exception {
PListWrapper plist = MacHelper.readPListFromAppImage(appImage);
checkStringValue(plist, "CFBundleTypeRole", "Viewer");
checkStringValue(plist, "LSHandlerRank", "Default");
checkStringValue(plist, "NSDocumentClass", "SomeClass");
checkBoolValue(plist, "LSTypeIsPackage", true);
checkBoolValue(plist, "LSSupportsOpeningDocumentsInPlace", false);
checkBoolValue(plist, "UISupportsDocumentBrowser", false);
checkArrayValue(plist, "NSExportableTypes", List.of("public.png",
"public.jpg"));
checkArrayValue(plist, "UTTypeConformsTo", List.of("public.image",
"public.data"));
}
}
|