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"));
}
Aggregations