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.incubator.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 WARNING_1 44 = "WARNING: Unknown module: me.mymodule.foo"; 45 46 private static final String WARNING_2 47 = "WARNING: Unknown module: other.mod.bar"; 48 49 private static final String[] CMD = { 50 "--type", "app-image", 51 "--input", "input", 52 "--description", "the two options below should cause two app execution " 53 + "Warnings with two lines output saying: " 54 + "WARNING: Unknown module: <module-name>", 55 "--dest", OUTPUT, 56 "--name", "test", 57 "--main-jar", "hello.jar", 58 "--main-class", "Hello", 59 "--java-options", 60 "--add-exports=java.base/sun.util=me.mymodule.foo,ALL-UNNAMED", 61 "--java-options", 62 "--add-exports=java.base/sun.security.util=other.mod.bar,ALL-UNNAMED", 63 }; 64 65 private static void validate() throws Exception { 66 File outfile = new File("app.out"); 67 68 int retVal = JPackageHelper.execute(outfile, app); 69 if (retVal != 0) { 70 throw new AssertionError( 71 "Test application exited with error: " + retVal); 72 } 73 74 if (!outfile.exists()) { 75 throw new AssertionError( 76 "outfile: " + outfile + " was not created"); 77 } 78 79 String output = Files.readString(outfile.toPath()); 80 System.out.println("App output:"); 81 System.out.print(output); 82 83 String[] result = JPackageHelper.splitAndFilter(output); 84 if (result.length != 4) { 85 throw new AssertionError( 86 "Unexpected number of lines: " + result.length 87 + " - output: " + output); 88 } 89 90 String nextWarning = WARNING_1; 91 if (!result[0].startsWith(nextWarning)){ 92 nextWarning = WARNING_2; 93 if (!result[0].startsWith(WARNING_2)){ 94 throw new AssertionError("Unexpected result[0]: " + result[0]); 95 } else { 96 nextWarning = WARNING_1; 97 } 98 } 99 100 if (!result[1].startsWith(nextWarning)) { 101 throw new AssertionError("Unexpected result[1]: " + result[1]); 102 } 103 104 if (!result[2].trim().endsWith("jpackage test application")) { 105 throw new AssertionError("Unexpected result[2]: " + result[2]); 106 } 107 108 if (!result[3].trim().equals("args.length: 0")) { 109 throw new AssertionError("Unexpected result[3]: " + result[3]); 110 } 111 } 112 113 public static void main(String[] args) throws Exception { 114 JPackageHelper.createHelloImageJar(); 115 String output = JPackageHelper.executeCLI(true, CMD); 116 validate(); 117 118 JPackageHelper.deleteOutputFolder(OUTPUT); 119 output = JPackageHelper.executeToolProvider(true, CMD); 120 validate(); 121 } 122 123 }