All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.org.codehaus.janino.Compiler Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version

/*
 * Janino - An embedded Java[TM] compiler
 *
 * Copyright (c) 2001-2010 Arno Unkrig. All rights reserved.
 * Copyright (c) 2015-2016 TIBCO Software Inc. 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. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
 *       products derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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 com.hazelcast.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.EnumSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.hazelcast.org.codehaus.commons.compiler.CompileException;
import com.hazelcast.org.codehaus.commons.compiler.ErrorHandler;
import com.hazelcast.org.codehaus.commons.compiler.Location;
import com.hazelcast.org.codehaus.commons.compiler.WarningHandler;
import com.hazelcast.org.codehaus.commons.nullanalysis.Nullable;
import com.hazelcast.org.codehaus.janino.Java.CompilationUnit;
import com.hazelcast.org.codehaus.janino.util.Benchmark;
import com.hazelcast.org.codehaus.janino.util.ClassFile;
import com.hazelcast.org.codehaus.janino.util.StringPattern;
import com.hazelcast.org.codehaus.janino.util.resource.DirectoryResourceCreator;
import com.hazelcast.org.codehaus.janino.util.resource.DirectoryResourceFinder;
import com.hazelcast.org.codehaus.janino.util.resource.FileResource;
import com.hazelcast.org.codehaus.janino.util.resource.FileResourceCreator;
import com.hazelcast.org.codehaus.janino.util.resource.PathResourceFinder;
import com.hazelcast.org.codehaus.janino.util.resource.Resource;
import com.hazelcast.org.codehaus.janino.util.resource.ResourceCreator;
import com.hazelcast.org.codehaus.janino.util.resource.ResourceFinder;


/**
 * A simplified substitute for the javac tool.
 * 

* Usage: *

*
 *     java com.hazelcast.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 com.hazelcast.org.codehaus.janino.Compiler -help
 * 
*/ public class Compiler { private static final Logger LOGGER = Logger.getLogger(Compiler.class.getName()); /** * Command line interface. */ public static void main(String[] args) { File destinationDirectory = Compiler.NO_DESTINATION_DIRECTORY; File[] sourcePath = null; File[] classPath = { new File(".") }; File[] extDirs = null; File[] bootClassPath = null; String characterEncoding = 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)) { sourcePath = PathResourceFinder.parsePath(args[++i]); } else if ("-classpath".equals(arg)) { classPath = PathResourceFinder.parsePath(args[++i]); } else if ("-extdirs".equals(arg)) { extDirs = PathResourceFinder.parsePath(args[++i]); } else if ("-bootclasspath".equals(arg)) { bootClassPath = PathResourceFinder.parsePath(args[++i]); } else if ("-encoding".equals(arg)) { characterEncoding = 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); System.exit(1); } else { System.err.println("Unrecognized command line option \"" + arg + "\"; try \"-help\"."); System.exit(1); } } // Get source file names. if (i == args.length) { System.err.println("No source files given on command line; try \"-help\"."); System.exit(1); } 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( sourcePath, classPath, extDirs, bootClassPath, destinationDirectory, characterEncoding, verbose, debugSource, debugLines, debugVars, warningHandlePatterns, rebuild ); // Compile source files. try { compiler.compile(sourceFiles); } catch (Exception e) { if (verbose) { e.printStackTrace(); } else { System.err.println(e.toString()); } System.exit(1); } } private static final String USAGE = ( "" + "Usage:%n" + "%n" + " java " + Compiler.class.getName() + " [




© 2015 - 2024 Weber Informatics LLC | Privacy Policy