langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Main.java
author alundblad
Wed, 22 Apr 2015 13:50:23 +0200
changeset 30012 660da74452cf
parent 29780 8f8e54a1fa20
child 31506 4e07f827a794
permissions -rw-r--r--
8078261: Initialization of DocLint triggers out of order initialization of Dependencies Summary: Changed initialization order. Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
30012
660da74452cf 8078261: Initialization of DocLint triggers out of order initialization of Dependencies
alundblad
parents: 29780
diff changeset
     2
 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5319
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5319
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5319
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5319
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5319
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.main;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
    28
import java.io.FileNotFoundException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.io.PrintWriter;
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
    31
import java.net.URL;
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27846
diff changeset
    32
import java.nio.file.NoSuchFileException;
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
    33
import java.security.DigestInputStream;
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
    34
import java.security.MessageDigest;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
    35
import java.security.NoSuchAlgorithmException;
10193
3e1ef5e9f4fd 7061125: Proposed javac argument processing performance improvement
jjg
parents: 9071
diff changeset
    36
import java.util.Set;
14548
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
    37
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
    38
import javax.tools.JavaFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
14960
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents: 14954
diff changeset
    40
import com.sun.tools.javac.api.BasicJavacTask;
1208
5072b0dd3d52 6743107: clean up use of static caches in file manager
jjg
parents: 735
diff changeset
    41
import com.sun.tools.javac.file.CacheFSInfo;
29780
8f8e54a1fa20 8076420: Consolidate javac file handling in javac.file package
jjg
parents: 27852
diff changeset
    42
import com.sun.tools.javac.file.BaseFileManager;
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 10
diff changeset
    43
import com.sun.tools.javac.file.JavacFileManager;
14548
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
    44
import com.sun.tools.javac.processing.AnnotationProcessingError;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import com.sun.tools.javac.util.*;
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
    46
import com.sun.tools.javac.util.Log.PrefixKind;
14548
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
    47
import com.sun.tools.javac.util.Log.WriterKind;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
14548
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
    49
/** This class provides a command line interface to the javac compiler.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    51
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    52
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
public class Main {
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /** The name of the compiler, for use in diagnostics.
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    String ownName;
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    /** The writer to use for diagnostic output.
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    PrintWriter out;
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10638
diff changeset
    66
    /** The log to use for diagnostic output.
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10638
diff changeset
    67
     */
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14960
diff changeset
    68
    public Log log;
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10638
diff changeset
    69
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    /**
9071
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
    71
     * If true, certain errors will cause an exception, such as command line
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
    72
     * arg errors, or exceptions in user provided code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     */
