use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.
the class T6430241 method testSimpleAPI.
void testSimpleAPI(boolean expectWarnings, String... opts) {
System.err.println("test simple API: " + Arrays.asList(opts));
String[] args = initArgs(opts);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
JavacTool tool = JavacTool.create();
int rc = tool.run(null, null, ps, args);
String out = showOutput(baos.toString());
checkCompilationOK(rc);
checkOutput(out, expectWarnings);
}
use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.
the class T6430241 method testTaskAPI.
void testTaskAPI(boolean expectWarnings, Iterable<? extends File> pcp) throws Exception {
System.err.println("test task API: " + pcp);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
if (pcp != null)
fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavacTask task = tool.getTask(pw, fm, null, null, null, files);
boolean ok = task.call();
String out = showOutput(sw.toString());
checkCompilationOK(ok);
checkOutput(out, expectWarnings);
}
use of com.sun.tools.javac.api.JavacTool in project ceylon-compiler by ceylon.
the class T6348193 method test.
public static void test(NoYes secMgr, NoGoodBad config, NoYes proc) throws IOException {
if (verbose)
System.err.println("secMgr:" + secMgr + " config:" + config + " proc:" + proc);
if (secMgr == NoYes.YES && System.getSecurityManager() == null)
System.setSecurityManager(new NoLoaderSecurityManager());
installConfigFile(config);
processed.delete();
List<String> args = new ArrayList<String>();
//args.add("-XprintRounds");
if (proc == NoYes.YES) {
args.add("-processor");
args.add(myName);
}
args.add("-processorpath");
args.add(System.getProperty("java.class.path"));
args.add("-d");
args.add(".");
// avoid using class loader
JavacTool t = JavacTool.create();
MyDiagListener dl = new MyDiagListener();
PrintWriter out = new PrintWriter(System.err, true);
StandardJavaFileManager fm = t.getStandardFileManager(dl, null, null);
File file = new File(System.getProperty("test.src"), myName + ".java");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(file));
boolean ok = t.getTask(out, null, dl, args, null, files).call();
if (config == NoGoodBad.GOOD || proc == NoYes.YES) {
if (secMgr == NoYes.YES) {
if (dl.last == null)
throw new AssertionError("Security manager installed, and processors present, " + " but no diagnostic received");
} else {
if (!processed.exists())
throw new AssertionError("No security manager installed, and processors present, " + " but no processing occurred");
}
} else if (config == NoGoodBad.BAD) {
// TODO: should verify that no compiler crash occurred
// needs revised JSR199 spec
} else {
if (processed.exists())
throw new AssertionError("No processors present, but processing occurred!");
}
if (verbose)
System.err.println("OK");
}
Aggregations