author | herrick |
Wed, 16 Oct 2019 10:32:08 -0400 | |
branch | JDK-8200758-branch |
changeset 58648 | 3bf53ffa9ae7 |
parent 58416 | f09bf58c1f17 |
child 58993 | b5e1baa9d2c3 |
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; |
58648 | 27 |
import java.util.Collections; |
58113 | 28 |
import java.util.Optional; |
29 |
import java.util.Set; |
|
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", |
58416 | 38 |
TKit.isWindows() ? "jdk.jpackage.internal.WinMsiBundler" : null), |
58113 | 39 |
WIN_EXE(".exe", |
58416 | 40 |
TKit.isWindows() ? "jdk.jpackage.internal.WinMsiBundler" : null), |
58113 | 41 |
LINUX_DEB(".deb", |
58416 | 42 |
TKit.isLinux() ? "jdk.jpackage.internal.LinuxDebBundler" : null), |
58113 | 43 |
LINUX_RPM(".rpm", |
58416 | 44 |
TKit.isLinux() ? "jdk.jpackage.internal.LinuxRpmBundler" : null), |
45 |
MAC_DMG(".dmg", TKit.isOSX() ? "jdk.jpackage.internal.MacDmgBundler" : null), |
|
46 |
MAC_PKG(".pkg", TKit.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) { |
58416 | 59 |
TKit.trace(String.format("Bundler %s supported", getName())); |
58036
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); |
58416 | 98 |
return ((Boolean) supported.invoke( |
99 |
clazz.getConstructor().newInstance(), true)); |
|
100 |
} catch (ClassNotFoundException | IllegalAccessException ex) { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
101 |
} catch (InstantiationException | NoSuchMethodException |
58416 | 102 |
| InvocationTargetException ex) { |
103 |
Functional.rethrowUnchecked(ex); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
104 |
} |
58416 | 105 |
return false; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
106 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
107 |
|
58416 | 108 |
private final String name; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
109 |
private final String suffix; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
110 |
private final boolean supported; |
58113 | 111 |
|
112 |
public final static Set<PackageType> LINUX = Set.of(LINUX_DEB, LINUX_RPM); |
|
113 |
public final static Set<PackageType> WINDOWS = Set.of(WIN_EXE, WIN_MSI); |
|
114 |
public final static Set<PackageType> MAC = Set.of(MAC_PKG, MAC_DMG); |
|
115 |
public final static Set<PackageType> NATIVE = Stream.concat( |
|
116 |
Stream.concat(LINUX.stream(), WINDOWS.stream()), |
|
117 |
MAC.stream()).collect(Collectors.toUnmodifiableSet()); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
118 |
|
58113 | 119 |
private final static class Inner { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
120 |
|
58648 | 121 |
private final static Set<String> DISABLED_PACKAGERS = Optional.ofNullable( |
122 |
TKit.tokenizeConfigProperty("disabledPackagers")).orElse( |
|
123 |
Collections.emptySet()); |
|
58113 | 124 |
} |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
125 |
} |