langtools/src/share/classes/com/sun/tools/javac/Main.java
author poonam
Tue, 26 Feb 2013 08:58:20 -0800
changeset 15808 c75f11af1033
parent 10638 c8e9604cf151
child 16303 b5dca0b42963
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 5520
diff changeset
     2
 * Copyright (c) 1999, 2011, 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: 1789
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: 1789
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: 1789
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
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;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.PrintWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * The programmatic interface for the Java Programming Language
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * compiler, javac.
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * <p>Except for the two methods
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * {@link #compile(java.lang.String[])}
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * {@link #compile(java.lang.String[],java.io.PrintWriter)},
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * nothing described in this source file is part of any supported
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * API.  If you write code that depends on this, you do so at your own
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * risk.  This code and its internal interfaces are subject to change
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * or deletion without notice.
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
public class Main {
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    /** Unsupported command line interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
     * @param args   The command line parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    public static void main(String[] args) throws Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
      if (args.length > 0 && args[0].equals("-Xjdb")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
        String[] newargs = new String[args.length + 2];
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        Class<?> c = Class.forName("com.sun.tools.example.debug.tty.TTY");
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 10
diff changeset
    53
        Method method = c.getDeclaredMethod ("main", new Class<?>[] {args.getClass()});
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        method.setAccessible(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
        System.arraycopy(args, 1, newargs, 3, args.length - 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
        newargs[0] = "-connect";
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        newargs[1] = "com.sun.jdi.CommandLineLaunch:options=-esa -ea:com.sun.tools...";
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        newargs[2] = "com.sun.tools.javac.Main";
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
        method.invoke(null, new Object[] { newargs });
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
      } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
        System.exit(compile(args));
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
      }
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    /** Programmatic interface to the Java Programming Language
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * compiler, javac.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * @param args The command line arguments that would normally be
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * passed to the javac program as described in the man page.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     * @return an integer equivalent to the exit value from invoking
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * javac, see the man page for details.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    public static int compile(String[] args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        com.sun.tools.javac.main.Main compiler =
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
            new com.sun.tools.javac.main.Main("javac");
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 8032
diff changeset
    76
        return compiler.compile(args).exitCode;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    /** Programmatic interface to the Java Programming Language
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     * compiler, javac.
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     * @param args The command line arguments that would normally be
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     * passed to the javac program as described in the man page.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     * @param out PrintWriter to which the compiler's diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     * output is directed.
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     * @return an integer equivalent to the exit value from invoking
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     * javac, see the man page for details.
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    public static int compile(String[] args, PrintWriter out) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        com.sun.tools.javac.main.Main compiler =
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
            new com.sun.tools.javac.main.Main("javac", out);
10638
c8e9604cf151 7075721: javac should have public enum for exit codes
jjg
parents: 8032
diff changeset
    94
        return compiler.compile(args).exitCode;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
}