use of javax.tools.StandardJavaFileManager in project bazel by bazelbuild.
the class IjarTests method makeCompilationTask.
private JavaCompiler.CompilationTask makeCompilationTask(String... files) throws IOException {
JavaCompiler compiler = BazelJavaCompiler.newInstance();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
fileManager.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(new File("third_party/ijar/test/interface_ijar_testlib.jar")));
fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(getTmpDir()));
diagnostics = new DiagnosticCollector<JavaFileObject>();
return compiler.getTask(null, fileManager, diagnostics, // used for deprecation tests
Arrays.asList("-Xlint:deprecation"), null, fileManager.getJavaFileObjects(files));
}
use of javax.tools.StandardJavaFileManager in project buck by facebook.
the class DefaultClassUsageFileWriterTest method fileReadOrderDoesntAffectClassesUsedOutput.
@Test
public void fileReadOrderDoesntAffectClassesUsedOutput() throws IOException {
ProjectFilesystem filesystem = FakeProjectFilesystem.createRealTempFilesystem();
Path testJarPath = filesystem.getPathForRelativePath("test.jar");
Path testTwoJarPath = filesystem.getPathForRelativePath("test2.jar");
Path outputOne = filesystem.getPathForRelativePath("used-classes-one.json");
Path outputTwo = filesystem.getPathForRelativePath("used-classes-two.json");
FakeStandardJavaFileManager fakeFileManager = new FakeStandardJavaFileManager();
fakeFileManager.addFile(testJarPath, OTHER_FILE_NAME, JavaFileObject.Kind.OTHER);
fakeFileManager.addFile(testJarPath, SOURCE_FILE_NAME, JavaFileObject.Kind.SOURCE);
fakeFileManager.addFile(testJarPath, HTML_FILE_NAME, JavaFileObject.Kind.HTML);
fakeFileManager.addFile(testJarPath, SINGLE_NON_JAVA_FILE_NAME, JavaFileObject.Kind.OTHER);
for (String fileName : FILE_NAMES) {
fakeFileManager.addFile(testJarPath, fileName, JavaFileObject.Kind.CLASS);
}
for (String fileName : FILE_NAMES) {
fakeFileManager.addFile(testTwoJarPath, fileName, JavaFileObject.Kind.CLASS);
}
DefaultClassUsageFileWriter writerOne = new DefaultClassUsageFileWriter(outputOne);
{
StandardJavaFileManager wrappedFileManager = writerOne.wrapFileManager(fakeFileManager);
for (JavaFileObject javaFileObject : wrappedFileManager.list(null, null, null, false)) {
javaFileObject.openInputStream();
}
}
writerOne.writeFile(filesystem, ObjectMappers.newDefaultInstance());
DefaultClassUsageFileWriter writerTwo = new DefaultClassUsageFileWriter(outputTwo);
{
StandardJavaFileManager wrappedFileManager = writerTwo.wrapFileManager(fakeFileManager);
Iterable<JavaFileObject> fileObjects = wrappedFileManager.list(null, null, null, false);
for (JavaFileObject javaFileObject : FluentIterable.from(fileObjects).toList().reverse()) {
javaFileObject.openInputStream();
}
}
writerTwo.writeFile(filesystem, ObjectMappers.newDefaultInstance());
assertEquals(new String(Files.readAllBytes(outputOne)), new String(Files.readAllBytes(outputTwo)));
}
use of javax.tools.StandardJavaFileManager in project hibernate-orm by hibernate.
the class CompilationStatement method compile.
private void compile(List<File> sourceFiles) throws Exception {
List<String> options = createJavaOptions();
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(sourceFiles);
compileSources(options, compiler, diagnostics, fileManager, compilationUnits);
compilationDiagnostics.addAll(diagnostics.getDiagnostics());
fileManager.close();
}
use of javax.tools.StandardJavaFileManager in project error-prone by google.
the class CompilerBasedTest method compile.
protected void compile(TreeScanner scanner, JavaFileObject fileObject) {
JavaCompiler compiler = JavacTool.create();
DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticsCollector, Locale.ENGLISH, UTF_8);
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(CharStreams.nullWriter(), fileManager, diagnosticsCollector, ImmutableList.<String>of(), null, ImmutableList.of(fileObject));
try {
this.sourceFile = SourceFile.create(fileObject);
Iterable<? extends CompilationUnitTree> trees = task.parse();
task.analyze();
for (CompilationUnitTree tree : trees) {
scanner.scan((JCCompilationUnit) tree);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
this.context = task.getContext();
}
use of javax.tools.StandardJavaFileManager in project jdk8u_jdk by JetBrains.
the class ManyMethodsBenchmarkApp method main.
public static void main(String[] args) throws Exception {
System.out.println("test started: ManyMethodsBenchmarkApp");
// Create source files with many methods
File base = new File("Base.java");
try (FileWriter fw = new FileWriter(base)) {
fw.write("public class Base {\n");
final int L = 10;
// Each of the first L methods makes calls to its own chunk of METHOD_COUNT/L methods
for (int k = 0; k < L; k++) {
fw.write(" public void f" + k + "() {\n");
int shift = (k == 0) ? L : 0;
for (int i = (k * (METHOD_COUNT / L)) + shift; i < (k + 1) * METHOD_COUNT / L; i++) {
fw.write(" f" + i + "();\n");
}
fw.write(" }\n");
}
// The rest of (METHOD_COUNT - L) methods have empty body
for (int i = L; i < METHOD_COUNT; i++) {
fw.write(" public static void f" + i + "() {}\n");
}
fw.write("}\n");
}
// Compile the generated source files.
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
List<File> files = Arrays.asList(new File[] { base });
try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null)) {
compiler.getTask(null, fileManager, null, null, null, fileManager.getJavaFileObjectsFromFiles(files)).call();
}
benchmarkClassOperations("Base");
ManyMethodsBenchmarkAgent.instr();
// Cleanup
base.delete();
new File("Base.class").delete();
if (!ManyMethodsBenchmarkAgent.completed) {
throw new Exception("ERROR: ManyMethodsBenchmarkAgent did not complete.");
}
if (ManyMethodsBenchmarkAgent.fail) {
throw new Exception("ERROR: ManyMethodsBenchmarkAgent failed.");
} else {
System.out.println("ManyMethodsBenchmarkAgent succeeded.");
}
System.out.println("test finished: ManyMethodsBenchmarkApp");
}
Aggregations