author | herrick |
Wed, 11 Sep 2019 13:26:36 -0400 | |
branch | JDK-8200758-branch |
changeset 58115 | 4a27283b542d |
parent 58114 | 42df7de58e39 |
child 58301 | e0efb29609bd |
permissions | -rw-r--r-- |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
1 |
/* |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
4 |
* |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
8 |
* |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
13 |
* accompanied this code). |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
14 |
* |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
18 |
* |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
21 |
* questions. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
22 |
*/ |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
23 |
package jdk.jpackage.test; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
24 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
25 |
import java.lang.reflect.InvocationTargetException; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
26 |
import java.lang.reflect.Method; |
58115 | 27 |
import java.util.HashMap; |
28 |
import java.util.Map; |
|
58113 | 29 |
import java.util.Optional; |
30 |
import java.util.Set; |
|
58115 | 31 |
import java.util.function.Supplier; |
58113 | 32 |
import java.util.stream.Collectors; |
33 |
import java.util.stream.Stream; |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
34 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
35 |
/** |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
36 |
* jpackage package type traits. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
37 |
*/ |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
38 |
public enum PackageType { |
58113 | 39 |
WIN_MSI(".msi", |
40 |
Test.isWindows() ? "jdk.jpackage.internal.WinMsiBundler" : null), |
|
41 |
WIN_EXE(".exe", |
|
42 |
Test.isWindows() ? "jdk.jpackage.internal.WinMsiBundler" : null), |
|
43 |
LINUX_DEB(".deb", |
|
44 |
Test.isLinux() ? "jdk.jpackage.internal.LinuxDebBundler" : null), |
|
45 |
LINUX_RPM(".rpm", |
|
46 |
Test.isLinux() ? "jdk.jpackage.internal.LinuxRpmBundler" : null), |
|
47 |
MAC_DMG(".dmg", Test.isOSX() ? "jdk.jpackage.internal.MacDmgBundler" : null), |
|
48 |
MAC_PKG(".pkg", Test.isOSX() ? "jdk.jpackage.internal.MacPkgBundler" : null), |
|
58115 | 49 |
IMAGE("app-image", null, null); |
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
58113
diff
changeset
|
50 |
|
58115 | 51 |
PackageType(String packageName, String bundleSuffix, String bundlerClass) { |
52 |
name = packageName; |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
53 |
suffix = bundleSuffix; |
58113 | 54 |
if (bundlerClass != null && !Inner.DISABLED_PACKAGERS.contains(getName())) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
55 |
supported = isBundlerSupported(bundlerClass); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
56 |
} else { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
57 |
supported = false; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
58 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
59 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
60 |
if (suffix != null && supported) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
61 |
Test.trace(String.format("Bundler %s supported", getName())); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
62 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
63 |
} |
58115 | 64 |
|
65 |
PackageType(String bundleSuffix, String bundlerClass) { |
|
66 |
this(bundleSuffix.substring(1), bundleSuffix, bundlerClass); |
|
67 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
68 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
69 |
void applyTo(JPackageCommand cmd) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
70 |
cmd.addArguments("--package-type", getName()); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
71 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
72 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
73 |
String getSuffix() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
74 |
return suffix; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
75 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
76 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
77 |
boolean isSupported() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
78 |
return supported; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
79 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
80 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
81 |
String getName() { |
58115 | 82 |
return name; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
83 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
84 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
85 |
static PackageType fromSuffix(String packageFilename) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
86 |
if (packageFilename != null) { |
58113 | 87 |
for (PackageType v : values()) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
88 |
if (packageFilename.endsWith(v.getSuffix())) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
89 |
return v; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
90 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
91 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
92 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
93 |
return null; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
94 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
95 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
96 |
private static boolean isBundlerSupported(String bundlerClass) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
97 |
try { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
98 |
Class clazz = Class.forName(bundlerClass); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
99 |
Method isSupported = clazz.getDeclaredMethod("isSupported"); |
58113 | 100 |
return ((Boolean) isSupported.invoke(clazz)); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
101 |
} catch (ClassNotFoundException ex) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
102 |
return false; |
58113 | 103 |
} catch (IllegalAccessException | InvocationTargetException ex) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
104 |
throw new RuntimeException(ex); |
58113 | 105 |
} catch (NoSuchMethodException ex) { |
106 |
// Not all bundler classes has isSupported() method. |
|
107 |
return true; |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
108 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
109 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
110 |
|
58115 | 111 |
private String name; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
112 |
private final String suffix; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
113 |
private final boolean supported; |
58113 | 114 |
|
115 |
public final static Set<PackageType> LINUX = Set.of(LINUX_DEB, LINUX_RPM); |
|
116 |
public final static Set<PackageType> WINDOWS = Set.of(WIN_EXE, WIN_MSI); |
|
117 |
public final static Set<PackageType> MAC = Set.of(MAC_PKG, MAC_DMG); |
|
118 |
public final static Set<PackageType> NATIVE = Stream.concat( |
|
119 |
Stream.concat(LINUX.stream(), WINDOWS.stream()), |
|
120 |
MAC.stream()).collect(Collectors.toUnmodifiableSet()); |
|
58115 | 121 |
|
122 |
public final static PackageType DEFAULT = ((Supplier<PackageType>) () -> { |
|
123 |
if (Test.isLinux()) { |
|
124 |
return LINUX.stream().filter(v -> v.isSupported()).findFirst().orElseThrow(); |
|
125 |
} |
|
126 |
||
127 |
if (Test.isWindows()) { |
|
128 |
return WIN_EXE; |
|
129 |
} |
|
130 |
||
131 |
if (Test.isOSX()) { |
|
132 |
return MAC_DMG; |
|
133 |
} |
|
134 |
||
135 |
throw new IllegalStateException("Unknwon platform"); |
|
136 |
}).get(); |
|
137 |
||
58113 | 138 |
private final static class Inner { |
58115 | 139 |
|
58113 | 140 |
private final static Set<String> DISABLED_PACKAGERS = Stream.of( |
141 |
Optional.ofNullable( |
|
142 |
System.getProperty("jpackage.test.disabledPackagers")).orElse( |
|
143 |
"").split(",")).collect(Collectors.toUnmodifiableSet()); |
|
144 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
145 |
} |