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