private FileObject getMetadataResource() throws IOException { return this.environment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", METADATA_PATH); }
@Override public FileObject getResource( JavaFileManager.Location location, CharSequence pkg, CharSequence relativeName) throws IOException { return delegate.getResource(location, pkg, relativeName); } }
@Override public FileObject getResource(Location location, CharSequence pkg, CharSequence relativeName) throws IOException { return delegate().getResource(location, pkg, relativeName); } }
private static String getClasspathResourceText(Filer filer, String resourceName) throws IOException { return filer.getResource(StandardLocation.CLASS_OUTPUT, "", resourceName) .getCharContent(true) .toString(); } }
@Override public Reader openStream() throws IOException { return getFiler() .getResource(StandardLocation.SOURCE_OUTPUT, "", packagePath + filename) .openReader(true); } }.read();
public String getTemplateResourceFileAsString(String resourceFileName) throws IOException { FileObject fileObject = processingEnv.getFiler().getResource( StandardLocation.CLASS_OUTPUT, "", resourceFileName); return fileObject.getCharContent(true).toString(); }
/** * Helper method for obtaining resources from a {@link Filer}, taking care of some javac * peculiarities. */ private static Optional<FileObject> getResource( final Filer filer, final JavaFileManager.Location location, final String packageName, final String filePath) { try { final FileObject resource = filer.getResource(location, packageName, filePath); resource.openInputStream().close(); return Optional.of(resource); } catch (final Exception e) { // ClientCodeException can be thrown by a bug in the javac ClientCodeWrapper if (!(e instanceof FileNotFoundException || e.getClass().getName().equals("com.sun.tools.javac.util.ClientCodeException"))) { throw new RuntimeException( String.format("Error opening resource %s/%s", packageName, filePath), e.getCause()); } return Optional.empty(); } } }
@Override public CharSequence extract(ProcessingEnvironment environment, TypeElement element) throws IOException { try { FileObject resource = environment.getFiler().getResource( StandardLocation.SOURCE_PATH, "", toFilename(element)); return resource.getCharContent(true); } catch (UnsupportedOperationException | IllegalArgumentException ex) { return UNABLE_TO_EXTRACT; } }
void addTo( String line, String... path ) throws IOException FileObject fo = processingEnv.getFiler().getResource( StandardLocation.CLASS_OUTPUT, "", path( path ) ); URI uri = fo.toUri(); File file;
List<Exception> suppressed = Lists.newArrayList(); try { return filer.getResource(StandardLocation.SOURCE_PATH, packageName, relativeName) .getCharContent(true) .toString(); suppressed.add(cannotGetFromSourcePath); try { return filer.getResource(StandardLocation.CLASS_OUTPUT, packageName, relativeName) .getCharContent(true) .toString(); suppressed.add(cannotGetFromOutputPath); try { return filer.getResource(StandardLocation.CLASS_PATH, "", packageName.toString().replace('.', '/') + '/' + relativeName)
private void readExistingEntriesInto(Collection<String> services) { try { FileObject existing = getFiler().getResource(StandardLocation.CLASS_OUTPUT, key.packageName, key.relativeName); FluentIterable.from(CharStreams.readLines(existing.openReader(true))) .filter(Predicates.not(Predicates.contains(SERVICE_FILE_COMMENT_LINE))) .copyInto(services); } catch (Exception ex) { // unable to read existing file } }
private List<File> findTranslationFiles(final MessageInterface messageInterface) throws IOException { final String packageName = messageInterface.packageName(); final String interfaceName = messageInterface.simpleName(); final String classTranslationFilesPath; //User defined if (translationFilesPath != null) { classTranslationFilesPath = translationFilesPath + packageName.replace('.', File.separatorChar); //By default use the class output folder } else { FileObject fObj = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, packageName, interfaceName); classTranslationFilesPath = fObj.toUri().getPath().replace(interfaceName, ""); } final List<File> result; File[] files = new File(classTranslationFilesPath).listFiles(new TranslationFileFilter(interfaceName)); if (files == null) { result = Collections.emptyList(); } else { result = Arrays.asList(files); Collections.sort(result, new Comparator<File>() { public int compare(final File o1, final File o2) { int result = o1.getAbsolutePath().compareTo(o2.getAbsolutePath()); result = (result != 0 ? result : Integer.signum(o1.getName().length() - o2.getName().length())); return result; } }); } return result; }
FileObject fileObject = context.getProcessingEnvironment() .getFiler() .getResource( StandardLocation.CLASS_OUTPUT, pkg, name ); ormStream = fileObject.openInputStream();
if (doc == null) { try { FileObject layer = filer.getResource(StandardLocation.CLASS_OUTPUT, "", GENERATED_LAYER); InputStream is = layer.openInputStream(); try {
try { try { FileObject in = filer.getResource(StandardLocation.SOURCE_PATH, "", rsrc); in.openInputStream().close(); processingEnv.getMessager().printMessage(Kind.ERROR, FileObject in = filer.getResource(StandardLocation.CLASS_OUTPUT, "", rsrc); InputStream is = in.openInputStream(); try {
FileObject obj = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "", typeElt.getQualifiedName().toString().replace('.', '/') + ".java"); File srcFolder = new File(obj.toUri()).getParentFile(); String filename = Case.SNAKE.format(Case.CAMEL.parse(typeElt.getSimpleName().toString()));
for (Location loc : new Location[] {StandardLocation.SOURCE_PATH, /* #181355 */StandardLocation.CLASS_OUTPUT, StandardLocation.CLASS_PATH, StandardLocation.PLATFORM_CLASS_PATH}) { try { FileObject f = processingEnv.getFiler().getResource(loc, "", resource); if (loc.isOutputLocation()) { f.openInputStream().close(); try { try { FileObject f = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "", resource); f.openInputStream().close(); return f; } catch (FileNotFoundException x) { try { FileObject f = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", resource); f.openInputStream().close(); return f;
@Test public void testLoad() throws IOException { final PropNameInterStageStore store = new PropNameInterStageStore(mFiler); final FileObject fileObject = makeFileObjectForString("arg0\narg1\n"); when(mFiler.getResource(any(JavaFileManager.Location.class), anyString(), anyString())) .thenReturn(fileObject); final Optional<ImmutableList<String>> strings = store.loadNames(new MockName("com.example.MyComponentSpec")); LithoAssertions.assertThat(strings.isPresent()).isTrue(); LithoAssertions.assertThat(strings.get()).containsExactly("arg0", "arg1"); verify(mFiler) .getResource( StandardLocation.CLASS_PATH, "", "META-INF/litho/com.example.MyComponentSpec.props"); }
InputStream is = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, pkg, "Bundle.properties").openInputStream(); try { p.load(is); InputStream is = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, pkg, "Bundle.properties").openInputStream(); try { Matcher m = Pattern.compile(" /[*][*]\r?\n(?: [*].+\r?\n)+ [*] @see (?:[\\w-]+)\r?\n [*]/\r?\n static String (\\w+).+\r?\n .+\r?\n [}]\r?\n").matcher(processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, pkg, "Bundle.java").getCharContent(false)); while (m.find()) { String identifier = m.group(1);
@Override public Map<String, Set<String>> read() { Map<String, Set<String>> extensions = new HashMap<>(); try { FileObject file = getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", EXTENSIONS_RESOURCE); // TODO try to calculate the extension point Set<String> entries = new HashSet<>(); read(file.openReader(true), entries); extensions.put(null, entries); } catch (FileNotFoundException | NoSuchFileException e) { // doesn't exist, ignore } catch (FilerException e) { // re-opening the file for reading or after writing is ignorable } catch (IOException e) { error(e.getMessage()); } return extensions; }