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