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()); } }
protected void compile(String source, ClassType projectionType, String[] names, Type[] types, String id, Map<String, Object> constants) throws IOException { // create source source = createSource(source, projectionType, names, types, id, constants); // compile SimpleJavaFileObject javaFileObject = new MemSourceFileObject(id, source); Writer out = new StringWriter(); CompilationTask task = compiler.getTask(out, fileManager, null, compilationOptions, null, Collections.singletonList(javaFileObject)); if (!task.call().booleanValue()) { throw new CodegenException("Compilation of " + source + " failed.\n" + out.toString()); } }
@Override public JavaFileObject getJavaFileForOutput(Location location, String name, Kind kind, FileObject sibling) throws IOException { JavaFileObject javaFileObject = null; LocationAndKind key = new LocationAndKind(location, kind); if (ramFileSystem.containsKey(key)) { javaFileObject = ramFileSystem.get(key).get(name); if (javaFileObject != null) { return javaFileObject; } } if (kind == Kind.SOURCE) { javaFileObject = new MemSourceFileObject(name); } else { javaFileObject = new MemJavaFileObject(urlPrefix, name, kind); } register(key, javaFileObject); return javaFileObject; }
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()); } }