private FileObject createMetadataResource() throws IOException { return this.environment.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", METADATA_PATH); }
@Override public FileObject createResource( JavaFileManager.Location location, CharSequence pkg, CharSequence relativeName, Element... originatingElements) throws IOException { return delegate.createResource(location, pkg, relativeName, originatingElements); }
private void write(TypeElement c) throws IOException { FileObject f = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/services/hudson.Plugin"); try (Writer w = new OutputStreamWriter(f.openOutputStream(), "UTF-8")) { w.write(c.getQualifiedName().toString()); } }
public FileObject getFileObject(String pkg, String name) throws IOException { return processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, pkg, name); }
@Override public void generate() { final String fileName = "org.robolectric.internal.ShadowProvider"; try { FileObject file = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/services/" + fileName); PrintWriter pw = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); pw.println(shadowPackage + '.' + GEN_CLASS); pw.close(); } catch (IOException e) { messager.printMessage(Diagnostic.Kind.ERROR, "Failed to write service loader metadata file: " + e); throw new RuntimeException(e); } } }
/** {@inheritDoc} */ @Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); try { FileObject manifest = processingEnv .getFiler() .createResource(StandardLocation.SOURCE_OUTPUT, "", "bugPatterns.txt"); pw = new PrintWriter(new OutputStreamWriter(manifest.openOutputStream(), UTF_8)); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public Writer openStream() throws IOException { return getFiler() .createResource(StandardLocation.CLASS_OUTPUT, key.packageName, key.relativeName) .openWriter(); } }.writeLines(services, "\n");
@Override public FileObject createResource( Location location, CharSequence pkg, CharSequence relativeName, Element... originatingElements) throws IOException { return delegate().createResource(location, pkg, relativeName, originatingElements); }
@Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { FileObject resource = filer.createResource(StandardLocation.SOURCE_OUTPUT, pkg.name(), fileName); return resource.openOutputStream(); }
dummySourceFile = filer.createResource(StandardLocation.SOURCE_OUTPUT, "", "dummy" + System.currentTimeMillis()); } catch (IOException ignored) { throw new FileNotFoundException();
private BufferedWriter createWriter(final String packageName, final String fileName) throws IOException { if (reportPath == null) { return new BufferedWriter(processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, packageName, fileName).openWriter()); } final Path outputPath = Paths.get(reportPath, packageName.replace(".", FileSystems.getDefault().getSeparator()), fileName); Files.createDirectories(outputPath.getParent()); return Files.newBufferedWriter(outputPath, StandardCharsets.UTF_8, StandardOpenOption.CREATE); }
void writeDotFile(TypeElement module, Map<String, Binding<?>> bindings) throws IOException { JavaFileManager.Location location = StandardLocation.SOURCE_OUTPUT; String path = getPackage(module).getQualifiedName().toString(); String file = module.getQualifiedName().toString().substring(path.length() + 1) + ".dot"; FileObject resource = processingEnv.getFiler().createResource(location, path, file, module); Writer writer = resource.openWriter(); GraphVizWriter dotWriter = new GraphVizWriter(writer); new GraphVisualizer().write(bindings, dotWriter); dotWriter.close(); }
private void writeServices() { for (Map.Entry<Filer,Map<String,SortedSet<ServiceLoaderLine>>> outputFiles : outputFilesByProcessor.entrySet()) { Filer filer = outputFiles.getKey(); for (Map.Entry<String,SortedSet<ServiceLoaderLine>> entry : outputFiles.getValue().entrySet()) { try { FileObject out = filer.createResource(StandardLocation.CLASS_OUTPUT, "", entry.getKey(), originatingElementsByProcessor.get(filer).get(entry.getKey()).toArray(new Element[0])); OutputStream os = out.openOutputStream(); try { PrintWriter w = new PrintWriter(new OutputStreamWriter(os, "UTF-8")); for (ServiceLoaderLine line : entry.getValue()) { line.write(w); } w.flush(); w.close(); } finally { os.close(); } } catch (IOException x) { processingEnv.getMessager().printMessage(Kind.ERROR, "Failed to write to " + entry.getKey() + ": " + x.toString()); } } } }
final FileObject resource = processingEnv.getFiler().createResource( StandardLocation.CLASS_OUTPUT, "", "META-INF/services/orbit/classes/" + elementUtils.getBinaryName(e) + ".yml", e); + ((classId < 0) ? "/m" : "/") + Math.abs(classId) + ".name"; final FileObject classIdResource = processingEnv.getFiler().createResource( StandardLocation.CLASS_OUTPUT, "", fileName, e);
/** Saves the prop names of the given spec model at a well-known path within the resources. */ public void saveNames(SpecModel specModel) throws IOException { // This is quite important, because we must not open resources without writing to them // due to a bug in the Buck caching layer. if (specModel.getRawProps().isEmpty()) { return; } final FileObject outputFile = mFiler.createResource( StandardLocation.CLASS_OUTPUT, "", BASE_PATH + specModel.getSpecTypeName() + FILE_EXT); try (Writer writer = new BufferedWriter(new OutputStreamWriter(outputFile.openOutputStream()))) { for (final PropModel propModel : specModel.getRawProps()) { writer.write(propModel.getName() + "\n"); } for (final InjectPropModel propModel : specModel.getRawInjectProps()) { writer.write(propModel.getName() + "\n"); } } }
FileObject sourceFile = processingEnv.getFiler().createResource( SOURCE_OUTPUT, generator.getOutputPackage(),
final FileObject fileObject = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, messageInterface.packageName(), fileName);
p.setComment(entry2.getKey(), entry2.getValue(), false); OutputStream os = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, pkg, "Bundle.properties", elements).openOutputStream(); try { p.store(os);
byte[] data = baos.toByteArray(); XMLUtil.parse(new InputSource(new ByteArrayInputStream(data)), true, true, ERROR_HANDLER, ENTITY_RESOLVER); FileObject layer = filer.createResource(StandardLocation.CLASS_OUTPUT, "", GENERATED_LAYER, originatingElementsA); OutputStream os = layer.openOutputStream(); try {
@Test public void testSave() throws IOException { final PropNameInterStageStore store = new PropNameInterStageStore(mFiler); final MockSpecModel specModel = MockSpecModel.newBuilder() .rawProps(ImmutableList.of(makePropModel("param0"), makePropModel("param1"))) .rawInjectProps(ImmutableList.of(makeInjectPropModel("injectParam0"))) .specTypeName(ClassName.get(MyTestSpec.class)) .build(); store.saveNames(specModel); verify(mFiler) .createResource( StandardLocation.CLASS_OUTPUT, "", "META-INF/litho/com.facebook.litho.specmodels.processor.PropNameInterStageStoreTest.MyTestSpec.props"); // Not checking the actually written values here because Java IO is a horrible mess. }