org.eclipse.jdt.core.compiler.batch.BatchCompiler Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2008, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.core.compiler.batch;
import java.io.PrintWriter;
import org.eclipse.jdt.core.compiler.CompilationProgress;
import org.eclipse.jdt.internal.compiler.batch.Main;
/**
* A public API for invoking the Eclipse Compiler for Java. E.g.
*
* BatchCompiler.compile("C:\\mySources\\X.java -d C:\\myOutput", new PrintWriter(System.out), new PrintWriter(System.err), null);
*
*
* @since 3.4
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public final class BatchCompiler {
/**
* Invokes the Eclipse Compiler for Java with the given command line arguments, using the given writers
* to print messages, and reporting progress to the given compilation progress. Returns whether
* the compilation completed successfully.
*
* Reasons for a compilation failing to complete successfully include:
*
* - an error was reported
* - a runtime exception occurred
* - the compilation was canceled using the compilation progress
*
*
* The specification of the command line arguments is defined by running the batch compiler's help
*
BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);
*
*
* @param commandLine the command line arguments passed to the compiler
* @param outWriter the writer used to print standard messages
* @param errWriter the writer used to print error messages
* @param progress the object to report progress to and to provide cancellation, or null
if no progress is needed
* @return whether the compilation completed successfully
*/
public static boolean compile(String commandLine, PrintWriter outWriter, PrintWriter errWriter, CompilationProgress progress) {
return compile(Main.tokenize(commandLine), outWriter, errWriter, progress);
}
/**
* Invokes the Eclipse Compiler for Java with the given command line arguments, using the given writers
* to print messages, and reporting progress to the given compilation progress. Returns whether
* the compilation completed successfully.
*
* Reasons for a compilation failing to complete successfully include:
*
* - an error was reported
* - a runtime exception occurred
* - the compilation was canceled using the compilation progress
*
*
* The specification of the command line arguments is defined by running the batch compiler's help
*
BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);
*
* Note that a true
returned value indicates that no errors were reported, no runtime exceptions
* occurred and that the compilation was not canceled.
*
* @param commandLineArguments the command line arguments passed to the compiler
* @param outWriter the writer used to print standard messages
* @param errWriter the writer used to print error messages
* @param progress the object to report progress to and to provide cancellation, or null
if no progress is needed
* @return whether the compilation completed successfully
*/
public static boolean compile(String[] commandLineArguments, PrintWriter outWriter, PrintWriter errWriter, CompilationProgress progress) {
return Main.compile(commandLineArguments, outWriter, errWriter, progress);
}
private BatchCompiler() {
// prevent instantiation
}
}