author | herrick |
Tue, 24 Sep 2019 13:43:58 -0400 | |
branch | JDK-8200758-branch |
changeset 58302 | 718bd56695b3 |
parent 58301 | e0efb29609bd |
child 58304 | 7a61351edad2 |
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 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
25 |
import java.io.FileOutputStream; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
26 |
import java.io.IOException; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
27 |
import java.nio.file.Files; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
28 |
import java.nio.file.Path; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
29 |
import java.security.SecureRandom; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
30 |
import java.util.ArrayList; |
58113 | 31 |
import java.util.Arrays; |
32 |
import java.util.Collection; |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
33 |
import java.util.HashMap; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
34 |
import java.util.List; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
35 |
import java.util.ListIterator; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
36 |
import java.util.Map; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
37 |
import java.util.function.Consumer; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
38 |
import java.util.function.Function; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
39 |
import java.util.function.Supplier; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
40 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
41 |
/** |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
42 |
* jpackage command line with prerequisite actions. Prerequisite actions can be |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
43 |
* anything. The simplest is to compile test application and pack in a jar for |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
44 |
* use on jpackage command line. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
45 |
*/ |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
46 |
public final class JPackageCommand extends CommandArguments<JPackageCommand> { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
47 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
48 |
public JPackageCommand() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
49 |
actions = new ArrayList<>(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
50 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
51 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
52 |
JPackageCommand createImmutableCopy() { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
53 |
JPackageCommand reply = new JPackageCommand(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
54 |
reply.immutable = true; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
55 |
reply.args.addAll(args); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
56 |
return reply; |
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 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
59 |
public JPackageCommand setArgumentValue(String argName, String newValue) { |
58113 | 60 |
verifyMutable(); |
61 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
62 |
String prevArg = null; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
63 |
ListIterator<String> it = args.listIterator(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
64 |
while (it.hasNext()) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
65 |
String value = it.next(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
66 |
if (prevArg != null && prevArg.equals(argName)) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
67 |
if (newValue != null) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
68 |
it.set(newValue); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
69 |
} else { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
70 |
it.remove(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
71 |
it.previous(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
72 |
it.remove(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
73 |
} |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
74 |
return this; |
58036
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 |
prevArg = value; |
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 |
if (newValue != null) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
80 |
addArguments(argName, newValue); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
81 |
} |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
82 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
83 |
return this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
84 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
85 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
86 |
public JPackageCommand setArgumentValue(String argName, Path newValue) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
87 |
return setArgumentValue(argName, newValue.toString()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
88 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
89 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
90 |
public JPackageCommand removeArgument(String argName) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
91 |
return setArgumentValue(argName, (String)null); |
58036
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 |
|
58113 | 94 |
public boolean hasArgument(String argName) { |
95 |
return args.contains(argName); |
|
96 |
} |
|
97 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
98 |
public <T> T getArgumentValue(String argName, |
58113 | 99 |
Function<JPackageCommand, T> defaultValueSupplier, |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
100 |
Function<String, T> stringConverter) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
101 |
String prevArg = null; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
102 |
for (String arg : args) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
103 |
if (prevArg != null && prevArg.equals(argName)) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
104 |
return stringConverter.apply(arg); |
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 |
prevArg = arg; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
107 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
108 |
if (defaultValueSupplier != null) { |
58113 | 109 |
return defaultValueSupplier.apply(this); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
110 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
111 |
return null; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
112 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
113 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
114 |
public String getArgumentValue(String argName, |
58113 | 115 |
Function<JPackageCommand, String> defaultValueSupplier) { |
116 |
return getArgumentValue(argName, defaultValueSupplier, v -> v); |
|
117 |
} |
|
118 |
||
119 |
public <T> T getArgumentValue(String argName, |
|
120 |
Supplier<T> defaultValueSupplier, |
|
121 |
Function<String, T> stringConverter) { |
|
122 |
return getArgumentValue(argName, (unused) -> defaultValueSupplier.get(), |
|
123 |
stringConverter); |
|
124 |
} |
|
125 |
||
126 |
public String getArgumentValue(String argName, |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
127 |
Supplier<String> defaultValueSupplier) { |
58113 | 128 |
return getArgumentValue(argName, defaultValueSupplier, v -> v); |
129 |
} |
|
130 |
||
131 |
public String getArgumentValue(String argName) { |
|
132 |
return getArgumentValue(argName, (Supplier<String>)null); |
|
133 |
} |
|
134 |
||
135 |
public String[] getAllArgumentValues(String argName) { |
|
136 |
List<String> values = new ArrayList<>(); |
|
137 |
String prevArg = null; |
|
138 |
for (String arg : args) { |
|
139 |
if (prevArg != null && prevArg.equals(argName)) { |
|
140 |
values.add(arg); |
|
141 |
} |
|
142 |
prevArg = arg; |
|
143 |
} |
|
144 |
return values.toArray(String[]::new); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
145 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
146 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
147 |
public JPackageCommand addArguments(String name, Path value) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
148 |
return addArguments(name, value.toString()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
149 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
150 |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
151 |
public PackageType packageType() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
152 |
return getArgumentValue("--package-type", |
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
58113
diff
changeset
|
153 |
() -> PackageType.DEFAULT, |
58115 | 154 |
(v) -> PACKAGE_TYPES.get(v)); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
155 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
156 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
157 |
public Path outputDir() { |
58147
45a9084fe981
8230521: rename --output/-o option and add default value (".")
herrick
parents:
58115
diff
changeset
|
158 |
return getArgumentValue("--dest", () -> Test.defaultOutputDir(), Path::of); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
159 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
160 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
161 |
public Path inputDir() { |
58113 | 162 |
return getArgumentValue("--input", () -> Test.defaultInputDir(),Path::of); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
163 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
164 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
165 |
public String version() { |
58113 | 166 |
return getArgumentValue("--app-version", () -> "1.0"); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
167 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
168 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
169 |
public String name() { |
58113 | 170 |
return getArgumentValue("--name", () -> getArgumentValue("--main-class")); |
171 |
} |
|
172 |
||
173 |
public boolean isRuntime() { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
174 |
return hasArgument("--runtime-image") |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
175 |
&& !hasArgument("--main-jar") |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
176 |
&& !hasArgument("--module") |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
177 |
&& !hasArgument("--app-image"); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
178 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
179 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
180 |
public JPackageCommand setDefaultInputOutput() { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
181 |
addArguments("--input", Test.defaultInputDir()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
182 |
addArguments("--dest", Test.defaultOutputDir()); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
183 |
return this; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
184 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
185 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
186 |
public JPackageCommand setFakeRuntime() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
187 |
verifyMutable(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
188 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
189 |
try { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
190 |
Path fakeRuntimeDir = Test.workDir().resolve("fake_runtime"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
191 |
Files.createDirectories(fakeRuntimeDir); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
192 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
193 |
if (Test.isWindows() || Test.isLinux()) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
194 |
// Needed to make WindowsAppBundler happy as it copies MSVC dlls |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
195 |
// from `bin` directory. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
196 |
// Need to make the code in rpm spec happy as it assumes there is |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
197 |
// always something in application image. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
198 |
fakeRuntimeDir.resolve("bin").toFile().mkdir(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
199 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
200 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
201 |
Path bulk = fakeRuntimeDir.resolve(Path.of("bin", "bulk")); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
202 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
203 |
// Mak sure fake runtime takes some disk space. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
204 |
// Package bundles with 0KB size are unexpected and considered |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
205 |
// an error by PackageTest. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
206 |
Files.createDirectories(bulk.getParent()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
207 |
try (FileOutputStream out = new FileOutputStream(bulk.toFile())) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
208 |
byte[] bytes = new byte[4 * 1024]; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
209 |
new SecureRandom().nextBytes(bytes); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
210 |
out.write(bytes); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
211 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
212 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
213 |
addArguments("--runtime-image", fakeRuntimeDir); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
214 |
} catch (IOException ex) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
215 |
throw new RuntimeException(ex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
216 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
217 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
218 |
return this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
219 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
220 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
221 |
JPackageCommand addAction(Consumer<JPackageCommand> action) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
222 |
verifyMutable(); |
58113 | 223 |
actions.add(action); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
224 |
return this; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
225 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
226 |
|
58113 | 227 |
public static JPackageCommand helloAppImage() { |
228 |
JPackageCommand cmd = new JPackageCommand(); |
|
229 |
cmd.setDefaultInputOutput().setDefaultAppName(); |
|
58115 | 230 |
PackageType.IMAGE.applyTo(cmd); |
58113 | 231 |
HelloApp.addTo(cmd); |
232 |
return cmd; |
|
233 |
} |
|
234 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
235 |
public JPackageCommand setPackageType(PackageType type) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
236 |
verifyMutable(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
237 |
type.applyTo(this); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
238 |
return this; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
239 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
240 |
|
58113 | 241 |
JPackageCommand setDefaultAppName() { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
242 |
addArguments("--name", Test.enclosingMainMethodClass().getSimpleName()); |
58113 | 243 |
return this; |
244 |
} |
|
245 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
246 |
public Path outputBundle() { |
58113 | 247 |
final PackageType type = packageType(); |
248 |
if (PackageType.IMAGE == type) { |
|
249 |
return null; |
|
250 |
} |
|
251 |
||
252 |
String bundleName = null; |
|
253 |
if (PackageType.LINUX.contains(type)) { |
|
254 |
bundleName = LinuxHelper.getBundleName(this); |
|
255 |
} else if (PackageType.WINDOWS.contains(type)) { |
|
256 |
bundleName = WindowsHelper.getBundleName(this); |
|
257 |
} else if (PackageType.MAC.contains(type)) { |
|
258 |
bundleName = MacHelper.getBundleName(this); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
259 |
} |
58113 | 260 |
|
261 |
return outputDir().resolve(bundleName); |
|
262 |
} |
|
263 |
||
264 |
/** |
|
265 |
* Returns path to directory where application will be installed. |
|
266 |
* |
|
267 |
* E.g. on Linux for app named Foo default the function will return |
|
268 |
* `/opt/foo` |
|
269 |
*/ |
|
270 |
public Path appInstallationDirectory() { |
|
271 |
final PackageType type = packageType(); |
|
272 |
if (PackageType.IMAGE == type) { |
|
273 |
return null; |
|
274 |
} |
|
275 |
||
276 |
if (PackageType.LINUX.contains(type)) { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
277 |
if (isRuntime()) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
278 |
// Not fancy, but OK. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
279 |
return Path.of(getArgumentValue("--install-dir", () -> "/opt"), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
280 |
LinuxHelper.getPackageName(this)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
281 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
282 |
|
58113 | 283 |
// Launcher is in "bin" subfolder of the installation directory. |
284 |
return launcherInstallationPath().getParent().getParent(); |
|
285 |
} |
|
286 |
||
287 |
if (PackageType.WINDOWS.contains(type)) { |
|
288 |
return WindowsHelper.getInstallationDirectory(this); |
|
289 |
} |
|
290 |
||
291 |
if (PackageType.MAC.contains(type)) { |
|
292 |
return MacHelper.getInstallationDirectory(this); |
|
293 |
} |
|
294 |
||
295 |
throw new IllegalArgumentException("Unexpected package type"); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
296 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
297 |
|
58113 | 298 |
/** |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
299 |
* Returns path where application's Java runtime will be installed. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
300 |
* If the command will package Java run-time only, still returns path to |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
301 |
* runtime subdirectory. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
302 |
* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
303 |
* E.g. on Linux for app named `Foo` the function will return |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
304 |
* `/opt/foo/runtime` |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
305 |
*/ |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
306 |
public Path appRuntimeInstallationDirectory() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
307 |
if (PackageType.IMAGE == packageType()) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
308 |
return null; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
309 |
} |
58302 | 310 |
return appInstallationDirectory().resolve(appRuntimePath(packageType())); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
311 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
312 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
313 |
/** |
58113 | 314 |
* Returns path where application launcher will be installed. |
315 |
* If the command will package Java run-time only, still returns path to |
|
316 |
* application launcher. |
|
317 |
* |
|
318 |
* E.g. on Linux for app named Foo default the function will return |
|
319 |
* `/opt/foo/bin/Foo` |
|
320 |
*/ |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
321 |
public Path launcherInstallationPath() { |
58113 | 322 |
final PackageType type = packageType(); |
323 |
if (PackageType.IMAGE == type) { |
|
324 |
return null; |
|
325 |
} |
|
326 |
||
327 |
if (PackageType.LINUX.contains(type)) { |
|
328 |
return outputDir().resolve(LinuxHelper.getLauncherPath(this)); |
|
329 |
} |
|
330 |
||
331 |
if (PackageType.WINDOWS.contains(type)) { |
|
332 |
return appInstallationDirectory().resolve(name() + ".exe"); |
|
333 |
} |
|
334 |
||
335 |
if (PackageType.MAC.contains(type)) { |
|
336 |
return appInstallationDirectory().resolve(Path.of("Contents", "MacOS", name())); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
337 |
} |
58113 | 338 |
|
339 |
throw new IllegalArgumentException("Unexpected package type"); |
|
340 |
} |
|
341 |
||
342 |
/** |
|
343 |
* Returns path to application image directory. |
|
344 |
* |
|
58147
45a9084fe981
8230521: rename --output/-o option and add default value (".")
herrick
parents:
58115
diff
changeset
|
345 |
* E.g. if --dest is set to `foo` and --name is set to `bar` the function |
58113 | 346 |
* will return `foo/bar` path. |
347 |
* |
|
348 |
* @throws IllegalArgumentException is command is doing platform packaging |
|
349 |
*/ |
|
350 |
public Path appImage() { |
|
351 |
final PackageType type = packageType(); |
|
352 |
if (PackageType.IMAGE != type) { |
|
353 |
throw new IllegalArgumentException("Unexpected package type"); |
|
354 |
} |
|
355 |
||
356 |
return outputDir().resolve(name()); |
|
357 |
} |
|
358 |
||
359 |
/** |
|
360 |
* Returns path to application launcher relative to image directory. |
|
361 |
* |
|
362 |
* E.g. if --name is set to `Foo` the function will return `bin/Foo` path on |
|
363 |
* Linux, and `Foo.exe` on Windows. |
|
364 |
* |
|
365 |
* @throws IllegalArgumentException is command is doing platform packaging |
|
366 |
*/ |
|
367 |
public Path launcherPathInAppImage() { |
|
368 |
final PackageType type = packageType(); |
|
369 |
if (PackageType.IMAGE != type) { |
|
370 |
throw new IllegalArgumentException("Unexpected package type"); |
|
371 |
} |
|
372 |
||
373 |
if (Test.isLinux()) { |
|
374 |
return Path.of("bin", name()); |
|
375 |
} |
|
376 |
||
377 |
if (Test.isOSX()) { |
|
378 |
return Path.of("Contents", "MacOS", name()); |
|
379 |
} |
|
380 |
||
381 |
if (Test.isWindows()) { |
|
382 |
return Path.of(name() + ".exe"); |
|
383 |
} |
|
384 |
||
385 |
throw new IllegalArgumentException("Unexpected package type"); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
386 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
387 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
388 |
/** |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
389 |
* Returns path to runtime directory relative to image directory. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
390 |
* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
391 |
* @throws IllegalArgumentException if command is configured for platform |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
392 |
* packaging |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
393 |
*/ |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
394 |
public Path appRuntimeDirectoryInAppImage() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
395 |
final PackageType type = packageType(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
396 |
if (PackageType.IMAGE != type) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
397 |
throw new IllegalArgumentException("Unexpected package type"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
398 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
399 |
|
58302 | 400 |
return appRuntimePath(type); |
401 |
} |
|
402 |
||
403 |
private static Path appRuntimePath(PackageType type) { |
|
404 |
if (PackageType.LINUX.contains(type)) { |
|
405 |
return Path.of("lib/runtime"); |
|
406 |
} |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
407 |
return Path.of("runtime"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
408 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
409 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
410 |
public boolean isFakeRuntimeInAppImage(String msg) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
411 |
return isFakeRuntime(appImage().resolve( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
412 |
appRuntimeDirectoryInAppImage()), msg); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
413 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
414 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
415 |
public boolean isFakeRuntimeInstalled(String msg) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
416 |
return isFakeRuntime(appRuntimeInstallationDirectory(), msg); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
417 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
418 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
419 |
private static boolean isFakeRuntime(Path runtimeDir, String msg) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
420 |
final List<Path> criticalRuntimeFiles; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
421 |
if (Test.isWindows()) { |
58302 | 422 |
criticalRuntimeFiles = List.of(Path.of("bin\\server\\jvm.dll")); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
423 |
} else if (Test.isLinux()) { |
58302 | 424 |
criticalRuntimeFiles = List.of(Path.of("lib/server/libjvm.so")); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
425 |
} else if (Test.isOSX()) { |
58302 | 426 |
criticalRuntimeFiles = List.of(Path.of("lib/server/libjvm.dylib")); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
427 |
} else { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
428 |
throw new IllegalArgumentException("Unknwon platform"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
429 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
430 |
|
58302 | 431 |
if (criticalRuntimeFiles.stream().filter( |
432 |
v -> runtimeDir.resolve(v).toFile().exists()).findFirst().orElse( |
|
433 |
null) == null) { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
434 |
// Fake runtime |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
435 |
Test.trace(String.format( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
436 |
"%s because application runtime directory [%s] is incomplete", |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
437 |
msg, runtimeDir)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
438 |
return true; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
439 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
440 |
return false; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
441 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
442 |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
443 |
public Executor.Result execute() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
444 |
verifyMutable(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
445 |
if (actions != null) { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
446 |
actions.stream().forEach(r -> r.accept(this)); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
447 |
} |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
448 |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
449 |
return new Executor() |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
450 |
.setExecutable(JavaTool.JPACKAGE) |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
451 |
.dumpOtput() |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
452 |
.addArguments(new JPackageCommand().addArguments( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
453 |
args).adjustArgumentsBeforeExecution().args) |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
454 |
.execute(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
455 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
456 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
457 |
private JPackageCommand adjustArgumentsBeforeExecution() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
458 |
if (!hasArgument("--runtime-image") && !hasArgument("--app-image") && DEFAULT_RUNTIME_IMAGE != null) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
459 |
addArguments("--runtime-image", DEFAULT_RUNTIME_IMAGE); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
460 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
461 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
462 |
if (!hasArgument("--verbose") && Test.VERBOSE_JPACKAGE) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
463 |
addArgument("--verbose"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
464 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
465 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
466 |
return this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
467 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
468 |
|
58113 | 469 |
String getPrintableCommandLine() { |
470 |
return new Executor() |
|
471 |
.setExecutable(JavaTool.JPACKAGE) |
|
472 |
.addArguments(args) |
|
473 |
.getPrintableCommandLine(); |
|
474 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
475 |
|
58113 | 476 |
void verifyIsOfType(Collection<PackageType> types) { |
477 |
verifyIsOfType(types.toArray(PackageType[]::new)); |
|
478 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
479 |
|
58113 | 480 |
void verifyIsOfType(PackageType ... types) { |
481 |
if (!Arrays.asList(types).contains(packageType())) { |
|
482 |
throw new IllegalArgumentException("Unexpected package type"); |
|
483 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
484 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
485 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
486 |
@Override |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
487 |
protected boolean isMutable() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
488 |
return !immutable; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
489 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
490 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
491 |
private final List<Consumer<JPackageCommand>> actions; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
492 |
private boolean immutable; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
493 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
494 |
private final static Map<String, PackageType> PACKAGE_TYPES |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
495 |
= new Supplier<Map<String, PackageType>>() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
496 |
@Override |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
497 |
public Map<String, PackageType> get() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
498 |
Map<String, PackageType> reply = new HashMap<>(); |
58115 | 499 |
for (PackageType type : PackageType.values()) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
500 |
reply.put(type.getName(), type); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
501 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
502 |
return reply; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
503 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
504 |
}.get(); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
505 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
506 |
public final static Path DEFAULT_RUNTIME_IMAGE; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
507 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
508 |
static { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
509 |
// Set the property to the path of run-time image to speed up |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
510 |
// building app images and platform bundles by avoiding running jlink |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
511 |
// The value of the property will be automativcally appended to |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
512 |
// jpackage command line if the command line doesn't have |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
513 |
// `--runtime-image` parameter set. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
514 |
String val = Test.getConfigProperty("runtime-image"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
515 |
if (val != null) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
516 |
DEFAULT_RUNTIME_IMAGE = Path.of(val); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
517 |
} else { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
518 |
DEFAULT_RUNTIME_IMAGE = null; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
519 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
520 |
} |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
521 |
} |