List of usage examples for javax.tools FileObject toUri
URI toUri();
From source file:io.fabric8.kubernetes.generator.processor.AbstractKubernetesAnnotationProcessor.java
private FileObject getFileObject(String fileName) throws IOException { FileObject fileObject = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", fileName); Path path = Paths.get(fileObject.toUri()); File file = path.toFile();/*w w w . jav a 2s .co m*/ if (file.exists() && !file.delete()) { throw new IOException("Failed to delete old kubernetes json file: " + fileName); } fileObject = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", fileName); return fileObject; }
From source file:org.callimachusproject.rewrite.ProxyPostAdvice.java
protected HttpUriRequest createRequest(String location, Header[] headers, ObjectMessage message, FluidBuilder fb) throws IOException, FluidException { Object target = message.getTarget(); Integer bodyIndex = getBodyIndex(message.getMethod()); if (bodyIndex == null && target instanceof FileObject && contains(headers, "Content-Type")) { FileObject file = (FileObject) target; InputStream in = file.openInputStream(); if (in != null) { HttpPost req = new HttpPost(location); req.setHeaders(headers);//from w ww . ja v a2s. c o m if (!contains(headers, "Content-Location")) { String uri = file.toUri().toASCIIString(); req.setHeader("Content-Location", uri); } req.setEntity(new StreamEntity(in)); return req; } } if (bodyIndex == null) { HttpPost req = new HttpPost(location); req.setHeaders(headers); return req; } HttpPost req = new HttpPost(location); req.setHeaders(headers); Object body = message.getParameters()[bodyIndex]; Fluid fluid = fb.consume(body, getSystemId(), bodyFluidType); req.setEntity(fluid.asHttpEntity()); return req; }
From source file:info.archinnov.achilles.internals.apt.processors.meta.AchillesProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (!this.processed) { try {/*from w ww . j a va2 s .com*/ final GlobalParsingContext parsingContext = parseCodecRegistry(annotations, roundEnv); final List<EntityMetaSignature> tableAndViewSignatures = discoverAndValidateTablesAndViews( annotations, roundEnv, parsingContext); final FunctionsContext udfContext = parseAndValidateFunctionRegistry(parsingContext, annotations, roundEnv, tableAndViewSignatures); final TypeSpec managerFactoryBuilder = ManagerFactoryBuilderCodeGen.buildInstance(); final ManagersAndDSLClasses managersAndDSLClasses = ManagerFactoryCodeGen.buildInstance(aptUtils, tableAndViewSignatures, udfContext, parsingContext); aptUtils.printNote("[Achilles] Reading previously generated source files (if exist)"); try { final FileObject resource = aptUtils.filer.getResource(StandardLocation.SOURCE_OUTPUT, GENERATED_PACKAGE, MANAGER_FACTORY_BUILDER_CLASS); final File generatedSourceFolder = new File(resource.toUri().getRawPath() .replaceAll("(.+/info/archinnov/achilles/generated/).+", "$1")); aptUtils.printNote("[Achilles] Cleaning previously generated source files folder : '%s'", generatedSourceFolder.getPath()); FileUtils.deleteDirectory(generatedSourceFolder); } catch (IOException ioe) { aptUtils.printNote( "[Achilles] No previously generated source files found, proceed to code generation"); } aptUtils.printNote("[Achilles] Generating CQL compatible types (used by the application) as class"); for (TypeSpec typeSpec : FunctionParameterTypesCodeGen.buildParameterTypesClasses(udfContext)) { JavaFile.builder(FUNCTION_PACKAGE, typeSpec).build().writeTo(aptUtils.filer); } aptUtils.printNote("[Achilles] Generating SystemFunctions"); JavaFile.builder(FUNCTION_PACKAGE, FunctionsRegistryCodeGen .generateFunctionsRegistryClass(SYSTEM_FUNCTIONS_CLASS, SYSTEM_FUNCTIONS)).build() .writeTo(aptUtils.filer); aptUtils.printNote("[Achilles] Generating FunctionsRegistry"); JavaFile.builder(FUNCTION_PACKAGE, FunctionsRegistryCodeGen .generateFunctionsRegistryClass(FUNCTIONS_REGISTRY_CLASS, udfContext.functionSignatures)) .build().writeTo(aptUtils.filer); aptUtils.printNote("[Achilles] Generating ManagerFactoryBuilder"); JavaFile.builder(GENERATED_PACKAGE, managerFactoryBuilder).build().writeTo(aptUtils.filer); aptUtils.printNote("[Achilles] Generating Manager factory class"); JavaFile.builder(GENERATED_PACKAGE, managersAndDSLClasses.managerFactoryClass).build() .writeTo(aptUtils.filer); aptUtils.printNote("[Achilles] Generating UDT meta classes"); for (TypeSpec typeSpec : parsingContext.udtTypes.values()) { JavaFile.builder(UDT_META_PACKAGE, typeSpec).build().writeTo(aptUtils.filer); } aptUtils.printNote("[Achilles] Generating entity meta classes"); for (EntityMetaSignature signature : tableAndViewSignatures) { JavaFile.builder(ENTITY_META_PACKAGE, signature.sourceCode).build().writeTo(aptUtils.filer); } aptUtils.printNote("[Achilles] Generating manager classes"); for (TypeSpec manager : managersAndDSLClasses.managerClasses) { JavaFile.builder(MANAGER_PACKAGE, manager).build().writeTo(aptUtils.filer); } aptUtils.printNote("[Achilles] Generating DSL classes"); for (TypeSpec dsl : managersAndDSLClasses.dslClasses) { JavaFile.builder(DSL_PACKAGE, dsl).build().writeTo(aptUtils.filer); } } catch (AchillesException e) { e.printStackTrace(); aptUtils.printError("Error while parsing: %s", e.getMessage(), e); } catch (IllegalStateException e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); aptUtils.printError("Error while parsing: %s", sw.toString(), e); } catch (IOException e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); aptUtils.printError("Fail generating source file : %s", sw.toString(), e); } catch (Throwable throwable) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); aptUtils.printError("Fail generating source file : %s", sw.toString(), throwable); } finally { this.processed = true; } } return true; }
From source file:org.callimachusproject.auth.DigestPasswordAccessor.java
private String readString(FileObject file) { try {//www .j a va2s. co m Reader reader = file.openReader(true); if (reader == null) return null; try { return new Scanner(reader).next(); } finally { reader.close(); } } catch (IOException | NoSuchElementException e) { logger.error(file.toUri().toASCIIString(), e); return null; } }
From source file:org.callimachusproject.behaviours.ZipArchiveSupport.java
public XMLEventReader createAtomFeedFromArchive(final String id, final String entryPattern) throws IOException { final FileObject file = this; final XMLEventFactory ef = XMLEventFactory.newInstance(); final byte[] buf = new byte[1024]; final ZipArchiveInputStream zip = new ZipArchiveInputStream(file.openInputStream()); return new XMLEventReaderBase() { private boolean started; private boolean ended; public void close() throws XMLStreamException { try { zip.close();//from w ww . j av a2 s. co m } catch (IOException e) { throw new XMLStreamException(e); } } protected boolean more() throws XMLStreamException { try { ZipArchiveEntry entry; if (!started) { Namespace atom = ef.createNamespace(FEED.getPrefix(), FEED.getNamespaceURI()); add(ef.createStartDocument()); add(ef.createStartElement(FEED, null, Arrays.asList(atom).iterator())); add(ef.createStartElement(TITLE, null, null)); add(ef.createCharacters(file.getName())); add(ef.createEndElement(TITLE, null)); add(ef.createStartElement(ID, null, null)); add(ef.createCharacters(id)); add(ef.createEndElement(ID, null)); Attribute href = ef.createAttribute("href", file.toUri().toASCIIString()); List<Attribute> attrs = Arrays.asList(href, ef.createAttribute("type", "application/zip")); add(ef.createStartElement(LINK, attrs.iterator(), null)); add(ef.createEndElement(LINK, null)); add(ef.createStartElement(UPDATED, null, null)); add(ef.createCharacters(format(new Date(file.getLastModified())))); add(ef.createEndElement(UPDATED, null)); started = true; return true; } else if (started && !ended && (entry = zip.getNextZipEntry()) != null) { String name = entry.getName(); String link = entryPattern.replace("{entry}", PercentCodec.encode(name)); MimetypesFileTypeMap mimetypes = new javax.activation.MimetypesFileTypeMap(); String type = mimetypes.getContentType(name); if (type == null || type.length() == 0) { type = "application/octet-stream"; } add(ef.createStartElement(ENTRY, null, null)); add(ef.createStartElement(TITLE, null, null)); add(ef.createCharacters(name)); add(ef.createEndElement(TITLE, null)); Attribute href = ef.createAttribute("href", link); List<Attribute> attrs = Arrays.asList(href, ef.createAttribute("type", type)); add(ef.createStartElement(LINK, attrs.iterator(), null)); add(ef.createEndElement(LINK, null)); long size = entry.getSize(); if (size > 0) { zip.skip(size); } else { while (zip.read(buf, 0, buf.length) >= 0) ; } add(ef.createEndElement(ENTRY, null)); return true; } else if (!ended) { add(ef.createEndElement(FEED, null)); add(ef.createEndDocument()); ended = true; return true; } else { return false; } } catch (IOException e) { throw new XMLStreamException(e); } } }; }
From source file:org.jannocessor.processor.JannocessorProcessorBase.java
private FileInformation readFile(Location location, String pkg, String filename) { try {/*from w w w . j a v a2 s. c om*/ FileObject file = filer.getResource(location, pkg, filename); InputStream inputStream = file.openInputStream(); String content = IOUtils.toString(inputStream); inputStream.close(); Date lastModified = new Date(file.getLastModified()); String name = new File(file.toUri()).getCanonicalPath(); return new DefaultFileInformation(content, name, lastModified); } catch (IOException e) { return null; } }
From source file:org.jannocessor.processor.JannocessorProcessorBase.java
private String getPath(Location location) { String path;/* w w w.j a v a 2 s.c o m*/ try { FileObject tempFile = filer.getResource(location, "", "jannocessor_temporary"); path = tempFile.toUri().getPath().replaceFirst("/jannocessor_temporary$", "").substring(1); } catch (Exception e) { try { FileObject tempFile = filer.createResource(location, "", "jannocessor_temporary"); path = tempFile.toUri().getPath().replaceFirst("/jannocessor_temporary$", "").substring(1); tempFile.delete(); } catch (Exception e2) { throw new RuntimeException("Cannot calculate path: " + location, e2); } } return path; }