Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/jpackage/macosx/MacFileAssociationsTest.java
41149 views
1
/*
2
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.nio.file.Path;
25
import java.util.List;
26
import java.util.Map;
27
import static java.util.Map.entry;
28
import jdk.jpackage.test.JPackageCommand;
29
import jdk.jpackage.test.TKit;
30
import jdk.jpackage.test.MacHelper;
31
import jdk.jpackage.test.MacHelper.PListWrapper;
32
import jdk.jpackage.test.Annotations.Test;
33
34
/**
35
* Tests generation of app image with --file-associations and mac additional file
36
* association arguments. Test will verify that arguments correctly propagated to
37
* Info.plist.
38
*/
39
40
/*
41
* @test
42
* @summary jpackage with --file-associations and mac specific file association args
43
* @library ../helpers
44
* @build jdk.jpackage.test.*
45
* @build MacFileAssociationsTest
46
* @modules jdk.jpackage/jdk.jpackage.internal
47
* @requires (os.family == "mac")
48
* @run main/othervm -Xmx512m jdk.jpackage.test.Main
49
* --jpt-run=MacFileAssociationsTest
50
*/
51
public class MacFileAssociationsTest {
52
53
@Test
54
public static void test() throws Exception {
55
final Path propFile = TKit.workDir().resolve("fa.properties");
56
Map<String, String> map = Map.ofEntries(
57
entry("mime-type", "application/x-jpackage-foo"),
58
entry("extension", "foo"),
59
entry("description", "bar"),
60
entry("mac.CFBundleTypeRole", "Viewer"),
61
entry("mac.LSHandlerRank", "Default"),
62
entry("mac.NSDocumentClass", "SomeClass"),
63
entry("mac.LSTypeIsPackage", "true"),
64
entry("mac.LSSupportsOpeningDocumentsInPlace", "false"),
65
entry("mac.UISupportsDocumentBrowser", "false"),
66
entry("mac.NSExportableTypes", "public.png, public.jpg"),
67
entry("mac.UTTypeConformsTo", "public.image, public.data"));
68
TKit.createPropertiesFile(propFile, map);
69
70
JPackageCommand cmd = JPackageCommand.helloAppImage();
71
cmd.addArguments("--file-associations", propFile);
72
cmd.executeAndAssertHelloAppImageCreated();
73
74
Path appImage = cmd.outputBundle();
75
verifyPList(appImage);
76
}
77
78
private static void checkStringValue(PListWrapper plist, String key, String value) {
79
String result = plist.queryValue(key);
80
TKit.assertEquals(value, result, String.format(
81
"Check value of %s plist key", key));
82
}
83
84
private static void checkBoolValue(PListWrapper plist, String key, Boolean value) {
85
Boolean result = plist.queryBoolValue(key);
86
TKit.assertEquals(value.toString(), result.toString(), String.format(
87
"Check value of %s plist key", key));
88
}
89
90
private static void checkArrayValue(PListWrapper plist, String key,
91
List<String> values) {
92
List<String> result = plist.queryArrayValue(key);
93
TKit.assertStringListEquals(values, result, String.format(
94
"Check value of %s plist key", key));
95
}
96
97
private static void verifyPList(Path appImage) throws Exception {
98
PListWrapper plist = MacHelper.readPListFromAppImage(appImage);
99
checkStringValue(plist, "CFBundleTypeRole", "Viewer");
100
checkStringValue(plist, "LSHandlerRank", "Default");
101
checkStringValue(plist, "NSDocumentClass", "SomeClass");
102
103
checkBoolValue(plist, "LSTypeIsPackage", true);
104
checkBoolValue(plist, "LSSupportsOpeningDocumentsInPlace", false);
105
checkBoolValue(plist, "UISupportsDocumentBrowser", false);
106
107
checkArrayValue(plist, "NSExportableTypes", List.of("public.png",
108
"public.jpg"));
109
110
checkArrayValue(plist, "UTTypeConformsTo", List.of("public.image",
111
"public.data"));
112
}
113
}
114
115