9071
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
    74
    boolean apiMode;
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
    75
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    /** Result codes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    79
    public enum Result {
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    80
        OK(0),        // Compilation completed with no errors.
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    81
        ERROR(1),     // Completed but reported errors.
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    82
        CMDERR(2),    // Bad command-line arguments
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    83
        SYSERR(3),    // System error or resource exhaustion.
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    84
        ABNORMAL(4);  // Compiler terminated abnormally
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    85
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    86
        Result(int exitCode) {
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    87
            this.exitCode = exitCode;
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    88
        }
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    89
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    90
        public boolean isOK() {
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    91
            return (exitCode == 0);
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    92
        }
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    93
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    94
        public final int exitCode;
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
    95
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * Construct a compiler instance.
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
    99
     * @param name the name of this tool
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    public Main(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        this(name, new PrintWriter(System.err, true));
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     * Construct a compiler instance.
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   107
     * @param name the name of this tool
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   108
     * @param out a stream to which to write messages
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    public Main(String name, PrintWriter out) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        this.ownName = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        this.out = out;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    }
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14960
diff changeset
   114
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    /** Report a usage error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    void error(String key, Object... args) {
9071
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
   118
        if (apiMode) {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   119
            String msg = log.localize(PrefixKind.JAVAC, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            throw new PropagatedException(new IllegalStateException(msg));
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        warning(key, args);
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   123
        log.printLines(PrefixKind.JAVAC, "msg.usage", ownName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    /** Report a warning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    void warning(String key, Object... args) {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   129
        log.printRawLines(ownName + ": " + log.localize(PrefixKind.JAVAC, key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   133
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   134
     * Programmatic interface for main function.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   135
     * @param args  the command line parameters
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   136
     * @return the result of the compilation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
   138
    public Result compile(String[] args) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        Context context = new Context();
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        JavacFileManager.preRegister(context); // can't create it until Log has been set up
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
   141
        Result result = compile(args, context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        if (fileManager instanceof JavacFileManager) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            // A fresh context was created above, so jfm must be a JavacFileManager
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
            ((JavacFileManager)fileManager).close();
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   149
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   150
     * Internal version of compile, allowing context to be provided.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   151
     * Note that the context needs to have a file manager set up.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   152
     * @param argv  the command line parameters
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   153
     * @param context the context
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   154
     * @return the result of the compilation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     */
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   156
    public Result compile(String[] argv, Context context) {
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10638
diff changeset
   157
        context.put(Log.outKey, out);
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10638
diff changeset
   158
        log = Log.instance(context);
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10638
diff changeset
   159
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   160
        if (argv.length == 0) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   161
            Option.HELP.process(new OptionHelper.GrumpyHelper(log) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   162
                @Override
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   163
                public String getOwnName() { return ownName; }
27846
8a7a3a187e24 8058445: Javac throws exception when displaying info
jjg
parents: 27226
diff changeset
   164
                @Override
8a7a3a187e24 8058445: Javac throws exception when displaying info
jjg
parents: 27226
diff changeset
   165
                public void put(String name, String value) { }
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   166
            }, "-help");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   167
            return Result.CMDERR;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   168
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        try {
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   171
            argv = CommandLine.parse(argv);
27852
2e6ad0e4fe20 8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents: 27846
diff changeset
   172
        } catch (FileNotFoundException | NoSuchFileException e) {
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   173
            warning("err.file.not.found", e.getMessage());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   174
            return Result.SYSERR;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   175
        } catch (IOException ex) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   176
            log.printLines(PrefixKind.JAVAC, "msg.io");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   177
            ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   178
            return Result.SYSERR;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   179
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   181
        Arguments args = Arguments.instance(context);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   182
        args.init(ownName, argv);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   183
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   184
        if (log.nerrors > 0)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   185
            return Result.CMDERR;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   186
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   187
        Options options = Options.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   189
        // init Log
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   190
        boolean forceStdOut = options.isSet("stdout");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   191
        if (forceStdOut) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   192
            log.flush();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   193
            log.setWriters(new PrintWriter(System.out, true));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   194
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   196
        // init CacheFSInfo
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   197
        // allow System property in following line as a Mustang legacy
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   198
        boolean batchMode = (options.isUnset("nonBatchMode")
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   199
                    && System.getProperty("nonBatchMode") == null);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   200
        if (batchMode)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   201
            CacheFSInfo.preRegister(context);
24897
655b72d7b96e 7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents: 23792
diff changeset
   202
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   203
        // init file manager
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   204
        fileManager = context.get(JavaFileManager.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   205
        if (fileManager instanceof BaseFileManager) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   206
            ((BaseFileManager) fileManager).setContext(context); // reinit with options
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   207
            ((BaseFileManager) fileManager).handleOptions(args.getDeferredFileManagerOptions());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   208
        }
14548
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
   209
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   210
        // handle this here so it works even if no other options given
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   211
        String showClass = options.get("showClass");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   212
        if (showClass != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   213
            if (showClass.equals("showClass")) // no value given for option
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   214
                showClass = "com.sun.tools.javac.Main";
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   215
            showClass(showClass);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   216
        }
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25445
diff changeset
   217
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   218
        boolean ok = args.validate();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   219
        if (!ok || log.nerrors > 0)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   220
            return Result.CMDERR;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   221
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   222
        if (args.isEmpty())
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   223
            return Result.OK;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
30012
660da74452cf 8078261: Initialization of DocLint triggers out of order initialization of Dependencies
alundblad
parents: 29780
diff changeset
   225
        // init Depeendencies
