test/jdk/tools/jpackage/share/JavaOptionsBase.java
author herrick
Mon, 01 Jul 2019 18:31:16 -0400
branchJDK-8200758-branch
changeset 57446 5a5b85f00a63
parent 57445 test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageJavaOptionsBase.java@405ddd80496e
permissions -rw-r--r--
8226891: rename and re-layout jpackage tests. Reviewed-by: almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57307
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     1
/*
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     4
 *
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     8
 *
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    13
 * accompanied this code).
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    14
 *
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    18
 *
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    21
 * questions.
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    22
 */
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    23
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    24
import java.io.File;
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    25
import java.nio.file.Files;
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    26
import java.util.ArrayList;
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    27
import java.util.List;
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    28
57446
5a5b85f00a63 8226891: rename and re-layout jpackage tests.
herrick
parents: 57445
diff changeset
    29
public class JavaOptionsBase {
57307
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    30
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    31
    private static final String app = JPackagePath.getApp();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    32
    private static final String appOutput = JPackagePath.getAppOutputFile();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    33
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    34
    private static final String ARGUMENT1 = "-Dparam1=Some Param 1";
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    35
    private static final String ARGUMENT2 = "-Dparam2=Some \"Param\" 2";
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    36
    private static final String ARGUMENT3 =
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    37
            "-Dparam3=Some \"Param\" with \" 3";
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    38
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    39
    private static final List<String> arguments = new ArrayList<>();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    40
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    41
    private static void initArguments(boolean toolProvider, String [] cmd) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    42
        if (arguments.isEmpty()) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    43
            arguments.add(ARGUMENT1);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    44
            arguments.add(ARGUMENT2);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    45
            arguments.add(ARGUMENT3);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    46
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    47
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    48
        String argumentsMap = JPackageHelper.listToArgumentsMap(arguments,
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    49
                toolProvider);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    50
        cmd[cmd.length - 1] = argumentsMap;
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    51
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    52
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    53
    private static void initArguments2(boolean toolProvider, String [] cmd) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    54
        int index = cmd.length - 6;
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    55
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    56
        cmd[index++] = "--java-options";
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    57
        arguments.clear();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    58
        arguments.add(ARGUMENT1);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    59
        cmd[index++] = JPackageHelper.listToArgumentsMap(arguments,
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    60
                toolProvider);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    61
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    62
        cmd[index++] = "--java-options";
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    63
        arguments.clear();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    64
        arguments.add(ARGUMENT2);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    65
        cmd[index++] = JPackageHelper.listToArgumentsMap(arguments,
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    66
                toolProvider);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    67
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    68
        cmd[index++] = "--java-options";
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    69
        arguments.clear();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    70
        arguments.add(ARGUMENT3);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    71
        cmd[index++] = JPackageHelper.listToArgumentsMap(arguments,
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    72
                toolProvider);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    73
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    74
        arguments.clear();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    75
        arguments.add(ARGUMENT1);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    76
        arguments.add(ARGUMENT2);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    77
        arguments.add(ARGUMENT3);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    78
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    79
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    80
    private static void validateResult(String[] result, List<String> args)
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    81
            throws Exception {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    82
        if (result.length != (args.size() + 2)) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    83
            for (String r : result) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    84
                System.err.println(r.trim());
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    85
            }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    86
            throw new AssertionError("Unexpected number of lines: "
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    87
                    + result.length);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    88
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    89
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    90
        if (!result[0].trim().equals("jpackage test application")) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    91
            throw new AssertionError("Unexpected result[0]: " + result[0]);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    92
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    93
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    94
        if (!result[1].trim().equals("args.length: 0")) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    95
            throw new AssertionError("Unexpected result[1]: " + result[1]);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    96
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    97
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    98
        int index = 2;
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
    99
        for (String arg : args) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   100
            if (!result[index].trim().equals(arg)) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   101
                throw new AssertionError("Unexpected result[" + index + "]: "
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   102
                    + result[index]);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   103
            }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   104
            index++;
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   105
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   106
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   107
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   108
    private static void validate(List<String> expectedArgs) throws Exception {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   109
        int retVal = JPackageHelper.execute(null, app);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   110
        if (retVal != 0) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   111
            throw new AssertionError("Test application exited with error: "
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   112
                    + retVal);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   113
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   114
57445
405ddd80496e 8226904: current working directory wrong running jpackage app
herrick
parents: 57419
diff changeset
   115
        File outfile = new File(appOutput);
57307
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   116
        if (!outfile.exists()) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   117
            throw new AssertionError(appOutput + " was not created");
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   118
        }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   119
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   120
        String output = Files.readString(outfile.toPath());
57419
44c2481650ce 8225092: Several jpackage tests failes when run with jcov enabled
herrick
parents: 57307
diff changeset
   121
        String[] result = JPackageHelper.splitAndFilter(output);
57307
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   122
        validateResult(result, expectedArgs);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   123
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   124
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   125
    public static void testCreateAppImageJavaOptions(String [] cmd) throws Exception {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   126
        initArguments(false, cmd);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   127
        JPackageHelper.executeCLI(true, cmd);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   128
        validate(arguments);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   129
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   130
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   131
    public static void testCreateAppImageJavaOptionsToolProvider(String [] cmd) throws Exception {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   132
        initArguments(true, cmd);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   133
        JPackageHelper.executeToolProvider(true, cmd);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   134
        validate(arguments);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   135
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   136
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   137
    public static void testCreateAppImageJavaOptions2(String [] cmd) throws Exception {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   138
        initArguments2(false, cmd);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   139
        JPackageHelper.executeCLI(true, cmd);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   140
        validate(arguments);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   141
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   142
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   143
    public static void testCreateAppImageJavaOptions2ToolProvider(String [] cmd) throws Exception {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   144
        initArguments2(true, cmd);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   145
        JPackageHelper.executeToolProvider(true, cmd);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   146
        validate(arguments);
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   147
    }
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents:
diff changeset
   148
}