langtools/src/share/classes/com/sun/tools/javac/main/Main.java
author jjg
Wed, 03 Sep 2008 10:46:25 -0700
changeset 1208 5072b0dd3d52
parent 735 372aa565a221
child 1471 57506cdfb7b4
permissions -rw-r--r--
6743107: clean up use of static caches in file manager Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
735
372aa565a221 6719955: Update copyright year
xdono
parents: 731
diff changeset
     2
 * Copyright 1999-2008 Sun Microsystems, Inc.  All Rights Reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.main;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.File;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.io.PrintWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.MissingResourceException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.code.Source;
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
    34
import com.sun.tools.javac.file.CacheFSInfo;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 10
diff changeset
    35
import com.sun.tools.javac.file.JavacFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.tools.javac.jvm.Target;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.main.JavacOption.Option;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.javac.main.RecognizedOptions.OptionHelper;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.processing.AnnotationProcessingError;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import javax.tools.JavaFileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import javax.annotation.processing.Processor;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
/** This class provides a commandline interface to the GJC compiler.
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *  you write code that depends on this, you do so at your own risk.
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
public class Main {
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /** The name of the compiler, for use in diagnostics.
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    String ownName;
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /** The writer to use for diagnostic output.
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    PrintWriter out;
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * If true, any command line arg errors will cause an exception.
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    boolean fatalErrors;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    /** Result codes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    static final int
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        EXIT_OK = 0,        // Compilation completed with no errors.
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        EXIT_ERROR = 1,     // Completed but reported errors.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        EXIT_CMDERR = 2,    // Bad command-line arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        EXIT_SYSERR = 3,    // System error or resource exhaustion.
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        EXIT_ABNORMAL = 4;  // Compiler terminated abnormally
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    private Option[] recognizedOptions = RecognizedOptions.getJavaCompilerOptions(new OptionHelper() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        public void setOut(PrintWriter out) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
            Main.this.out = out;
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        public void error(String key, Object... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
            Main.this.error(key, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        public void printVersion() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
            Log.printLines(out, getLocalizedString("version", ownName,  JavaCompiler.version()));
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        public void printFullVersion() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
            Log.printLines(out, getLocalizedString("fullVersion", ownName,  JavaCompiler.fullVersion()));
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        public void printHelp() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
            help();
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        public void printXhelp() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
            xhelp();
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        public void addFile(File f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            if (!filenames.contains(f))
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
                filenames.append(f);
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        public void addClassName(String s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
            classnames.append(s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    });
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     * Construct a compiler instance.
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    public Main(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        this(name, new PrintWriter(System.err, true));
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     * Construct a compiler instance.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    public Main(String name, PrintWriter out) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        this.ownName = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        this.out = out;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    /** A table of all options that's passed to the JavaCompiler constructor.  */
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    private Options options = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    /** The list of source files to process
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    public ListBuffer<File> filenames = null; // XXX sb protected
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    /** List of class files names passed on the command line
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    public ListBuffer<String> classnames = null; // XXX sb protected
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    /** Print a string that explains usage.
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    void help() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        Log.printLines(out, getLocalizedString("msg.usage.header", ownName));
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        for (int i=0; i<recognizedOptions.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            recognizedOptions[i].help(out);
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    /** Print a string that explains usage for X options.
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    void xhelp() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        for (int i=0; i<recognizedOptions.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
            recognizedOptions[i].xhelp(out);
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        Log.printLines(out, getLocalizedString("msg.usage.nonstandard.footer"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    /** Report a usage error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    void error(String key, Object... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        if (fatalErrors) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
            String msg = getLocalizedString(key, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
            throw new PropagatedException(new IllegalStateException(msg));
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        warning(key, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        Log.printLines(out, getLocalizedString("msg.usage", ownName));
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    /** Report a warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    void warning(String key, Object... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        Log.printLines(out, ownName + ": "
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
                       + getLocalizedString(key, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    public Option getOption(String flag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        for (Option option : recognizedOptions) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            if (option.matches(flag))
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
                return option;
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    public void setOptions(Options options) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        if (options == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
            throw new NullPointerException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        this.options = options;
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    public void setFatalErrors(boolean fatalErrors) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        this.fatalErrors = fatalErrors;
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    /** Process command line arguments: store all command line options
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     *  in `options' table and return all source filenames.
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     *  @param flags    The array of command line arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    public List<File> processArgs(String[] flags) { // XXX sb protected
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        int ac = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        while (ac < flags.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
            String flag = flags[ac];
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
            ac++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
            Option option = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
            if (flag.length() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
                // quick hack to speed up file processing:
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
                // if the option does not begin with '-', there is no need to check
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
                // most of the compiler options.
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
                int firstOptionToCheck = flag.charAt(0) == '-' ? 0 : recognizedOptions.length-1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
                for (int j=firstOptionToCheck; j<recognizedOptions.length; j++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
                    if (recognizedOptions[j].matches(flag)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
                        option = recognizedOptions[j];
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
            if (option == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
                error("err.invalid.flag", flag);
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
            if (option.hasArg()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
                if (ac == flags.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
                    error("err.req.arg", flag);
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
                    return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
                String operand = flags[ac];
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
                ac++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
                if (option.process(options, flag, operand))
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
                    return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
                if (option.process(options, flag))
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
                    return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        if (!checkDirectory("-d"))
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        if (!checkDirectory("-s"))
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        String sourceString = options.get("-source");
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        Source source = (sourceString != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
            ? Source.lookup(sourceString)
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
            : Source.DEFAULT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        String targetString = options.get("-target");
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        Target target = (targetString != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            ? Target.lookup(targetString)
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            : Target.DEFAULT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        // We don't check source/target consistency for CLDC, as J2ME
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        // profiles are not aligned with J2SE targets; moreover, a
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        // single CLDC target may have many profiles.  In addition,
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        // this is needed for the continued functioning of the JSR14
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        // prototype.
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
        if (Character.isDigit(target.name.charAt(0))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
            if (target.compareTo(source.requiredTarget()) < 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                if (targetString != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                    if (sourceString == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                        warning("warn.target.default.source.conflict",
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
                                targetString,
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                                source.requiredTarget().name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
                        warning("warn.source.target.conflict",
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
                                sourceString,
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
                                source.requiredTarget().name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
                    return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
                    options.put("-target", source.requiredTarget().name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
                if (targetString == null && !source.allowGenerics()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
                    options.put("-target", Target.JDK1_4.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        return filenames.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
    // where
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        private boolean checkDirectory(String optName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
            String value = options.get(optName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
            if (value == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
            File file = new File(value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            if (!file.exists()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
                error("err.dir.not.found", value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
            if (!file.isDirectory()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
                error("err.file.not.directory", value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    /** Programmatic interface for main function.
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
     * @param args    The command line parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
    public int compile(String[] args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        Context context = new Context();
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        JavacFileManager.preRegister(context); // can't create it until Log has been set up
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        int result = compile(args, context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        if (fileManager instanceof JavacFileManager) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            // A fresh context was created above, so jfm must be a JavacFileManager
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
            ((JavacFileManager)fileManager).close();
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
    public int compile(String[] args, Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        return compile(args, context, List.<JavaFileObject>nil(), null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    /** Programmatic interface for main function.
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
     * @param args    The command line parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    public int compile(String[] args,
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
                       Context context,
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
                       List<JavaFileObject> fileObjects,
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
                       Iterable<? extends Processor> processors)
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        if (options == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
            options = Options.instance(context); // creates a new one
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
        filenames = new ListBuffer<File>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
        classnames = new ListBuffer<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        JavaCompiler comp = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
         * TODO: Logic below about what is an acceptable command line
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
         * should be updated to take annotation processing semantics
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
         * into account.
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
            if (args.length == 0 && fileObjects.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
                help();
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
                return EXIT_CMDERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
            List<File> filenames;
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
                filenames = processArgs(CommandLine.parse(args));
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
                if (filenames == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
                    // null signals an error in options, abort
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
                    return EXIT_CMDERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
                } else if (filenames.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
                    // it is allowed to compile nothing if just asking for help or version info
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
                    if (options.get("-help") != null
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
                        || options.get("-X") != null
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
                        || options.get("-version") != null
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
                        || options.get("-fullversion") != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
                        return EXIT_OK;
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
                    error("err.no.source.files");
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
                    return EXIT_CMDERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            } catch (java.io.FileNotFoundException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                Log.printLines(out, ownName + ": " +
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                               getLocalizedString("err.file.not.found",
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                                                  e.getMessage()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                return EXIT_SYSERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
            boolean forceStdOut = options.get("stdout") != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            if (forceStdOut) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
                out.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
                out = new PrintWriter(System.out, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
            context.put(Log.outKey, out);
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   372
            // allow System property in following line as a Mustang legacy
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   373
            boolean batchMode = (options.get("nonBatchMode") == null
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   374
                        && System.getProperty("nonBatchMode") == null);
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   375
            if (batchMode)
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   376
                CacheFSInfo.preRegister(context);
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
   377
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
            fileManager = context.get(JavaFileManager.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
            comp = JavaCompiler.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
            if (comp == null) return EXIT_SYSERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
            if (!filenames.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
                // add filenames to fileObjects
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
                comp = JavaCompiler.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
                List<JavaFileObject> otherFiles = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
                JavacFileManager dfm = (JavacFileManager)fileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
                for (JavaFileObject fo : dfm.getJavaFileObjectsFromFiles(filenames))
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
                    otherFiles = otherFiles.prepend(fo);
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
                for (JavaFileObject fo : otherFiles)
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
                    fileObjects = fileObjects.prepend(fo);
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
            comp.compile(fileObjects,
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
                         classnames.toList(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
                         processors);
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            if (comp.errorCount() != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
                options.get("-Werror") != null && comp.warningCount() != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
                return EXIT_ERROR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        } catch (IOException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
            ioMessage(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
            return EXIT_SYSERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        } catch (OutOfMemoryError ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
            resourceMessage(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
            return EXIT_SYSERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        } catch (StackOverflowError ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
            resourceMessage(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
            return EXIT_SYSERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        } catch (FatalError ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
            feMessage(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
            return EXIT_SYSERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
        } catch(AnnotationProcessingError ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
            apMessage(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
            return EXIT_SYSERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
        } catch (ClientCodeException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
            // as specified by javax.tools.JavaCompiler#getTask
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
            // and javax.tools.JavaCompiler.CompilationTask#call
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
            throw new RuntimeException(ex.getCause());
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
        } catch (PropagatedException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
            throw ex.getCause();
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        } catch (Throwable ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            // Nasty.  If we've already reported an error, compensate
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
            // for buggy compiler error recovery by swallowing thrown
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
            // exceptions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
            if (comp == null || comp.errorCount() == 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
                options == null || options.get("dev") != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
                bugMessage(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
            return EXIT_ABNORMAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
            if (comp != null) comp.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
            filenames = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
            options = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
        return EXIT_OK;
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
    /** Print a message reporting an internal error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
    void bugMessage(Throwable ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
        Log.printLines(out, getLocalizedString("msg.bug",
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
                                               JavaCompiler.version()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        ex.printStackTrace(out);
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
    /** Print a message reporting an fatal error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
    void feMessage(Throwable ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
        Log.printLines(out, ex.getMessage());
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
    /** Print a message reporting an input/output error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
    void ioMessage(Throwable ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
        Log.printLines(out, getLocalizedString("msg.io"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        ex.printStackTrace(out);
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
    /** Print a message reporting an out-of-resources error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
    void resourceMessage(Throwable ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
        Log.printLines(out, getLocalizedString("msg.resource"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
//      System.out.println("(name buffer len = " + Name.names.length + " " + Name.nc);//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        ex.printStackTrace(out);
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
    /** Print a message reporting an uncaught exception from an
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
     * annotation processor.
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
    void apMessage(AnnotationProcessingError ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
        Log.printLines(out,
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
                       getLocalizedString("msg.proc.annotation.uncaught.exception"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
        ex.getCause().printStackTrace();
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
    private JavaFileManager fileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
    /* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
     * Internationalization
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
     *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
    /** Find a localized string in the resource bundle.
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
     *  @param key     The key for the localized string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
    public static String getLocalizedString(String key, Object... args) { // FIXME sb private
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
            if (messages == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
                messages = new Messages(javacBundleName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
            return messages.getLocalizedString("javac." + key, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        catch (MissingResourceException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
            throw new Error("Fatal Error: Resource for javac is missing", e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
    public static void useRawMessages(boolean enable) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
        if (enable) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
            messages = new Messages(javacBundleName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
                    public String getLocalizedString(String key, Object... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
                        return key;
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
                };
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
            messages = new Messages(javacBundleName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
    private static final String javacBundleName =
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
        "com.sun.tools.javac.resources.javac";
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
    private static Messages messages;
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
}