use of javax.tools.JavaCompiler in project buck by facebook.
the class DalvikStatsToolTest method compileSources.
private void compileSources(File outputDir, JavaSourceFromString... sources) {
ImmutableList.Builder<String> builder = ImmutableList.builder();
builder.add("-d", outputDir.toString());
builder.add("-target", TARGETED_JAVA_VERSION);
builder.add("-source", TARGETED_JAVA_VERSION);
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, builder.build(), null, Arrays.asList(sources));
assertTrue(task.call());
}
use of javax.tools.JavaCompiler in project jsonschema2pojo by joelittlejohn.
the class CompilerWarningIT method parameters.
@Parameters(name = "{0}")
public static Collection<Object[]> parameters() {
JavaCompiler systemJavaCompiler = Compiler.systemJavaCompiler();
JavaCompiler eclipseCompiler = Compiler.eclipseCompiler();
return Arrays.asList(new Object[][] { { "includeAccessorsWithSystemJavaCompiler", systemJavaCompiler, config("includeDynamicAccessors", true), "/schema/dynamic/parentType.json", Matchers.empty() }, { "includeAccessorsWithEclipseCompiler", eclipseCompiler, config("includeDynamicAccessors", true), "/schema/dynamic/parentType.json", onlyCastExceptions() } });
}
use of javax.tools.JavaCompiler in project querydsl by querydsl.
the class MetaDataSerializerTest method compile.
private void compile(MetaDataExporter exporter) {
JavaCompiler compiler = new SimpleCompiler();
Set<String> classes = exporter.getClasses();
int compilationResult = compiler.run(null, null, null, classes.toArray(new String[classes.size()]));
if (compilationResult == 0) {
System.out.println("Compilation is successful");
} else {
Assert.fail("Compilation Failed");
}
}
use of javax.tools.JavaCompiler in project lombok by rzwitserloot.
the class TestClassFileMetaData method compile.
static byte[] compile(File file) {
try {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
File tempDir = getTempDir();
tempDir.mkdirs();
List<String> options = Arrays.asList("-proc:none", "-d", tempDir.getAbsolutePath());
StringWriter captureWarnings = new StringWriter();
final StringBuilder compilerErrors = new StringBuilder();
DiagnosticListener<JavaFileObject> diagnostics = new DiagnosticListener<JavaFileObject>() {
@Override
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
compilerErrors.append(diagnostic.toString()).append("\n");
}
};
CompilationTask task = compiler.getTask(captureWarnings, null, diagnostics, options, null, Collections.singleton(new ContentBasedJavaFileObject(file.getPath(), readFileAsString(file))));
Boolean taskResult = task.call();
assertTrue("Compilation task didn't succeed: \n<Warnings and Errors>\n" + compilerErrors.toString() + "\n</Warnings and Errors>", taskResult);
return PostCompilerApp.readFile(new File(tempDir, file.getName().replaceAll("\\.java$", ".class")));
} catch (Exception e) {
throw Lombok.sneakyThrow(e);
}
}
use of javax.tools.JavaCompiler in project jadx by skylot.
the class StaticCompiler method compile.
public static List<File> compile(List<File> files, File outDir, boolean includeDebugInfo) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(files);
StaticFileManager staticFileManager = new StaticFileManager(fileManager, outDir);
List<String> options = new ArrayList<String>();
options.add(includeDebugInfo ? "-g" : "-g:none");
options.addAll(COMMON_ARGS);
CompilationTask task = compiler.getTask(null, staticFileManager, null, options, null, compilationUnits);
Boolean result = task.call();
fileManager.close();
if (Boolean.TRUE.equals(result)) {
return staticFileManager.outputFiles();
}
return Collections.emptyList();
}
Aggregations