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 error-prone by google.
the class BaseErrorProneCompiler method run.
public Result run(String[] argv) {
try {
argv = CommandLine.parse(argv);
} catch (IOException e) {
throw new IOError(e);
}
List<String> javacOpts = new ArrayList<>();
List<String> sources = new ArrayList<>();
for (String arg : argv) {
// TODO(cushon): is there a better way to categorize javacopts?
if (!arg.startsWith("-") && arg.endsWith(".java")) {
sources.add(arg);
} else {
javacOpts.add(arg);
}
}
StandardJavaFileManager fileManager = new MaskedFileManager();
return run(javacOpts.toArray(new String[0]), fileManager, ImmutableList.copyOf(fileManager.getJavaFileObjectsFromStrings(sources)), null);
}
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 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();
}
Aggregations