langtools/src/share/classes/com/sun/tools/javac/Main.java
author jjg
Thu, 10 Jun 2010 16:08:01 -0700
changeset 5847 1908176fd6e3
parent 5520 86e4b9a9da40
child 8032 e1aa25ccdabb
permissions -rw-r--r--
6944312: Potential rebranding issues in openjdk/langtools repository sources Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
     2
 * Copyright (c) 1999, 2006, 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
    static {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
        ClassLoader loader = Main.class.getClassLoader();
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
        if (loader != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
            loader.setPackageAssertionStatus("com.sun.tools.javac", true);
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /** Unsupported command line interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * @param args   The command line parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    public static void main(String[] args) throws Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
      if (args.length > 0 && args[0].equals("-Xjdb")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        String[] newargs = new String[args.length + 2];
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        Class<?> c = Class.forName("com.sun.tools.example.debug.tty.TTY");
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 10
diff changeset
    59
        Method method = c.getDeclaredMethod ("main", new Class<?>[] {args.getClass()});
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
        method.setAccessible(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
        System.arraycopy(args, 1, newargs, 3, args.length - 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        newargs[0] = "-connect";
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        newargs[1] = "com.sun.jdi.CommandLineLaunch:options=-esa -ea:com.sun.tools...";
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        newargs[2] = "com.sun.tools.javac.Main";
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        method.invoke(null, new Object[] { newargs });
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
      } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        System.exit(compile(args));
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
      }
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    /** Programmatic interface to the Java Programming Language
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     * compiler, javac.
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * @param args The command line arguments that would normally be
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * passed to the javac program as described in the man page.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * @return an integer equivalent to the exit value from invoking
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * javac, see the man page for details.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    public static int compile(String[] args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        com.sun.tools.javac.main.Main compiler =
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            new com.sun.tools.javac.main.Main("javac");
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        return compiler.compile(args);
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    /** Programmatic interface to the Java Programming Language
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     * compiler, javac.
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     * @param args The command line arguments that would normally be
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     * passed to the javac program as described in the man page.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     * @param out PrintWriter to which the compiler's diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * output is directed.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     * @return an integer equivalent to the exit value from invoking
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     * javac, see the man page for details.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    public static int compile(String[] args, PrintWriter out) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        com.sun.tools.javac.main.Main compiler =
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
            new com.sun.tools.javac.main.Main("javac", out);
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        return compiler.compile(args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
}