001: /*
002: * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.javac;
027:
028: import java.io.PrintWriter;
029: import java.lang.reflect.*;
030:
031: import com.sun.tools.javac.util.Version;
032:
033: /**
034: * The programmatic interface for the Java Programming Language
035: * compiler, javac.
036: *
037: * <p>Except for the two methods
038: * {@link #compile(java.lang.String[])}
039: * {@link #compile(java.lang.String[],java.io.PrintWriter)},
040: * nothing described in this source file is part of any supported
041: * API. If you write code that depends on this, you do so at your own
042: * risk. This code and its internal interfaces are subject to change
043: * or deletion without notice.
044: */
045: @Version("@(#)Main.java 1.32 07/05/05")
046: public class Main {
047:
048: static {
049: ClassLoader loader = Main.class.getClassLoader();
050: if (loader != null)
051: loader.setPackageAssertionStatus("com.sun.tools.javac",
052: true);
053: }
054:
055: /** Unsupported command line interface.
056: * @param args The command line parameters.
057: */
058: public static void main(String[] args) throws Exception {
059: if (args.length > 0 && args[0].equals("-Xjdb")) {
060: String[] newargs = new String[args.length + 2];
061: Class<?> c = Class
062: .forName("com.sun.tools.example.debug.tty.TTY");
063: Method method = c.getDeclaredMethod("main",
064: new Class[] { args.getClass() });
065: method.setAccessible(true);
066: System.arraycopy(args, 1, newargs, 3, args.length - 1);
067: newargs[0] = "-connect";
068: newargs[1] = "com.sun.jdi.CommandLineLaunch:options=-esa -ea:com.sun.tools...";
069: newargs[2] = "com.sun.tools.javac.Main";
070: method.invoke(null, new Object[] { newargs });
071: } else {
072: System.exit(compile(args));
073: }
074: }
075:
076: /** Programmatic interface to the Java Programming Language
077: * compiler, javac.
078: *
079: * @param args The command line arguments that would normally be
080: * passed to the javac program as described in the man page.
081: * @return an integer equivalent to the exit value from invoking
082: * javac, see the man page for details.
083: */
084: public static int compile(String[] args) {
085: com.sun.tools.javac.main.Main compiler = new com.sun.tools.javac.main.Main(
086: "javac");
087: return compiler.compile(args);
088: }
089:
090: /** Programmatic interface to the Java Programming Language
091: * compiler, javac.
092: *
093: * @param args The command line arguments that would normally be
094: * passed to the javac program as described in the man page.
095: * @param out PrintWriter to which the compiler's diagnostic
096: * output is directed.
097: * @return an integer equivalent to the exit value from invoking
098: * javac, see the man page for details.
099: */
100: public static int compile(String[] args, PrintWriter out) {
101: com.sun.tools.javac.main.Main compiler = new com.sun.tools.javac.main.Main(
102: "javac", out);
103: return compiler.compile(args);
104: }
105: }
|