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()); } }
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 ECJEvaluatorFactory(ClassLoader parent, CompilerOptions compilerOptions) { this.parentClassLoader = parent; this.fileManager = new MemFileManager(parent, new EclipseFileManager(Locale.getDefault(), Charset.defaultCharset())); this.loader = fileManager.getClassLoader(StandardLocation.CLASS_OUTPUT); this.compilerOptions = compilerOptions; }
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()); } }