langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java
author mcimadamore
Mon, 31 Aug 2015 17:33:34 +0100
changeset 32454 b0ac04e0fefe
parent 31936 02f1cfc234a0
child 34480 124ac002c969
permissions -rw-r--r--
8129962: Investigate performance improvements in langtools combo tests Summary: New combo API that runs all combo instances in a shared javac context (whenever possible). Reviewed-by: jjg, jlahoda, vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     1
/*
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     4
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    10
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    15
 * accompanied this code).
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    16
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    20
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    23
 * questions.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    24
 */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    25
package com.sun.tools.javac.main;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    26
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    27
import java.io.File;
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    28
import java.io.IOException;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    29
import java.nio.file.Path;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    30
import java.util.Collection;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    31
import java.util.Collections;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    32
import java.util.Iterator;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    33
import java.util.LinkedHashMap;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    34
import java.util.LinkedHashSet;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    35
import java.util.Map;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    36
import java.util.Set;
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    37
import java.util.stream.Stream;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    38
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    39
import javax.tools.JavaFileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    40
import javax.tools.JavaFileObject;
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    41
import javax.tools.StandardJavaFileManager;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    42
import javax.tools.StandardLocation;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    43
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    44
import com.sun.tools.doclint.DocLint;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    45
import com.sun.tools.javac.code.Lint.LintCategory;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    46
import com.sun.tools.javac.code.Source;
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    47
import com.sun.tools.javac.file.BaseFileManager;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    48
import com.sun.tools.javac.file.JavacFileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    49
import com.sun.tools.javac.jvm.Profile;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    50
import com.sun.tools.javac.jvm.Target;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    51
import com.sun.tools.javac.main.OptionHelper.GrumpyHelper;
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    52
import com.sun.tools.javac.platform.PlatformDescription;
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 31506
diff changeset
    53
import com.sun.tools.javac.platform.PlatformUtils;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    54
import com.sun.tools.javac.util.Context;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    55
import com.sun.tools.javac.util.List;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    56
import com.sun.tools.javac.util.ListBuffer;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    57
import com.sun.tools.javac.util.Log;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    58
import com.sun.tools.javac.util.Log.PrefixKind;
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
    59
import com.sun.tools.javac.util.Log.WriterKind;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    60
import com.sun.tools.javac.util.Options;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    61
import com.sun.tools.javac.util.PropagatedException;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    62
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    63
/**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    64
 * Shared option and argument handling for command line and API usage of javac.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    65
 */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    66
