Search in sources :

Example 6 with EclipseCompiler

use of org.eclipse.jdt.internal.compiler.tool.EclipseCompiler in project querydsl by querydsl.

the class EclipseCompilationTest method test.

@Test
@Ignore
public void test() throws IOException {
    System.setProperty("jdt.compiler.useSingleThread", "true");
    // select classes
    List<String> classes = new ArrayList<String>();
    for (File file : new File(packagePath).listFiles()) {
        if (file.getName().endsWith(".java")) {
            classes.add(file.getPath());
        }
    }
    // prepare output
    File out = new File("target/out-eclipse");
    FileUtils.delete(out);
    if (!out.mkdirs()) {
        Assert.fail("Creation of " + out.getPath() + " failed");
    }
    String classPath = SimpleCompiler.getClassPath((URLClassLoader) getClass().getClassLoader());
    JavaCompiler compiler = new EclipseCompiler();
    List<String> options = new ArrayList<String>();
    options.add("-s");
    options.add("target/out-eclipse");
    options.add("-proc:only");
    options.add("-processor");
    options.add(QuerydslAnnotationProcessor.class.getName());
    options.add("-Aquerydsl.entityAccessors=true");
    options.add("-cp");
    options.add(classPath);
    options.add("-source");
    options.add("1.6");
    options.add("-verbose");
    options.addAll(classes);
    int compilationResult = compiler.run(null, System.out, System.err, options.toArray(new String[0]));
    if (compilationResult == 0) {
        System.out.println("Compilation is successful");
    } else {
        Assert.fail("Compilation Failed");
    }
    File resultFile = new File("target/out-eclipse/com/querydsl/eclipse/QSimpleEntity.java");
    assertTrue(resultFile.exists());
    String result = new String(Files.readAllBytes(resultFile.toPath()), StandardCharsets.UTF_8);
    assertTrue(result.contains("NumberPath<java.math.BigDecimal> bigDecimalProp"));
    assertTrue(result.contains("NumberPath<Integer> integerProp"));
    assertTrue(result.contains("NumberPath<Integer> intProp"));
    assertTrue(result.contains("StringPath stringProp"));
}
Also used : EclipseCompiler(org.eclipse.jdt.internal.compiler.tool.EclipseCompiler) ArrayList(java.util.ArrayList) JavaCompiler(javax.tools.JavaCompiler) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

EclipseCompiler (org.eclipse.jdt.internal.compiler.tool.EclipseCompiler)6 File (java.io.File)5 ArrayList (java.util.ArrayList)3 JavaCompiler (javax.tools.JavaCompiler)3 StandardJavaFileManager (javax.tools.StandardJavaFileManager)3 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 Writer (java.io.Writer)2 DiagnosticCollector (javax.tools.DiagnosticCollector)2 CompilationTask (javax.tools.JavaCompiler.CompilationTask)2 JavaFileObject (javax.tools.JavaFileObject)2 AutoAnnotationProcessor (com.google.auto.value.processor.AutoAnnotationProcessor)1 AutoBuilderProcessor (com.google.auto.value.processor.AutoBuilderProcessor)1 AutoOneOfProcessor (com.google.auto.value.processor.AutoOneOfProcessor)1 AutoValueProcessor (com.google.auto.value.processor.AutoValueProcessor)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 FileWriter (java.io.FileWriter)1 StringReader (java.io.StringReader)1 MalformedURLException (java.net.MalformedURLException)1