660da74452cf 8078261: Initialization of DocLint triggers out of order initialization of Dependencies
alundblad
parents: 29780
diff changeset
   226
        if (options.isSet("completionDeps")) {
660da74452cf 8078261: Initialization of DocLint triggers out of order initialization of Dependencies
alundblad
parents: 29780
diff changeset
   227
            Dependencies.GraphDependencies.preRegister(context);
660da74452cf 8078261: Initialization of DocLint triggers out of order initialization of Dependencies
alundblad
parents: 29780
diff changeset
   228
        }
660da74452cf 8078261: Initialization of DocLint triggers out of order initialization of Dependencies
alundblad
parents: 29780
diff changeset
   229
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   230
        // init plugins
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   231
        Set<List<String>> pluginOpts = args.getPluginOpts();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   232
        if (!pluginOpts.isEmpty()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   233
            BasicJavacTask t = (BasicJavacTask) BasicJavacTask.instance(context);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   234
            t.initPlugins(pluginOpts);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   235
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   236
30012
660da74452cf 8078261: Initialization of DocLint triggers out of order initialization of Dependencies
alundblad
parents: 29780
diff changeset
   237
        // init JavaCompiler
660da74452cf 8078261: Initialization of DocLint triggers out of order initialization of Dependencies
alundblad
parents: 29780
diff changeset
   238
        JavaCompiler comp = JavaCompiler.instance(context);
660da74452cf 8078261: Initialization of DocLint triggers out of order initialization of Dependencies
alundblad
parents: 29780
diff changeset
   239
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   240
        // init doclint
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   241
        List<String> docLintOpts = args.getDocLintOpts();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   242
        if (!docLintOpts.isEmpty()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   243
            BasicJavacTask t = (BasicJavacTask) BasicJavacTask.instance(context);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   244
            t.initDocLint(docLintOpts);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   245
        }
14960
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents: 14954
diff changeset
   246
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   247
        if (options.get(Option.XSTDOUT) != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   248
            // Stdout reassigned - ask compiler to close it when it is done
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   249
            comp.closeables = comp.closeables.prepend(log.getWriter(WriterKind.NOTICE));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   250
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   251
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   252
        try {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   253
            comp.compile(args.getFileObjects(), args.getClassNames(), null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
1866
734286a0cc38 6794959: add new switch -XDexpectKeys=key,key....
jjg
parents: 1471
diff changeset
   255
            if (log.expectDiagKeys != null) {
7335
8b390fd27190 6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents: 6721
diff changeset
   256
                if (log.expectDiagKeys.isEmpty()) {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   257
                    log.printRawLines("all expected diagnostics found");
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
   258
                    return Result.OK;
1866
734286a0cc38 6794959: add new switch -XDexpectKeys=key,key....
jjg
parents: 1471
diff changeset
   259
                } else {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   260
                    log.printRawLines("expected diagnostic keys not found: " + log.expectDiagKeys);
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
   261
                    return Result.ERROR;
1866
734286a0cc38 6794959: add new switch -XDexpectKeys=key,key....
jjg
parents: 1471
diff changeset
   262
                }
734286a0cc38 6794959: add new switch -XDexpectKeys=key,key....
jjg
parents: 1471
diff changeset
   263
            }
734286a0cc38 6794959: add new switch -XDexpectKeys=key,key....
jjg
parents: 1471
diff changeset
   264
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   265
            return (comp.errorCount() == 0) ? Result.OK : Result.ERROR;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   266
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   267
        } catch (OutOfMemoryError | StackOverflowError ex) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
            resourceMessage(ex);
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
   269
            return Result.SYSERR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
        } catch (FatalError ex) {
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   271
            feMessage(ex, options);
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
   272
            return Result.SYSERR;
9071
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
   273
        } catch (AnnotationProcessingError ex) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
            apMessage(ex);
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
   275
            return Result.SYSERR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        } catch (PropagatedException ex) {
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   277
            // TODO: what about errors from plugins?   should not simply rethrow the error here
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
            throw ex.getCause();
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        } catch (Throwable ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
            // Nasty.  If we've already reported an error, compensate
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            // for buggy compiler error recovery by swallowing thrown
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
            // exceptions.
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   283
            if (comp == null || comp.errorCount() == 0 || options.isSet("dev"))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                bugMessage(ex);
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 10193
diff changeset
   285
            return Result.ABNORMAL;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        } finally {
9071
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
   287
            if (comp != null) {
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
   288
                try {
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
   289
                    comp.close();
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
   290
                } catch (ClientCodeException ex) {
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
   291
                    throw new RuntimeException(ex.getCause());
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
   292
                }
88cd61b4e5aa 6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents: 8623
diff changeset
   293
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
    /** Print a message reporting an internal error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
    void bugMessage(Throwable ex) {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   300
        log.printLines(PrefixKind.JAVAC, "msg.bug", JavaCompiler.version());
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   301
        ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
6581
f58f0ce45802 6980707: Reduce use of IOException in JavaCompiler
jjg
parents: 5857
diff changeset
   304
    /** Print a message reporting a fatal error.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
     */
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   306
    void feMessage(Throwable ex, Options options) {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   307
        log.printRawLines(ex.getMessage());
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
   308
        if (ex.getCause() != null && options.isSet("dev")) {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   309
            ex.getCause().printStackTrace(log.getWriter(WriterKind.NOTICE));
6581
f58f0ce45802 6980707: Reduce use of IOException in JavaCompiler
jjg
parents: 5857
diff changeset
   310
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
    /** Print a message reporting an input/output error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
    void ioMessage(Throwable ex) {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   316
        log.printLines(PrefixKind.JAVAC, "msg.io");
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   317
        ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    /** Print a message reporting an out-of-resources error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
    void resourceMessage(Throwable ex) {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   323
        log.printLines(PrefixKind.JAVAC, "msg.resource");
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   324
        ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
    /** Print a message reporting an uncaught exception from an
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
     * annotation processor.
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
    void apMessage(AnnotationProcessingError ex) {
14448
91aa6570b59a 7198690: missing compiler message
jjg
parents: 13631
diff changeset
   331
        log.printLines(PrefixKind.JAVAC, "msg.proc.annotation.uncaught.exception");
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   332
        ex.getCause().printStackTrace(log.getWriter(WriterKind.NOTICE));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
14548
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
   335
    /** Print a message reporting an uncaught exception from an
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
   336
     * annotation processor.
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
   337
     */
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
   338
    void pluginMessage(Throwable ex) {
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
   339
        log.printLines(PrefixKind.JAVAC, "msg.plugin.uncaught.exception");
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
   340
        ex.printStackTrace(log.getWriter(WriterKind.NOTICE));
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
   341
    }
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14448
diff changeset
   342
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   343
    /** Display the location and checksum of a class. */
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   344
    void showClass(String className) {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   345
        PrintWriter pw = log.getWriter(WriterKind.NOTICE);
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   346
        pw.println("javac: show class: " + className);
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   347
        URL url = getClass().getResource('/' + className.replace('.', '/') + ".class");
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   348
        if (url == null)
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   349
            pw.println("  class not found");
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   350
        else {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   351
            pw.println("  " + url);
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   352
            try {
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   353
                final String algorithm = "MD5";
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   354
                byte[] digest;
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   355
                MessageDigest md = MessageDigest.getInstance(algorithm);
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 19489
diff changeset
   356
                try (DigestInputStream in = new DigestInputStream(url.openStream(), md)) {
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   357
                    byte[] buf = new byte[8192];
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   358
                    int n;
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   359
                    do { n = in.read(buf); } while (n > 0);
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   360
                    digest = md.digest();
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   361
                }
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   362
                StringBuilder sb = new StringBuilder();
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   363
                for (byte b: digest)
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   364
                    sb.append(String.format("%02x", b));
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   365
                pw.println("  " + algorithm + " checksum: " + sb);
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   366
            } catch (NoSuchAlgorithmException | IOException e) {
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   367
                pw.println("  cannot compute digest: " + e);
5319
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   368
            }
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   369
        }
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   370
    }
63dc7f367a37 6942649: add hidden option to identify location and version of javac classes
jjg
parents: 2723
diff changeset
   371
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   372
    // TODO: update this to JavacFileManager
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
    private JavaFileManager fileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
    /* ************************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
     * Internationalization
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
     *************************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
11053
48713f779b1d 7108669: cleanup Log methods for direct printing to streams
jjg
parents: 11052
diff changeset
   379
    public static final String javacBundleName =
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        "com.sun.tools.javac.resources.javac";
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
}