use of javax.tools.JavaCompiler.CompilationTask in project ceylon by eclipse.
the class T6458823 method main.
public static void main(String[] args) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) {
throw new RuntimeException("can't get javax.tools.JavaCompiler!");
}
DiagnosticCollector<JavaFileObject> diagColl = new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
List<String> options = new ArrayList<String>();
options.add("-processor");
options.add("MyProcessor");
options.add("-proc:only");
List<File> files = new ArrayList<File>();
files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
final CompilationTask task = compiler.getTask(null, fm, diagColl, options, null, fm.getJavaFileObjectsFromFiles(files));
task.call();
int diagCount = 0;
for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
if (diag.getKind() != Diagnostic.Kind.WARNING) {
throw new AssertionError("Only warnings expected");
}
System.out.println(diag);
if (diag.getPosition() == Diagnostic.NOPOS) {
throw new AssertionError("No position info in message");
}
if (diag.getSource() == null) {
throw new AssertionError("No source info in message");
}
diagCount++;
}
if (diagCount != 2) {
throw new AssertionError("unexpected number of warnings: " + diagCount + ", expected: 2");
}
}
use of javax.tools.JavaCompiler.CompilationTask in project ceylon by eclipse.
the class T7031108 method compile.
void compile(JavaCompiler comp, JavaFileManager fm, DiagnosticListener<JavaFileObject> dl, String processor, JavaFileObject... files) throws Exception {
System.err.println("compile processor:" + processor + ", files:" + Arrays.asList(files));
List<String> opts = new ArrayList<String>();
if (processor != null) {
// opts.add("-verbose");
opts.addAll(Arrays.asList("-processor", processor));
}
CompilationTask task = comp.getTask(null, fm, dl, opts, null, Arrays.asList(files));
boolean ok = task.call();
if (dl == null && !ok)
throw new Exception("compilation failed");
}
use of javax.tools.JavaCompiler.CompilationTask in project ceylon by eclipse.
the class TreePosRoundsTest method main.
public static void main(String... args) throws Exception {
String testSrc = System.getProperty("test.src");
String testClasses = System.getProperty("test.classes");
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
String thisName = TreePosRoundsTest.class.getName();
File thisFile = new File(testSrc, thisName + ".java");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
List<String> options = Arrays.asList("-proc:only", "-processor", thisName, "-processorpath", testClasses);
CompilationTask t = c.getTask(null, fm, null, options, null, files);
boolean ok = t.call();
if (!ok)
throw new Exception("processing failed");
}
use of javax.tools.JavaCompiler.CompilationTask in project ceylon by eclipse.
the class EagerInterfaceCompletionTest method compile.
void compile(DiagnosticChecker dc, JavaSource... sources) {
try {
CompilationTask ct = javacTool.getTask(null, null, dc, Arrays.asList("-d", testDir.getAbsolutePath(), "-cp", testDir.getAbsolutePath()), null, Arrays.asList(sources));
ct.call();
} catch (Exception e) {
e.printStackTrace();
error("Internal compilation error");
}
}
use of javax.tools.JavaCompiler.CompilationTask in project ceylon by eclipse.
the class TestGetResource2 method testMissingResource.
private void testMissingResource(JavaCompiler javac) throws Exception {
System.err.println("testMissingResource");
File tmpdir = new File("testMissingResource");
File srcdir = new File(tmpdir, "src");
File destdir = new File(tmpdir, "dest");
write(srcdir, "pkg/X.java", "package pkg; class X {}");
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 when missing resource: " + result);
expect(result, false);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
Aggregations