JavaApp extends Process { public void compile() { if(!compiled) { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); int exit; if(classpath.length() > 0) { StandardJavaFileManager fileManager = compiler .getStandardFileManager(null, null, null); List<File> cpList = Lists.newArrayList(); String[] parts = classpath.split(CLASSPATH_SEPARATOR); for (String part : parts) { cpList.add(new File(part)); } try { fileManager.setLocation(StandardLocation.CLASS_PATH, cpList); } catch (IOException e) { throw CheckedExceptions.wrapAsRuntimeException(e); } Iterable<? extends JavaFileObject> compilationUnits = fileManager .getJavaFileObjectsFromStrings( Arrays.asList(sourceFile)); CompilationTask task = compiler.getTask(null, fileManager, null, Lists.newArrayList("-classpath", classpath), null, compilationUnits); exit = task.call() ? 0 : 1; } else { exit = compiler.run(null, null, null, sourceFile); } if(exit == 0) { compiled = true; } else { throw new RuntimeException("Could not compile source"); } } } JavaApp(String source);  JavaApp(String classpath, String source, ArrayList<String> options);  JavaApp(String classpath, String source, String... options); void compile(); @Override void destroy(); @Override int exitValue(); @Override InputStream getErrorStream(); @Override InputStream getInputStream(); @Override OutputStream getOutputStream(); boolean isRunning(); void onPrematureShutdown(final PrematureShutdownHandler handler); long pid(); void run(); boolean tryCompile(); @Override int waitFor(); static final String CLASSPATH_SEPARATOR; }
@Test(expected = Exception.class) public void testBadSource() { JavaApp app = new JavaApp(BAD_SOURCE); try { app.compile(); } catch (Exception e) { System.out.println("[INFO] You can ignore the error message above"); throw e; } }