@Override public int compile(final OutputStream out, final OutputStream errors, final String outputPath, final String toCompile, final String classpath) { return BatchCompiler.compile(new String[] { "-classpath", classpath, "-d", outputPath, "-source", "1.8", toCompile }, new PrintWriter(out), new PrintWriter(errors), new CompilationProgress() { @Override public void begin(final int remainingWork) { } @Override public void done() { } @Override public boolean isCanceled() { return false; } @Override public void setTaskName(final String name) { } @Override public void worked(final int workIncrement, final int remainingWork) { } }) ? 0 : -1; } }
/** * 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. * <p> * Reasons for a compilation failing to complete successfully include:</p> * <ul> * <li>an error was reported</li> * <li>a runtime exception occurred</li> * <li>the compilation was canceled using the compilation progress</li> * </ul> * <p> * The specification of the command line arguments is defined by running the batch compiler's help * <pre>BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);</pre> * </p> * * @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 <code>null</code> 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. * <p> * Reasons for a compilation failing to complete successfully include:</p> * <ul> * <li>an error was reported</li> * <li>a runtime exception occurred</li> * <li>the compilation was canceled using the compilation progress</li> * </ul> * <p> * The specification of the command line arguments is defined by running the batch compiler's help * <pre>BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);</pre> * </p> * * @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 <code>null</code> 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. * <p> * Reasons for a compilation failing to complete successfully include:</p> * <ul> * <li>an error was reported</li> * <li>a runtime exception occurred</li> * <li>the compilation was canceled using the compilation progress</li> * </ul> * <p> * The specification of the command line arguments is defined by running the batch compiler's help * <pre>BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);</pre> * </p> * * @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 <code>null</code> 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. * <p> * Reasons for a compilation failing to complete successfully include:</p> * <ul> * <li>an error was reported</li> * <li>a runtime exception occurred</li> * <li>the compilation was canceled using the compilation progress</li> * </ul> * <p> * The specification of the command line arguments is defined by running the batch compiler's help * <pre>BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);</pre> * </p> * * @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 <code>null</code> 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. * <p> * Reasons for a compilation failing to complete successfully include:</p> * <ul> * <li>an error was reported</li> * <li>a runtime exception occurred</li> * <li>the compilation was canceled using the compilation progress</li> * </ul> * <p> * The specification of the command line arguments is defined by running the batch compiler's help * <pre>BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);</pre> * </p> * * @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 <code>null</code> 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. * <p> * Reasons for a compilation failing to complete successfully include:</p> * <ul> * <li>an error was reported</li> * <li>a runtime exception occurred</li> * <li>the compilation was canceled using the compilation progress</li> * </ul> * <p> * The specification of the command line arguments is defined by running the batch compiler's help * <pre>BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);</pre> * </p> * * @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 <code>null</code> 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. * <p> * Reasons for a compilation failing to complete successfully include:</p> * <ul> * <li>an error was reported</li> * <li>a runtime exception occurred</li> * <li>the compilation was canceled using the compilation progress</li> * </ul> * <p> * The specification of the command line arguments is defined by running the batch compiler's help * <pre>BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);</pre> * </p> * * @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 <code>null</code> 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. * <p> * Reasons for a compilation failing to complete successfully include:</p> * <ul> * <li>an error was reported</li> * <li>a runtime exception occurred</li> * <li>the compilation was canceled using the compilation progress</li> * </ul> * <p> * The specification of the command line arguments is defined by running the batch compiler's help * <pre>BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);</pre> * </p> * * @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 <code>null</code> 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. * <p> * Reasons for a compilation failing to complete successfully include:</p> * <ul> * <li>an error was reported</li> * <li>a runtime exception occurred</li> * <li>the compilation was canceled using the compilation progress</li> * </ul> * <p> * The specification of the command line arguments is defined by running the batch compiler's help * <pre>BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);</pre> * </p> * * @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 <code>null</code> 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. * <p> * Reasons for a compilation failing to complete successfully include:</p> * <ul> * <li>an error was reported</li> * <li>a runtime exception occurred</li> * <li>the compilation was canceled using the compilation progress</li> * </ul> * <p> * The specification of the command line arguments is defined by running the batch compiler's help * <pre>BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);</pre> * </p> * * @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 <code>null</code> 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); }
return BatchCompiler.compile(arguments, outWriter, errWriter, new ProgressMonitorCompilationProgress(progress));
@Override public CompilationResult compile(Iterable<String> sourceRoots, File outputClassDirectory) { Iterable<String> validSourceRoots = IterableExtensions.filter(sourceRoots, new EmptyOrMissingFilter()); if (!containsJavaFiles(validSourceRoots)) { return CompilationResult.SKIPPED; } List<String> commandLine = Lists.newArrayList(); if (configuration.isVerbose()) { commandLine.add("-verbose"); } if (classPath != null) { Iterable<String> validClasspath = IterableExtensions.filter(classPath, new EmptyOrMissingFilter()); if (validClasspath.iterator().hasNext()) { commandLine.add("-cp \"" + concat(File.pathSeparator, Lists.newArrayList(validClasspath)) + "\""); } } commandLine.add("-d \"" + outputClassDirectory.toString() + "\""); commandLine.add("-source " + configuration.getSourceLevel()); commandLine.add("-target " + configuration.getTargetLevel()); commandLine.add("-proceedOnError"); for (String src : validSourceRoots) { commandLine.add("\"" + src + "\""); } String cmdLine = concat(" ", commandLine); debugLog("invoke batch compiler with '" + cmdLine + "'"); boolean result = BatchCompiler.compile(cmdLine, new PrintWriter(getOutputWriter()), new PrintWriter( getErrorWriter()), null); return result ? CompilationResult.SUCCEEDED : CompilationResult.FAILED; }
return BatchCompiler.compile(concat(" ", commandLine), outWriter, outWriter, null);