use of javax.tools.JavaCompiler.CompilationTask in project ceylon-compiler by ceylon.
the class Test method test.
void test(List<String> options, String expect) throws Exception {
System.err.println("test: " + options);
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavaFileObject f = new MyFileObject("myfo://test", "class Bad { Missing x; }");
List<? extends JavaFileObject> files = Arrays.asList(f);
CompilationTask task = javac.getTask(pw, null, null, options, null, files);
boolean ok = task.call();
pw.close();
String out = sw.toString();
if (!out.isEmpty())
System.err.println(out);
if (ok)
throw new Exception("Compilation succeeded unexpectedly");
if (!out.contains(expect))
throw new Exception("expected text not found: " + expect);
}
use of javax.tools.JavaCompiler.CompilationTask in project ceylon-compiler by ceylon.
the class T6378728 method main.
public static void main(String[] args) {
// Get a compiler tool
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
String srcdir = System.getProperty("test.src");
File source = new File(srcdir, "T6378728.java");
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
CompilationTask task = compiler.getTask(null, new ExceptionalFileManager(fm), null, Arrays.asList("-proc:only"), null, fm.getJavaFileObjectsFromFiles(Arrays.asList(source)));
if (!task.call())
throw new RuntimeException("Unexpected compilation failure");
}
use of javax.tools.JavaCompiler.CompilationTask in project ceylon-compiler by ceylon.
the class BcTests method testBinaryVersionIncompatibleModule2.
// tests after we renamed module_.class to $module_.class
@Test
public void testBinaryVersionIncompatibleModule2() throws IOException {
CompilationTask compiler = compileJava("binaryVersionOld2/$module_.java");
Assert.assertTrue(compiler.call());
// so now make a jar containing the java module
File jarFolder = new File(destDir, "com/redhat/ceylon/compiler/java/test/bc/binaryVersionOld2/1/");
jarFolder.mkdirs();
File jarFile = new File(jarFolder, "com.redhat.ceylon.compiler.java.test.bc.binaryVersionOld2-1.jar");
// now jar it up
JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(jarFile));
ZipEntry entry = new ZipEntry("com/redhat/ceylon/compiler/java/test/bc/binaryVersionOld2/$module_.class");
outputStream.putNextEntry(entry);
File javaClass = new File(destDir, "com/redhat/ceylon/compiler/java/test/bc/binaryVersionOld2/$module_.class");
FileInputStream inputStream = new FileInputStream(javaClass);
Util.copy(inputStream, outputStream);
inputStream.close();
outputStream.close();
assertErrors("binaryVersion2/module", new CompilerError(21, "version '1' of module 'com.redhat.ceylon.compiler.java.test.bc.binaryVersionOld2' was compiled by" + " an incompatible version of the compiler" + " (binary version 0.0 of module is not compatible with binary version " + Versions.JVM_BINARY_MAJOR_VERSION + "." + Versions.JVM_BINARY_MINOR_VERSION + " of this compiler)"));
}
use of javax.tools.JavaCompiler.CompilationTask in project ceylon-compiler by ceylon.
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");
}
}
use of javax.tools.JavaCompiler.CompilationTask in project ceylon-compiler by ceylon.
the class TestGetResource2 method testSingleSourceDir.
private void testSingleSourceDir(JavaCompiler javac) throws Exception {
System.err.println("testSingleSourceDir");
File tmpdir = new File("testSingleSourceDir");
File srcdir = new File(tmpdir, "src");
File destdir = new File(tmpdir, "dest");
write(srcdir, "pkg/X.java", "package pkg; class X {}");
write(srcdir, "resources/file.txt", "hello");
destdir.mkdirs();
CompilationTask task = javac.getTask(null, null, null, Arrays.asList("-sourcepath", srcdir.toString(), "-d", destdir.toString()), Collections.singleton("pkg.X"), null);
task.setProcessors(Collections.singleton(new AnnoProc()));
boolean result = task.call();
System.err.println("javac result with single source dir: " + result);
expect(result, true);
}
Aggregations