author | herrick |
Tue, 24 Sep 2019 13:41:16 -0400 | |
branch | JDK-8200758-branch |
changeset 58301 | e0efb29609bd |
parent 58113 | 885b0543f6e4 |
child 58304 | 7a61351edad2 |
permissions | -rw-r--r-- |
58113 | 1 |
/* |
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
package jdk.jpackage.test; |
|
24 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
25 |
import java.io.BufferedOutputStream; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
26 |
import java.io.FileNotFoundException; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
27 |
import java.io.FileOutputStream; |
58113 | 28 |
import java.io.IOException; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
29 |
import java.io.PrintStream; |
58113 | 30 |
import java.nio.file.FileSystems; |
31 |
import java.nio.file.Files; |
|
32 |
import java.nio.file.Path; |
|
33 |
import java.nio.file.StandardWatchEventKinds; |
|
34 |
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; |
|
35 |
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; |
|
36 |
import java.nio.file.WatchEvent; |
|
37 |
import java.nio.file.WatchKey; |
|
38 |
import java.nio.file.WatchService; |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
39 |
import java.util.Collection; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
40 |
import java.util.List; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
41 |
import java.util.Map; |
58113 | 42 |
import java.util.Set; |
43 |
import java.util.concurrent.TimeUnit; |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
44 |
import java.util.function.Consumer; |
58113 | 45 |
import java.util.function.Supplier; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
46 |
import java.util.stream.Collectors; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
47 |
import jdk.jpackage.internal.IOUtils; |
58113 | 48 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
49 |
final public class Test { |
58113 | 50 |
|
51 |
public static final Path TEST_SRC_ROOT = new Supplier<Path>() { |
|
52 |
@Override |
|
53 |
public Path get() { |
|
54 |
Path root = Path.of(System.getProperty("test.src")); |
|
55 |
||
56 |
for (int i = 0; i != 10; ++i) { |
|
57 |
if (root.resolve("apps").toFile().isDirectory()) { |
|
58 |
return root.toAbsolutePath(); |
|
59 |
} |
|
60 |
root = root.resolve(".."); |
|
61 |
} |
|
62 |
||
63 |
throw new RuntimeException("Failed to locate apps directory"); |
|
64 |
} |
|
65 |
}.get(); |
|
66 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
67 |
private static class Instance implements AutoCloseable { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
68 |
Instance(String args[]) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
69 |
assertCount = 0; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
70 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
71 |
name = enclosingMainMethodClass().getSimpleName(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
72 |
extraLogStream = openLogStream(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
73 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
74 |
currentTest = this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
75 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
76 |
log(String.format("[ RUN ] %s", name)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
77 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
78 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
79 |
@Override |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
80 |
public void close() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
81 |
log(String.format("%s %s; checks=%d", |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
82 |
success ? "[ OK ]" : "[ FAILED ]", name, assertCount)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
83 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
84 |
if (extraLogStream != null) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
85 |
extraLogStream.close(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
86 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
87 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
88 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
89 |
void notifyAssert() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
90 |
assertCount++; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
91 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
92 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
93 |
void notifySuccess() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
94 |
success = true; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
95 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
96 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
97 |
private int assertCount; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
98 |
private boolean success; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
99 |
private final String name; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
100 |
private final PrintStream extraLogStream; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
101 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
102 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
103 |
public static void run(String args[], TestBody action) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
104 |
if (currentTest != null) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
105 |
throw new IllegalStateException( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
106 |
"Unexpeced nested or concurrent Test.run() call"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
107 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
108 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
109 |
try (Instance instance = new Instance(args)) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
110 |
action.run(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
111 |
instance.notifySuccess(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
112 |
} catch (Exception ex) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
113 |
throw new RuntimeException(ex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
114 |
} finally { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
115 |
currentTest = null; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
116 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
117 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
118 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
119 |
public static interface TestBody { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
120 |
public void run() throws Exception; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
121 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
122 |
|
58113 | 123 |
public static Path workDir() { |
124 |
return Path.of("."); |
|
125 |
} |
|
126 |
||
127 |
static Path defaultInputDir() { |
|
128 |
return workDir().resolve("input"); |
|
129 |
} |
|
130 |
||
131 |
static Path defaultOutputDir() { |
|
132 |
return workDir().resolve("output"); |
|
133 |
} |
|
134 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
135 |
static Class enclosingMainMethodClass() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
136 |
StackTraceElement st[] = Thread.currentThread().getStackTrace(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
137 |
for (StackTraceElement ste : st) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
138 |
if ("main".equals(ste.getMethodName())) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
139 |
try { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
140 |
return Class.forName(ste.getClassName()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
141 |
} catch (ClassNotFoundException ex) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
142 |
throw new RuntimeException(ex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
143 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
144 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
145 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
146 |
return null; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
147 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
148 |
|
58113 | 149 |
static boolean isWindows() { |
150 |
return (OS.contains("win")); |
|
151 |
} |
|
152 |
||
153 |
static boolean isOSX() { |
|
154 |
return (OS.contains("mac")); |
|
155 |
} |
|
156 |
||
157 |
static boolean isLinux() { |
|
158 |
return ((OS.contains("nix") || OS.contains("nux"))); |
|
159 |
} |
|
160 |
||
161 |
static private void log(String v) { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
162 |
System.out.println(v); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
163 |
if (currentTest != null && currentTest.extraLogStream != null) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
164 |
currentTest.extraLogStream.println(v); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
165 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
166 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
167 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
168 |
public static Class getTestClass () { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
169 |
return enclosingMainMethodClass(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
170 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
171 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
172 |
public static void createPropertiesFile(Path propsFilename, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
173 |
Collection<Map.Entry<String, String>> props) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
174 |
trace(String.format("Create [%s] properties file...", |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
175 |
propsFilename.toAbsolutePath().normalize())); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
176 |
try { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
177 |
Files.write(propsFilename, props.stream().peek(e -> trace( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
178 |
String.format("%s=%s", e.getKey(), e.getValue()))).map( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
179 |
e -> String.format("%s=%s", e.getKey(), e.getValue())).collect( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
180 |
Collectors.toList())); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
181 |
} catch (IOException ex) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
182 |
throw new RuntimeException(ex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
183 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
184 |
trace("Done"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
185 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
186 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
187 |
public static void createPropertiesFile(Path propsFilename, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
188 |
Map.Entry<String, String>... props) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
189 |
createPropertiesFile(propsFilename, List.of(props)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
190 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
191 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
192 |
public static void createPropertiesFile(Path propsFilename, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
193 |
Map<String, String> props) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
194 |
createPropertiesFile(propsFilename, props.entrySet()); |
58113 | 195 |
} |
196 |
||
197 |
public static void trace(String v) { |
|
198 |
if (TRACE) { |
|
199 |
log("TRACE: " + v); |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
private static void traceAssert(String v) { |
|
204 |
if (TRACE_ASSERTS) { |
|
205 |
log("TRACE: " + v); |
|
206 |
} |
|
207 |
} |
|
208 |
||
209 |
public static void error(String v) { |
|
210 |
log("ERROR: " + v); |
|
211 |
throw new AssertionError(v); |
|
212 |
} |
|
213 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
214 |
private static final String TEMP_FILE_PREFIX = null; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
215 |
|
58113 | 216 |
public static Path createTempDirectory() throws IOException { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
217 |
return Files.createTempDirectory(workDir(), TEMP_FILE_PREFIX); |
58113 | 218 |
} |
219 |
||
220 |
public static Path createTempFile(String suffix) throws IOException { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
221 |
return Files.createTempFile(workDir(), TEMP_FILE_PREFIX, suffix); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
222 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
223 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
224 |
public static void withTempFile(String suffix, Consumer<Path> action) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
225 |
Path tempFile = null; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
226 |
boolean keepIt = true; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
227 |
try { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
228 |
tempFile = createTempFile(suffix); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
229 |
action.accept(tempFile); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
230 |
keepIt = false; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
231 |
} catch (IOException ex) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
232 |
throw new RuntimeException(ex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
233 |
} finally { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
234 |
if (tempFile != null && !keepIt) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
235 |
try { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
236 |
Files.deleteIfExists(tempFile); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
237 |
} catch (IOException ex) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
238 |
throw new RuntimeException(ex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
239 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
240 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
241 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
242 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
243 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
244 |
public static void withTempDirectory(Consumer<Path> action) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
245 |
Path tempDir = null; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
246 |
boolean keepIt = true; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
247 |
try { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
248 |
tempDir = createTempDirectory(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
249 |
action.accept(tempDir); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
250 |
keepIt = false; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
251 |
} catch (IOException ex) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
252 |
throw new RuntimeException(ex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
253 |
} finally { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
254 |
try { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
255 |
if (tempDir != null && tempDir.toFile().isDirectory() && !keepIt) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
256 |
IOUtils.deleteRecursive(tempDir.toFile()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
257 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
258 |
} catch (IOException ex) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
259 |
throw new RuntimeException(ex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
260 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
261 |
} |
58113 | 262 |
} |
263 |
||
264 |
public static void waitForFileCreated(Path fileToWaitFor, |
|
265 |
long timeoutSeconds) throws IOException { |
|
266 |
||
267 |
trace(String.format("Wait for file [%s] to be available", fileToWaitFor)); |
|
268 |
||
269 |
WatchService ws = FileSystems.getDefault().newWatchService(); |
|
270 |
||
271 |
Path watchDirectory = fileToWaitFor.toAbsolutePath().getParent(); |
|
272 |
watchDirectory.register(ws, ENTRY_CREATE, ENTRY_MODIFY); |
|
273 |
||
274 |
long waitUntil = System.currentTimeMillis() + timeoutSeconds * 1000; |
|
275 |
for (;;) { |
|
276 |
long timeout = waitUntil - System.currentTimeMillis(); |
|
277 |
assertTrue(timeout > 0, String.format( |
|
278 |
"Check timeout value %d is positive", timeout)); |
|
279 |
||
280 |
WatchKey key = null; |
|
281 |
try { |
|
282 |
key = ws.poll(timeout, TimeUnit.MILLISECONDS); |
|
283 |
} catch (InterruptedException ex) { |
|
284 |
throw new RuntimeException(ex); |
|
285 |
} |
|
286 |
||
287 |
if (key == null) { |
|
288 |
if (fileToWaitFor.toFile().exists()) { |
|
289 |
trace(String.format( |
|
290 |
"File [%s] is available after poll timeout expired", |
|
291 |
fileToWaitFor)); |
|
292 |
return; |
|
293 |
} |
|
294 |
assertUnexpected(String.format("Timeout expired", timeout)); |
|
295 |
} |
|
296 |
||
297 |
for (WatchEvent<?> event : key.pollEvents()) { |
|
298 |
if (event.kind() == StandardWatchEventKinds.OVERFLOW) { |
|
299 |
continue; |
|
300 |
} |
|
301 |
Path contextPath = (Path) event.context(); |
|
302 |
if (Files.isSameFile(watchDirectory.resolve(contextPath), |
|
303 |
fileToWaitFor)) { |
|
304 |
trace(String.format("File [%s] is available", fileToWaitFor)); |
|
305 |
return; |
|
306 |
} |
|
307 |
} |
|
308 |
||
309 |
if (!key.reset()) { |
|
310 |
assertUnexpected("Watch key invalidated"); |
|
311 |
} |
|
312 |
} |
|
313 |
} |
|
314 |
||
315 |
private static String concatMessages(String msg, String msg2) { |
|
316 |
if (msg2 != null && !msg2.isBlank()) { |
|
317 |
return msg + ": " + msg2; |
|
318 |
} |
|
319 |
return msg; |
|
320 |
} |
|
321 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
322 |
public static void assertEquals(long expected, long actual, String msg) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
323 |
currentTest.notifyAssert(); |
58113 | 324 |
if (expected != actual) { |
325 |
error(concatMessages(String.format( |
|
326 |
"Expected [%d]. Actual [%d]", expected, actual), |
|
327 |
msg)); |
|
328 |
} |
|
329 |
||
330 |
traceAssert(String.format("assertEquals(%d): %s", expected, msg)); |
|
331 |
} |
|
332 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
333 |
public static void assertNotEquals(long expected, long actual, String msg) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
334 |
currentTest.notifyAssert(); |
58113 | 335 |
if (expected == actual) { |
336 |
error(concatMessages(String.format("Unexpected [%d] value", actual), |
|
337 |
msg)); |
|
338 |
} |
|
339 |
||
340 |
traceAssert(String.format("assertNotEquals(%d, %d): %s", expected, |
|
341 |
actual, msg)); |
|
342 |
} |
|
343 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
344 |
public static void assertEquals(String expected, String actual, String msg) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
345 |
currentTest.notifyAssert(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
346 |
if ((actual != null && !actual.equals(expected)) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
347 |
|| (expected != null && !expected.equals(actual))) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
348 |
error(concatMessages(String.format( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
349 |
"Expected [%s]. Actual [%s]", expected, actual), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
350 |
msg)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
351 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
352 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
353 |
traceAssert(String.format("assertEquals(%s): %s", expected, msg)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
354 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
355 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
356 |
public static void assertNotEquals(String expected, String actual, String msg) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
357 |
currentTest.notifyAssert(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
358 |
if ((actual != null && !actual.equals(expected)) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
359 |
|| (expected != null && !expected.equals(actual))) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
360 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
361 |
traceAssert(String.format("assertNotEquals(%s, %s): %s", expected, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
362 |
actual, msg)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
363 |
return; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
364 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
365 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
366 |
error(concatMessages(String.format("Unexpected [%s] value", actual), msg)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
367 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
368 |
|
58113 | 369 |
public static void assertNull(Object value, String msg) { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
370 |
currentTest.notifyAssert(); |
58113 | 371 |
if (value != null) { |
372 |
error(concatMessages(String.format("Unexpected not null value [%s]", |
|
373 |
value), msg)); |
|
374 |
} |
|
375 |
||
376 |
traceAssert(String.format("assertNull(): %s", msg)); |
|
377 |
} |
|
378 |
||
379 |
public static void assertNotNull(Object value, String msg) { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
380 |
currentTest.notifyAssert(); |
58113 | 381 |
if (value == null) { |
382 |
error(concatMessages("Unexpected null value", msg)); |
|
383 |
} |
|
384 |
||
385 |
traceAssert(String.format("assertNotNull(%s): %s", value, msg)); |
|
386 |
} |
|
387 |
||
388 |
public static void assertTrue(boolean actual, String msg) { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
389 |
currentTest.notifyAssert(); |
58113 | 390 |
if (!actual) { |
391 |
error(concatMessages("Unexpected FALSE", msg)); |
|
392 |
} |
|
393 |
||
394 |
traceAssert(String.format("assertTrue(): %s", msg)); |
|
395 |
} |
|
396 |
||
397 |
public static void assertFalse(boolean actual, String msg) { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
398 |
currentTest.notifyAssert(); |
58113 | 399 |
if (actual) { |
400 |
error(concatMessages("Unexpected TRUE", msg)); |
|
401 |
} |
|
402 |
||
403 |
traceAssert(String.format("assertFalse(): %s", msg)); |
|
404 |
} |
|
405 |
||
406 |
public static void assertPathExists(Path path, boolean exists) { |
|
407 |
if (exists) { |
|
408 |
assertTrue(path.toFile().exists(), String.format( |
|
409 |
"Check [%s] path exists", path)); |
|
410 |
} else { |
|
411 |
assertFalse(path.toFile().exists(), String.format( |
|
412 |
"Check [%s] path doesn't exist", path)); |
|
413 |
} |
|
414 |
} |
|
415 |
||
416 |
public static void assertDirectoryExists(Path path, boolean exists) { |
|
417 |
assertPathExists(path, exists); |
|
418 |
if (exists) { |
|
419 |
assertTrue(path.toFile().isDirectory(), String.format( |
|
420 |
"Check [%s] is a directory", path)); |
|
421 |
} |
|
422 |
} |
|
423 |
||
424 |
public static void assertFileExists(Path path, boolean exists) { |
|
425 |
assertPathExists(path, exists); |
|
426 |
if (exists) { |
|
427 |
assertTrue(path.toFile().isFile(), String.format( |
|
428 |
"Check [%s] is a file", path)); |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
public static void assertExecutableFileExists(Path path, boolean exists) { |
|
433 |
assertFileExists(path, exists); |
|
434 |
if (exists) { |
|
435 |
assertTrue(path.toFile().canExecute(), String.format( |
|
436 |
"Check [%s] file is executable", path)); |
|
437 |
} |
|
438 |
} |
|
439 |
||
440 |
public static void assertUnexpected(String msg) { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
441 |
currentTest.notifyAssert(); |
58113 | 442 |
error(concatMessages("Unexpected", msg)); |
443 |
} |
|
444 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
445 |
private static PrintStream openLogStream() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
446 |
if (LOG_FILE == null) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
447 |
return null; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
448 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
449 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
450 |
try { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
451 |
return new PrintStream(new FileOutputStream(LOG_FILE.toFile(), true)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
452 |
} catch (FileNotFoundException ex) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
453 |
throw new RuntimeException(ex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
454 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
455 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
456 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
457 |
private static Instance currentTest; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
458 |
|
58113 | 459 |
private static final boolean TRACE; |
460 |
private static final boolean TRACE_ASSERTS; |
|
461 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
462 |
static final boolean VERBOSE_JPACKAGE; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
463 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
464 |
static String getConfigProperty(String propertyName) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
465 |
return System.getProperty(getConfigPropertyName(propertyName)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
466 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
467 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
468 |
static String getConfigPropertyName(String propertyName) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
469 |
return "jpackage.test." + propertyName; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
470 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
471 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
472 |
static final Path LOG_FILE = new Supplier<Path>() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
473 |
@Override |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
474 |
public Path get() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
475 |
String val = getConfigProperty("logfile"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
476 |
if (val == null) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
477 |
return null; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
478 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
479 |
return Path.of(val); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
480 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
481 |
}.get(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
482 |
|
58113 | 483 |
static { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
484 |
String val = getConfigProperty("suppress-logging"); |
58113 | 485 |
if (val == null) { |
486 |
TRACE = true; |
|
487 |
TRACE_ASSERTS = true; |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
488 |
VERBOSE_JPACKAGE = true; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
489 |
} else if ("all".equals(val.toLowerCase())) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
490 |
TRACE = false; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
491 |
TRACE_ASSERTS = false; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
492 |
VERBOSE_JPACKAGE = false; |
58113 | 493 |
} else { |
494 |
Set<String> logOptions = Set.of(val.toLowerCase().split(",")); |
|
495 |
TRACE = !(logOptions.contains("trace") || logOptions.contains("t")); |
|
496 |
TRACE_ASSERTS = !(logOptions.contains("assert") || logOptions.contains( |
|
497 |
"a")); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
498 |
VERBOSE_JPACKAGE = !(logOptions.contains("jpackage") || logOptions.contains( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
499 |
"jp")); |
58113 | 500 |
} |
501 |
} |
|
502 |
||
503 |
private static final String OS = System.getProperty("os.name").toLowerCase(); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
504 |
} |