author | herrick |
Mon, 30 Sep 2019 19:11:19 -0400 | |
branch | JDK-8200758-branch |
changeset 58416 | f09bf58c1f17 |
parent 58304 | 7a61351edad2 |
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 |
|
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; |
58416 | 30 |
import java.util.*; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
31 |
import java.util.function.Consumer; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
32 |
import java.util.function.Function; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
33 |
import java.util.function.Supplier; |
58416 | 34 |
import java.util.regex.Pattern; |
35 |
import java.util.stream.Collectors; |
|
36 |
import java.util.stream.Stream; |
|
37 |
import jdk.jpackage.test.Functional.ThrowingConsumer; |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
38 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
39 |
/** |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
40 |
* jpackage command line with prerequisite actions. Prerequisite actions can be |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
41 |
* 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
|
42 |
* use on jpackage command line. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
43 |
*/ |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
44 |
public final class JPackageCommand extends CommandArguments<JPackageCommand> { |
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 JPackageCommand() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
47 |
actions = new ArrayList<>(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
48 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
49 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
50 |
JPackageCommand createImmutableCopy() { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
51 |
JPackageCommand reply = new JPackageCommand(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
52 |
reply.immutable = true; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
53 |
reply.args.addAll(args); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
54 |
return reply; |
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 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
57 |
public JPackageCommand setArgumentValue(String argName, String newValue) { |
58113 | 58 |
verifyMutable(); |
59 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
60 |
String prevArg = null; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
61 |
ListIterator<String> it = args.listIterator(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
62 |
while (it.hasNext()) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
63 |
String value = it.next(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
64 |
if (prevArg != null && prevArg.equals(argName)) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
65 |
if (newValue != null) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
66 |
it.set(newValue); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
67 |
} else { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
68 |
it.remove(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
69 |
it.previous(); |
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 |
} |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
72 |
return this; |
58036
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 |
prevArg = value; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
75 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
76 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
77 |
if (newValue != null) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
78 |
addArguments(argName, newValue); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
79 |
} |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
80 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
81 |
return this; |
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 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
84 |
public JPackageCommand setArgumentValue(String argName, Path newValue) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
85 |
return setArgumentValue(argName, newValue.toString()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
86 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
87 |
|
58416 | 88 |
public JPackageCommand removeArgumentWithValue(String argName) { |
89 |
return setArgumentValue(argName, (String)null); |
|
90 |
} |
|
91 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
92 |
public JPackageCommand removeArgument(String argName) { |
58416 | 93 |
args = args.stream().filter(arg -> !arg.equals(argName)).collect( |
94 |
Collectors.toList()); |
|
95 |
return this; |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
96 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
97 |
|
58113 | 98 |
public boolean hasArgument(String argName) { |
99 |
return args.contains(argName); |
|
100 |
} |
|
101 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
102 |
public <T> T getArgumentValue(String argName, |
58113 | 103 |
Function<JPackageCommand, T> defaultValueSupplier, |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
104 |
Function<String, T> stringConverter) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
105 |
String prevArg = null; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
106 |
for (String arg : args) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
107 |
if (prevArg != null && prevArg.equals(argName)) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
108 |
return stringConverter.apply(arg); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
109 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
110 |
prevArg = arg; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
111 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
112 |
if (defaultValueSupplier != null) { |
58113 | 113 |
return defaultValueSupplier.apply(this); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
114 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
115 |
return null; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
116 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
117 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
118 |
public String getArgumentValue(String argName, |
58113 | 119 |
Function<JPackageCommand, String> defaultValueSupplier) { |
120 |
return getArgumentValue(argName, defaultValueSupplier, v -> v); |
|
121 |
} |
|
122 |
||
123 |
public <T> T getArgumentValue(String argName, |
|
124 |
Supplier<T> defaultValueSupplier, |
|
125 |
Function<String, T> stringConverter) { |
|
126 |
return getArgumentValue(argName, (unused) -> defaultValueSupplier.get(), |
|
127 |
stringConverter); |
|
128 |
} |
|
129 |
||
130 |
public String getArgumentValue(String argName, |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
131 |
Supplier<String> defaultValueSupplier) { |
58113 | 132 |
return getArgumentValue(argName, defaultValueSupplier, v -> v); |
133 |
} |
|
134 |
||
135 |
public String getArgumentValue(String argName) { |
|
136 |
return getArgumentValue(argName, (Supplier<String>)null); |
|
137 |
} |
|
138 |
||
139 |
public String[] getAllArgumentValues(String argName) { |
|
140 |
List<String> values = new ArrayList<>(); |
|
141 |
String prevArg = null; |
|
142 |
for (String arg : args) { |
|
143 |
if (prevArg != null && prevArg.equals(argName)) { |
|
144 |
values.add(arg); |
|
145 |
} |
|
146 |
prevArg = arg; |
|
147 |
} |
|
148 |
return values.toArray(String[]::new); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
149 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
150 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
151 |
public JPackageCommand addArguments(String name, Path value) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
152 |
return addArguments(name, value.toString()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
153 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
154 |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
155 |
public PackageType packageType() { |
58416 | 156 |
// Don't try to be in sync with jpackage defaults. Keep it simple: |
157 |
// if no `--package-type` explicitely set on the command line, consider |
|
158 |
// this is operator's fault. |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
159 |
return getArgumentValue("--package-type", |
58416 | 160 |
() -> { |
161 |
throw new IllegalStateException("Package type not set"); |
|
162 |
}, PACKAGE_TYPES::get); |
|
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 Path outputDir() { |
58416 | 166 |
return getArgumentValue("--dest", () -> Path.of("."), Path::of); |
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 Path inputDir() { |
58416 | 170 |
return getArgumentValue("--input", () -> null, Path::of); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
171 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
172 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
173 |
public String version() { |
58113 | 174 |
return getArgumentValue("--app-version", () -> "1.0"); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
175 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
176 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
177 |
public String name() { |
58113 | 178 |
return getArgumentValue("--name", () -> getArgumentValue("--main-class")); |
179 |
} |
|
180 |
||
181 |
public boolean isRuntime() { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
182 |
return hasArgument("--runtime-image") |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
183 |
&& !hasArgument("--main-jar") |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
184 |
&& !hasArgument("--module") |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
185 |
&& !hasArgument("--app-image"); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
186 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
187 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
188 |
public JPackageCommand setDefaultInputOutput() { |
58416 | 189 |
addArguments("--input", TKit.defaultInputDir()); |
190 |
addArguments("--dest", TKit.defaultOutputDir()); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
191 |
return this; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
192 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
193 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
194 |
public JPackageCommand setFakeRuntime() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
195 |
verifyMutable(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
196 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
197 |
try { |
58416 | 198 |
Path fakeRuntimeDir = TKit.workDir().resolve("fake_runtime"); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
199 |
Files.createDirectories(fakeRuntimeDir); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
200 |
|
58416 | 201 |
if (TKit.isWindows() || TKit.isLinux()) { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
202 |
// Needed to make WindowsAppBundler happy as it copies MSVC dlls |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
203 |
// from `bin` directory. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
204 |
// 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
|
205 |
// always something in application image. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
206 |
fakeRuntimeDir.resolve("bin").toFile().mkdir(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
207 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
208 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
209 |
Path bulk = fakeRuntimeDir.resolve(Path.of("bin", "bulk")); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
210 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
211 |
// Mak sure fake runtime takes some disk space. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
212 |
// Package bundles with 0KB size are unexpected and considered |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
213 |
// an error by PackageTest. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
214 |
Files.createDirectories(bulk.getParent()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
215 |
try (FileOutputStream out = new FileOutputStream(bulk.toFile())) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
216 |
byte[] bytes = new byte[4 * 1024]; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
217 |
new SecureRandom().nextBytes(bytes); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
218 |
out.write(bytes); |
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 |
addArguments("--runtime-image", fakeRuntimeDir); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
222 |
} catch (IOException ex) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
223 |
throw new RuntimeException(ex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
224 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
225 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
226 |
return this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
227 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
228 |
|
58416 | 229 |
JPackageCommand addAction(ThrowingConsumer<JPackageCommand> action) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
230 |
verifyMutable(); |
58416 | 231 |
actions.add(ThrowingConsumer.toConsumer(action)); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
232 |
return this; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
233 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
234 |
|
58113 | 235 |
public static JPackageCommand helloAppImage() { |
58416 | 236 |
return helloAppImage(null); |
237 |
} |
|
238 |
||
239 |
/** |
|
240 |
* Creates new JPackageCommand instance configured with the test Java app. |
|
241 |
* For the explanation of `javaAppDesc` parameter, see documentation for |
|
242 |
* HelloApp.addTo() method. |
|
243 |
* |
|
244 |
* @param javaAppDesc Java application description |
|
245 |
* @return this |
|
246 |
*/ |
|
247 |
public static JPackageCommand helloAppImage(String javaAppDesc) { |
|
58113 | 248 |
JPackageCommand cmd = new JPackageCommand(); |
249 |
cmd.setDefaultInputOutput().setDefaultAppName(); |
|
58115 | 250 |
PackageType.IMAGE.applyTo(cmd); |
58416 | 251 |
HelloApp.addTo(cmd, javaAppDesc); |
58113 | 252 |
return cmd; |
253 |
} |
|
254 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
255 |
public JPackageCommand setPackageType(PackageType type) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
256 |
verifyMutable(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
257 |
type.applyTo(this); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
258 |
return this; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
259 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
260 |
|
58113 | 261 |
JPackageCommand setDefaultAppName() { |
58416 | 262 |
return addArguments("--name", TKit.getCurrentDefaultAppName()); |
58113 | 263 |
} |
264 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
265 |
public Path outputBundle() { |
58113 | 266 |
final PackageType type = packageType(); |
267 |
if (PackageType.IMAGE == type) { |
|
268 |
return null; |
|
269 |
} |
|
270 |
||
271 |
String bundleName = null; |
|
272 |
if (PackageType.LINUX.contains(type)) { |
|
273 |
bundleName = LinuxHelper.getBundleName(this); |
|
274 |
} else if (PackageType.WINDOWS.contains(type)) { |
|
275 |
bundleName = WindowsHelper.getBundleName(this); |
|
276 |
} else if (PackageType.MAC.contains(type)) { |
|
277 |
bundleName = MacHelper.getBundleName(this); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
278 |
} |
58113 | 279 |
|
280 |
return outputDir().resolve(bundleName); |
|
281 |
} |
|
282 |
||
283 |
/** |
|
284 |
* Returns path to directory where application will be installed. |
|
285 |
* |
|
286 |
* E.g. on Linux for app named Foo default the function will return |
|
287 |
* `/opt/foo` |
|
288 |
*/ |
|
289 |
public Path appInstallationDirectory() { |
|
290 |
final PackageType type = packageType(); |
|
291 |
if (PackageType.IMAGE == type) { |
|
292 |
return null; |
|
293 |
} |
|
294 |
||
295 |
if (PackageType.LINUX.contains(type)) { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
296 |
if (isRuntime()) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
297 |
// Not fancy, but OK. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
298 |
return Path.of(getArgumentValue("--install-dir", () -> "/opt"), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
299 |
LinuxHelper.getPackageName(this)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
300 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
301 |
|
58113 | 302 |
// Launcher is in "bin" subfolder of the installation directory. |
303 |
return launcherInstallationPath().getParent().getParent(); |
|
304 |
} |
|
305 |
||
306 |
if (PackageType.WINDOWS.contains(type)) { |
|
307 |
return WindowsHelper.getInstallationDirectory(this); |
|
308 |
} |
|
309 |
||
310 |
if (PackageType.MAC.contains(type)) { |
|
311 |
return MacHelper.getInstallationDirectory(this); |
|
312 |
} |
|
313 |
||
58416 | 314 |
throw throwUnexpectedPackageTypeError(); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
315 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
316 |
|
58113 | 317 |
/** |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
318 |
* Returns path where application's Java runtime will be installed. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
319 |
* 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
|
320 |
* runtime subdirectory. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
321 |
* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
322 |
* 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
|
323 |
* `/opt/foo/runtime` |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
324 |
*/ |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
325 |
public Path appRuntimeInstallationDirectory() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
326 |
if (PackageType.IMAGE == packageType()) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
327 |
return null; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
328 |
} |
58302 | 329 |
return appInstallationDirectory().resolve(appRuntimePath(packageType())); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
330 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
331 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
332 |
/** |
58113 | 333 |
* Returns path where application launcher will be installed. |
334 |
* If the command will package Java run-time only, still returns path to |
|
335 |
* application launcher. |
|
336 |
* |
|
337 |
* E.g. on Linux for app named Foo default the function will return |
|
338 |
* `/opt/foo/bin/Foo` |
|
339 |
*/ |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
340 |
public Path launcherInstallationPath() { |
58113 | 341 |
final PackageType type = packageType(); |
342 |
if (PackageType.IMAGE == type) { |
|
343 |
return null; |
|
344 |
} |
|
345 |
||
346 |
if (PackageType.LINUX.contains(type)) { |
|
347 |
return outputDir().resolve(LinuxHelper.getLauncherPath(this)); |
|
348 |
} |
|
349 |
||
350 |
if (PackageType.WINDOWS.contains(type)) { |
|
351 |
return appInstallationDirectory().resolve(name() + ".exe"); |
|
352 |
} |
|
353 |
||
354 |
if (PackageType.MAC.contains(type)) { |
|
355 |
return appInstallationDirectory().resolve(Path.of("Contents", "MacOS", name())); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
356 |
} |
58113 | 357 |
|
58416 | 358 |
throw throwUnexpectedPackageTypeError(); |
58113 | 359 |
} |
360 |
||
361 |
/** |
|
362 |
* Returns path to application image directory. |
|
363 |
* |
|
58147
45a9084fe981
8230521: rename --output/-o option and add default value (".")
herrick
parents:
58115
diff
changeset
|
364 |
* E.g. if --dest is set to `foo` and --name is set to `bar` the function |
58416 | 365 |
* will return `foo/bar` path on Linux and Windows and `foo/bar.app` on macOS. |
58113 | 366 |
* |
367 |
* @throws IllegalArgumentException is command is doing platform packaging |
|
368 |
*/ |
|
369 |
public Path appImage() { |
|
58416 | 370 |
verifyIsOfType(PackageType.IMAGE); |
371 |
String dirName = name(); |
|
372 |
if (TKit.isOSX()) { |
|
373 |
dirName = dirName + ".app"; |
|
58113 | 374 |
} |
58416 | 375 |
return outputDir().resolve(dirName); |
58113 | 376 |
} |
377 |
||
378 |
/** |
|
379 |
* Returns path to application launcher relative to image directory. |
|
380 |
* |
|
381 |
* E.g. if --name is set to `Foo` the function will return `bin/Foo` path on |
|
382 |
* Linux, and `Foo.exe` on Windows. |
|
383 |
* |
|
384 |
* @throws IllegalArgumentException is command is doing platform packaging |
|
385 |
*/ |
|
386 |
public Path launcherPathInAppImage() { |
|
58416 | 387 |
verifyIsOfType(PackageType.IMAGE); |
58113 | 388 |
|
58416 | 389 |
if (TKit.isLinux()) { |
58113 | 390 |
return Path.of("bin", name()); |
391 |
} |
|
392 |
||
58416 | 393 |
if (TKit.isOSX()) { |
58113 | 394 |
return Path.of("Contents", "MacOS", name()); |
395 |
} |
|
396 |
||
58416 | 397 |
if (TKit.isWindows()) { |
58113 | 398 |
return Path.of(name() + ".exe"); |
399 |
} |
|
400 |
||
58416 | 401 |
throw TKit.throwUnknownPlatformError(); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
402 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
403 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
404 |
/** |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
405 |
* Returns path to runtime directory relative to image directory. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
406 |
* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
407 |
* @throws IllegalArgumentException if command is configured for platform |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
408 |
* packaging |
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 Path appRuntimeDirectoryInAppImage() { |
58416 | 411 |
verifyIsOfType(PackageType.IMAGE); |
412 |
return appRuntimePath(packageType()); |
|
58302 | 413 |
} |
414 |
||
415 |
private static Path appRuntimePath(PackageType type) { |
|
58416 | 416 |
if (TKit.isLinux()) { |
58302 | 417 |
return Path.of("lib/runtime"); |
418 |
} |
|
58416 | 419 |
if (TKit.isOSX()) { |
420 |
return Path.of("Contents/runtime"); |
|
421 |
} |
|
422 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
423 |
return Path.of("runtime"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
424 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
425 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
426 |
public boolean isFakeRuntimeInAppImage(String msg) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
427 |
return isFakeRuntime(appImage().resolve( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
428 |
appRuntimeDirectoryInAppImage()), msg); |
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 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
431 |
public boolean isFakeRuntimeInstalled(String msg) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
432 |
return isFakeRuntime(appRuntimeInstallationDirectory(), msg); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
433 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
434 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
435 |
private static boolean isFakeRuntime(Path runtimeDir, String msg) { |
58416 | 436 |
final Collection<Path> criticalRuntimeFiles; |
437 |
if (TKit.isWindows()) { |
|
438 |
criticalRuntimeFiles = WindowsHelper.CRITICAL_RUNTIME_FILES; |
|
439 |
} else if (TKit.isLinux()) { |
|
440 |
criticalRuntimeFiles = LinuxHelper.CRITICAL_RUNTIME_FILES; |
|
441 |
} else if (TKit.isOSX()) { |
|
442 |
criticalRuntimeFiles = MacHelper.CRITICAL_RUNTIME_FILES; |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
443 |
} else { |
58416 | 444 |
throw TKit.throwUnknownPlatformError(); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
445 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
446 |
|
58302 | 447 |
if (criticalRuntimeFiles.stream().filter( |
448 |
v -> runtimeDir.resolve(v).toFile().exists()).findFirst().orElse( |
|
449 |
null) == null) { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
450 |
// Fake runtime |
58416 | 451 |
TKit.trace(String.format( |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
452 |
"%s because application runtime directory [%s] is incomplete", |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
453 |
msg, runtimeDir)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
454 |
return true; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
455 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
456 |
return false; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
457 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
458 |
|
58416 | 459 |
public static void useToolProviderByDefault() { |
460 |
defaultWithToolProvider = true; |
|
461 |
} |
|
462 |
||
463 |
public static void useExecutableByDefault() { |
|
464 |
defaultWithToolProvider = false; |
|
465 |
} |
|
466 |
||
467 |
public JPackageCommand useToolProvider(boolean v) { |
|
468 |
verifyMutable(); |
|
469 |
withToolProvider = v; |
|
470 |
return this; |
|
471 |
} |
|
472 |
||
473 |
public JPackageCommand saveConsoleOutput(boolean v) { |
|
474 |
verifyMutable(); |
|
475 |
saveConsoleOutput = v; |
|
476 |
return this; |
|
477 |
} |
|
478 |
||
479 |
public JPackageCommand dumpOutput(boolean v) { |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
480 |
verifyMutable(); |
58416 | 481 |
suppressOutput = !v; |
482 |
return this; |
|
483 |
} |
|
484 |
||
485 |
public boolean isWithToolProvider() { |
|
486 |
return Optional.ofNullable(withToolProvider).orElse( |
|
487 |
defaultWithToolProvider); |
|
488 |
} |
|
489 |
||
490 |
public void executePrerequisiteActions() { |
|
491 |
verifyMutable(); |
|
492 |
if (!actionsExecuted) { |
|
493 |
actionsExecuted = true; |
|
494 |
if (actions != null) { |
|
495 |
actions.stream().forEach(r -> r.accept(this)); |
|
496 |
} |
|
497 |
} |
|
498 |
} |
|
499 |
||
500 |
public Executor.Result execute() { |
|
501 |
executePrerequisiteActions(); |
|
502 |
||
503 |
if (packageType() == PackageType.IMAGE) { |
|
504 |
TKit.deleteDirectoryContentsRecursive(outputDir()); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
505 |
} |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
506 |
|
58416 | 507 |
Executor exec = new Executor() |
508 |
.saveOutput(saveConsoleOutput).dumpOutput(!suppressOutput) |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
509 |
.addArguments(new JPackageCommand().addArguments( |
58416 | 510 |
args).adjustArgumentsBeforeExecution().args); |
511 |
||
512 |
if (isWithToolProvider()) { |
|
513 |
exec.setToolProvider(JavaTool.JPACKAGE.asToolProvider()); |
|
514 |
} else { |
|
515 |
exec.setExecutable(JavaTool.JPACKAGE); |
|
516 |
} |
|
517 |
return exec.execute(); |
|
518 |
} |
|
519 |
||
520 |
public JPackageCommand executeAndAssertHelloAppImageCreated() { |
|
521 |
executeAndAssertImageCreated(); |
|
522 |
HelloApp.executeLauncherAndVerifyOutput(this); |
|
523 |
return this; |
|
524 |
} |
|
525 |
||
526 |
public JPackageCommand executeAndAssertImageCreated() { |
|
527 |
execute().assertExitCodeIsZero(); |
|
528 |
return assertImageCreated(); |
|
529 |
} |
|
530 |
||
531 |
public JPackageCommand assertImageCreated() { |
|
532 |
verifyIsOfType(PackageType.IMAGE); |
|
533 |
TKit.assertExecutableFileExists(appImage().resolve( |
|
534 |
launcherPathInAppImage())); |
|
535 |
TKit.assertDirectoryExists(appImage().resolve( |
|
536 |
appRuntimeDirectoryInAppImage())); |
|
537 |
return this; |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
538 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
539 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
540 |
private JPackageCommand adjustArgumentsBeforeExecution() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
541 |
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
|
542 |
addArguments("--runtime-image", DEFAULT_RUNTIME_IMAGE); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
543 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
544 |
|
58416 | 545 |
if (!hasArgument("--verbose") && TKit.VERBOSE_JPACKAGE) { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
546 |
addArgument("--verbose"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
547 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
548 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
549 |
return this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
550 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
551 |
|
58416 | 552 |
private static RuntimeException throwUnexpectedPackageTypeError() { |
553 |
throw new IllegalArgumentException("Unexpected package type"); |
|
554 |
} |
|
555 |
||
58113 | 556 |
String getPrintableCommandLine() { |
557 |
return new Executor() |
|
558 |
.setExecutable(JavaTool.JPACKAGE) |
|
559 |
.addArguments(args) |
|
560 |
.getPrintableCommandLine(); |
|
561 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
562 |
|
58304 | 563 |
public void verifyIsOfType(Collection<PackageType> types) { |
58113 | 564 |
verifyIsOfType(types.toArray(PackageType[]::new)); |
565 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
566 |
|
58304 | 567 |
public void verifyIsOfType(PackageType ... types) { |
58113 | 568 |
if (!Arrays.asList(types).contains(packageType())) { |
58416 | 569 |
throwUnexpectedPackageTypeError(); |
58113 | 570 |
} |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
571 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
572 |
|
58416 | 573 |
public static String escapeAndJoin(String... args) { |
574 |
return escapeAndJoin(List.of(args)); |
|
575 |
} |
|
576 |
||
577 |
public static String escapeAndJoin(List<String> args) { |
|
578 |
Pattern whitespaceRegexp = Pattern.compile("\\s"); |
|
579 |
||
580 |
return args.stream().map(v -> { |
|
581 |
String str = v; |
|
582 |
// Escape quotes. |
|
583 |
str = str.replace("\"", "\\\""); |
|
584 |
// Escape backslashes. |
|
585 |
str = str.replace("\\", "\\\\"); |
|
586 |
// If value contains whitespace characters, put the value in quotes |
|
587 |
if (whitespaceRegexp.matcher(str).find()) { |
|
588 |
str = "\"" + str + "\""; |
|
589 |
} |
|
590 |
return str; |
|
591 |
}).collect(Collectors.joining(" ")); |
|
592 |
} |
|
593 |
||
594 |
public static Path relativePathInRuntime(JavaTool tool) { |
|
595 |
Path path = tool.relativePathInJavaHome(); |
|
596 |
if (TKit.isOSX()) { |
|
597 |
path = Path.of("Contents/Home").resolve(path); |
|
598 |
} |
|
599 |
return path; |
|
600 |
} |
|
601 |
||
602 |
public static Stream<String> filterOutput(Stream<String> jpackageOutput) { |
|
603 |
// Skip "WARNING: Using experimental tool jpackage" first line of output |
|
604 |
return jpackageOutput.skip(1); |
|
605 |
} |
|
606 |
||
607 |
public static List<String> filterOutput(List<String> jpackageOutput) { |
|
608 |
return filterOutput(jpackageOutput.stream()).collect(Collectors.toList()); |
|
609 |
} |
|
610 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
611 |
@Override |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
612 |
protected boolean isMutable() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
613 |
return !immutable; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
614 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
615 |
|
58416 | 616 |
private Boolean withToolProvider; |
617 |
private boolean saveConsoleOutput; |
|
618 |
private boolean suppressOutput; |
|
619 |
private boolean immutable; |
|
620 |
private boolean actionsExecuted; |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
621 |
private final List<Consumer<JPackageCommand>> actions; |
58416 | 622 |
private static boolean defaultWithToolProvider; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
623 |
|
58416 | 624 |
private final static Map<String, PackageType> PACKAGE_TYPES = Functional.identity( |
625 |
() -> { |
|
626 |
Map<String, PackageType> reply = new HashMap<>(); |
|
627 |
for (PackageType type : PackageType.values()) { |
|
628 |
reply.put(type.getName(), type); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
629 |
} |
58416 | 630 |
return reply; |
631 |
}).get(); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
632 |
|
58416 | 633 |
public final static Path DEFAULT_RUNTIME_IMAGE = Functional.identity(() -> { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
634 |
// 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
|
635 |
// building app images and platform bundles by avoiding running jlink |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
636 |
// The value of the property will be automativcally appended to |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
637 |
// jpackage command line if the command line doesn't have |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
638 |
// `--runtime-image` parameter set. |
58416 | 639 |
String val = TKit.getConfigProperty("runtime-image"); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
640 |
if (val != null) { |
58416 | 641 |
return Path.of(val); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
642 |
} |
58416 | 643 |
return null; |
644 |
}).get(); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
645 |
} |