test/jdk/tools/launcher/ArgsFileTest.java
author mr
Wed, 16 Jan 2019 16:27:21 -0800
changeset 53372 4003935e6e5f
parent 47216 71c04702a3d5
child 59020 aebd72de84b0
permissions -rw-r--r--
8216532: tools/launcher/Test7029048.java fails (Solaris) Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     1
/*
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     4
 *
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     8
 *
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    13
 * accompanied this code).
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    14
 *
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    18
 *
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    21
 * questions.
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    22
 */
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    23
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    24
/**
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    25
 * @test
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    26
 * @bug 8027634
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    27
 * @summary Argument parsing from file
45944
882cea808912 8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents: 43325
diff changeset
    28
 * @modules jdk.compiler
882cea808912 8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents: 43325
diff changeset
    29
 *          jdk.zipfs
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    30
 * @build TestHelper
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    31
 * @run main ArgsFileTest
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    32
 */
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    33
import java.io.File;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    34
import java.io.IOException;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    35
import java.util.ArrayList;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    36
import java.util.Arrays;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    37
import java.util.Collections;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    38
import java.util.HashMap;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    39
import java.util.List;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    40
import java.util.Map;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    41
import java.util.regex.Matcher;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    42
import java.util.regex.Pattern;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    43
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    44
public class ArgsFileTest extends TestHelper {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    45
    private static File testJar = null;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    46
    private static Map<String, String> env = new HashMap<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    47
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    48
    static void init() throws IOException {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    49
        if  (testJar != null) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    50
            return;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    51
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    52
        testJar = new File("test.jar");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    53
        StringBuilder tsrc = new StringBuilder();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    54
        tsrc.append("public static void main(String... args) {\n");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    55
        tsrc.append("   for (String x : args) {\n");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    56
        tsrc.append("        System.out.println(x);\n");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    57
        tsrc.append("   }\n");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    58
        tsrc.append("}\n");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    59
        createJar(testJar, new File("Foo"), tsrc.toString());
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    60
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    61
        env.put(JLDEBUG_KEY, "true");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    62
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    63
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    64
    private File createArgFile(String fname, List<String> lines) throws IOException {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    65
        File argFile = new File(fname);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    66
        argFile.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    67
        createAFile(argFile, lines);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    68
        return argFile;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    69
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    70
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    71
    private void verifyOptions(List<String> args, TestResult tr) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    72
        if (args.isEmpty()) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    73
            return;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    74
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    75
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    76
        int i = 1;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    77
        for (String x : args) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    78
            tr.matches(".*argv\\[" + i + "\\] = " + Pattern.quote(x) + ".*");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    79
            i++;
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    80
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    81
        if (! tr.testStatus) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    82
            System.out.println(tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    83
            throw new RuntimeException("test fails");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    84
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    85
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    86
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    87
    private void verifyUserArgs(List<String> args, TestResult tr, int index) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    88
        if (javaCmd != TestHelper.javaCmd) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    89
            tr.contains("\tFirst application arg index: 1");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    90
        } else {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    91
            tr.contains("\tFirst application arg index: " + index);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    92
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    93
            for (String arg: args) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    94
                tr.matches("^" + Pattern.quote(arg) + "$");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    95
            }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    96
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    97
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    98
        if (! tr.testStatus) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
    99
            System.out.println(tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   100
            throw new RuntimeException("test fails");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   101
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   102
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   103
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   104
    @Test
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   105
    public void expandAll() throws IOException {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   106
        List<String> lines = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   107
        lines.add("-Xmx32m");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   108
        lines.add("-Xint");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   109
        File argFile1 = createArgFile("argFile1", lines);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   110
        lines = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   111
        lines.add("-jar");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   112
        lines.add("test.jar");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   113
        lines.add("uarg1 @uarg2 @@uarg3 -uarg4 uarg5");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   114
        File argFile2 = createArgFile("argFile2", lines);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   115
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   116
        TestResult tr = doExec(env, javaCmd, "@argFile1", "@argFile2");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   117
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   118
        List<String> appArgs = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   119
        appArgs.add("uarg1");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   120
        appArgs.add("@uarg2");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   121
        appArgs.add("@@uarg3");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   122
        appArgs.add("-uarg4");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   123
        appArgs.add("uarg5");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   124
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   125
        List<String> options = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   126
        options.add("-Xmx32m");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   127
        options.add("-Xint");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   128
        options.add("-jar");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   129
        options.add("test.jar");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   130
        options.addAll(appArgs);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   131
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   132
        verifyOptions(options, tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   133
        verifyUserArgs(appArgs, tr, 5);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   134
        argFile1.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   135
        argFile2.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   136
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   137
        File cpFile = createArgFile("cpFile", Arrays.asList("-cp", "test.jar"));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   138
        List<String> appCmd = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   139
        appCmd.add("Foo");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   140
        appCmd.addAll(appArgs);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   141
        File appFile = createArgFile("appFile", appCmd);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   142
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   143
        tr = doExec(env, javaCmd, "@cpFile", "@appFile");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   144
        verifyOptions(Arrays.asList("-cp", "test.jar", "Foo",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   145
                "uarg1", "@uarg2", "@@uarg3", "-uarg4", "uarg5"), tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   146
        verifyUserArgs(appArgs, tr, 4);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   147
        cpFile.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   148
        appFile.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   149
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   150
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   151
    @Test
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   152
    public void escapeArg() throws IOException {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   153
        List<String> lines = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   154
        lines.add("-Xmx32m");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   155
        lines.add("-Xint");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   156
        File argFile1 = createArgFile("argFile1", lines);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   157
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   158
        TestResult tr = doExec(env, javaCmd, "-cp", "@@arg", "-cp", "@",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   159
                "-cp", "@@@cp", "@argFile1", "@@@@Main@@@@", "-version");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   160
        List<String> options = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   161
        options.add("-cp");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   162
        options.add("@arg");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   163
        options.add("-cp");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   164
        options.add("@");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   165
        options.add("-cp");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   166
        options.add("@@cp");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   167
        options.add("-Xmx32m");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   168
        options.add("-Xint");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   169
        options.add("@@@Main@@@@");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   170
        options.add("-version");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   171
        verifyOptions(options, tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   172
        verifyUserArgs(Collections.emptyList(), tr, options.size());
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   173
        argFile1.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   174
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   175
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   176
    @Test
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   177
    public void killSwitch() throws IOException {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   178
        List<String> lines = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   179
        lines.add("-Xmx32m");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   180
        lines.add("-Xint");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   181
        File argFile1 = createArgFile("argFile1", lines);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   182
        lines = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   183
        lines.add("-jar");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   184
        lines.add("test.jar");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   185
        lines.add("uarg1 @uarg2 @@uarg3 -uarg4 uarg5");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   186
        File argFile2 = createArgFile("argFile2", lines);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   187
        File argKill = createArgFile("argKill",
43325
033e4cced1dc 8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents: 32267
diff changeset
   188
            Collections.singletonList("--disable-@files"));
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   189
43325
033e4cced1dc 8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents: 32267
diff changeset
   190
        TestResult tr = doExec(env, javaCmd, "@argFile1", "--disable-@files", "@argFile2");
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   191
        List<String> options = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   192
        options.add("-Xmx32m");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   193
        options.add("-Xint");
43325
033e4cced1dc 8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents: 32267
diff changeset
   194
        options.add("--disable-@files");
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   195
        options.add("@argFile2");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   196
        verifyOptions(options, tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   197
        // Main class is @argFile2
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   198
        verifyUserArgs(Collections.emptyList(), tr, 5);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   199
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   200
        // Specify in file is same as specify inline
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   201
        tr = doExec(env, javaCmd, "@argFile1", "@argKill", "@argFile2");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   202
        verifyOptions(options, tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   203
        // Main class is @argFile2
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   204
        verifyUserArgs(Collections.emptyList(), tr, 5);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   205
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   206
        // multiple is fine, once on is on.
43325
033e4cced1dc 8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents: 32267
diff changeset
   207
        tr = doExec(env, javaCmd, "@argKill", "@argFile1", "--disable-@files", "@argFile2");
033e4cced1dc 8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents: 32267
diff changeset
   208
        options = Arrays.asList("--disable-@files", "@argFile1",
033e4cced1dc 8170832: Add a new launcher environment variable JAVA_OPTIONS
henryjen
parents: 32267
diff changeset
   209
                "--disable-@files", "@argFile2");
32267
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   210
        verifyOptions(options, tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   211
        verifyUserArgs(Collections.emptyList(), tr, 3);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   212
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   213
        // after main class, becoming an user application argument
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   214
        tr = doExec(env, javaCmd, "@argFile2", "@argKill");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   215
        options = Arrays.asList("-jar", "test.jar", "uarg1", "@uarg2", "@@uarg3",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   216
                "-uarg4", "uarg5", "@argKill");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   217
        verifyOptions(options, tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   218
        verifyUserArgs(Arrays.asList("uarg1", "@uarg2", "@@uarg3",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   219
                "-uarg4", "uarg5", "@argKill"), tr, 3);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   220
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   221
        argFile1.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   222
        argFile2.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   223
        argKill.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   224
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   225
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   226
    @Test
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   227
    public void userApplication() throws IOException {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   228
        List<String> lines = new ArrayList<>();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   229
        lines.add("-Xmx32m");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   230
        lines.add("-Xint");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   231
        File vmArgs = createArgFile("vmArgs", lines);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   232
        File jarOpt = createArgFile("jarOpt", Arrays.asList("-jar"));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   233
        File cpOpt = createArgFile("cpOpt", Arrays.asList("-cp"));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   234
        File jarArg = createArgFile("jarArg", Arrays.asList("test.jar"));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   235
        File userArgs = createArgFile("userArgs", Arrays.asList("-opt", "arg", "--longopt"));
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   236
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   237
        TestResult tr = doExec(env, javaCmd,
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   238
                "@vmArgs", "@jarOpt", "test.jar", "-opt", "arg", "--longopt");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   239
        verifyOptions(Arrays.asList(
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   240
                "-Xmx32m", "-Xint", "-jar", "test.jar", "-opt", "arg", "--longopt"), tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   241
        verifyUserArgs(Arrays.asList("-opt", "arg", "--longopt"), tr, 5);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   242
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   243
        tr = doExec(env, javaCmd, "@jarOpt", "@jarArg", "@vmArgs");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   244
        verifyOptions(Arrays.asList("-jar", "test.jar", "@vmArgs"), tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   245
        verifyUserArgs(Arrays.asList("@vmArgs"), tr, 3);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   246
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   247
        tr = doExec(env, javaCmd, "-cp", "@jarArg", "@vmArgs", "Foo", "@userArgs");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   248
        verifyOptions(Arrays.asList("-cp", "test.jar", "-Xmx32m", "-Xint",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   249
                "Foo", "@userArgs"), tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   250
        verifyUserArgs(Arrays.asList("@userArgs"), tr, 6);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   251
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   252
        tr = doExec(env, javaCmd, "@cpOpt", "@jarArg", "@vmArgs", "Foo", "@userArgs");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   253
        verifyOptions(Arrays.asList("-cp", "test.jar", "-Xmx32m", "-Xint",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   254
                "Foo", "@userArgs"), tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   255
        verifyUserArgs(Arrays.asList("@userArgs"), tr, 6);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   256
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   257
        tr = doExec(env, javaCmd, "@cpOpt", "test.jar", "@vmArgs", "Foo", "@userArgs");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   258
        verifyOptions(Arrays.asList("-cp", "test.jar", "-Xmx32m", "-Xint",
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   259
                "Foo", "@userArgs"), tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   260
        verifyUserArgs(Arrays.asList("@userArgs"), tr, 6);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   261
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   262
        vmArgs.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   263
        jarOpt.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   264
        cpOpt.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   265
        jarArg.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   266
        userArgs.delete();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   267
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   268
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   269
    // test with missing file
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   270
    @Test
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   271
    public void missingFileNegativeTest() throws IOException {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   272
        TestResult tr = doExec(javaCmd, "@" + "missing.cmd");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   273
        tr.checkNegative();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   274
        tr.contains("Error: could not open `missing.cmd'");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   275
        if (!tr.testStatus) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   276
            System.out.println(tr);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   277
            throw new RuntimeException("test fails");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   278
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   279
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   280
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   281
    public static void main(String... args) throws Exception {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   282
        init();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   283
        ArgsFileTest a = new ArgsFileTest();
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   284
        a.run(args);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   285
        if (testExitValue > 0) {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   286
            System.out.println("Total of " + testExitValue + " failed");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   287
            System.exit(1);
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   288
        } else {
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   289
            System.out.println("All tests pass");
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   290
        }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   291
    }
4e96a9ee01b1 8027634: Support @argfiles for java command-line tool
henryjen
parents:
diff changeset
   292
}