private boolean canWrite(final ClasspathInfo cpInfo) { final FileManagerTransaction fmTx = ClasspathInfoAccessor.getINSTANCE().getFileManagerTransaction(cpInfo); assert fmTx != null; return fmTx.canWrite(); }
@Override JavaFileObject createFileObject(Location location, File file, File root, JavaFileFilterImplementation filter, Charset encoding) { return getDelegate().createFileObject(location, file, root, filter, encoding); }
@Override public void delete(File file) { getDelegate().delete(file); }
public static Future<Void> runConcurrent(@NonNull final FileSystem.AtomicAction action) throws IOException { Parameters.notNull("action", action); //NOI18N final FileManagerTransaction fmtx = TransactionContext.get().get(FileManagerTransaction.class); if (fmtx == null) { throw new IllegalStateException("No FileManagerTransaction"); //NOI18N } final Future<Void> res; fmtx.fork(); try { action.run(); } finally { res = fmtx.join(); } return res; }
FileManagerTransaction.class, hasCache ? FileManagerTransaction.writeBack(root): FileManagerTransaction.writeThrough()). register( ProcessorGenerated.class,
@Override public JavaFileObject getJavaFileForInput(Location l, String className, Kind kind) { if (kind == JavaFileObject.Kind.CLASS) { int dot = className.lastIndexOf('.'); String dir = dot == -1 ? "" : FileObjects.convertPackage2Folder(className.substring(0, dot)); javax.tools.FileObject fo = tx.readFileObject(l, dir, className.substring(dot + 1)); if (fo != null) { return (JavaFileObject)fo; } } return super.getJavaFileForInput(l, className, kind); }
@Override public Iterable<JavaFileObject> list(Location l, String packageName, Set<Kind> kinds, boolean recursive) { return fileTx.filter(l, packageName, super.list(l, packageName, kinds, recursive)); }
final boolean virtual = active.virtual; final JavacTaskImpl jtFin = jt; barriers.offer(FileManagerTransaction.runConcurrent(new FileSystem.AtomicAction(){ @Override public void run() throws IOException {
} else { fmTx = FileManagerTransaction.treeLoaderOnly(); pgTx = ProcessorGenerated.nullWrite();
@Override public javax.tools.FileObject getFileForInput(Location l, String pkgName, String relativeName) { final String[] names = FileObjects.getFolderAndBaseName( FileObjects.resolveRelativePath(pkgName, relativeName), FileObjects.NBFS_SEPARATOR_CHAR); javax.tools.FileObject fo = tx.readFileObject(l, names[0], names[1]); if (fo != null) { return fo; } return super.getFileForInput(l, pkgName, relativeName); }
@Override public Iterable<JavaFileObject> list(Location l, String packageName, Set<Kind> kinds, boolean recursive) { final Iterable<JavaFileObject> sr = super.list(l, packageName, kinds, recursive); return tx.filter(l, packageName, sr); }
final Future<Void> done = FileManagerTransaction.runConcurrent(new FileSystem.AtomicAction() { @Override public void run() throws IOException {
@Override public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException { if (!hasLocation(location)) { throw new IllegalArgumentException(String.valueOf(location)); } final File root = new File(outputRoot); final File file = FileUtil.normalizeFile(new File ( root, FileObjects.resolveRelativePath(packageName, relativeName).replace(FileObjects.NBFS_SEPARATOR_CHAR, File.separatorChar))); //NOI18N return tx.createFileObject(location, file, root,null,null); }
@Override public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { if (!hasLocation(location)) { throw new IllegalArgumentException(String.valueOf(location)); } final File root = new File(outputRoot); final String path = FileObjects.resolveRelativePath(packageName, relativeName); final String[] names = FileObjects.getFolderAndBaseName(path, FileObjects.NBFS_SEPARATOR_CHAR); final javax.tools.FileObject jfo = tx.readFileObject(location, names[0], names[1]); if (jfo != null) { return (JavaFileObject) jfo; } final Archive archive = provider.getArchive(BaseUtilities.toURI(root).toURL(), false); return archive != null ? archive.getFile(path) : null; }
private static void cleanUpResources ( @NonNull final Context ctx, @NonNull final FileManagerTransaction fmTx) throws IOException { final File classFolder = JavaIndex.getClassFolder(ctx); final File resourcesFile = new File (classFolder,FileObjects.RESOURCES); try { for (String fileName : readRSFile(resourcesFile)) { File f = new File (classFolder, fileName); fmTx.delete(f); } fmTx.delete(resourcesFile); } catch (IOException ioe) { //Nothing to delete - pass } }
@Override Iterable<JavaFileObject> filter(Location location, String packageName, Iterable<JavaFileObject> files) { return getDelegate().filter(location, packageName, files); }
@Override public javax.tools.FileObject getFileForOutput(Location l, String pkgName, String relativeName, javax.tools.FileObject sibling) throws IOException, UnsupportedOperationException, IllegalArgumentException { if (StandardLocation.SOURCE_OUTPUT != l) { throw new UnsupportedOperationException("Only apt output is supported."); // NOI18N } final FileObject aptRoot = getAptRoot(sibling); if (aptRoot == null) { throw new UnsupportedOperationException(noAptRootDebug(sibling)); } final String nameStr = pkgName.length() == 0 ? relativeName : pkgName.replace('.', File.separatorChar) + File.separatorChar + relativeName; //NOI18N //Always on master fs -> file is save. File rootFile = FileUtil.toFile(aptRoot); return fileTx.createFileObject(l, new File(rootFile,nameStr), rootFile, null, null); }
@Override public JavaFileObject getJavaFileForInput(Location location, String className, JavaFileObject.Kind kind) throws IOException { if (!hasLocation(location)) { throw new IllegalArgumentException(String.valueOf(location)); } final String [] names = FileObjects.getParentRelativePathAndName(className); if (kind == JavaFileObject.Kind.CLASS) { javax.tools.FileObject fo = tx.readFileObject(location, names[0], names[1]); if (fo != null) { return (JavaFileObject)fo; } } names[1] = names[1] + kind.extension; try { final File root = new File (outputRoot); Archive archive = provider.getArchive (BaseUtilities.toURI(root).toURL(), false); if (archive != null) { Iterable<JavaFileObject> files = archive.getFiles(names[0], null, null, null); for (JavaFileObject e : files) { if (names[1].equals(e.getName())) { return e; } } } } catch (IOException e) { Exceptions.printStackTrace(e); } return null; }
sourceRelativeURLPairs.add(Pair.of(fileName, BaseUtilities.toURI(f).toURL())); fmTx.delete(f); fmTx.delete(file); removedTypes.add(ElementHandleAccessor.getInstance().create(ElementKind.OTHER, className)); removedFiles.add(f); fmTx.delete(f); fmTx.delete(file); removedTypes.add(ElementHandleAccessor.getInstance().create(ElementKind.OTHER, className)); removedFiles.add(f); fmTx.delete(f);
@Override public JavaFileObject getJavaFileForOutput (Location l, String className, JavaFileObject.Kind kind, javax.tools.FileObject sibling) throws IOException, UnsupportedOperationException, IllegalArgumentException { if (StandardLocation.SOURCE_OUTPUT != l) { throw new UnsupportedOperationException("Only apt output is supported."); // NOI18N } final FileObject aptRoot = getAptRoot(sibling); if (aptRoot == null) { throw new UnsupportedOperationException(noAptRootDebug(sibling)); } final String nameStr = className.replace('.', File.separatorChar) + kind.extension; //NOI18N //Always on master fs -> file is save. File rootFile = FileUtil.toFile(aptRoot); final JavaFileObject result = fileTx.createFileObject(l, new File(rootFile,nameStr), rootFile, null, null); return result; }