author | herrick |
Thu, 06 Jun 2019 19:31:11 -0400 | |
branch | JDK-8200758-branch |
changeset 57395 | 521c02b9eed0 |
parent 57324 | c1d3935fbb79 |
child 57405 | 539d8b3f9e1e |
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.FileWriter; |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
29 |
import java.io.BufferedWriter; |
57241
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
30 |
import java.nio.file.FileVisitResult; |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
31 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
32 |
import java.nio.file.Files; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
33 |
import java.nio.file.Path; |
57241
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
34 |
import java.nio.file.SimpleFileVisitor; |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
35 |
import java.nio.file.attribute.BasicFileAttributes; |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
36 |
import java.util.ArrayList; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
37 |
import java.util.List; |
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 |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
68 |
File testSrc = new File(System.getProperty("test.src") + File.separator + ".." |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
69 |
+ File.separator + "apps"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
70 |
if (testSrc.exists()) { |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
71 |
TEST_SRC_ROOT = System.getProperty("test.src") + File.separator + ".."; |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
72 |
} else { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
73 |
testSrc = new File(System.getProperty("test.src") + File.separator |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
74 |
+ ".." + File.separator + ".." + File.separator + "apps"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
75 |
if (testSrc.exists()) { |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
76 |
TEST_SRC_ROOT = System.getProperty("test.src") + File.separator + ".." |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
77 |
+ File.separator + ".."; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
78 |
} else { |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
79 |
testSrc = new File(System.getProperty("test.src") + File.separator |
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
80 |
+ ".." + File.separator + ".." + File.separator + ".." |
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
81 |
+ File.separator + "apps"); |
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
82 |
if (testSrc.exists()) { |
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
83 |
TEST_SRC_ROOT = System.getProperty("test.src") + File.separator + ".." |
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
84 |
+ File.separator + ".." + File.separator + ".."; |
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
85 |
} else { |
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
86 |
TEST_SRC_ROOT = System.getProperty("test.src"); |
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
87 |
} |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
88 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
89 |
} |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
90 |
|
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
91 |
TEST_SRC = System.getProperty("test.src"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
92 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
93 |
|
57039 | 94 |
static final ToolProvider JPACKAGE_TOOL = |
95 |
ToolProvider.findFirst("jpackage").orElseThrow( |
|
96 |
() -> new RuntimeException("jpackage tool not found")); |
|
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
97 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
98 |
public static int execute(File out, String... command) throws Exception { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
99 |
if (VERBOSE) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
100 |
System.out.print("Execute command: "); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
101 |
for (String c : command) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
102 |
System.out.print(c); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
103 |
System.out.print(" "); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
104 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
105 |
System.out.println(); |
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 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
108 |
ProcessBuilder builder = new ProcessBuilder(command); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
109 |
if (out != null) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
110 |
builder.redirectErrorStream(true); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
111 |
builder.redirectOutput(out); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
112 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
113 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
114 |
Process process = builder.start(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
115 |
return process.waitFor(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
116 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
117 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
118 |
public static Process executeNoWait(File out, String... command) throws Exception { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
119 |
if (VERBOSE) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
120 |
System.out.print("Execute command: "); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
121 |
for (String c : command) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
122 |
System.out.print(c); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
123 |
System.out.print(" "); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
124 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
125 |
System.out.println(); |
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 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
128 |
ProcessBuilder builder = new ProcessBuilder(command); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
129 |
if (out != null) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
130 |
builder.redirectErrorStream(true); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
131 |
builder.redirectOutput(out); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
132 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
133 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
134 |
return builder.start(); |
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 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
137 |
private static String[] getCommand(String... args) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
138 |
String[] command; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
139 |
if (args == null) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
140 |
command = new String[1]; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
141 |
} else { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
142 |
command = new String[args.length + 1]; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
143 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
144 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
145 |
int index = 0; |
57039 | 146 |
command[index] = JPACKAGE.toString(); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
147 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
148 |
if (args != null) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
149 |
for (String arg : args) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
150 |
index++; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
151 |
command[index] = arg; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
152 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
153 |
} |
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 |
return command; |
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 |
|
57314 | 158 |
public static void deleteRecursive(File path) throws IOException { |
57241
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
159 |
if (!path.exists()) { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
160 |
return; |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
161 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
162 |
|
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
163 |
Path directory = path.toPath(); |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
164 |
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
165 |
@Override |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
166 |
public FileVisitResult visitFile(Path file, |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
167 |
BasicFileAttributes attr) throws IOException { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
168 |
if (OS.startsWith("win")) { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
169 |
try { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
170 |
Files.setAttribute(file, "dos:readonly", false); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
171 |
} catch (Exception ioe) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
172 |
// just report and try to contune |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
173 |
System.err.println("IOException: " + ioe); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
174 |
ioe.printStackTrace(System.err); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
175 |
} |
57241
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
176 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
177 |
Files.delete(file); |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
178 |
return FileVisitResult.CONTINUE; |
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 |
|
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
181 |
@Override |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
182 |
public FileVisitResult preVisitDirectory(Path dir, |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
183 |
BasicFileAttributes attr) throws IOException { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
184 |
if (OS.startsWith("win")) { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
185 |
Files.setAttribute(dir, "dos:readonly", false); |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
186 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
187 |
return FileVisitResult.CONTINUE; |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
188 |
} |
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 |
@Override |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
191 |
public FileVisitResult postVisitDirectory(Path dir, IOException e) |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
192 |
throws IOException { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
193 |
Files.delete(dir); |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
194 |
return FileVisitResult.CONTINUE; |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
195 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
196 |
}); |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
197 |
} |
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 |
public static void deleteOutputFolder(String output) throws IOException { |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
200 |
File outputFolder = new File(output); |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
201 |
System.out.println("AMDEBUG output: " + outputFolder.getAbsolutePath()); |
57314 | 202 |
try { |
203 |
deleteRecursive(outputFolder); |
|
204 |
} catch (IOException ioe) { |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
205 |
System.err.println("IOException: " + ioe); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
206 |
ioe.printStackTrace(System.err); |
57314 | 207 |
deleteRecursive(outputFolder); |
208 |
} |
|
57241
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
209 |
} |
e11f3bf34083
8219889: Update jpackage tests for JDK-8219678 changes
herrick
parents:
57151
diff
changeset
|
210 |
|
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
211 |
public static String executeCLI(boolean retValZero, String... args) throws Exception { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
212 |
int retVal; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
213 |
File outfile = new File("output.log"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
214 |
try { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
215 |
String[] command = getCommand(args); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
216 |
retVal = execute(outfile, command); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
217 |
} catch (Exception ex) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
218 |
if (outfile.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
219 |
System.err.println(Files.readString(outfile.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
220 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
221 |
throw ex; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
222 |
} |
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 |
String output = Files.readString(outfile.toPath()); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
225 |
if (retValZero) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
226 |
if (retVal != 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
227 |
System.err.println(output); |
57039 | 228 |
throw new AssertionError("jpackage exited with error: " + retVal); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
229 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
230 |
} else { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
231 |
if (retVal == 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
232 |
System.err.println(output); |
57039 | 233 |
throw new AssertionError("jpackage exited without error: " + retVal); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
234 |
} |
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 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
237 |
if (VERBOSE) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
238 |
System.out.println("output ="); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
239 |
System.out.println(output); |
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 |
return output; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
243 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
244 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
245 |
public static String executeToolProvider(boolean retValZero, String... args) throws Exception { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
246 |
StringWriter writer = new StringWriter(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
247 |
PrintWriter pw = new PrintWriter(writer); |
57039 | 248 |
int retVal = JPACKAGE_TOOL.run(pw, pw, args); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
249 |
String output = writer.toString(); |
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 |
if (retValZero) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
252 |
if (retVal != 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
253 |
System.err.println(output); |
57039 | 254 |
throw new AssertionError("jpackage exited with error: " + retVal); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
255 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
256 |
} else { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
257 |
if (retVal == 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
258 |
System.err.println(output); |
57039 | 259 |
throw new AssertionError("jpackage exited without error"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
260 |
} |
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 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
263 |
if (VERBOSE) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
264 |
System.out.println("output ="); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
265 |
System.out.println(output); |
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 |
return output; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
269 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
270 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
271 |
public static boolean isWindows() { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
272 |
return (OS.contains("win")); |
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 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
275 |
public static boolean isOSX() { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
276 |
return (OS.contains("mac")); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
277 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
278 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
279 |
public static boolean isLinux() { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
280 |
return ((OS.contains("nix") || OS.contains("nux"))); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
281 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
282 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
283 |
public static void createHelloImageJar(String inputDir) throws Exception { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
284 |
createJar(false, "Hello", "image", inputDir); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
285 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
286 |
|
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
287 |
public static void createHelloImageJar() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
288 |
createJar(false, "Hello", "image", "input"); |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
289 |
} |
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
290 |
|
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
291 |
public static void createHelloImageJarWithMainClass() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
292 |
createJar(true, "Hello", "image", "input"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
293 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
294 |
|
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
295 |
public static void createHelloInstallerJar() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
296 |
createJar(false, "Hello", "installer", "input"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
297 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
298 |
|
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
299 |
public static void createHelloInstallerJarWithMainClass() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
300 |
createJar(true, "Hello", "installer", "input"); |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
301 |
} |
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
302 |
|
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
303 |
private static void createJar(boolean mainClassAttribute, String name, |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
304 |
String testType, String inputDir) throws Exception { |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
305 |
int retVal; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
306 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
307 |
File input = new File(inputDir); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
308 |
if (!input.exists()) { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
309 |
input.mkdirs(); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
310 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
311 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
312 |
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
|
313 |
+ File.separator + testType + File.separator + name + ".java"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
314 |
Path dst = Path.of(name + ".java"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
315 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
316 |
if (dst.toFile().exists()) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
317 |
Files.delete(dst); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
318 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
319 |
Files.copy(src, dst); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
320 |
|
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
321 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
322 |
File javacLog = new File("javac.log"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
323 |
try { |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
324 |
retVal = execute(javacLog, JAVAC.toString(), name + ".java"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
325 |
} catch (Exception ex) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
326 |
if (javacLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
327 |
System.err.println(Files.readString(javacLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
328 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
329 |
throw ex; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
330 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
331 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
332 |
if (retVal != 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
333 |
if (javacLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
334 |
System.err.println(Files.readString(javacLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
335 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
336 |
throw new AssertionError("javac exited with error: " + retVal); |
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 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
339 |
File jarLog = new File("jar.log"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
340 |
try { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
341 |
List<String> args = new ArrayList<>(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
342 |
args.add(JAR.toString()); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
343 |
args.add("-c"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
344 |
args.add("-v"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
345 |
args.add("-f"); |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
346 |
args.add(inputDir + File.separator + name.toLowerCase() + ".jar"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
347 |
if (mainClassAttribute) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
348 |
args.add("-e"); |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
349 |
args.add(name); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
350 |
} |
57079
c53a2eca0f57
8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents:
57039
diff
changeset
|
351 |
args.add(name + ".class"); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
352 |
retVal = execute(jarLog, args.stream().toArray(String[]::new)); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
353 |
} catch (Exception ex) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
354 |
if (jarLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
355 |
System.err.println(Files.readString(jarLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
356 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
357 |
throw ex; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
358 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
359 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
360 |
if (retVal != 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
361 |
if (jarLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
362 |
System.err.println(Files.readString(jarLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
363 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
364 |
throw new AssertionError("jar exited with error: " + retVal); |
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 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
367 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
368 |
public static void createHelloModule() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
369 |
createModule("Hello.java", "input", "hello", true); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
370 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
371 |
|
57324
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
372 |
public static void createOtherModule() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
373 |
createModule("Other.java", "input-other", "other", false); |
57324
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
374 |
} |
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
375 |
|
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
376 |
private static void createModule(String javaFile, String inputDir, |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
377 |
String aName, boolean createModularJar) throws Exception { |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
378 |
int retVal; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
379 |
|
57324
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
380 |
File input = new File(inputDir); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
381 |
if (!input.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
382 |
input.mkdir(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
383 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
384 |
|
57324
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
385 |
File module = new File("module" + File.separator + "com." + aName); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
386 |
if (!module.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
387 |
module.mkdirs(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
388 |
} |
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 |
File javacLog = new File("javac.log"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
391 |
try { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
392 |
List<String> args = new ArrayList<>(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
393 |
args.add(JAVAC.toString()); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
394 |
args.add("-d"); |
57324
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
395 |
args.add("module" + File.separator + "com." + aName); |
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
396 |
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
|
397 |
+ "com." + aName + File.separator + "module-info.java"); |
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
398 |
args.add(TEST_SRC_ROOT + File.separator + "apps" |
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
399 |
+ File.separator + "com." + aName + File.separator + "com" |
c1d3935fbb79
8222406: Multiple arguments for the same option - aggragation broken
herrick
parents:
57314
diff
changeset
|
400 |
+ File.separator + aName + File.separator + javaFile); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
401 |
retVal = execute(javacLog, args.stream().toArray(String[]::new)); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
402 |
} catch (Exception ex) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
403 |
if (javacLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
404 |
System.err.println(Files.readString(javacLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
405 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
406 |
throw ex; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
407 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
408 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
409 |
if (retVal != 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
410 |
if (javacLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
411 |
System.err.println(Files.readString(javacLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
412 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
413 |
throw new AssertionError("javac exited with error: " + retVal); |
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 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
416 |
if (createModularJar) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
417 |
File jarLog = new File("jar.log"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
418 |
try { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
419 |
List<String> args = new ArrayList<>(); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
420 |
args.add(JAR.toString()); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
421 |
args.add("--create"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
422 |
args.add("--file"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
423 |
args.add(inputDir + File.separator + "com." + aName + ".jar"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
424 |
args.add("-C"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
425 |
args.add("module" + File.separator + "com." + aName); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
426 |
args.add("."); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
427 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
428 |
retVal = execute(jarLog, args.stream().toArray(String[]::new)); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
429 |
} catch (Exception ex) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
430 |
if (jarLog.exists()) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
431 |
System.err.println(Files.readString(jarLog.toPath())); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
432 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
433 |
throw ex; |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
434 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
435 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
436 |
if (retVal != 0) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
437 |
if (jarLog.exists()) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
438 |
System.err.println(Files.readString(jarLog.toPath())); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
439 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
440 |
throw new AssertionError("jar exited with error: " + retVal); |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
441 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
442 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
443 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
444 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
445 |
public static void createRuntime() throws Exception { |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
446 |
List<String> moreArgs = new ArrayList<>(); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
447 |
createRuntime(moreArgs); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
448 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
449 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
450 |
public static void createRuntime(List<String> moreArgs) throws Exception { |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
451 |
int retVal; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
452 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
453 |
File jlinkLog = new File("jlink.log"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
454 |
try { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
455 |
List<String> args = new ArrayList<>(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
456 |
args.add(JLINK.toString()); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
457 |
args.add("--output"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
458 |
args.add("runtime"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
459 |
args.add("--add-modules"); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
460 |
args.add("java.base"); |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
461 |
args.addAll(moreArgs); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
462 |
|
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
463 |
retVal = execute(jlinkLog, args.stream().toArray(String[]::new)); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
464 |
} catch (Exception ex) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
465 |
if (jlinkLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
466 |
System.err.println(Files.readString(jlinkLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
467 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
468 |
throw ex; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
469 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
470 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
471 |
if (retVal != 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
472 |
if (jlinkLog.exists()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
473 |
System.err.println(Files.readString(jlinkLog.toPath())); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
474 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
475 |
throw new AssertionError("jlink exited with error: " + retVal); |
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 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
478 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
479 |
public static String listToArgumentsMap(List<String> arguments, boolean toolProvider) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
480 |
if (arguments.isEmpty()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
481 |
return ""; |
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 |
String argsStr = ""; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
485 |
for (int i = 0; i < arguments.size(); i++) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
486 |
String arg = arguments.get(i); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
487 |
argsStr += quote(arg, toolProvider); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
488 |
if ((i + 1) != arguments.size()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
489 |
argsStr += " "; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
490 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
491 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
492 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
493 |
if (!toolProvider && isWindows()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
494 |
if (argsStr.contains(" ")) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
495 |
if (argsStr.contains("\"")) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
496 |
argsStr = escapeQuote(argsStr, toolProvider); |
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 |
argsStr = "\"" + argsStr + "\""; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
499 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
500 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
501 |
return argsStr; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
502 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
503 |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
504 |
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
|
505 |
throws IOException { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
506 |
ArrayList<String> newAList = new ArrayList<>(); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
507 |
String fileString = null; |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
508 |
for (int i=0; i<cmd.length; i++) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
509 |
if (i == ndx) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
510 |
newAList.add("@argfile.cmds"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
511 |
fileString = cmd[i]; |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
512 |
} else if (i > ndx && i < ndx + len) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
513 |
fileString += " " + cmd[i]; |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
514 |
} else { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
515 |
newAList.add(cmd[i]); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
516 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
517 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
518 |
if (fileString != null) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
519 |
Path path = new File("argfile.cmds").toPath(); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
520 |
try (BufferedWriter bw = Files.newBufferedWriter(path); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
521 |
PrintWriter out = new PrintWriter(bw)) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
522 |
out.println(fileString); |
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 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
525 |
return newAList.toArray(new String[0]); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
526 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57324
diff
changeset
|
527 |
|
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
528 |
private static String quote(String in, boolean toolProvider) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
529 |
if (in == null) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
530 |
return null; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
531 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
532 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
533 |
if (in.isEmpty()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
534 |
return ""; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
535 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
536 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
537 |
if (!in.contains("=")) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
538 |
// Not a property |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
539 |
if (in.contains(" ")) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
540 |
in = escapeQuote(in, toolProvider); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
541 |
return "\"" + in + "\""; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
542 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
543 |
return in; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
544 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
545 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
546 |
if (!in.contains(" ")) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
547 |
return in; // No need to quote |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
548 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
549 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
550 |
int paramIndex = in.indexOf("="); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
551 |
if (paramIndex <= 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
552 |
return in; // Something wrong, just skip quoting |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
553 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
554 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
555 |
String param = in.substring(0, paramIndex); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
556 |
String value = in.substring(paramIndex + 1); |
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 |
if (value.length() == 0) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
559 |
return in; // No need to quote |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
560 |
} |
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 |
value = escapeQuote(value, toolProvider); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
563 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
564 |
return param + "=" + "\"" + value + "\""; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
565 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
566 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
567 |
private static String escapeQuote(String in, boolean toolProvider) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
568 |
if (in == null) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
569 |
return null; |
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.isEmpty()) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
573 |
return ""; |
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 |
if (in.contains("\"")) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
577 |
// Use code points to preserve non-ASCII chars |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
578 |
StringBuilder sb = new StringBuilder(); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
579 |
int codeLen = in.codePointCount(0, in.length()); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
580 |
for (int i = 0; i < codeLen; i++) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
581 |
int code = in.codePointAt(i); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
582 |
// Note: No need to escape '\' on Linux or OS X |
57039 | 583 |
// jpackage expects us to pass arguments and properties with |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
584 |
// quotes and spaces as a map |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
585 |
// with quotes being escaped with additional \ for |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
586 |
// internal quotes. |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
587 |
// So if we want two properties below: |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
588 |
// -Djnlp.Prop1=Some "Value" 1 |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
589 |
// -Djnlp.Prop2=Some Value 2 |
57039 | 590 |
// jpackage will need: |
57031
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
591 |
// "-Djnlp.Prop1=\"Some \\"Value\\" 1\" -Djnlp.Prop2=\"Some Value 2\"" |
57039 | 592 |
// 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
|
593 |
// 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
|
594 |
// "-Djnlp.Prop1=\\\"Some \\\\\\\"Value\\\\\\\" 1\\\" -Djnlp.Prop2=\\\"Some Value 2\\\"" |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
595 |
switch (code) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
596 |
case '"': |
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 (i == 0 || in.codePointAt(i - 1) != '\\') { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
599 |
sb.appendCodePoint('\\'); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
600 |
sb.appendCodePoint(code); |
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 |
break; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
603 |
case '\\': |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
604 |
// We need to escape already escaped symbols as well |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
605 |
if ((i + 1) < codeLen) { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
606 |
int nextCode = in.codePointAt(i + 1); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
607 |
if (nextCode == '"') { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
608 |
// \" -> \\\" |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
609 |
sb.appendCodePoint('\\'); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
610 |
sb.appendCodePoint('\\'); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
611 |
sb.appendCodePoint('\\'); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
612 |
sb.appendCodePoint(nextCode); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
613 |
} else { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
614 |
sb.appendCodePoint('\\'); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
615 |
sb.appendCodePoint(code); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
616 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
617 |
} else { |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
618 |
sb.appendCodePoint(code); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
619 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
620 |
break; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
621 |
default: |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
622 |
sb.appendCodePoint(code); |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
623 |
break; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
624 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
625 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
626 |
return sb.toString(); |
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 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
629 |
return in; |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
630 |
} |
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
631 |
|
ea4755429ed8
8214021: Create additional automated tests for jpackager
herrick
parents:
diff
changeset
|
632 |
} |