public static void assertCompiles(String name, String source) { URLClassLoader parent = (URLClassLoader) CompileUtils.class.getClassLoader(); SimpleCompiler compiler = new SimpleCompiler(); MemFileManager fileManager = new MemFileManager(parent, compiler.getStandardFileManager(null, null, null)); String classpath = SimpleCompiler.getClassPath(parent); List<String> compilationOptions = Arrays.asList("-classpath", classpath, "-g:none"); // compile SimpleJavaFileObject javaFileObject = new MemSourceFileObject(name, source); Writer out = new StringWriter(); JavaCompiler.CompilationTask task = compiler.getTask(out, fileManager, null, compilationOptions, null, Collections.singletonList(javaFileObject)); if (!task.call()) { Assert.fail("Compilation of " + source + " failed.\n" + out.toString()); } }
private String getClasspath() { if (classPath == null) { if (classLoader instanceof URLClassLoader) { classPath = getClassPath((URLClassLoader) classLoader); } else { throw new IllegalArgumentException("Unsupported ClassLoader " + classLoader); } } return classPath; }
public JDKEvaluatorFactory(URLClassLoader parent, JavaCompiler compiler) { this.fileManager = new MemFileManager(parent, compiler.getStandardFileManager(null, null, null)); this.compiler = compiler; this.classpath = SimpleCompiler.getClassPath(parent); this.loader = fileManager.getClassLoader(StandardLocation.CLASS_OUTPUT); this.compilationOptions = Arrays.asList("-classpath", classpath, "-g:none"); }
public static void assertCompiles(String name, String source) { URLClassLoader parent = (URLClassLoader) CompileUtils.class.getClassLoader(); SimpleCompiler compiler = new SimpleCompiler(); MemFileManager fileManager = new MemFileManager(parent, compiler.getStandardFileManager(null, null, null)); String classpath = SimpleCompiler.getClassPath(parent); List<String> compilationOptions = Arrays.asList("-classpath", classpath, "-g:none"); // compile SimpleJavaFileObject javaFileObject = new MemSourceFileObject(name, source); Writer out = new StringWriter(); JavaCompiler.CompilationTask task = compiler.getTask(out, fileManager, null, compilationOptions, null, Collections.singletonList(javaFileObject)); if (!task.call()) { Assert.fail("Compilation of " + source + " failed.\n" + out.toString()); } }