|
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.File; |
|
25 import java.nio.file.Files; |
|
26 |
|
27 /* |
|
28 * @test |
|
29 * @summary jpackage create image with --java-options test |
|
30 * @library ../helpers |
|
31 * @build JPackageHelper |
|
32 * @build JPackagePath |
|
33 * @build JavaOptionsBase |
|
34 * @modules jdk.jpackage |
|
35 * @run main/othervm -Xmx512m JavaOptionsEqualsTest |
|
36 */ |
|
37 public class JavaOptionsEqualsTest { |
|
38 |
|
39 private static final String app = JPackagePath.getApp(); |
|
40 |
|
41 private static final String OUTPUT = "output"; |
|
42 |
|
43 private static final String[] CMD = { |
|
44 "--input", "input", |
|
45 "--description", "the two options below should cause two app execution " |
|
46 + "Warnings with two lines output saying: " |
|
47 + "WARNING: Unknown module: <module-name>", |
|
48 "--output", OUTPUT, |
|
49 "--name", "test", |
|
50 "--main-jar", "hello.jar", |
|
51 "--main-class", "Hello", |
|
52 "--java-options", |
|
53 "--add-exports=java.base/sun.util=me.mymodule.foo,ALL-UNNAMED", |
|
54 "--java-options", |
|
55 "--add-exports=java.base/sun.security.util=other.mod.bar,ALL-UNNAMED", |
|
56 }; |
|
57 |
|
58 private static void validate() throws Exception { |
|
59 File outfile = new File("app.out"); |
|
60 |
|
61 int retVal = JPackageHelper.execute(outfile, app); |
|
62 if (retVal != 0) { |
|
63 throw new AssertionError( |
|
64 "Test application exited with error: " + retVal); |
|
65 } |
|
66 |
|
67 if (!outfile.exists()) { |
|
68 throw new AssertionError( |
|
69 "outfile: " + outfile + " was not created"); |
|
70 } |
|
71 |
|
72 String output = Files.readString(outfile.toPath()); |
|
73 String[] result = JPackageHelper.splitAndFilter(output); |
|
74 if (result.length != 4) { |
|
75 throw new AssertionError( |
|
76 "Unexpected number of lines: " + result.length |
|
77 + " - output: " + output); |
|
78 } |
|
79 |
|
80 if (!result[0].startsWith("WARNING: Unknown module: me.mymodule.foo")){ |
|
81 throw new AssertionError("Unexpected result[0]: " + result[0]); |
|
82 } |
|
83 |
|
84 if (result[1].equals(result[0])) { |
|
85 System.err.println("--- This is known bug JDK-8224486, remove this " |
|
86 + "if/else block when JDK-8224486 is fixed"); |
|
87 } else |
|
88 |
|
89 if (!result[1].startsWith("WARNING: Unknown module: other.mod.bar")) { |
|
90 throw new AssertionError("Unexpected result[1]: " + result[1]); |
|
91 } |
|
92 |
|
93 if (!result[2].trim().endsWith("jpackage test application")) { |
|
94 throw new AssertionError("Unexpected result[2]: " + result[2]); |
|
95 } |
|
96 |
|
97 if (!result[3].trim().equals("args.length: 0")) { |
|
98 throw new AssertionError("Unexpected result[3]: " + result[3]); |
|
99 } |
|
100 } |
|
101 |
|
102 public static void main(String[] args) throws Exception { |
|
103 JPackageHelper.createHelloImageJar(); |
|
104 String output = JPackageHelper.executeCLI(true, CMD); |
|
105 validate(); |
|
106 |
|
107 JPackageHelper.deleteOutputFolder(OUTPUT); |
|
108 output = JPackageHelper.executeToolProvider(true, CMD); |
|
109 validate(); |
|
110 } |
|
111 |
|
112 } |