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()); } }
@Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { FileObject resource = filer.createResource(StandardLocation.SOURCE_OUTPUT, pkg.name(), fileName); return resource.openOutputStream(); }
public void writeStream(FileObject fileObject, byte[] data) throws IOException { OutputStream stream = fileObject.openOutputStream(); stream.write(data); stream.close(); }
/** {@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 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); } } }
public void writeMetadata(CandidateComponentsMetadata metadata) throws IOException { if (!metadata.getItems().isEmpty()) { try (OutputStream outputStream = createMetadataResource().openOutputStream()) { PropertiesMarshaller.write(metadata, outputStream); } } }
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()); } } } }
/** 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"); } } }
getFullyQualifiedClassName( entity, metaModelPackage ) ); OutputStream os = fo.openOutputStream(); PrintWriter pw = new PrintWriter( os );
p.setComment(entry2.getKey(), entry2.getValue(), false); OutputStream os = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, pkg, "Bundle.properties", elements).openOutputStream(); try { p.store(os);
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 { os.write(data);
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { StandardLocation loc; if(fileName.endsWith(".java")) { // Annotation Processing doesn't do the proper Unicode escaping on Java source files, // so we can't rely on Filer.createSourceFile. loc = SOURCE_PATH; } else { // put non-Java files directly to the output folder loc = CLASS_PATH; } return filer.createResource(loc, pkg.name(), fileName).openOutputStream(); }
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) { if (!originatingElements.isEmpty()) { try { processingEnv.getFiler().createResource( StandardLocation.CLASS_OUTPUT, "", "META-INF/.bytecodePatched", originatingElements.toArray(new Element[originatingElements.size()])). openOutputStream().close(); } catch (IOException x) { processingEnv.getMessager().printMessage(Kind.ERROR, x.getMessage()); } } return false; } for (Element e : roundEnv.getElementsAnnotatedWith(PatchedPublic.class)) { if (e.getAnnotationMirrors().size() > 1) { processingEnv.getMessager().printMessage(Kind.ERROR, "Cannot currently mix @PatchedPublic with other annotations", e); continue; } if (e.getModifiers().contains(Modifier.PUBLIC)) { processingEnv.getMessager().printMessage(Kind.ERROR, "@PatchedPublic cannot be applied to what is already public", e); continue; } originatingElements.add(e); } return true; }
@Override protected void write(GeneratedResource resource) { FileObject file; try { file = processingEnv.getFiler().createResource(SOURCE_OUTPUT, EMPTY, resource.getPath()); } catch (IOException e) { throw wrapException(e, resource); } try (OutputStream out = file.openOutputStream()) { out.write(resource.getContent()); out.flush(); } catch (IOException e) { throw wrapException(e, resource); } }
@Test public void write() throws Exception { FileObject file = mock(FileObject.class); when(processingEnvironment.getFiler().createResource(SOURCE_OUTPUT, EMPTY, RESOURCE_PATH)).thenReturn(file); OutputStream out = mock(OutputStream.class, RETURNS_DEEP_STUBS); when(file.openOutputStream()).thenReturn(out); generator.generateFor(extensionModel); verify(out).write(RESOURCE_CONTENT); verify(out).flush(); } }
p.setComment(entry2.getKey(), entry2.getValue(), false); OutputStream os = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, pkg, "Bundle.properties", elements).openOutputStream(); try { p.store(os);
/** * @throws IllegalStateException {@inheritDoc} * @throws UnsupportedOperationException {@inheritDoc} * @throws IOException {@inheritDoc} */ public OutputStream openOutputStream() throws IOException { return fileObject.openOutputStream(); }
private void writeServices( final Filer filer, final String resourceFile, final Collection<String> services ) throws Exception { final FileObject file = createResource(filer, resourceFile); final OutputStream outputStream = file.openOutputStream(); try { IOUtils.writeLines(services, "\n", outputStream, StandardCharsets.UTF_8); } finally { IOUtils.closeQuietly(outputStream); } }
@Override public OutputStream openOutputStream() throws IOException { try { return clientFileObject.openOutputStream(); } catch (ClientCodeException e) { throw e; } catch (RuntimeException e) { throw new ClientCodeException(e); } catch (Error e) { throw new ClientCodeException(e); } }
void writeMojosXml(TreeMap<String, MojoDescriptor> descriptors) throws IOException { PluginDescriptor mojos = new PluginDescriptor(); for (MojoDescriptor descriptor : descriptors.values()) { mojos.addMojo(descriptor); } FileObject output = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", PATH_MOJOS_XML); try (OutputStream out = output.openOutputStream()) { new PluginDescriptorXpp3Writer().write(out, mojos); } }