test/jdk/tools/jpackage/share/ArgumentsTest.java
branchJDK-8200758-branch
changeset 58416 f09bf58c1f17
parent 58147 45a9084fe981
child 58648 3bf53ffa9ae7
equal deleted inserted replaced
58415:73f8e557549a 58416:f09bf58c1f17
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    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
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
       
    24 import java.nio.file.Path;
       
    25 import java.util.List;
       
    26 import jdk.jpackage.test.TKit;
       
    27 import jdk.jpackage.test.HelloApp;
       
    28 import jdk.jpackage.test.Functional.ThrowingConsumer;
       
    29 import jdk.jpackage.test.JPackageCommand;
       
    30 import jdk.jpackage.test.Annotations.*;
       
    31 
       
    32 
       
    33 /*
       
    34  * Tricky arguments used in the test require a bunch of levels of character
       
    35  * escaping for proper encoding them in a single string to be used as a value of
       
    36  * `--arguments` option. String with encoded arguments doesn't go through the
       
    37  * system to jpackage executable as is because OS is interpreting escape
       
    38  * characters. This is true for Windows at least.
       
    39  *
       
    40  * String mapping performed by the system corrupts the string and jpackage exits
       
    41  * with error. There is no problem with string corruption when jpackage is used
       
    42  * as tool provider. This is not jpackage issue, so just always run this test
       
    43  * with jpackage used as tool provider.
       
    44  * /
       
    45 
    24 /*
    46 /*
    25  * @test
    47  * @test
    26  * @summary jpackage create image with --arguments test
    48  * @summary jpackage create image with --arguments test
    27  * @library ../helpers
    49  * @library ../helpers
    28  * @build JPackageHelper
    50  * @build jdk.jpackage.test.*
    29  * @build JPackagePath
       
    30  * @build ArgumentsBase
       
    31  * @modules jdk.jpackage
    51  * @modules jdk.jpackage
    32  * @run main/othervm -Xmx512m ArgumentsTest
    52  * @compile ArgumentsTest.java
       
    53  * @run main/othervm -Xmx512m jdk.jpackage.test.Main
       
    54  *  --jpt-run=ArgumentsTest
       
    55  *  --jpt-before-run=jdk.jpackage.test.JPackageCommand.useToolProviderByDefault
    33  */
    56  */
    34 public class ArgumentsTest {
    57 public class ArgumentsTest {
    35     private static final String OUTPUT = "output";
    58     @Test
    36 
    59     @Parameter("Goodbye")
    37     private static final String[] CMD = {
    60     @Parameter("com.hello/com.hello.Hello")
    38         "--package-type", "app-image",
    61     public static void testApp(String javaAppDesc) {
    39         "--input", "input",
    62         testIt(javaAppDesc, null);
    40         "--dest", OUTPUT,
       
    41         "--name", "test",
       
    42         "--main-jar", "hello.jar",
       
    43         "--main-class", "Hello",
       
    44         "--arguments", "TBD"};
       
    45 
       
    46     public static void main(String[] args) throws Exception {
       
    47         JPackageHelper.createHelloImageJar();
       
    48         ArgumentsBase.testCreateAppImage(CMD);
       
    49         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    50         ArgumentsBase.testCreateAppImageToolProvider(CMD);
       
    51     }
    63     }
    52 
    64 
       
    65     private static void testIt(String javaAppDesc,
       
    66             ThrowingConsumer<JPackageCommand> initializer) {
       
    67 
       
    68         JPackageCommand cmd = JPackageCommand.helloAppImage(javaAppDesc).addArguments(
       
    69                 "--arguments", JPackageCommand.escapeAndJoin(TRICKY_ARGUMENTS));
       
    70         if (initializer != null) {
       
    71             ThrowingConsumer.toConsumer(initializer).accept(cmd);
       
    72         }
       
    73 
       
    74         cmd.executeAndAssertImageCreated();
       
    75 
       
    76         Path launcherPath = cmd.appImage().resolve(cmd.launcherPathInAppImage());
       
    77         if (!cmd.isFakeRuntimeInAppImage(String.format(
       
    78                 "Not running [%s] launcher", launcherPath))) {
       
    79             HelloApp.executeAndVerifyOutput(launcherPath, TRICKY_ARGUMENTS);
       
    80         }
       
    81     }
       
    82 
       
    83     private final static List<String> TRICKY_ARGUMENTS = List.of(
       
    84         "argument",
       
    85         "Some Arguments",
       
    86         "Value \"with\" quotes"
       
    87     );
    53 }
    88 }