author | herrick |
Mon, 30 Sep 2019 19:11:19 -0400 | |
branch | JDK-8200758-branch |
changeset 58416 | f09bf58c1f17 |
parent 58301 | e0efb29609bd |
child 58648 | 3bf53ffa9ae7 |
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; |
|
29 |
import java.util.stream.Collectors; |
|
30 |
import java.util.stream.Stream; |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
31 |
|
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 |
* jpackage package type traits. |
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 |
public enum PackageType { |
58113 | 36 |
WIN_MSI(".msi", |
58416 | 37 |
TKit.isWindows() ? "jdk.jpackage.internal.WinMsiBundler" : null), |
58113 | 38 |
WIN_EXE(".exe", |
58416 | 39 |
TKit.isWindows() ? "jdk.jpackage.internal.WinMsiBundler" : null), |
58113 | 40 |
LINUX_DEB(".deb", |
58416 | 41 |
TKit.isLinux() ? "jdk.jpackage.internal.LinuxDebBundler" : null), |
58113 | 42 |
LINUX_RPM(".rpm", |
58416 | 43 |
TKit.isLinux() ? "jdk.jpackage.internal.LinuxRpmBundler" : null), |
44 |
MAC_DMG(".dmg", TKit.isOSX() ? "jdk.jpackage.internal.MacDmgBundler" : null), |
|
45 |
MAC_PKG(".pkg", TKit.isOSX() ? "jdk.jpackage.internal.MacPkgBundler" : null), |
|
58115 | 46 |
IMAGE("app-image", null, null); |
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
58113
diff
changeset
|
47 |
|
58115 | 48 |
PackageType(String packageName, String bundleSuffix, String bundlerClass) { |
49 |
name = packageName; |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
50 |
suffix = bundleSuffix; |
58113 | 51 |
if (bundlerClass != null && !Inner.DISABLED_PACKAGERS.contains(getName())) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
52 |
supported = isBundlerSupported(bundlerClass); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
53 |
} else { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
54 |
supported = false; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
55 |
} |
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 |
if (suffix != null && supported) { |
58416 | 58 |
TKit.trace(String.format("Bundler %s supported", getName())); |
58036
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 |
} |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
61 |
|
58115 | 62 |
PackageType(String bundleSuffix, String bundlerClass) { |
63 |
this(bundleSuffix.substring(1), bundleSuffix, bundlerClass); |
|
64 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
65 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
66 |
void applyTo(JPackageCommand cmd) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
67 |
cmd.addArguments("--package-type", getName()); |
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 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
70 |
String getSuffix() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
71 |
return suffix; |
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 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
74 |
boolean isSupported() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
75 |
return supported; |
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 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
78 |
String getName() { |
58115 | 79 |
return name; |
58036
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 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
82 |
static PackageType fromSuffix(String packageFilename) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
83 |
if (packageFilename != null) { |
58113 | 84 |
for (PackageType v : values()) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
85 |
if (packageFilename.endsWith(v.getSuffix())) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
86 |
return v; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
87 |
} |
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 |
return null; |
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 |
private static boolean isBundlerSupported(String bundlerClass) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
94 |
try { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
95 |
Class clazz = Class.forName(bundlerClass); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
96 |
Method supported = clazz.getMethod("supported", boolean.class); |
58416 | 97 |
return ((Boolean) supported.invoke( |
98 |
clazz.getConstructor().newInstance(), true)); |
|
99 |
} catch (ClassNotFoundException | IllegalAccessException ex) { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
100 |
} catch (InstantiationException | NoSuchMethodException |
58416 | 101 |
| InvocationTargetException ex) { |
102 |
Functional.rethrowUnchecked(ex); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
103 |
} |
58416 | 104 |
return false; |
58036
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 |
|
58416 | 107 |
private final 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 |
|
58113 | 118 |
private final static class Inner { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
119 |
|
58113 | 120 |
private final static Set<String> DISABLED_PACKAGERS = Stream.of( |
121 |
Optional.ofNullable( |
|
58416 | 122 |
TKit.getConfigProperty("disabledPackagers")).orElse( |
58113 | 123 |
"").split(",")).collect(Collectors.toUnmodifiableSet()); |
124 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
125 |
} |