langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/CommandLine.java
author ksrini
Wed, 15 Feb 2017 18:07:28 -0800
changeset 43874 d49715456f51
parent 41438 5e21aa284a82
permissions -rw-r--r--
8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
43874
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
     2
 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5004
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5004
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5004
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5004
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5004
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.main;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.io.Reader;
36157
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 25874
diff changeset
    30
import java.nio.file.Files;
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 25874
diff changeset
    31
import java.nio.file.Paths;
43874
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    32
import java.util.ArrayList;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    33
import java.util.Arrays;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    34
import java.util.List;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * Various utility methods for processing Java tool command line arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    39
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    40
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
public class CommandLine {
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
     * Process Win32-style command files for the specified command line
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
     * arguments and return the resulting arguments. A command file argument
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
     * is of the form '@file' where 'file' is the name of the file whose
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     * contents are to be parsed for additional arguments. The contents of
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     * the command file are parsed using StreamTokenizer and the original
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     * '@file' argument replaced with the resulting tokens. Recursive command
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
     * files are not supported. The '@' character itself can be quoted with
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * the sequence '@@'.
41438
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
    54
     * @param args the arguments that may contain @files
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
    55
     * @return the arguments, with @files expanded
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
    56
     * @throws IOException if there is a problem reading any of the @files
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     */
41438
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
    58
    public static String[] parse(String[] args) throws IOException {
43874
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    59
        List<String> newArgs = new ArrayList<>();
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    60
        appendParsedCommandArgs(newArgs, Arrays.asList(args));
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    61
        return newArgs.toArray(new String[newArgs.size()]);
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    62
    }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    63
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    64
    private static void appendParsedCommandArgs(List<String> newArgs, List<String> args) throws IOException {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 7681
diff changeset
    65
        for (String arg : args) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
            if (arg.length() > 1 && arg.charAt(0) == '@') {
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
                arg = arg.substring(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
                if (arg.charAt(0) == '@') {
43874
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    69
                    newArgs.add(arg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
                    loadCmdFile(arg, newArgs);
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
            } else {
43874
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    74
                newArgs.add(arg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
43874
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    79
    /**
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    80
     * Process the given environment variable and appends any Win32-style
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    81
     * command files for the specified command line arguments and return
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    82
     * the resulting arguments. A command file argument
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    83
     * is of the form '@file' where 'file' is the name of the file whose
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    84
     * contents are to be parsed for additional arguments. The contents of
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    85
     * the command file are parsed using StreamTokenizer and the original
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    86
     * '@file' argument replaced with the resulting tokens. Recursive command
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    87
     * files are not supported. The '@' character itself can be quoted with
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    88
     * the sequence '@@'.
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    89
     * @param envVariable the env variable to process
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    90
     * @param args the arguments that may contain @files
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    91
     * @return the arguments, with environment variable's content and expansion of @files
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    92
     * @throws IOException if there is a problem reading any of the @files
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    93
     * @throws com.sun.tools.javac.main.CommandLine.UnmatchedQuote
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    94
     */
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    95
    public static List<String> parse(String envVariable, List<String> args)
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    96
            throws IOException, UnmatchedQuote {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    97
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    98
        List<String> inArgs = new ArrayList<>();
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
    99
        appendParsedEnvVariables(inArgs, envVariable);
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   100
        inArgs.addAll(args);
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   101
        List<String> newArgs = new ArrayList<>();
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   102
        appendParsedCommandArgs(newArgs, inArgs);
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   103
        return newArgs;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   104
    }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   105
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   106
    /**
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   107
     * Process the given environment variable and appends any Win32-style
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   108
     * command files for the specified command line arguments and return
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   109
     * the resulting arguments. A command file argument
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   110
     * is of the form '@file' where 'file' is the name of the file whose
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   111
     * contents are to be parsed for additional arguments. The contents of
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   112
     * the command file are parsed using StreamTokenizer and the original
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   113
     * '@file' argument replaced with the resulting tokens. Recursive command
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   114
     * files are not supported. The '@' character itself can be quoted with
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   115
     * the sequence '@@'.
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   116
     * @param envVariable the env variable to process
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   117
     * @param args the arguments that may contain @files
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   118
     * @return the arguments, with environment variable's content and expansion of @files
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   119
     * @throws IOException if there is a problem reading any of the @files
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   120
     * @throws com.sun.tools.javac.main.CommandLine.UnmatchedQuote
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   121
     */
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   122
    public static String[] parse(String envVariable, String[] args) throws IOException, UnmatchedQuote {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   123
        List<String> out = parse(envVariable, Arrays.asList(args));
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   124
        return out.toArray(new String[out.size()]);
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   125
    }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   126
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   127
    private static void loadCmdFile(String name, List<String> args) throws IOException {
36157
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 25874
diff changeset
   128
        try (Reader r = Files.newBufferedReader(Paths.get(name))) {
41438
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   129
            Tokenizer t = new Tokenizer(r);
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   130
            String s;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   131
            while ((s = t.nextToken()) != null) {
43874
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   132
                args.add(s);
41438
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   133
            }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   134
        }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   135
    }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   136
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   137
    public static class Tokenizer {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   138
        private final Reader in;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   139
        private int ch;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   140
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   141
        public Tokenizer(Reader in) throws IOException {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   142
            this.in = in;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   143
            ch = in.read();
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   144
        }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   145
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   146
        public String nextToken() throws IOException {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   147
            skipWhite();
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   148
            if (ch == -1) {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   149
                return null;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   150
            }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   151
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   152
            StringBuilder sb = new StringBuilder();
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   153
            char quoteChar = 0;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   154
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   155
            while (ch != -1) {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   156
                switch (ch) {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   157
                    case ' ':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   158
                    case '\t':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   159
                    case '\f':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   160
                        if (quoteChar == 0) {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   161
                            return sb.toString();
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   162
                        }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   163
                        sb.append((char) ch);
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   164
                        break;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   165
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   166
                    case '\n':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   167
                    case '\r':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   168
                        return sb.toString();
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   169
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   170
                    case '\'':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   171
                    case '"':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   172
                        if (quoteChar == 0) {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   173
                            quoteChar = (char) ch;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   174
                        } else if (quoteChar == ch) {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   175
                            quoteChar = 0;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   176
                        } else {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   177
                            sb.append((char) ch);
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   178
                        }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   179
                        break;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   180
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   181
                    case '\\':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   182
                        if (quoteChar != 0) {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   183
                            ch = in.read();
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   184
                            switch (ch) {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   185
                                case '\n':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   186
                                case '\r':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   187
                                    while (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\f') {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   188
                                        ch = in.read();
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   189
                                    }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   190
                                    continue;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   191
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   192
                                case 'n':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   193
                                    ch = '\n';
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   194
                                    break;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   195
                                case 'r':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   196
                                    ch = '\r';
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   197
                                    break;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   198
                                case 't':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   199
                                    ch = '\t';
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   200
                                    break;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   201
                                case 'f':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   202
                                    ch = '\f';
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   203
                                    break;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   204
                            }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   205
                        }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   206
                        sb.append((char) ch);
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   207
                        break;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   208
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   209
                    default:
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   210
                        sb.append((char) ch);
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   211
                }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   212
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   213
                ch = in.read();
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   214
            }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   215
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   216
            return sb.toString();
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   217
        }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   218
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   219
        void skipWhite() throws IOException {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   220
            while (ch != -1) {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   221
                switch (ch) {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   222
                    case ' ':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   223
                    case '\t':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   224
                    case '\n':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   225
                    case '\r':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   226
                    case '\f':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   227
                        break;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   228
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   229
                    case '#':
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   230
                        ch = in.read();
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   231
                        while (ch != '\n' && ch != '\r' && ch != -1) {
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   232
                            ch = in.read();
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   233
                        }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   234
                        break;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   235
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   236
                    default:
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   237
                        return;
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   238
                }
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   239
5e21aa284a82 8166472: javac/javadoc expands @files incorrectly
jjg
parents: 36157
diff changeset
   240
                ch = in.read();
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 7681
diff changeset
   241
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
    }
43874
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   244
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   245
    @SuppressWarnings("fallthrough")
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   246
    private static void appendParsedEnvVariables(List<String> newArgs, String envVariable)
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   247
            throws UnmatchedQuote {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   248
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   249
        if (envVariable == null) {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   250
            return;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   251
        }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   252
        String in = System.getenv(envVariable);
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   253
        if (in == null || in.trim().isEmpty()) {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   254
            return;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   255
        }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   256
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   257
        final char NUL = (char)0;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   258
        final int len = in.length();
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   259
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   260
        int pos = 0;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   261
        StringBuilder sb = new StringBuilder();
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   262
        char quote = NUL;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   263
        char ch;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   264
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   265
        loop:
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   266
        while (pos < len) {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   267
            ch = in.charAt(pos);
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   268
            switch (ch) {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   269
                case '\"': case '\'':
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   270
                    if (quote == NUL) {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   271
                        quote = ch;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   272
                    } else if (quote == ch) {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   273
                        quote = NUL;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   274
                    } else {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   275
                        sb.append(ch);
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   276
                    }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   277
                    pos++;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   278
                    break;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   279
                case '\f': case '\n': case '\r': case '\t': case ' ':
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   280
                    if (quote == NUL) {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   281
                        newArgs.add(sb.toString());
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   282
                        sb.setLength(0);
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   283
                        while (ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' || ch == ' ') {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   284
                            pos++;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   285
                            if (pos >= len) {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   286
                                break loop;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   287
                            }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   288
                            ch = in.charAt(pos);
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   289
                        }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   290
                        break;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   291
                    }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   292
                    // fall through
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   293
                default:
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   294
                    sb.append(ch);
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   295
                    pos++;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   296
            }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   297
        }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   298
        if (sb.length() != 0) {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   299
            newArgs.add(sb.toString());
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   300
        }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   301
        if (quote != NUL) {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   302
            throw new UnmatchedQuote(envVariable);
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   303
        }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   304
    }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   305
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   306
    public static class UnmatchedQuote extends Exception {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   307
        private static final long serialVersionUID = 0;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   308
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   309
        public final String variableName;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   310
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   311
        UnmatchedQuote(String variable) {
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   312
            this.variableName = variable;
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   313
        }
d49715456f51 8173308: JAVAC_OPTIONS should be updated to align with JAVA_OPTIONS
ksrini
parents: 41438
diff changeset
   314
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
}