public class Arguments {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    67
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    68
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    69
     * The context key for the arguments.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    70
     */
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 31936
diff changeset
    71
    public static final Context.Key<Arguments> argsKey = new Context.Key<>();
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    72
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    73
    private String ownName;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    74
    private Set<String> classNames;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    75
    private Set<File> files;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    76
    private Map<Option, String> deferredFileManagerOptions;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    77
    private Set<JavaFileObject> fileObjects;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    78
    private final Options options;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    79
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    80
    private JavaFileManager fileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    81
    private final Log log;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    82
    private final Context context;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    83
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    84
    private enum ErrorMode { ILLEGAL_ARGUMENT, ILLEGAL_STATE, LOG };
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    85
    private ErrorMode errorMode;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    86
    private boolean errors;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    87
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    88
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    89
     * Gets the Arguments instance for this context.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    90
     *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    91
     * @param context the content
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    92
     * @return the Arguments instance for this context.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    93
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    94
    public static Arguments instance(Context context) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    95
        Arguments instance = context.get(argsKey);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    96
        if (instance == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    97
            instance = new Arguments(context);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    98
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    99
        return instance;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   100
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   101
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   102
    protected Arguments(Context context) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   103
        context.put(argsKey, this);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   104
        options = Options.instance(context);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   105
        log = Log.instance(context);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   106
        this.context = context;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   107
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   108
        // Ideally, we could init this here and update/configure it as
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   109
        // needed, but right now, initializing a file manager triggers
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   110
        // initialization of other items in the context, such as Lint
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   111
        // and FSInfo, which should not be initialized until after
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   112
        // processArgs
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   113
        //        fileManager = context.get(JavaFileManager.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   114
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   115
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   116
    private final OptionHelper cmdLineHelper = new OptionHelper() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   117
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   118
        public String get(Option option) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   119
            return options.get(option);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   120
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   121
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   122
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   123
        public void put(String name, String value) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   124
            options.put(name, value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   125
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   126
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   127
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   128
        public void remove(String name) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   129
            options.remove(name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   130
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   131
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   132
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   133
        public boolean handleFileManagerOption(Option option, String value) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   134
            options.put(option.getText(), value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   135
            deferredFileManagerOptions.put(option, value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   136
            return true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   137
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   138
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   139
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   140
        public Log getLog() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   141
            return log;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   142
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   143
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   144
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   145
        public String getOwnName() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   146
            return ownName;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   147
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   148
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   149
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   150
        public void error(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   151
            Arguments.this.error(key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   152
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   153
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   154
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   155
        public void addFile(File f) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   156
            files.add(f);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   157
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   158
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   159
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   160
        public void addClassName(String s) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   161
            classNames.add(s);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   162
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   163
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   164
    };
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   165
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   166
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   167
     * Initializes this Args instance with a set of command line args.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   168
     * The args will be processed in conjunction with the full set of
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   169
     * command line options, including -help, -version etc.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   170
     * The args may also contain class names and filenames.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   171
     * Any errors during this call, and later during validate, will be reported
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   172
     * to the log.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   173
     * @param ownName the name of this tool; used to prefix messages
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   174
     * @param args the args to be processed
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   175
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   176
    public void init(String ownName, String... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   177
        this.ownName = ownName;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   178
        errorMode = ErrorMode.LOG;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   179
        files = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   180
        deferredFileManagerOptions = new LinkedHashMap<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   181
        fileObjects = null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   182
        classNames = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   183
        processArgs(List.from(args), Option.getJavaCompilerOptions(), cmdLineHelper, true, false);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   184
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   185
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   186
    private final OptionHelper apiHelper = new GrumpyHelper(null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   187
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   188
        public String get(Option option) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   189
            return options.get(option.getText());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   190
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   191
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   192
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   193
        public void put(String name, String value) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   194
            options.put(name, value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   195
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   196
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   197
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   198
        public void remove(String name) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   199
            options.remove(name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   200
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   201
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   202
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   203
        public void error(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   204
            Arguments.this.error(key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   205
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   206
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   207
        @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   208
        public Log getLog() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   209
            return Arguments.this.log;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   210
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   211
    };
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   212
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   213
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   214
     * Initializes this Args instance with the parameters for a JavacTask.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   215
     * The options will be processed in conjunction with the restricted set
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   216
     * of tool options, which does not include -help, -version, etc,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   217
     * nor does it include classes and filenames, which should be specified
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   218
     * separately.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   219
     * File manager options are handled directly by the file manager.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   220
     * Any errors found while processing individual args will be reported
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   221
     * via IllegalArgumentException.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   222
     * Any subsequent errors during validate will be reported via IllegalStateException.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   223
     * @param ownName the name of this tool; used to prefix messages
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   224
     * @param options the options to be processed
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   225
     * @param classNames the classes to be subject to annotation processing
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   226
     * @param files the files to be compiled
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   227
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   228
    public void init(String ownName,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   229
            Iterable<String> options,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   230
            Iterable<String> classNames,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   231
            Iterable<? extends JavaFileObject> files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   232
        this.ownName = ownName;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   233
        this.classNames = toSet(classNames);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   234
        this.fileObjects = toSet(files);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   235
        this.files = null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   236
        errorMode = ErrorMode.ILLEGAL_ARGUMENT;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   237
        if (options != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   238
            processArgs(toList(options), Option.getJavacToolOptions(), apiHelper, false, true);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   239
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   240
        errorMode = ErrorMode.ILLEGAL_STATE;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   241
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   242
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   243
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   244
     * Gets the files to be compiled.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   245
     * @return the files to be compiled
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   246
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   247
    public Set<JavaFileObject> getFileObjects() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   248
        if (fileObjects == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   249
            if (files == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   250
                fileObjects = Collections.emptySet();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   251
            } else {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   252
                fileObjects = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   253
                JavacFileManager jfm = (JavacFileManager) getFileManager();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   254
                for (JavaFileObject fo: jfm.getJavaFileObjectsFromFiles(files))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   255
                    fileObjects.add(fo);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   256
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   257
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   258
        return fileObjects;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   259
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   260
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   261
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   262
     * Gets the classes to be subject to annotation processing.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   263
     * @return the classes to be subject to annotation processing
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   264
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   265
    public Set<String> getClassNames() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   266
        return classNames;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   267
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   268
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   269
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   270
     * Processes strings containing options and operands.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   271
     * @param args the strings to be processed
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   272
     * @param allowableOpts the set of option declarations that are applicable
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   273
     * @param helper a help for use by Option.process
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   274
     * @param allowOperands whether or not to check for files and classes
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   275
     * @param checkFileManager whether or not to check if the file manager can handle
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   276
     *      options which are not recognized by any of allowableOpts
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   277
     * @return true if all the strings were successfully processed; false otherwise
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   278
     * @throws IllegalArgumentException if a problem occurs and errorMode is set to
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   279
     *      ILLEGAL_ARGUMENT
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   280
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   281
    private boolean processArgs(Iterable<String> args,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   282
            Set<Option> allowableOpts, OptionHelper helper,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   283
            boolean allowOperands, boolean checkFileManager) {
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   284
        if (!doProcessArgs(args, allowableOpts, helper, allowOperands, checkFileManager))
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   285
            return false;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   286
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   287
        String platformString = options.get(Option.RELEASE);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   288
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   289
        checkOptionAllowed(platformString == null,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   290
                option -> error("err.release.bootclasspath.conflict", option.getText()),
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   291
                Option.BOOTCLASSPATH, Option.XBOOTCLASSPATH, Option.XBOOTCLASSPATH_APPEND,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   292
                Option.XBOOTCLASSPATH_PREPEND, Option.ENDORSEDDIRS, Option.EXTDIRS, Option.SOURCE,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   293
                Option.TARGET);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   294
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   295
        if (platformString != null) {
31936
02f1cfc234a0 8086737: Add support for -release to Javadoc
jlahoda
parents: 31506
diff changeset
   296
            PlatformDescription platformDescription = PlatformUtils.lookupPlatformDescription(platformString);
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   297
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   298
            if (platformDescription == null) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   299
                error("err.unsupported.release.version", platformString);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   300
                return false;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   301
            }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   302
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   303
            options.put(Option.SOURCE, platformDescription.getSourceVersion());
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   304
            options.put(Option.TARGET, platformDescription.getTargetVersion());
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   305
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   306
            context.put(PlatformDescription.class, platformDescription);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   307
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   308
            if (!doProcessArgs(platformDescription.getAdditionalOptions(), allowableOpts, helper, allowOperands, checkFileManager))
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   309
                return false;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   310
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   311
            Collection<Path> platformCP = platformDescription.getPlatformPath();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   312
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   313
            if (platformCP != null) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   314
                JavaFileManager fm = getFileManager();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   315
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   316
                if (!(fm instanceof StandardJavaFileManager)) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   317
                    error("err.release.not.standard.file.manager");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   318
                    return false;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   319
                }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   320
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   321
                try {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   322
                    StandardJavaFileManager sfm = (StandardJavaFileManager) fm;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   323
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   324
                    sfm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, platformCP);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   325
                } catch (IOException ex) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   326
                    log.printLines(PrefixKind.JAVAC, "msg.io");
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   327
                    ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   328
                    return false;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   329
                }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   330
            }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   331
        }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   332
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   333
        options.notifyListeners();
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   334
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   335
        return true;
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   336
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   337
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   338
    private boolean doProcessArgs(Iterable<String> args,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   339
            Set<Option> allowableOpts, OptionHelper helper,
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   340
            boolean allowOperands, boolean checkFileManager) {
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   341
        JavaFileManager fm = checkFileManager ? getFileManager() : null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   342
        Iterator<String> argIter = args.iterator();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   343
        while (argIter.hasNext()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   344
            String arg = argIter.next();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   345
            if (arg.isEmpty()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   346
                error("err.invalid.flag", arg);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   347
                return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   348
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   349
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   350
            Option option = null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   351
            if (arg.startsWith("-")) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   352
                for (Option o : allowableOpts) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   353
                    if (o.matches(arg)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   354
                        option = o;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   355
                        break;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   356
                    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   357
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   358
            } else if (allowOperands && Option.SOURCEFILE.matches(arg)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   359
                option = Option.SOURCEFILE;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   360
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   361
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   362
            if (option == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   363
                if (fm != null && fm.handleOption(arg, argIter)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   364
                    continue;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   365
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   366
                error("err.invalid.flag", arg);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   367
                return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   368
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   369
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   370
            if (option.hasArg()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   371
                if (!argIter.hasNext()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   372
                    error("err.req.arg", arg);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   373
                    return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   374
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   375
                String operand = argIter.next();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   376
                if (option.process(helper, arg, operand)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   377
                    return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   378
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   379
            } else {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   380
                if (option.process(helper, arg)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   381
                    return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   382
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   383
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   384
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   385
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   386
        return true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   387
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   388
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   389
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   390
     * Validates the overall consistency of the options and operands
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   391
     * processed by processOptions.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   392
     * @return true if all args are successfully validating; false otherwise.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   393
     * @throws IllegalStateException if a problem is found and errorMode is set to
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   394
     *      ILLEGAL_STATE
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   395
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   396
    public boolean validate() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   397
        if (isEmpty()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   398
            // It is allowed to compile nothing if just asking for help or version info.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   399
            // But also note that none of these options are supported in API mode.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   400
            if (options.isSet(Option.HELP)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   401
                || options.isSet(Option.X)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   402
                || options.isSet(Option.VERSION)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   403
                || options.isSet(Option.FULLVERSION))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   404
                return true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   405
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   406
            if (JavaCompiler.explicitAnnotationProcessingRequested(options)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   407
                error("err.no.source.files.classes");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   408
            } else {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   409
                error("err.no.source.files");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   410
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   411
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   412
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   413
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   414
        if (!checkDirectory(Option.D)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   415
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   416
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   417
        if (!checkDirectory(Option.S)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   418
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   419
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   420
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   421
        String sourceString = options.get(Option.SOURCE);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   422
        Source source = (sourceString != null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   423
                ? Source.lookup(sourceString)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   424
                : Source.DEFAULT;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   425
        String targetString = options.get(Option.TARGET);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   426
        Target target = (targetString != null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   427
                ? Target.lookup(targetString)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   428
                : Target.DEFAULT;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   429
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   430
        // We don't check source/target consistency for CLDC, as J2ME
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   431
        // profiles are not aligned with J2SE targets; moreover, a
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   432
        // single CLDC target may have many profiles.  In addition,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   433
        // this is needed for the continued functioning of the JSR14
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   434
        // prototype.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   435
        if (Character.isDigit(target.name.charAt(0))) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   436
            if (target.compareTo(source.requiredTarget()) < 0) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   437
                if (targetString != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   438
                    if (sourceString == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   439
                        error("warn.target.default.source.conflict",
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   440
                                targetString,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   441
                                source.requiredTarget().name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   442
                    } else {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   443
                        error("warn.source.target.conflict",
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   444
                                sourceString,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   445
                                source.requiredTarget().name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   446
                    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   447
                    return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   448
                } else {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   449
                    target = source.requiredTarget();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   450
                    options.put("-target", target.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   451
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   452
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   453
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   454
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   455
        String profileString = options.get(Option.PROFILE);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   456
        if (profileString != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   457
            Profile profile = Profile.lookup(profileString);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   458
            if (!profile.isValid(target)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   459
                error("warn.profile.target.conflict", profileString, target.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   460
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   461
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   462
            // This check is only effective in command line mode,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   463
            // where the file manager options are added to options
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   464
            if (options.get(Option.BOOTCLASSPATH) != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   465
                error("err.profile.bootclasspath.conflict");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   466
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   467
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   468
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   469
        boolean lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   470
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   471
        if (lintOptions && source.compareTo(Source.DEFAULT) < 0 && !options.isSet(Option.RELEASE)) {
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   472
            JavaFileManager fm = getFileManager();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   473
            if (fm instanceof BaseFileManager) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   474
                if (((BaseFileManager) fm).isDefaultBootClassPath())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   475
                    log.warning(LintCategory.OPTIONS, "source.no.bootclasspath", source.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   476
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   477
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   478
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   479
        boolean obsoleteOptionFound = false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   480
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   481
        if (source.compareTo(Source.MIN) < 0) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   482
            log.error("option.removed.source", source.name, Source.MIN.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   483
        } else if (source == Source.MIN && lintOptions) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   484
            log.warning(LintCategory.OPTIONS, "option.obsolete.source", source.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   485
            obsoleteOptionFound = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   486
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   487
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   488
        if (target.compareTo(Target.MIN) < 0) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   489
            log.error("option.removed.target", target.name, Target.MIN.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   490
        } else if (target == Target.MIN && lintOptions) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   491
            log.warning(LintCategory.OPTIONS, "option.obsolete.target", target.name);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   492
            obsoleteOptionFound = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   493
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   494
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   495
        if (obsoleteOptionFound)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   496
            log.warning(LintCategory.OPTIONS, "option.obsolete.suppression");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   497
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   498
        return !errors;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   499
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   500
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   501
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   502
     * Returns true if there are no files or classes specified for use.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   503
     * @return true if there are no files or classes specified for use
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   504
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   505
    public boolean isEmpty() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   506
        return ((files == null) || files.isEmpty())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   507
                && ((fileObjects == null) || fileObjects.isEmpty())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   508
                && classNames.isEmpty();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   509
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   510
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   511
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   512
     * Gets the file manager options which may have been deferred
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   513
     * during processArgs.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   514
     * @return the deferred file manager options
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   515
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   516
    public Map<Option, String> getDeferredFileManagerOptions() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   517
        return deferredFileManagerOptions;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   518
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   519
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   520
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   521
     * Gets any options specifying plugins to be run.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   522
     * @return options for plugins
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   523
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   524
    public Set<List<String>> getPluginOpts() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   525
        String plugins = options.get(Option.PLUGIN);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   526
        if (plugins == null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   527
            return Collections.emptySet();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   528
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   529
        Set<List<String>> pluginOpts = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   530
        for (String plugin: plugins.split("\\x00")) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   531
            pluginOpts.add(List.from(plugin.split("\\s+")));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   532
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   533
        return Collections.unmodifiableSet(pluginOpts);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   534
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   535
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   536
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   537
     * Gets any options specifying how doclint should be run.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   538
     * An empty list is returned if no doclint options are specified
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   539
     * or if the only doclint option is -Xdoclint:none.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   540
     * @return options for doclint
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   541
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   542
    public List<String> getDocLintOpts() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   543
        String xdoclint = options.get(Option.XDOCLINT);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   544
        String xdoclintCustom = options.get(Option.XDOCLINT_CUSTOM);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   545
        if (xdoclint == null && xdoclintCustom == null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   546
            return List.nil();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   547
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   548
        Set<String> doclintOpts = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   549
        if (xdoclint != null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   550
            doclintOpts.add(DocLint.XMSGS_OPTION);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   551
        if (xdoclintCustom != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   552
            for (String s: xdoclintCustom.split("\\s+")) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   553
                if (s.isEmpty())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   554
                    continue;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   555
                doclintOpts.add(s.replace(Option.XDOCLINT_CUSTOM.text, DocLint.XMSGS_CUSTOM_PREFIX));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   556
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   557
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   558
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   559
        if (doclintOpts.equals(Collections.singleton(DocLint.XMSGS_CUSTOM_PREFIX + "none")))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   560
            return List.nil();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   561
29427
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   562
        String checkPackages = options.get(Option.XDOCLINT_PACKAGE);
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   563
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   564
        if (checkPackages != null) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   565
            for (String s : checkPackages.split("\\s+")) {
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   566
                doclintOpts.add(s.replace(Option.XDOCLINT_PACKAGE.text, DocLint.XCHECK_PACKAGE));
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   567
            }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   568
        }
44f4e6905b67 8071851: Provide filtering of doclint checking based on packages
jlahoda
parents: 26264
diff changeset
   569
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   570
        // standard doclet normally generates H1, H2,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   571
        // so for now, allow user comments to assume that
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   572
        doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   573
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   574
        return List.from(doclintOpts.toArray(new String[doclintOpts.size()]));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   575
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   576
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   577
    private boolean checkDirectory(Option option) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   578
        String value = options.get(option);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   579
        if (value == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   580
            return true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   581
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   582
        File file = new File(value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   583
        if (!file.exists()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   584
            error("err.dir.not.found", value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   585
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   586
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   587
        if (!file.isDirectory()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   588
            error("err.file.not.directory", value);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   589
            return false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   590
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   591
        return true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   592
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   593
31506
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   594
    private interface ErrorReporter {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   595
        void report(Option o);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   596
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   597
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   598
    void checkOptionAllowed(boolean allowed, ErrorReporter r, Option... opts) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   599
        if (!allowed) {
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   600
            Stream.of(opts)
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   601
                  .filter(options :: isSet)
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   602
                  .forEach(r :: report);
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   603
        }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   604
    }
4e07f827a794 8072480: javac should support compilation for a specific platform version
jlahoda
parents: 29780
diff changeset
   605
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   606
    void error(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   607
        errors = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   608
        switch (errorMode) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   609
            case ILLEGAL_ARGUMENT: {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   610
                String msg = log.localize(PrefixKind.JAVAC, key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   611
                throw new PropagatedException(new IllegalArgumentException(msg));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   612
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   613
            case ILLEGAL_STATE: {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   614
                String msg = log.localize(PrefixKind.JAVAC, key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   615
                throw new PropagatedException(new IllegalStateException(msg));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   616
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   617
            case LOG:
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   618
                report(key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   619
                log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   620
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   621
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   622
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   623
    void warning(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   624
        report(key, args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   625
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   626
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   627
    private void report(String key, Object... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   628
        log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   629
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   630
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   631
    private JavaFileManager getFileManager() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   632
        if (fileManager == null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   633
            fileManager = context.get(JavaFileManager.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   634
        return fileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   635
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   636
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   637
    <T> ListBuffer<T> toList(Iterable<? extends T> items) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   638
        ListBuffer<T> list = new ListBuffer<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   639
        if (items != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   640
            for (T item : items) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   641
                list.add(item);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   642
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   643
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   644
        return list;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   645
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   646
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   647
    <T> Set<T> toSet(Iterable<? extends T> items) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   648
        Set<T> set = new LinkedHashSet<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   649
        if (items != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   650
            for (T item : items) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   651
                set.add(item);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   652
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   653
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   654
        return set;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   655
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   656
}