author | herrick |
Sat, 29 Jun 2019 09:11:19 -0400 | |
branch | JDK-8200758-branch |
changeset 57445 | 405ddd80496e |
parent 57395 | 521c02b9eed0 |
permissions | -rw-r--r-- |
57307 | 1 |
/* |
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
import java.io.BufferedWriter; |
|
25 |
import java.io.File; |
|
26 |
import java.io.FileWriter; |
|
27 |
import java.io.PrintWriter; |
|
28 |
import java.nio.file.Files; |
|
29 |
import java.util.ArrayList; |
|
30 |
import java.util.List; |
|
31 |
||
32 |
public class JPackageCreateAppImageAddLauncherBase { |
|
33 |
private static final String app = JPackagePath.getApp(); |
|
34 |
private static final String appOutput = JPackagePath.getAppOutputFile(); |
|
35 |
||
36 |
// Note: quotes in argument for add launcher is not support by test |
|
37 |
private static final String ARGUMENT1 = "argument 1"; |
|
38 |
private static final String ARGUMENT2 = "argument 2"; |
|
39 |
private static final String ARGUMENT3 = "argument 3"; |
|
40 |
||
41 |
private static final List<String> arguments = new ArrayList<>(); |
|
42 |
||
43 |
private static final String PARAM1 = "-Dparam1=Some Param 1"; |
|
44 |
private static final String PARAM2 = "-Dparam2=Some Param 2"; |
|
45 |
private static final String PARAM3 = "-Dparam3=Some Param 3"; |
|
46 |
||
47 |
private static final List<String> vmArguments = new ArrayList<>(); |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
48 |
private static final List<String> empty = new ArrayList<>(); |
57307 | 49 |
|
50 |
private static void validateResult(List<String> args, List<String> vmArgs) |
|
51 |
throws Exception { |
|
57445
405ddd80496e
8226904: current working directory wrong running jpackage app
herrick
parents:
57395
diff
changeset
|
52 |
File outfile = new File(appOutput); |
57307 | 53 |
if (!outfile.exists()) { |
54 |
throw new AssertionError(appOutput + " was not created"); |
|
55 |
} |
|
56 |
||
57 |
String output = Files.readString(outfile.toPath()); |
|
58 |
String[] result = output.split("\n"); |
|
59 |
||
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
60 |
int expected = 2 + args.size() + vmArgs.size(); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
61 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
62 |
if (result.length != expected) { |
57307 | 63 |
throw new AssertionError("Unexpected number of lines: " |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
64 |
+ result.length + " expected: " + expected + " - results: " + output); |
57307 | 65 |
} |
66 |
||
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
67 |
if (!result[0].trim().endsWith("jpackage test application")) { |
57307 | 68 |
throw new AssertionError("Unexpected result[0]: " + result[0]); |
69 |
} |
|
70 |
||
71 |
if (!result[1].trim().equals("args.length: " + args.size())) { |
|
72 |
throw new AssertionError("Unexpected result[1]: " + result[1]); |
|
73 |
} |
|
74 |
||
75 |
int index = 2; |
|
76 |
for (String arg : args) { |
|
77 |
if (!result[index].trim().equals(arg)) { |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
78 |
throw new AssertionError("Unexpected result[" |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
79 |
+ index + "]: " + result[index]); |
57307 | 80 |
} |
81 |
index++; |
|
82 |
} |
|
83 |
||
84 |
for (String vmArg : vmArgs) { |
|
85 |
if (!result[index].trim().equals(vmArg)) { |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
86 |
throw new AssertionError("Unexpected result[" |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
87 |
+ index + "]: " + result[index]); |
57307 | 88 |
} |
89 |
index++; |
|
90 |
} |
|
91 |
} |
|
92 |
||
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
93 |
private static void validate(boolean includeArgs, String name) |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
94 |
throws Exception { |
57307 | 95 |
int retVal = JPackageHelper.execute(null, app); |
96 |
if (retVal != 0) { |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
97 |
throw new AssertionError("Test application " + app |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
98 |
+ " exited with error: " + retVal); |
57307 | 99 |
} |
100 |
validateResult(new ArrayList<>(), new ArrayList<>()); |
|
101 |
||
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
102 |
String app2 = JPackagePath.getAppSL(name); |
57307 | 103 |
retVal = JPackageHelper.execute(null, app2); |
104 |
if (retVal != 0) { |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
105 |
throw new AssertionError("Test application " + app2 |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
106 |
+ " exited with error: " + retVal); |
57307 | 107 |
} |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
108 |
if (includeArgs) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
109 |
validateResult(arguments, vmArguments); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
110 |
} else { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
111 |
validateResult(empty, empty); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
112 |
} |
57307 | 113 |
} |
114 |
||
115 |
public static void testCreateAppImage(String [] cmd) throws Exception { |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
116 |
testCreateAppImage(cmd, true, "test2"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
117 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
118 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
119 |
public static void testCreateAppImage(String [] cmd, |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
120 |
boolean includeArgs, String name) throws Exception { |
57307 | 121 |
JPackageHelper.executeCLI(true, cmd); |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
122 |
validate(includeArgs, name); |
57307 | 123 |
} |
124 |
||
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
125 |
public static void testCreateAppImageToolProvider(String [] cmd) |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
126 |
throws Exception { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
127 |
testCreateAppImageToolProvider(cmd, true, "test2"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
128 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
129 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
130 |
public static void testCreateAppImageToolProvider(String [] cmd, |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
131 |
boolean includeArgs, String name) throws Exception { |
57307 | 132 |
JPackageHelper.executeToolProvider(true, cmd); |
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
133 |
validate(includeArgs, name); |
57307 | 134 |
} |
135 |
||
136 |
public static void createSLProperties() throws Exception { |
|
137 |
arguments.add(ARGUMENT1); |
|
138 |
arguments.add(ARGUMENT2); |
|
139 |
arguments.add(ARGUMENT3); |
|
140 |
||
141 |
String argumentsMap = |
|
142 |
JPackageHelper.listToArgumentsMap(arguments, true); |
|
143 |
||
144 |
vmArguments.add(PARAM1); |
|
145 |
vmArguments.add(PARAM2); |
|
146 |
vmArguments.add(PARAM3); |
|
147 |
||
148 |
String vmArgumentsMap = |
|
149 |
JPackageHelper.listToArgumentsMap(vmArguments, true); |
|
150 |
||
151 |
try (PrintWriter out = new PrintWriter(new BufferedWriter( |
|
152 |
new FileWriter("sl.properties")))) { |
|
153 |
out.println("arguments=" + argumentsMap); |
|
154 |
out.println("java-options=" + vmArgumentsMap); |
|
155 |
} |
|
57395
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
156 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
157 |
try (PrintWriter out = new PrintWriter(new BufferedWriter( |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
158 |
new FileWriter("m1.properties")))) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
159 |
out.println("module=com.hello/com.hello.Hello"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
160 |
out.println("main-jar="); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
161 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
162 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
163 |
try (PrintWriter out = new PrintWriter(new BufferedWriter( |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
164 |
new FileWriter("j1.properties")))) { |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
165 |
out.println("main-jar hello.jar"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
166 |
out.println("main-class Hello"); |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
167 |
} |
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
168 |
|
521c02b9eed0
8224130: create additional automated tests for create-app-image
herrick
parents:
57330
diff
changeset
|
169 |
|
57307 | 170 |
} |
171 |
||
172 |
} |