/* * Janino - An embedded Java[TM] compiler * * Copyright (c) 2001-2010, Arno Unkrig * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the * following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the * following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ package org.codehaus.janino; import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import org.codehaus.commons.compiler.CompileException; import org.codehaus.commons.compiler.ErrorHandler; import org.codehaus.commons.compiler.Location; import org.codehaus.commons.compiler.WarningHandler; import org.codehaus.janino.Java.CompilationUnit; import org.codehaus.janino.util.Benchmark; import org.codehaus.janino.util.ClassFile; import org.codehaus.janino.util.StringPattern; import org.codehaus.janino.util.resource.DirectoryResourceCreator; import org.codehaus.janino.util.resource.DirectoryResourceFinder; import org.codehaus.janino.util.resource.FileResource; import org.codehaus.janino.util.resource.FileResourceCreator; import org.codehaus.janino.util.resource.PathResourceFinder; import org.codehaus.janino.util.resource.Resource; import org.codehaus.janino.util.resource.ResourceCreator; import org.codehaus.janino.util.resource.ResourceFinder; /** * A simplified substitute for the javac tool. * * Usage: *
 * java org.codehaus.janino.Compiler \
 *           [ -d destination-dir ] \
 *           [ -sourcepath dirlist ] \
 *           [ -classpath dirlist ] \
 *           [ -extdirs dirlist ] \
 *           [ -bootclasspath dirlist ] \
 *           [ -encoding encoding ] \
 *           [ -verbose ] \
 *           [ -g:none ] \
 *           [ -g:{source,lines,vars} ] \
 *           [ -warn:pattern-list ] \
 *           source-file ...
 * java org.codehaus.janino.Compiler -help
 * 
*/ @SuppressWarnings({ "rawtypes", "unchecked" }) public class Compiler { private static final boolean DEBUG = false; /** Command line interface. */ public static void BCV(String[] args) throws Exception { File destinationDirectory = Compiler.NO_DESTINATION_DIRECTORY; File[] optionalSourcePath = null; File[] classPath = { new File(".") }; File[] optionalExtDirs = null; File[] optionalBootClassPath = null; String optionalCharacterEncoding = null; boolean verbose = false; boolean debugSource = true; boolean debugLines = true; boolean debugVars = false; StringPattern[] warningHandlePatterns = Compiler.DEFAULT_WARNING_HANDLE_PATTERNS; boolean rebuild = false; // Process command line options. int i; for (i = 0; i < args.length; ++i) { String arg = args[i]; if (arg.charAt(0) != '-') break; if ("-d".equals(arg)) { destinationDirectory = new File(args[++i]); } else if ("-sourcepath".equals(arg)) { optionalSourcePath = PathResourceFinder.parsePath(args[++i]); } else if ("-classpath".equals(arg)) { classPath = PathResourceFinder.parsePath(args[++i]); } else if ("-extdirs".equals(arg)) { optionalExtDirs = PathResourceFinder.parsePath(args[++i]); } else if ("-bootclasspath".equals(arg)) { optionalBootClassPath = PathResourceFinder.parsePath(args[++i]); } else if ("-encoding".equals(arg)) { optionalCharacterEncoding = args[++i]; } else if ("-verbose".equals(arg)) { verbose = true; } else if ("-g".equals(arg)) { debugSource = true; debugLines = true; debugVars = true; } else if (arg.startsWith("-g:")) { if (arg.indexOf("none") != -1) debugSource = (debugLines = (debugVars = false)); if (arg.indexOf("source") != -1) debugSource = true; if (arg.indexOf("lines") != -1) debugLines = true; if (arg.indexOf("vars") != -1) debugVars = true; } else if (arg.startsWith("-warn:")) { warningHandlePatterns = StringPattern.parseCombinedPattern(arg.substring(6)); } else if ("-rebuild".equals(arg)) { rebuild = true; } else if ("-help".equals(arg)) { System.out.printf(Compiler.USAGE, (Object[]) null); } else { System.err.println("Unrecognized command line option \"" + arg + "\"; try \"-help\"."); } } // Get source file names. if (i == args.length) { System.err.println("No source files given on command line; try \"-help\"."); } File[] sourceFiles = new File[args.length - i]; for (int j = i; j < args.length; ++j) sourceFiles[j - i] = new File(args[j]); // Create the compiler object. final Compiler compiler = new Compiler( optionalSourcePath, classPath, optionalExtDirs, optionalBootClassPath, destinationDirectory, optionalCharacterEncoding, verbose, debugSource, debugLines, debugVars, warningHandlePatterns, rebuild ); // Compile source files. compiler.compile(sourceFiles); } private static final String USAGE = ( "" + "Usage:%n" + "%n" + " java " + Compiler.class.getName() + " [