1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/Main.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,102 @@ 1.4 +/* 1.5 + * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.javac; 1.30 + 1.31 +import java.io.PrintWriter; 1.32 +import java.lang.reflect.*; 1.33 + 1.34 + 1.35 +/** 1.36 + * The programmatic interface for the Java Programming Language 1.37 + * compiler, javac. 1.38 + * 1.39 + * <p>Except for the two methods 1.40 + * {@link #compile(java.lang.String[])} 1.41 + * {@link #compile(java.lang.String[],java.io.PrintWriter)}, 1.42 + * nothing described in this source file is part of any supported 1.43 + * API. If you write code that depends on this, you do so at your own 1.44 + * risk. This code and its internal interfaces are subject to change 1.45 + * or deletion without notice. 1.46 + */ 1.47 +public class Main { 1.48 + 1.49 + static { 1.50 + ClassLoader loader = Main.class.getClassLoader(); 1.51 + if (loader != null) 1.52 + loader.setPackageAssertionStatus("com.sun.tools.javac", true); 1.53 + } 1.54 + 1.55 + /** Unsupported command line interface. 1.56 + * @param args The command line parameters. 1.57 + */ 1.58 + public static void main(String[] args) throws Exception { 1.59 + if (args.length > 0 && args[0].equals("-Xjdb")) { 1.60 + String[] newargs = new String[args.length + 2]; 1.61 + Class<?> c = Class.forName("com.sun.tools.example.debug.tty.TTY"); 1.62 + Method method = c.getDeclaredMethod ("main", new Class[] {args.getClass()}); 1.63 + method.setAccessible(true); 1.64 + System.arraycopy(args, 1, newargs, 3, args.length - 1); 1.65 + newargs[0] = "-connect"; 1.66 + newargs[1] = "com.sun.jdi.CommandLineLaunch:options=-esa -ea:com.sun.tools..."; 1.67 + newargs[2] = "com.sun.tools.javac.Main"; 1.68 + method.invoke(null, new Object[] { newargs }); 1.69 + } else { 1.70 + System.exit(compile(args)); 1.71 + } 1.72 + } 1.73 + 1.74 + /** Programmatic interface to the Java Programming Language 1.75 + * compiler, javac. 1.76 + * 1.77 + * @param args The command line arguments that would normally be 1.78 + * passed to the javac program as described in the man page. 1.79 + * @return an integer equivalent to the exit value from invoking 1.80 + * javac, see the man page for details. 1.81 + */ 1.82 + public static int compile(String[] args) { 1.83 + com.sun.tools.javac.main.Main compiler = 1.84 + new com.sun.tools.javac.main.Main("javac"); 1.85 + return compiler.compile(args); 1.86 + } 1.87 + 1.88 + 1.89 + 1.90 + /** Programmatic interface to the Java Programming Language 1.91 + * compiler, javac. 1.92 + * 1.93 + * @param args The command line arguments that would normally be 1.94 + * passed to the javac program as described in the man page. 1.95 + * @param out PrintWriter to which the compiler's diagnostic 1.96 + * output is directed. 1.97 + * @return an integer equivalent to the exit value from invoking 1.98 + * javac, see the man page for details. 1.99 + */ 1.100 + public static int compile(String[] args, PrintWriter out) { 1.101 + com.sun.tools.javac.main.Main compiler = 1.102 + new com.sun.tools.javac.main.Main("javac", out); 1.103 + return compiler.compile(args); 1.104 + } 1.105 +}