author | herrick |
Tue, 10 Sep 2019 09:18:19 -0400 | |
branch | JDK-8200758-branch |
changeset 58113 | 885b0543f6e4 |
parent 58036 | f7f10023f7c0 |
child 58114 | 42df7de58e39 |
permissions | -rw-r--r-- |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
1 |
/* |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
4 |
* |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
8 |
* |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
13 |
* accompanied this code). |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
14 |
* |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
18 |
* |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
21 |
* questions. |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
22 |
*/ |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
23 |
package jdk.jpackage.test; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
24 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
25 |
import java.nio.file.Path; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
26 |
import java.util.ArrayList; |
58113 | 27 |
import java.util.Arrays; |
28 |
import java.util.Collection; |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
29 |
import java.util.HashMap; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
30 |
import java.util.List; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
31 |
import java.util.ListIterator; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
32 |
import java.util.Map; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
33 |
import java.util.function.Function; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
34 |
import java.util.function.Supplier; |
58113 | 35 |
import java.util.stream.Stream; |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
36 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
37 |
/** |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
38 |
* jpackage command line with prerequisite actions. Prerequisite actions can be |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
39 |
* 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
|
40 |
* use on jpackage command line. |
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 |
public final class JPackageCommand extends CommandArguments<JPackageCommand> { |
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 JPackageCommand() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
45 |
actions = new ArrayList<>(); |
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 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
48 |
static JPackageCommand createImmutable(JPackageCommand v) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
49 |
JPackageCommand reply = new JPackageCommand(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
50 |
reply.immutable = true; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
51 |
reply.args.addAll(v.args); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
52 |
return reply; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
53 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
54 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
55 |
public void setArgumentValue(String argName, String newValue) { |
58113 | 56 |
verifyMutable(); |
57 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
58 |
String prevArg = null; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
59 |
ListIterator<String> it = args.listIterator(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
60 |
while (it.hasNext()) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
61 |
String value = it.next(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
62 |
if (prevArg != null && prevArg.equals(argName)) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
63 |
if (newValue != null) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
64 |
it.set(newValue); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
65 |
} else { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
66 |
it.remove(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
67 |
it.previous(); |
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 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
70 |
return; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
71 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
72 |
prevArg = value; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
73 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
74 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
75 |
if (newValue != null) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
76 |
addArguments(argName, newValue); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
77 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
78 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
79 |
|
58113 | 80 |
public boolean hasArgument(String argName) { |
81 |
return args.contains(argName); |
|
82 |
} |
|
83 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
84 |
public <T> T getArgumentValue(String argName, |
58113 | 85 |
Function<JPackageCommand, T> defaultValueSupplier, |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
86 |
Function<String, T> stringConverter) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
87 |
String prevArg = null; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
88 |
for (String arg : args) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
89 |
if (prevArg != null && prevArg.equals(argName)) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
90 |
return stringConverter.apply(arg); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
91 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
92 |
prevArg = arg; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
93 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
94 |
if (defaultValueSupplier != null) { |
58113 | 95 |
return defaultValueSupplier.apply(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 |
return null; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
98 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
99 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
100 |
public String getArgumentValue(String argName, |
58113 | 101 |
Function<JPackageCommand, String> defaultValueSupplier) { |
102 |
return getArgumentValue(argName, defaultValueSupplier, v -> v); |
|
103 |
} |
|
104 |
||
105 |
public <T> T getArgumentValue(String argName, |
|
106 |
Supplier<T> defaultValueSupplier, |
|
107 |
Function<String, T> stringConverter) { |
|
108 |
return getArgumentValue(argName, (unused) -> defaultValueSupplier.get(), |
|
109 |
stringConverter); |
|
110 |
} |
|
111 |
||
112 |
public String getArgumentValue(String argName, |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
113 |
Supplier<String> defaultValueSupplier) { |
58113 | 114 |
return getArgumentValue(argName, defaultValueSupplier, v -> v); |
115 |
} |
|
116 |
||
117 |
public String getArgumentValue(String argName) { |
|
118 |
return getArgumentValue(argName, (Supplier<String>)null); |
|
119 |
} |
|
120 |
||
121 |
public String[] getAllArgumentValues(String argName) { |
|
122 |
List<String> values = new ArrayList<>(); |
|
123 |
String prevArg = null; |
|
124 |
for (String arg : args) { |
|
125 |
if (prevArg != null && prevArg.equals(argName)) { |
|
126 |
values.add(arg); |
|
127 |
} |
|
128 |
prevArg = arg; |
|
129 |
} |
|
130 |
return values.toArray(String[]::new); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
131 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
132 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
133 |
public PackageType packageType() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
134 |
return getArgumentValue("--package-type", |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
135 |
() -> PackageType.IMAGE, |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
136 |
(v) -> PACKAGE_TYPES.get(v)); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
137 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
138 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
139 |
public Path outputDir() { |
58113 | 140 |
return getArgumentValue("--output", () -> Test.defaultOutputDir(), Path::of); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
141 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
142 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
143 |
public Path inputDir() { |
58113 | 144 |
return getArgumentValue("--input", () -> Test.defaultInputDir(),Path::of); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
145 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
146 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
147 |
public String version() { |
58113 | 148 |
return getArgumentValue("--app-version", () -> "1.0"); |
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 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
151 |
public String name() { |
58113 | 152 |
return getArgumentValue("--name", () -> getArgumentValue("--main-class")); |
153 |
} |
|
154 |
||
155 |
public boolean isRuntime() { |
|
156 |
return getArgumentValue("--runtime-image", () -> false, v -> true); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
157 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
158 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
159 |
public JPackageCommand setDefaultInputOutput() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
160 |
verifyMutable(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
161 |
addArguments("--input", Test.defaultInputDir().toString()); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
162 |
addArguments("--output", Test.defaultOutputDir().toString()); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
163 |
return this; |
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 |
|
58113 | 166 |
JPackageCommand addAction(Runnable action) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
167 |
verifyMutable(); |
58113 | 168 |
actions.add(action); |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
169 |
return this; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
170 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
171 |
|
58113 | 172 |
public static JPackageCommand helloAppImage() { |
173 |
JPackageCommand cmd = new JPackageCommand(); |
|
174 |
cmd.setDefaultInputOutput().setDefaultAppName(); |
|
175 |
HelloApp.addTo(cmd); |
|
176 |
return cmd; |
|
177 |
} |
|
178 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
179 |
public JPackageCommand setPackageType(PackageType type) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
180 |
verifyMutable(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
181 |
type.applyTo(this); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
182 |
return this; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
183 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
184 |
|
58113 | 185 |
JPackageCommand setDefaultAppName() { |
186 |
StackTraceElement st[] = Thread.currentThread().getStackTrace(); |
|
187 |
for (StackTraceElement ste : st) { |
|
188 |
if ("main".equals(ste.getMethodName())) { |
|
189 |
String name = ste.getClassName(); |
|
190 |
name = Stream.of(name.split("[.$]")).reduce((f, l) -> l).get(); |
|
191 |
addArguments("--name", name); |
|
192 |
break; |
|
193 |
} |
|
194 |
} |
|
195 |
return this; |
|
196 |
} |
|
197 |
||
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
198 |
public Path outputBundle() { |
58113 | 199 |
final PackageType type = packageType(); |
200 |
if (PackageType.IMAGE == type) { |
|
201 |
return null; |
|
202 |
} |
|
203 |
||
204 |
String bundleName = null; |
|
205 |
if (PackageType.LINUX.contains(type)) { |
|
206 |
bundleName = LinuxHelper.getBundleName(this); |
|
207 |
} else if (PackageType.WINDOWS.contains(type)) { |
|
208 |
bundleName = WindowsHelper.getBundleName(this); |
|
209 |
} else if (PackageType.MAC.contains(type)) { |
|
210 |
bundleName = MacHelper.getBundleName(this); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
211 |
} |
58113 | 212 |
|
213 |
return outputDir().resolve(bundleName); |
|
214 |
} |
|
215 |
||
216 |
/** |
|
217 |
* Returns path to directory where application will be installed. |
|
218 |
* |
|
219 |
* E.g. on Linux for app named Foo default the function will return |
|
220 |
* `/opt/foo` |
|
221 |
*/ |
|
222 |
public Path appInstallationDirectory() { |
|
223 |
final PackageType type = packageType(); |
|
224 |
if (PackageType.IMAGE == type) { |
|
225 |
return null; |
|
226 |
} |
|
227 |
||
228 |
if (PackageType.LINUX.contains(type)) { |
|
229 |
// Launcher is in "bin" subfolder of the installation directory. |
|
230 |
return launcherInstallationPath().getParent().getParent(); |
|
231 |
} |
|
232 |
||
233 |
if (PackageType.WINDOWS.contains(type)) { |
|
234 |
return WindowsHelper.getInstallationDirectory(this); |
|
235 |
} |
|
236 |
||
237 |
if (PackageType.MAC.contains(type)) { |
|
238 |
return MacHelper.getInstallationDirectory(this); |
|
239 |
} |
|
240 |
||
241 |
throw new IllegalArgumentException("Unexpected package type"); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
242 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
243 |
|
58113 | 244 |
/** |
245 |
* Returns path where application launcher will be installed. |
|
246 |
* If the command will package Java run-time only, still returns path to |
|
247 |
* application launcher. |
|
248 |
* |
|
249 |
* E.g. on Linux for app named Foo default the function will return |
|
250 |
* `/opt/foo/bin/Foo` |
|
251 |
*/ |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
252 |
public Path launcherInstallationPath() { |
58113 | 253 |
final PackageType type = packageType(); |
254 |
if (PackageType.IMAGE == type) { |
|
255 |
return null; |
|
256 |
} |
|
257 |
||
258 |
if (PackageType.LINUX.contains(type)) { |
|
259 |
return outputDir().resolve(LinuxHelper.getLauncherPath(this)); |
|
260 |
} |
|
261 |
||
262 |
if (PackageType.WINDOWS.contains(type)) { |
|
263 |
return appInstallationDirectory().resolve(name() + ".exe"); |
|
264 |
} |
|
265 |
||
266 |
if (PackageType.MAC.contains(type)) { |
|
267 |
return appInstallationDirectory().resolve(Path.of("Contents", "MacOS", name())); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
268 |
} |
58113 | 269 |
|
270 |
throw new IllegalArgumentException("Unexpected package type"); |
|
271 |
} |
|
272 |
||
273 |
/** |
|
274 |
* Returns path to application image directory. |
|
275 |
* |
|
276 |
* E.g. if --output is set to `foo` and --name is set to `bar` the function |
|
277 |
* will return `foo/bar` path. |
|
278 |
* |
|
279 |
* @throws IllegalArgumentException is command is doing platform packaging |
|
280 |
*/ |
|
281 |
public Path appImage() { |
|
282 |
final PackageType type = packageType(); |
|
283 |
if (PackageType.IMAGE != type) { |
|
284 |
throw new IllegalArgumentException("Unexpected package type"); |
|
285 |
} |
|
286 |
||
287 |
return outputDir().resolve(name()); |
|
288 |
} |
|
289 |
||
290 |
/** |
|
291 |
* Returns path to application launcher relative to image directory. |
|
292 |
* |
|
293 |
* E.g. if --name is set to `Foo` the function will return `bin/Foo` path on |
|
294 |
* Linux, and `Foo.exe` on Windows. |
|
295 |
* |
|
296 |
* @throws IllegalArgumentException is command is doing platform packaging |
|
297 |
*/ |
|
298 |
public Path launcherPathInAppImage() { |
|
299 |
final PackageType type = packageType(); |
|
300 |
if (PackageType.IMAGE != type) { |
|
301 |
throw new IllegalArgumentException("Unexpected package type"); |
|
302 |
} |
|
303 |
||
304 |
if (Test.isLinux()) { |
|
305 |
return Path.of("bin", name()); |
|
306 |
} |
|
307 |
||
308 |
if (Test.isOSX()) { |
|
309 |
return Path.of("Contents", "MacOS", name()); |
|
310 |
} |
|
311 |
||
312 |
if (Test.isWindows()) { |
|
313 |
return Path.of(name() + ".exe"); |
|
314 |
} |
|
315 |
||
316 |
throw new IllegalArgumentException("Unexpected package type"); |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
317 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
318 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
319 |
public Executor.Result execute() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
320 |
verifyMutable(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
321 |
if (actions != null) { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
322 |
actions.stream().forEach(r -> r.run()); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
323 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
324 |
return new Executor() |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
325 |
.setExecutable(JavaTool.JPACKAGE) |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
326 |
.addArguments(args) |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
327 |
.execute(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
328 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
329 |
|
58113 | 330 |
String getPrintableCommandLine() { |
331 |
return new Executor() |
|
332 |
.setExecutable(JavaTool.JPACKAGE) |
|
333 |
.addArguments(args) |
|
334 |
.getPrintableCommandLine(); |
|
335 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
336 |
|
58113 | 337 |
void verifyIsOfType(Collection<PackageType> types) { |
338 |
verifyIsOfType(types.toArray(PackageType[]::new)); |
|
339 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
340 |
|
58113 | 341 |
void verifyIsOfType(PackageType ... types) { |
342 |
if (!Arrays.asList(types).contains(packageType())) { |
|
343 |
throw new IllegalArgumentException("Unexpected package type"); |
|
344 |
} |
|
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
345 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
346 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
347 |
@Override |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
348 |
protected boolean isMutable() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
349 |
return !immutable; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
350 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
351 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
352 |
private final List<Runnable> actions; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
353 |
private boolean immutable; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
354 |
|
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
355 |
private final static Map<String, PackageType> PACKAGE_TYPES |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
356 |
= new Supplier<Map<String, PackageType>>() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
357 |
@Override |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
358 |
public Map<String, PackageType> get() { |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
359 |
Map<String, PackageType> reply = new HashMap<>(); |
58113 | 360 |
for (PackageType type : PackageType.NATIVE) { |
58036
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
361 |
reply.put(type.getName(), type); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
362 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
363 |
return reply; |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
364 |
} |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
365 |
}.get(); |
f7f10023f7c0
8229840 : Add jtreg test for --linux-app-category option
herrick
parents:
diff
changeset
|
366 |
} |