Search in sources :

Example 1 with MemFileManager

use of com.querydsl.codegen.utils.MemFileManager in project querydsl by querydsl.

the class CompileUtils method assertCompiles.

public static void assertCompiles(String name, String source) {
    ClassLoader parent = 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());
    }
}
Also used : SimpleCompiler(com.querydsl.codegen.utils.SimpleCompiler) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) StringWriter(java.io.StringWriter) MemFileManager(com.querydsl.codegen.utils.MemFileManager) MemSourceFileObject(com.querydsl.codegen.utils.MemSourceFileObject) JavaCompiler(javax.tools.JavaCompiler) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

MemFileManager (com.querydsl.codegen.utils.MemFileManager)1 MemSourceFileObject (com.querydsl.codegen.utils.MemSourceFileObject)1 SimpleCompiler (com.querydsl.codegen.utils.SimpleCompiler)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 JavaCompiler (javax.tools.JavaCompiler)1 SimpleJavaFileObject (javax.tools.SimpleJavaFileObject)1