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    
032    /**
033     * The programmatic interface for the Java Programming Language
034     * compiler, javac.
035     *
036     * <p>Except for the two methods
037     * {@link #compile(java.lang.String[])}
038     * {@link #compile(java.lang.String[],java.io.PrintWriter)},
039     * nothing described in this source file is part of any supported
040     * API.  If you write code that depends on this, you do so at your own
041     * risk.  This code and its internal interfaces are subject to change
042     * or deletion without notice.
043     */
044    public class Main {
045    
046        static {
047            ClassLoader loader = Main.class.getClassLoader();
048            if (loader != null)
049                loader.setPackageAssertionStatus("com.sun.tools.javac", true);
050        }
051    
052        /** Unsupported command line interface.
053         * @param args   The command line parameters.
054         */
055        public static void main(String[] args) throws Exception {
056          if (args.length > 0 && args[0].equals("-Xjdb")) {
057            String[] newargs = new String[args.length + 2];
058            Class<?> c = Class.forName("com.sun.tools.example.debug.tty.TTY");
059            Method method = c.getDeclaredMethod ("main", new Class<?>[] {args.getClass()});
060            method.setAccessible(true);
061            System.arraycopy(args, 1, newargs, 3, args.length - 1);
062            newargs[0] = "-connect";
063            newargs[1] = "com.sun.jdi.CommandLineLaunch:options=-esa -ea:com.sun.tools...";
064            newargs[2] = "com.sun.tools.javac.Main";
065            method.invoke(null, new Object[] { newargs });
066          } else {
067            System.exit(compile(args));
068          }
069        }
070    
071        /** Programmatic interface to the Java Programming Language
072         * compiler, javac.
073         *
074         * @param args The command line arguments that would normally be
075         * passed to the javac program as described in the man page.
076         * @return an integer equivalent to the exit value from invoking
077         * javac, see the man page for details.
078         */
079        public static int compile(String[] args) {
080            com.sun.tools.javac.main.Main compiler =
081                new com.sun.tools.javac.main.Main("javac");
082            return compiler.compile(args);
083        }
084    
085    
086    
087        /** Programmatic interface to the Java Programming Language
088         * compiler, javac.
089         *
090         * @param args The command line arguments that would normally be
091         * passed to the javac program as described in the man page.
092         * @param out PrintWriter to which the compiler's diagnostic
093         * output is directed.
094         * @return an integer equivalent to the exit value from invoking
095         * javac, see the man page for details.
096         */
097        public static int compile(String[] args, PrintWriter out) {
098            com.sun.tools.javac.main.Main compiler =
099                new com.sun.tools.javac.main.Main("javac", out);
100            return compiler.compile(args);
101        }
102    }