author | herrick |
Thu, 27 Jun 2019 17:44:18 -0400 | |
branch | JDK-8200758-branch |
changeset 57438 | 4a31db8d42bd |
parent 57419 | 44c2481650ce |
child 58305 | d42b1f6960aa |
permissions | -rw-r--r-- |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57079
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
4 |
* |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
8 |
* |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
13 |
* accompanied this code). |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
14 |
* |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
18 |
* |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
21 |
* questions. |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
22 |
*/ |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
23 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
24 |
import java.io.File; |
57241
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
25 |
import java.io.IOException; |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
26 |
import java.io.PrintWriter; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
27 |
import java.io.StringWriter; |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
28 |
import java.io.BufferedWriter; |
57241
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
29 |
import java.nio.file.FileVisitResult; |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
30 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
31 |
import java.nio.file.Files; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
32 |
import java.nio.file.Path; |
57241
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
33 |
import java.nio.file.SimpleFileVisitor; |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
34 |
import java.nio.file.attribute.BasicFileAttributes; |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
35 |
import java.util.ArrayList; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
36 |
import java.util.List; |
57419
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
37 |
import java.util.Arrays; |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
38 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
39 |
import java.util.spi.ToolProvider; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
40 |
|
57039 | 41 |
public class JPackageHelper { |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
42 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
43 |
private static final boolean VERBOSE = false; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
44 |
private static final String OS = System.getProperty("os.name").toLowerCase(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
45 |
private static final String JAVA_HOME = System.getProperty("java.home"); |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
46 |
public static final String TEST_SRC_ROOT; |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
47 |
public static final String TEST_SRC; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
48 |
private static final Path BIN_DIR = Path.of(JAVA_HOME, "bin"); |
57039 | 49 |
private static final Path JPACKAGE; |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
50 |
private static final Path JAVAC; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
51 |
private static final Path JAR; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
52 |
private static final Path JLINK; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
53 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
54 |
static { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
55 |
if (OS.startsWith("win")) { |
57039 | 56 |
JPACKAGE = BIN_DIR.resolve("jpackage.exe"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
57 |
JAVAC = BIN_DIR.resolve("javac.exe"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
58 |
JAR = BIN_DIR.resolve("jar.exe"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
59 |
JLINK = BIN_DIR.resolve("jlink.exe"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
60 |
} else { |
57039 | 61 |
JPACKAGE = BIN_DIR.resolve("jpackage"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
62 |
JAVAC = BIN_DIR.resolve("javac"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
63 |
JAR = BIN_DIR.resolve("jar"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
64 |
JLINK = BIN_DIR.resolve("jlink"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
65 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
66 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
67 |
// Figure out test src based on where we called |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
68 |
TEST_SRC = System.getProperty("test.src"); |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
69 |
Path root = Path.of(TEST_SRC); |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
70 |
Path apps = Path.of(TEST_SRC, "apps"); |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
71 |
if (apps.toFile().exists()) { |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
72 |
// fine - test is at root |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
73 |
} else { |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
74 |
apps = Path.of(TEST_SRC, "..", "apps"); |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
75 |
if (apps.toFile().exists()) { |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
76 |
root = apps.getParent().normalize(); // test is 1 level down |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
77 |
} else { |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
78 |
apps = Path.of(TEST_SRC, "..", "..", "apps"); |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
79 |
if (apps.toFile().exists()) { |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
80 |
root = apps.getParent().normalize(); // 2 levels down |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
81 |
} else { |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
82 |
apps = Path.of(TEST_SRC, "..", "..", "..", "apps"); |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
83 |
if (apps.toFile().exists()) { |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
84 |
root = apps.getParent().normalize(); // 3 levels down |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
85 |
} else { |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
86 |
// if we ever have tests more than three levels |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
87 |
// down we need to add code here |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
88 |
throw new RuntimeException("we should never get here"); |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
89 |
} |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
90 |
} |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
91 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
92 |
} |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
93 |
TEST_SRC_ROOT = root.toString(); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
94 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
95 |
|
57039 | 96 |
static final ToolProvider JPACKAGE_TOOL = |
97 |
ToolProvider.findFirst("jpackage").orElseThrow( |
|
98 |
() -> new RuntimeException("jpackage tool not found")); |
|
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
99 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
100 |
public static int execute(File out, String... command) throws Exception { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
101 |
if (VERBOSE) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
102 |
System.out.print("Execute command: "); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
103 |
for (String c : command) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
104 |
System.out.print(c); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
105 |
System.out.print(" "); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
106 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
107 |
System.out.println(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
108 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
109 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
110 |
ProcessBuilder builder = new ProcessBuilder(command); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
111 |
if (out != null) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
112 |
builder.redirectErrorStream(true); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
113 |
builder.redirectOutput(out); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
114 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
115 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
116 |
Process process = builder.start(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
117 |
return process.waitFor(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
118 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
119 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
120 |
public static Process executeNoWait(File out, String... command) throws Exception { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
121 |
if (VERBOSE) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
122 |
System.out.print("Execute command: "); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
123 |
for (String c : command) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
124 |
System.out.print(c); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
125 |
System.out.print(" "); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
126 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
127 |
System.out.println(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
128 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
129 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
130 |
ProcessBuilder builder = new ProcessBuilder(command); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
131 |
if (out != null) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
132 |
builder.redirectErrorStream(true); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
133 |
builder.redirectOutput(out); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
134 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
135 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
136 |
return builder.start(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
137 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
138 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
139 |
private static String[] getCommand(String... args) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
140 |
String[] command; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
141 |
if (args == null) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
142 |
command = new String[1]; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
143 |
} else { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
144 |
command = new String[args.length + 1]; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
145 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
146 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
147 |
int index = 0; |
57039 | 148 |
command[index] = JPACKAGE.toString(); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
149 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
150 |
if (args != null) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
151 |
for (String arg : args) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
152 |
index++; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
153 |
command[index] = arg; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
154 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
155 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
156 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
157 |
return command; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
158 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
159 |
|
57314 | 160 |
public static void deleteRecursive(File path) throws IOException { |
57241
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
161 |
if (!path.exists()) { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
162 |
return; |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
163 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
164 |
|
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
165 |
Path directory = path.toPath(); |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
166 |
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
167 |
@Override |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
168 |
public FileVisitResult visitFile(Path file, |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
169 |
BasicFileAttributes attr) throws IOException { |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57419
diff
changeset
|
170 |
file.toFile().setWritable(true); |
57241
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
171 |
if (OS.startsWith("win")) { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
172 |
try { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
173 |
Files.setAttribute(file, "dos:readonly", false); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
174 |
} catch (Exception ioe) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
175 |
// just report and try to contune |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
176 |
System.err.println("IOException: " + ioe); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
177 |
ioe.printStackTrace(System.err); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
178 |
} |
57241
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
179 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
180 |
Files.delete(file); |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
181 |
return FileVisitResult.CONTINUE; |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
182 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
183 |
|
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
184 |
@Override |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
185 |
public FileVisitResult preVisitDirectory(Path dir, |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
186 |
BasicFileAttributes attr) throws IOException { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
187 |
if (OS.startsWith("win")) { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
188 |
Files.setAttribute(dir, "dos:readonly", false); |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
189 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
190 |
return FileVisitResult.CONTINUE; |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
191 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
192 |
|
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
193 |
@Override |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
194 |
public FileVisitResult postVisitDirectory(Path dir, IOException e) |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
195 |
throws IOException { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
196 |
Files.delete(dir); |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
197 |
return FileVisitResult.CONTINUE; |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
198 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
199 |
}); |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
200 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
201 |
|
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
202 |
public static void deleteOutputFolder(String output) throws IOException { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
203 |
File outputFolder = new File(output); |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
57395
diff
changeset
|
204 |
System.out.println("deleteOutputFolder: " + outputFolder.getAbsolutePath()); |
57314 | 205 |
try { |
206 |
deleteRecursive(outputFolder); |
|
207 |
} catch (IOException ioe) { |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
208 |
System.err.println("IOException: " + ioe); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
209 |
ioe.printStackTrace(System.err); |
57314 | 210 |
deleteRecursive(outputFolder); |
211 |
} |
|
57241
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
212 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
213 |
|
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
214 |
public static String executeCLI(boolean retValZero, String... args) throws Exception { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
215 |
int retVal; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
216 |
File outfile = new File("output.log"); |
57414
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57405
diff
changeset
|
217 |
String[] command = getCommand(args); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
218 |
try { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
219 |
retVal = execute(outfile, command); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
220 |
} catch (Exception ex) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
221 |
if (outfile.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
222 |
System.err.println(Files.readString(outfile.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
223 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
224 |
throw ex; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
225 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
226 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
227 |
String output = Files.readString(outfile.toPath()); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
228 |
if (retValZero) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
229 |
if (retVal != 0) { |
57414
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57405
diff
changeset
|
230 |
System.err.println("command run:"); |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57405
diff
changeset
|
231 |
for (String s : command) { System.err.println(s); } |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57405
diff
changeset
|
232 |
System.err.println("command output:"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
233 |
System.err.println(output); |
57039 | 234 |
throw new AssertionError("jpackage exited with error: " + retVal); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
235 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
236 |
} else { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
237 |
if (retVal == 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
238 |
System.err.println(output); |
57039 | 239 |
throw new AssertionError("jpackage exited without error: " + retVal); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
240 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
241 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
242 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
243 |
if (VERBOSE) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
244 |
System.out.println("output ="); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
245 |
System.out.println(output); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
246 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
247 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
248 |
return output; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
249 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
250 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
251 |
public static String executeToolProvider(boolean retValZero, String... args) throws Exception { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
252 |
StringWriter writer = new StringWriter(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
253 |
PrintWriter pw = new PrintWriter(writer); |
57039 | 254 |
int retVal = JPACKAGE_TOOL.run(pw, pw, args); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
255 |
String output = writer.toString(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
256 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
257 |
if (retValZero) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
258 |
if (retVal != 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
259 |
System.err.println(output); |
57039 | 260 |
throw new AssertionError("jpackage exited with error: " + retVal); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
261 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
262 |
} else { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
263 |
if (retVal == 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
264 |
System.err.println(output); |
57039 | 265 |
throw new AssertionError("jpackage exited without error"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
266 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
267 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
268 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
269 |
if (VERBOSE) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
270 |
System.out.println("output ="); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
271 |
System.out.println(output); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
272 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
273 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
274 |
return output; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
275 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
276 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
277 |
public static boolean isWindows() { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
278 |
return (OS.contains("win")); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
279 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
280 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
281 |
public static boolean isOSX() { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
282 |
return (OS.contains("mac")); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
283 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
284 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
285 |
public static boolean isLinux() { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
286 |
return ((OS.contains("nix") || OS.contains("nux"))); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
287 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
288 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
289 |
public static void createHelloImageJar(String inputDir) throws Exception { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
290 |
createJar(false, "Hello", "image", inputDir); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
291 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
292 |
|
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
293 |
public static void createHelloImageJar() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
294 |
createJar(false, "Hello", "image", "input"); |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
295 |
} |
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
296 |
|
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
297 |
public static void createHelloImageJarWithMainClass() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
298 |
createJar(true, "Hello", "image", "input"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
299 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
300 |
|
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
301 |
public static void createHelloInstallerJar() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
302 |
createJar(false, "Hello", "installer", "input"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
303 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
304 |
|
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
305 |
public static void createHelloInstallerJarWithMainClass() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
306 |
createJar(true, "Hello", "installer", "input"); |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
307 |
} |
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
308 |
|
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
309 |
private static void createJar(boolean mainClassAttribute, String name, |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
310 |
String testType, String inputDir) throws Exception { |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
311 |
int retVal; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
312 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
313 |
File input = new File(inputDir); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
314 |
if (!input.exists()) { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
315 |
input.mkdirs(); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
316 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
317 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
318 |
Path src = Path.of(TEST_SRC_ROOT + File.separator + "apps" |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
319 |
+ File.separator + testType + File.separator + name + ".java"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
320 |
Path dst = Path.of(name + ".java"); |
57405
539d8b3f9e1e
8224597: create automated tests for platform create-app-image options
herrick
parents:
57395
diff
changeset
|
321 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
322 |
if (dst.toFile().exists()) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
323 |
Files.delete(dst); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
324 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
325 |
Files.copy(src, dst); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
326 |
|
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
327 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
328 |
File javacLog = new File("javac.log"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
329 |
try { |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
330 |
retVal = execute(javacLog, JAVAC.toString(), name + ".java"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
331 |
} catch (Exception ex) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
332 |
if (javacLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
333 |
System.err.println(Files.readString(javacLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
334 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
335 |
throw ex; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
336 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
337 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
338 |
if (retVal != 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
339 |
if (javacLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
340 |
System.err.println(Files.readString(javacLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
341 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
342 |
throw new AssertionError("javac exited with error: " + retVal); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
343 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
344 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
345 |
File jarLog = new File("jar.log"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
346 |
try { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
347 |
List<String> args = new ArrayList<>(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
348 |
args.add(JAR.toString()); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
349 |
args.add("-c"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
350 |
args.add("-v"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
351 |
args.add("-f"); |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
352 |
args.add(inputDir + File.separator + name.toLowerCase() + ".jar"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
353 |
if (mainClassAttribute) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
354 |
args.add("-e"); |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
355 |
args.add(name); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
356 |
} |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
357 |
args.add(name + ".class"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
358 |
retVal = execute(jarLog, args.stream().toArray(String[]::new)); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
359 |
} catch (Exception ex) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
360 |
if (jarLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
361 |
System.err.println(Files.readString(jarLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
362 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
363 |
throw ex; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
364 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
365 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
366 |
if (retVal != 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
367 |
if (jarLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
368 |
System.err.println(Files.readString(jarLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
369 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
370 |
throw new AssertionError("jar exited with error: " + retVal); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
371 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
372 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
373 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
374 |
public static void createHelloModule() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
375 |
createModule("Hello.java", "input", "hello", true); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
376 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
377 |
|
57324
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
378 |
public static void createOtherModule() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
379 |
createModule("Other.java", "input-other", "other", false); |
57324
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
380 |
} |
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
381 |
|
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
382 |
private static void createModule(String javaFile, String inputDir, |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
383 |
String aName, boolean createModularJar) throws Exception { |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
384 |
int retVal; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
385 |
|
57324
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
386 |
File input = new File(inputDir); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
387 |
if (!input.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
388 |
input.mkdir(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
389 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
390 |
|
57324
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
391 |
File module = new File("module" + File.separator + "com." + aName); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
392 |
if (!module.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
393 |
module.mkdirs(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
394 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
395 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
396 |
File javacLog = new File("javac.log"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
397 |
try { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
398 |
List<String> args = new ArrayList<>(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
399 |
args.add(JAVAC.toString()); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
400 |
args.add("-d"); |
57324
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
401 |
args.add("module" + File.separator + "com." + aName); |
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
402 |
args.add(TEST_SRC_ROOT + File.separator + "apps" + File.separator |
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
403 |
+ "com." + aName + File.separator + "module-info.java"); |
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
404 |
args.add(TEST_SRC_ROOT + File.separator + "apps" |
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
405 |
+ File.separator + "com." + aName + File.separator + "com" |
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
406 |
+ File.separator + aName + File.separator + javaFile); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
407 |
retVal = execute(javacLog, args.stream().toArray(String[]::new)); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
408 |
} catch (Exception ex) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
409 |
if (javacLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
410 |
System.err.println(Files.readString(javacLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
411 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
412 |
throw ex; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
413 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
414 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
415 |
if (retVal != 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
416 |
if (javacLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
417 |
System.err.println(Files.readString(javacLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
418 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
419 |
throw new AssertionError("javac exited with error: " + retVal); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
420 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
421 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
422 |
if (createModularJar) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
423 |
File jarLog = new File("jar.log"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
424 |
try { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
425 |
List<String> args = new ArrayList<>(); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
426 |
args.add(JAR.toString()); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
427 |
args.add("--create"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
428 |
args.add("--file"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
429 |
args.add(inputDir + File.separator + "com." + aName + ".jar"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
430 |
args.add("-C"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
431 |
args.add("module" + File.separator + "com." + aName); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
432 |
args.add("."); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
433 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
434 |
retVal = execute(jarLog, args.stream().toArray(String[]::new)); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
435 |
} catch (Exception ex) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
436 |
if (jarLog.exists()) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
437 |
System.err.println(Files.readString(jarLog.toPath())); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
438 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
439 |
throw ex; |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
440 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
441 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
442 |
if (retVal != 0) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
443 |
if (jarLog.exists()) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
444 |
System.err.println(Files.readString(jarLog.toPath())); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
445 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
446 |
throw new AssertionError("jar exited with error: " + retVal); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
447 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
448 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
449 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
450 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
451 |
public static void createRuntime() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
452 |
List<String> moreArgs = new ArrayList<>(); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
453 |
createRuntime(moreArgs); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
454 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
455 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
456 |
public static void createRuntime(List<String> moreArgs) throws Exception { |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
457 |
int retVal; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
458 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
459 |
File jlinkLog = new File("jlink.log"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
460 |
try { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
461 |
List<String> args = new ArrayList<>(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
462 |
args.add(JLINK.toString()); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
463 |
args.add("--output"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
464 |
args.add("runtime"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
465 |
args.add("--add-modules"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
466 |
args.add("java.base"); |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
467 |
args.addAll(moreArgs); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
468 |
|
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
469 |
retVal = execute(jlinkLog, args.stream().toArray(String[]::new)); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
470 |
} catch (Exception ex) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
471 |
if (jlinkLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
472 |
System.err.println(Files.readString(jlinkLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
473 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
474 |
throw ex; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
475 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
476 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
477 |
if (retVal != 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
478 |
if (jlinkLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
479 |
System.err.println(Files.readString(jlinkLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
480 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
481 |
throw new AssertionError("jlink exited with error: " + retVal); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
482 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
483 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
484 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
485 |
public static String listToArgumentsMap(List<String> arguments, boolean toolProvider) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
486 |
if (arguments.isEmpty()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
487 |
return ""; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
488 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
489 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
490 |
String argsStr = ""; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
491 |
for (int i = 0; i < arguments.size(); i++) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
492 |
String arg = arguments.get(i); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
493 |
argsStr += quote(arg, toolProvider); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
494 |
if ((i + 1) != arguments.size()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
495 |
argsStr += " "; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
496 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
497 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
498 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
499 |
if (!toolProvider && isWindows()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
500 |
if (argsStr.contains(" ")) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
501 |
if (argsStr.contains("\"")) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
502 |
argsStr = escapeQuote(argsStr, toolProvider); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
503 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
504 |
argsStr = "\"" + argsStr + "\""; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
505 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
506 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
507 |
return argsStr; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
508 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
509 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
510 |
public static String[] cmdWithAtFilename(String [] cmd, int ndx, int len) |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
511 |
throws IOException { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
512 |
ArrayList<String> newAList = new ArrayList<>(); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
513 |
String fileString = null; |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
514 |
for (int i=0; i<cmd.length; i++) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
515 |
if (i == ndx) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
516 |
newAList.add("@argfile.cmds"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
517 |
fileString = cmd[i]; |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
518 |
} else if (i > ndx && i < ndx + len) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
519 |
fileString += " " + cmd[i]; |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
520 |
} else { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
521 |
newAList.add(cmd[i]); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
522 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
523 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
524 |
if (fileString != null) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
525 |
Path path = new File("argfile.cmds").toPath(); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
526 |
try (BufferedWriter bw = Files.newBufferedWriter(path); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
527 |
PrintWriter out = new PrintWriter(bw)) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
528 |
out.println(fileString); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
529 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
530 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
531 |
return newAList.toArray(new String[0]); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
532 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
533 |
|
57419
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
534 |
public static String [] splitAndFilter(String output) { |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
535 |
if (output == null) { |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
536 |
return null; |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
537 |
} |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
538 |
|
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
539 |
String[] result = output.split("\n"); |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
540 |
if (result == null || result.length == 0) { |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
541 |
return result; |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
542 |
} |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
543 |
|
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
544 |
List<String> origList = new ArrayList(Arrays.asList(result)); |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
545 |
List<String> newlist = new ArrayList(); |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
546 |
origList.stream().filter((str) -> |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
547 |
(!str.startsWith("Picked up"))).forEachOrdered((str) -> { |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
548 |
newlist.add(str); |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
549 |
}); |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
550 |
|
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
551 |
return newlist.toArray(new String[newlist.size()]); |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
552 |
} |
44c2481650ce
8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents:
57414
diff
changeset
|
553 |
|
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
554 |
private static String quote(String in, boolean toolProvider) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
555 |
if (in == null) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
556 |
return null; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
557 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
558 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
559 |
if (in.isEmpty()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
560 |
return ""; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
561 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
562 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
563 |
if (!in.contains("=")) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
564 |
// Not a property |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
565 |
if (in.contains(" ")) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
566 |
in = escapeQuote(in, toolProvider); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
567 |
return "\"" + in + "\""; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
568 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
569 |
return in; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
570 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
571 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
572 |
if (!in.contains(" ")) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
573 |
return in; // No need to quote |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
574 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
575 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
576 |
int paramIndex = in.indexOf("="); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
577 |
if (paramIndex <= 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
578 |
return in; // Something wrong, just skip quoting |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
579 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
580 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
581 |
String param = in.substring(0, paramIndex); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
582 |
String value = in.substring(paramIndex + 1); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
583 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
584 |
if (value.length() == 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
585 |
return in; // No need to quote |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
586 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
587 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
588 |
value = escapeQuote(value, toolProvider); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
589 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
590 |
return param + "=" + "\"" + value + "\""; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
591 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
592 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
593 |
private static String escapeQuote(String in, boolean toolProvider) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
594 |
if (in == null) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
595 |
return null; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
596 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
597 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
598 |
if (in.isEmpty()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
599 |
return ""; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
600 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
601 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
602 |
if (in.contains("\"")) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
603 |
// Use code points to preserve non-ASCII chars |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
604 |
StringBuilder sb = new StringBuilder(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
605 |
int codeLen = in.codePointCount(0, in.length()); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
606 |
for (int i = 0; i < codeLen; i++) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
607 |
int code = in.codePointAt(i); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
608 |
// Note: No need to escape '\' on Linux or OS X |
57039 | 609 |
// jpackage expects us to pass arguments and properties with |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
610 |
// quotes and spaces as a map |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
611 |
// with quotes being escaped with additional \ for |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
612 |
// internal quotes. |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
613 |
// So if we want two properties below: |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
614 |
// -Djnlp.Prop1=Some "Value" 1 |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
615 |
// -Djnlp.Prop2=Some Value 2 |
57039 | 616 |
// jpackage will need: |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
617 |
// "-Djnlp.Prop1=\"Some \\"Value\\" 1\" -Djnlp.Prop2=\"Some Value 2\"" |
57039 | 618 |
// but since we using ProcessBuilder to run jpackage we will need to escape |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
619 |
// our escape symbols as well, so we will need to pass string below to ProcessBuilder: |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
620 |
// "-Djnlp.Prop1=\\\"Some \\\\\\\"Value\\\\\\\" 1\\\" -Djnlp.Prop2=\\\"Some Value 2\\\"" |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
621 |
switch (code) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
622 |
case '"': |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
623 |
// " -> \" -> \\\" |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
624 |
if (i == 0 || in.codePointAt(i - 1) != '\\') { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
625 |
sb.appendCodePoint('\\'); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
626 |
sb.appendCodePoint(code); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
627 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
628 |
break; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
629 |
case '\\': |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
630 |
// We need to escape already escaped symbols as well |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
631 |
if ((i + 1) < codeLen) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
632 |
int nextCode = in.codePointAt(i + 1); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
633 |
if (nextCode == '"') { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
634 |
// \" -> \\\" |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
635 |
sb.appendCodePoint('\\'); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
636 |
sb.appendCodePoint('\\'); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
637 |
sb.appendCodePoint('\\'); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
638 |
sb.appendCodePoint(nextCode); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
639 |
} else { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
640 |
sb.appendCodePoint('\\'); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
641 |
sb.appendCodePoint(code); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
642 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
643 |
} else { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
644 |
sb.appendCodePoint(code); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
645 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
646 |
break; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
647 |
default: |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
648 |
sb.appendCodePoint(code); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
649 |
break; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
650 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
651 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
652 |
return sb.toString(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
653 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
654 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
655 |
return in; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
656 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
657 |
} |