protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean systemExit, Map customDefaultOptions, CompilationProgress compilationProgress) { this.logger = new Logger(this, outWriter, errWriter); this.proceed = true; this.out = outWriter; this.err = errWriter; this.systemExitWhenFinished = systemExit; this.options = new CompilerOptions().getMap(); this.ignoreOptionalProblemsFromFolders = null; this.progress = compilationProgress; if (customDefaultOptions != null) { this.didSpecifySource = customDefaultOptions.get(CompilerOptions.OPTION_Source) != null; this.didSpecifyTarget = customDefaultOptions.get(CompilerOptions.OPTION_TargetPlatform) != null; for (Iterator iter = customDefaultOptions.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); this.options.put(entry.getKey(), entry.getValue()); } } else { this.didSpecifySource = false; this.didSpecifyTarget = false; } this.classNames = null; }
@Override public final void run() { String command = getCommand(); CompilationProgress progress = getProgress(); // instantiate your subclass compiled = BatchCompiler.compile(command, new PrintWriter(out), new PrintWriter(err), progress); }
private boolean compile(String warnOpt, String annotOpt, String fileStr) { String cpStr = Strings.toSimpleString(File.pathSeparator, classpath); String cmd = String.format("-%s -classpath %s %s %s -d %s %s", javaVer, cpStr, warnOpt, annotOpt, outDir, fileStr); log.info("Executing => {}", cmd); CompilationProgress progress = new LogCompilationProgress(); StringWriter stdOut = new StringWriter(); PrintWriter out = new PrintWriter(stdOut); StringWriter errorOut = new StringWriter(); PrintWriter err = new PrintWriter(errorOut); boolean result = BatchCompiler.compile(cmd, out, err, progress); log.info("Result => [{}] {} {}", result ? "OK" : "FAIL", stdOut, errorOut); messages = parseMessages(errorOut); return result; }
public static void main(String[] args) { CompilationProgress progress = null; boolean ret = BatchCompiler.compile( "/Users/tudesheng/projects/haogrgr/haogrgr-test/src/test/java/com/haogrgr/test/main/Temp.java", new PrintWriter(System.out), new PrintWriter(System.err), progress); System.out.println(ret); }
protected CompilationProgress getProgress() { return null; }
@Override protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean systemExit, Map customDefaultOptions, CompilationProgress compilationProgress) { super.initialize(outWriter, errWriter, systemExit, customDefaultOptions, compilationProgress); this.javaFileObjectMap = new HashMap<CompilationUnit, JavaFileObject>(); }
public static boolean compile(String[] commandLineArguments, PrintWriter outWriter, PrintWriter errWriter, CompilationProgress progress) { return new Main(outWriter, errWriter, false /* systemExit */, null /* options */, progress).compile(commandLineArguments); }
public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished, Map customDefaultOptions, CompilationProgress compilationProgress) { this.initialize(outWriter, errWriter, systemExitWhenFinished, customDefaultOptions, compilationProgress); this.relocalize(); }
@Override @SuppressWarnings("rawtypes") protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean systemExit, Map customDefaultOptions, CompilationProgress compilationProgress) { super.initialize(outWriter, errWriter, systemExit, customDefaultOptions, compilationProgress); this.javaFileObjectMap = new HashMap<CompilationUnit, JavaFileObject>(); }
/** * 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> * Note that a <code>true</code> 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 <code>null</code> 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); }