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