author | herrick |
Tue, 24 Sep 2019 13:41:16 -0400 | |
branch | JDK-8200758-branch |
changeset 58301 | e0efb29609bd |
parent 58115 | 4a27283b542d |
child 58416 | f09bf58c1f17 |
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; |
58113 | 27 |
import java.util.Optional; |
28 |
import java.util.Set; |
|
58115 | 29 |
import java.util.function.Supplier; |
58113 | 30 |
import java.util.stream.Collectors; |
31 |
import java.util.stream.Stream; |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
32 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
33 |
/** |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
34 |
* jpackage package type traits. |
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 |
public enum PackageType { |
58113 | 37 |
WIN_MSI(".msi", |
38 |
Test.isWindows() ? "jdk.jpackage.internal.WinMsiBundler" : null), |
|
39 |
WIN_EXE(".exe", |
|
40 |
Test.isWindows() ? "jdk.jpackage.internal.WinMsiBundler" : null), |
|
41 |
LINUX_DEB(".deb", |
|
42 |
Test.isLinux() ? "jdk.jpackage.internal.LinuxDebBundler" : null), |
|
43 |
LINUX_RPM(".rpm", |
|
44 |
Test.isLinux() ? "jdk.jpackage.internal.LinuxRpmBundler" : null), |
|
45 |
MAC_DMG(".dmg", Test.isOSX() ? "jdk.jpackage.internal.MacDmgBundler" : null), |
|
46 |
MAC_PKG(".pkg", Test.isOSX() ? "jdk.jpackage.internal.MacPkgBundler" : null), |
|
58115 | 47 |
IMAGE("app-image", null, null); |
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
58113
diff
changeset
|
48 |
|
58115 | 49 |
PackageType(String packageName, String bundleSuffix, String bundlerClass) { |
50 |
name = packageName; |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
51 |
suffix = bundleSuffix; |
58113 | 52 |
if (bundlerClass != null && !Inner.DISABLED_PACKAGERS.contains(getName())) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
53 |
supported = isBundlerSupported(bundlerClass); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
54 |
} else { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
55 |
supported = false; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
56 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
57 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
58 |
if (suffix != null && supported) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
59 |
Test.trace(String.format("Bundler %s supported", getName())); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
60 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
61 |
} |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
62 |
|
58115 | 63 |
PackageType(String bundleSuffix, String bundlerClass) { |
64 |
this(bundleSuffix.substring(1), bundleSuffix, bundlerClass); |
|
65 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
66 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
67 |
void applyTo(JPackageCommand cmd) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
68 |
cmd.addArguments("--package-type", getName()); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
69 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
70 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
71 |
String getSuffix() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
72 |
return suffix; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
73 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
74 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
75 |
boolean isSupported() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
76 |
return supported; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
77 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
78 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
79 |
String getName() { |
58115 | 80 |
return name; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
81 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
82 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
83 |
static PackageType fromSuffix(String packageFilename) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
84 |
if (packageFilename != null) { |
58113 | 85 |
for (PackageType v : values()) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
86 |
if (packageFilename.endsWith(v.getSuffix())) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
87 |
return v; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
88 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
89 |
} |
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 |
return null; |
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 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
94 |
private static boolean isBundlerSupported(String bundlerClass) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
95 |
try { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
96 |
Class clazz = Class.forName(bundlerClass); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
97 |
Method supported = clazz.getMethod("supported", boolean.class); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
98 |
return ((Boolean) supported.invoke(clazz.newInstance(), true)); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
99 |
} catch (ClassNotFoundException ex) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
100 |
return false; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
101 |
} catch (InstantiationException | NoSuchMethodException |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
102 |
| IllegalAccessException | InvocationTargetException ex) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
103 |
throw new RuntimeException(ex); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
104 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
105 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
106 |
|
58115 | 107 |
private String name; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
108 |
private final String suffix; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
109 |
private final boolean supported; |
58113 | 110 |
|
111 |
public final static Set<PackageType> LINUX = Set.of(LINUX_DEB, LINUX_RPM); |
|
112 |
public final static Set<PackageType> WINDOWS = Set.of(WIN_EXE, WIN_MSI); |
|
113 |
public final static Set<PackageType> MAC = Set.of(MAC_PKG, MAC_DMG); |
|
114 |
public final static Set<PackageType> NATIVE = Stream.concat( |
|
115 |
Stream.concat(LINUX.stream(), WINDOWS.stream()), |
|
116 |
MAC.stream()).collect(Collectors.toUnmodifiableSet()); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
117 |
|
58115 | 118 |
public final static PackageType DEFAULT = ((Supplier<PackageType>) () -> { |
119 |
if (Test.isLinux()) { |
|
120 |
return LINUX.stream().filter(v -> v.isSupported()).findFirst().orElseThrow(); |
|
121 |
} |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
122 |
|
58115 | 123 |
if (Test.isWindows()) { |
124 |
return WIN_EXE; |
|
125 |
} |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
126 |
|
58115 | 127 |
if (Test.isOSX()) { |
128 |
return MAC_DMG; |
|
129 |
} |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
130 |
|
58115 | 131 |
throw new IllegalStateException("Unknwon platform"); |
132 |
}).get(); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
133 |
|
58113 | 134 |
private final static class Inner { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
135 |
|
58113 | 136 |
private final static Set<String> DISABLED_PACKAGERS = Stream.of( |
137 |
Optional.ofNullable( |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
138 |
Test.getConfigProperty("disabledPackagers")).orElse( |
58113 | 139 |
"").split(",")).collect(Collectors.toUnmodifiableSet()); |
140 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
141 |
} |