use of javax.tools.JavaCompiler.CompilationTask in project querydsl by querydsl.
the class JDKEvaluatorFactory method compile.
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());
}
}
use of javax.tools.JavaCompiler.CompilationTask in project ceylon by eclipse.
the class MainTest method compileAndJar.
public static File compileAndJar(String javaModule, String javaClassName, File addToClassPath) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
String javaModulePath = javaModule.replace('.', '/');
File moduleFile = new File("test/" + javaModulePath, javaClassName + ".java");
Iterable<? extends JavaFileObject> units = fileManager.getJavaFileObjects(moduleFile);
File destDir = new File("build/javaModules");
FileUtil.delete(destDir);
destDir.mkdirs();
List<String> options = new LinkedList<String>();
options.add("-d");
options.add(destDir.getPath());
if (addToClassPath != null) {
options.add("-cp");
options.add(addToClassPath.getPath());
}
CompilationTask task = compiler.getTask(null, null, null, options, null, units);
Boolean result = task.call();
assertTrue(result != null && result.booleanValue());
File compiledModuleFile = new File(destDir, javaModulePath + "/" + javaClassName + ".class");
assertTrue(compiledModuleFile.isFile());
return jar(compiledModuleFile, javaModulePath);
}
use of javax.tools.JavaCompiler.CompilationTask in project ceylon by eclipse.
the class MainTest method testCeylonModule.
@Test
public void testCeylonModule() throws IOException, ModuleNotFoundException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
File moduleFile = new File("test/foo/foo", "$module_.java");
Iterable<? extends JavaFileObject> units = fileManager.getJavaFileObjects(moduleFile);
File destDir = new File("build/mainTest");
FileUtil.delete(destDir);
destDir.mkdirs();
CompilationTask task = compiler.getTask(null, null, null, Arrays.asList("-d", destDir.getPath(), "-cp", "build/classes" + File.pathSeparator + LANGUAGE_MODULE_CAR + File.pathSeparator + MODEL_MODULE_CAR), null, units);
Boolean result = task.call();
assertTrue(result != null && result.booleanValue());
File compiledModuleFile = new File(destDir, "foo/foo/$module_.class");
assertTrue(compiledModuleFile.isFile());
File jar = jar(compiledModuleFile, "foo/foo");
try {
checkJarDependencies(jar);
} finally {
jar.delete();
}
}
use of javax.tools.JavaCompiler.CompilationTask in project ceylon by eclipse.
the class TestJavacTask_Lock method test.
void test(MethodKind first, MethodKind second) {
System.err.println("test: " + first + ", " + second);
File testSrc = new File(System.getProperty("test.src"));
String thisClassName = TestJavacTask_Lock.class.getName();
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(new File(testSrc, thisClassName + ".java"));
File tmpDir = new File(first + "_" + second);
tmpDir.mkdirs();
List<String> options = Arrays.asList("-d", tmpDir.getPath());
CompilationTask t = comp.getTask(null, fm, null, options, null, files);
try {
first.test(t);
second.test(t);
error("No exception thrown");
} catch (IllegalStateException e) {
System.err.println("Expected exception caught: " + e);
} catch (Exception e) {
error("Unexpected exception caught: " + e);
e.printStackTrace(System.err);
}
}
use of javax.tools.JavaCompiler.CompilationTask in project ceylon by eclipse.
the class T6900149 method main.
public static void main(String[] args) throws IOException {
DiagnosticCollector<JavaFileObject> diag = new DiagnosticCollector<JavaFileObject>();
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
File emptyFile = File.createTempFile("Empty", ".java");
File[] files = new File[] { emptyFile, emptyFile };
CompilationTask task = compiler.getTask(null, fm, diag, null, null, fm.getJavaFileObjects(files));
if (!task.call()) {
throw new AssertionError("compilation failed");
}
}
Aggregations