langtools/src/share/classes/com/sun/tools/sjavac/options/Option.java
author alundblad
Tue, 22 Apr 2014 16:51:10 +0200
changeset 24067 76e7b6bbbd85
child 26088 f479ca655ba1
permissions -rw-r--r--
8035063: Option handling in sjavac needs to be rewritten Summary: Option handling code rewritten. Exclusion / inclusion patterns changed from package to directories. Reviewed-by: jjg, jfranck
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24067
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     1
/*
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     4
 *
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    10
 *
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    15
 * accompanied this code).
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    16
 *
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    20
 *
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    23
 * questions.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    24
 */
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    25
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    26
package com.sun.tools.sjavac.options;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    27
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    28
import java.io.File;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    29
import java.nio.file.Path;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    30
import java.nio.file.Paths;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    31
import java.util.ArrayList;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    32
import java.util.List;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    33
import java.util.regex.Matcher;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    34
import java.util.regex.Pattern;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    35
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    36
import com.sun.tools.sjavac.CopyFile;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    37
import com.sun.tools.sjavac.Transformer;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    38
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    39
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    40
/**
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    41
 * Sjavac options can be classified as:
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    42
 *
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    43
 *  (1) relevant only for sjavac, such as --server
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    44
 *  (2) relevant for sjavac and javac, such as -d, or
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    45
 *  (3) relevant only for javac, such as -g.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    46
 *
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    47
 * This enum represents all options from (1) and (2). Note that instances of
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    48
 * this enum only entail static information about the option. For storage of
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    49
 * option values, refer to com.sun.tools.sjavac.options.Options.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    50
 */
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    51
public enum Option {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    52
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    53
    SRC("-src", "Location of source files to be compiled") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    54
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    55
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    56
            List<Path> paths = getFileListArg(iter, helper);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    57
            if (paths != null)
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    58
                helper.sourceRoots(paths);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    59
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    60
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    61
    SOURCEPATH("-sourcepath", "Specify search path for sources.") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    62
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    63
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    64
            List<Path> paths = getFileListArg(iter, helper);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    65
            if (paths != null)
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    66
                helper.sourcepath(paths);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    67
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    68
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    69
    MODULEPATH("-modulepath", "Specify search path for modules.") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    70
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    71
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    72
            List<Path> paths = getFileListArg(iter, helper);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    73
            if (paths != null)
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    74
                helper.modulepath(paths);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    75
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    76
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    77
    CLASSPATH("-classpath", "Specify search path for classes.") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    78
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    79
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    80
            List<Path> paths = getFileListArg(iter, helper);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    81
            if (paths != null)
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    82
                helper.classpath(paths);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    83
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    84
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    85
    CP("-cp", "An alias for -classpath") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    86
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    87
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    88
            CLASSPATH.processMatching(iter, helper);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    89
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    90
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    91
    X("-x", "Exclude directory from the subsequent source directory") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    92
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    93
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    94
            String pattern = getFilePatternArg(iter, helper);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    95
            if (pattern != null)
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    96
                helper.exclude(pattern);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    97
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    98
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
    99
    I("-i", "Include only the given directory from the subsequent source directory") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   100
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   101
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   102
            String pattern = getFilePatternArg(iter, helper);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   103
            if (pattern != null)
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   104
                helper.include(pattern);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   105
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   106
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   107
    XF("-xf", "Exclude a given file") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   108
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   109
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   110
            String pattern = getFilePatternArg(iter, helper);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   111
            if (pattern != null)
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   112
                helper.excludeFile(pattern);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   113
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   114
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   115
    IF("-if", "Include only the given file") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   116
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   117
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   118
            String pattern = getFilePatternArg(iter, helper);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   119
            if (pattern != null)
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   120
                helper.includeFile(pattern);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   121
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   122
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   123
    TR("-tr", "Translate resources") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   124
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   125
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   126
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   127
            if (!iter.hasNext()) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   128
                helper.reportError(arg + " must be followed by a translation rule");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   129
                return;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   130
            }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   131
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   132
            String trArg = iter.next();
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   133
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   134
            // Validate argument syntax. Examples:
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   135
            //   .prop=com.sun.tools.javac.smart.CompileProperties
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   136
            //   .idl=com.sun.corba.CompileIdl
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   137
            //   .g3=antlr.CompileGrammar,debug=true
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   138
            String ident = "[a-zA-Z_][a-zA-Z0-9_]*";
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   139
            Pattern p = Pattern.compile("(?<suffix>\\." + ident + ")=" +
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   140
                                        "(?<class>" + ident + "(\\." + ident + ")*)" +
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   141
                                        "(?<extra>,.*)?");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   142
            // Check syntax
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   143
            Matcher m = p.matcher(trArg);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   144
            if (!m.matches()) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   145
                helper.reportError("The string \"" + trArg + "\" is not a " +
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   146
                                   "valid translate pattern");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   147
                return;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   148
            }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   149
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   150
            // Extract relevant parts
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   151
            String suffix = m.group("suffix");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   152
            String classname = m.group("class");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   153
            String extra = m.group("extra");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   154
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   155
            // Valid suffix?
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   156
            if (suffix.matches("\\.(class|java)")) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   157
                helper.reportError("You cannot have a translator for " +
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   158
                                   suffix + " files!");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   159
                return;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   160
            }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   161
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   162
            // Construct transformer
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   163
            try {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   164
                Class<?> trCls = Class.forName(classname);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   165
                Transformer transformer = (Transformer) trCls.newInstance();
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   166
                transformer.setExtra(extra);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   167
                helper.addTransformer(suffix, transformer);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   168
            } catch (Exception e) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   169
                helper.reportError("Cannot use " + classname +
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   170
                                   " as a translator: " + e.getMessage());
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   171
            }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   172
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   173
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   174
    COPY("-copy", "Copy resources") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   175
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   176
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   177
            if (!iter.hasNext()) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   178
                helper.reportError(arg + " must be followed by a resource type");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   179
                return;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   180
            }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   181
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   182
            String copyArg = iter.next();
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   183
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   184
            // Validate argument syntax. Examples: .gif, .html
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   185
            if (!copyArg.matches("\\.[a-zA-Z_][a-zA-Z0-9_]*")) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   186
                helper.reportError("The string \"" + copyArg + "\" is not a " +
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   187
                                   "valid resource type.");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   188
                return;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   189
            }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   190
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   191
            helper.addTransformer(copyArg, new CopyFile());
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   192
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   193
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   194
    J("-j", "Number of cores") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   195
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   196
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   197
            if (!iter.hasNext() || !iter.peek().matches("\\d+")) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   198
                helper.reportError(arg + " must be followed by an integer");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   199
                return;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   200
            }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   201
            helper.numCores(Integer.parseInt(iter.next()));
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   202
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   203
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   204
    SERVER("--server:", "Specify server configuration file of running server") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   205
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   206
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   207
            helper.serverConf(iter.current().substring(arg.length()));
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   208
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   209
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   210
    STARTSERVER("--startserver:", "Start server and use the given configuration file") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   211
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   212
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   213
            helper.startServerConf(iter.current().substring(arg.length()));
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   214
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   215
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   216
    IMPLICIT("-implicit:", "Specify how to treat implicitly referenced source code") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   217
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   218
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   219
            helper.implicit(iter.current().substring(arg.length()));
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   220
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   221
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   222
    LOG("--log=", "Specify logging level") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   223
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   224
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   225
            helper.logLevel(iter.current().substring(arg.length()));
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   226
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   227
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   228
    VERBOSE("-verbose", "Set verbosity level to \"info\"") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   229
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   230
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   231
            helper.logLevel("info");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   232
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   233
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   234
    PERMIT_UNIDENTIFIED_ARTIFACTS("--permit-unidentified-artifacts", "Keep unidentified artifacts in destination directory") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   235
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   236
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   237
            helper.permitUnidentifiedArtifacts();
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   238
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   239
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   240
    PERMIT_SOURCES_WITHOUT_PACKAGE("--permit-sources-without-package", "Permit sources in the default package") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   241
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   242
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   243
            helper.permitDefaultPackage();
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   244
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   245
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   246
    COMPARE_FOUND_SOURCES("--compare-found-sources", "Compare found sources with given sources") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   247
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   248
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   249
            Path referenceSourceList = getFileArg(iter, helper, true, false);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   250
            if (referenceSourceList != null)
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   251
                helper.compareFoundSources(referenceSourceList);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   252
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   253
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   254
    D("-d", "Output destination directory") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   255
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   256
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   257
            Path dir = getFileArg(iter, helper, false, true);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   258
            if (dir != null)
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   259
                helper.destDir(dir);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   260
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   261
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   262
    S("-s", "Directory for generated sources") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   263
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   264
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   265
            Path dir = getFileArg(iter, helper, false, true);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   266
            if (dir != null)
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   267
                helper.generatedSourcesDir(dir);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   268
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   269
    },
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   270
    H("-h", "Directory for header files") {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   271
        @Override
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   272
        protected void processMatching(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   273
            Path dir = getFileArg(iter, helper, false, true);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   274
            if (dir != null)
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   275
                helper.headerDir(dir);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   276
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   277
    };
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   278
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   279
    public final String arg;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   280
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   281
    final String description;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   282
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   283
    private Option(String arg, String description) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   284
        this.arg = arg;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   285
        this.description = description;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   286
    }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   287
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   288
    /** Retrieve and verify syntax of file list argument. */
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   289
    List<Path> getFileListArg(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   290
        if (!iter.hasNext()) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   291
            helper.reportError(arg + " must be followed by a list of files " +
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   292
                              "separated by " + File.pathSeparator);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   293
            return null;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   294
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   295
        List<Path> result = new ArrayList<>();
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   296
        for (String pathStr : iter.next().split(File.pathSeparator))
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   297
            result.add(Paths.get(pathStr));
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   298
        return result;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   299
    }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   300
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   301
    /** Retrieve and verify syntax of file argument. */
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   302
    Path getFileArg(ArgumentIterator iter, OptionHelper helper, boolean fileAcceptable, boolean dirAcceptable) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   303
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   304
        if (!iter.hasNext()) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   305
            String errmsg = arg + " must be followed by ";
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   306
            if (fileAcceptable && dirAcceptable) errmsg += "a file or directory.";
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   307
            else if (fileAcceptable) errmsg += "a file.";
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   308
            else if (dirAcceptable)  errmsg += "a directory.";
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   309
            else throw new IllegalArgumentException("File or directory must be acceptable.");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   310
            helper.reportError(errmsg);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   311
            return null;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   312
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   313
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   314
        return Paths.get(iter.next());
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   315
    }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   316
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   317
    /** Retrieve the next file or package argument. */
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   318
    String getFilePatternArg(ArgumentIterator iter, OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   319
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   320
        if (!iter.hasNext()) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   321
            helper.reportError(arg + " must be followed by a file or directory pattern.");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   322
            return null;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   323
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   324
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   325
        return iter.next();
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   326
    }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   327
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   328
    // Future cleanup: Change the "=" syntax to ":" syntax to be consistent and
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   329
    // to follow the javac-option style.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   330
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   331
    public boolean hasOption() {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   332
        return arg.endsWith(":") || arg.endsWith("=");
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   333
    }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   334
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   335
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   336
    /**
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   337
     * Process current argument of argIter.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   338
     *
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   339
     * It's final, since the option customization is typically done in
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   340
     * processMatching.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   341
     *
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   342
     * @param argIter Iterator to read current and succeeding arguments from.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   343
     * @param helper The helper to report back to.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   344
     * @return true iff the argument was processed by this option.
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   345
     */
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   346
    public final boolean processCurrent(ArgumentIterator argIter,
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   347
                                        OptionHelper helper) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   348
        String fullArg = argIter.current(); // "-tr" or "-log=level"
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   349
        if (hasOption() ? fullArg.startsWith(arg) : fullArg.equals(arg)) {
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   350
            processMatching(argIter, helper);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   351
            return true;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   352
        }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   353
        // Did not match
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   354
        return false;
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   355
    }
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   356
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   357
    /** Called by process if the current argument matches this option. */
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   358
    protected abstract void processMatching(ArgumentIterator argIter,
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   359
                                            OptionHelper helper);
76e7b6bbbd85 8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff changeset
   360
}