Search in sources :

Example 1 with SimpleCompiler

use of com.mysema.codegen.SimpleCompiler in project querydsl by querydsl.

the class CompileUtils method assertCompiles.

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());
    }
}
Also used : SimpleCompiler(com.mysema.codegen.SimpleCompiler) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) StringWriter(java.io.StringWriter) MemFileManager(com.mysema.codegen.MemFileManager) URLClassLoader(java.net.URLClassLoader) MemSourceFileObject(com.mysema.codegen.MemSourceFileObject) JavaCompiler(javax.tools.JavaCompiler) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 2 with SimpleCompiler

use of com.mysema.codegen.SimpleCompiler in project querydsl by querydsl.

the class MetaDataSerializerTest method compile.

private void compile(MetaDataExporter exporter) {
    JavaCompiler compiler = new SimpleCompiler();
    Set<String> classes = exporter.getClasses();
    int compilationResult = compiler.run(null, null, null, classes.toArray(new String[classes.size()]));
    if (compilationResult == 0) {
        System.out.println("Compilation is successful");
    } else {
        Assert.fail("Compilation Failed");
    }
}
Also used : SimpleCompiler(com.mysema.codegen.SimpleCompiler) JavaCompiler(javax.tools.JavaCompiler)

Aggregations

SimpleCompiler (com.mysema.codegen.SimpleCompiler)2 JavaCompiler (javax.tools.JavaCompiler)2 MemFileManager (com.mysema.codegen.MemFileManager)1 MemSourceFileObject (com.mysema.codegen.MemSourceFileObject)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 URLClassLoader (java.net.URLClassLoader)1 SimpleJavaFileObject (javax.tools.SimpleJavaFileObject)1