com.intellij.openapi.vfs.newvfs.NewVirtualFile Java Examples
The following examples show how to use
com.intellij.openapi.vfs.newvfs.NewVirtualFile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalFileSystemRefreshWorker.java From consulo with Apache License 2.0 | 6 votes |
void scan() { NewVirtualFile root = myRefreshRoot; boolean rootDirty = root.isDirty(); if (LOG.isDebugEnabled()) LOG.debug("root=" + root + " dirty=" + rootDirty); if (!rootDirty) return; NewVirtualFileSystem fs = root.getFileSystem(); FileAttributes rootAttributes = fs.getAttributes(root); if (rootAttributes == null) { myHelper.scheduleDeletion(root); root.markClean(); return; } if (rootAttributes.isDirectory()) { fs = PersistentFS.replaceWithNativeFS(fs); } RefreshContext context = createRefreshContext(fs, PersistentFS.getInstance(), FilePathHashingStrategy.create(fs.isCaseSensitive())); context.submitRefreshRequest(() -> processFile(root, context)); context.waitForRefreshToFinish(); }
Example #2
Source File: StubUpdatingIndex.java From consulo with Apache License 2.0 | 6 votes |
public static boolean canHaveStub(@Nonnull ProjectLocator projectLocator, @Nullable Project project, @Nonnull VirtualFile file) { FileType fileType = SubstitutedFileType.substituteFileType(file, file.getFileType(), project == null ? projectLocator.guessProjectForFile(file) : project); if (fileType instanceof LanguageFileType) { final Language l = ((LanguageFileType)fileType).getLanguage(); final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l); if (parserDefinition == null) { return false; } final IFileElementType elementType = parserDefinition.getFileNodeType(); if (elementType instanceof IStubFileElementType) { if (((IStubFileElementType)elementType).shouldBuildStubFor(file)) { return true; } FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); if (file instanceof NewVirtualFile && fileBasedIndex instanceof FileBasedIndexImpl && ((FileBasedIndexImpl)fileBasedIndex).getIndex(INDEX_ID).isIndexedStateForFile(((NewVirtualFile)file).getId(), file)) { return true; } } } final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType); return builder != null && builder.acceptsFile(file); }
Example #3
Source File: ReadOnlyAttributeUtil.java From consulo with Apache License 2.0 | 6 votes |
/** * Sets specified read-only status for the spcified <code>file</code>. * This method can be performed only for files which are in local file system. * * @param file file which read-only attribute to be changed. * @param readOnlyStatus new read-only status. * @throws java.lang.IllegalArgumentException * if passed <code>file</code> doesn't * belong to the local file system. * @throws IOException if some <code>IOException</code> occurred. */ public static void setReadOnlyAttribute(VirtualFile file, boolean readOnlyStatus) throws IOException { if (file.getFileSystem().isReadOnly()) { throw new IllegalArgumentException("Wrong file system: " + file.getFileSystem()); } if (file.isWritable() == !readOnlyStatus) { return; } if (file instanceof NewVirtualFile) { ((NewVirtualFile)file).setWritable(!readOnlyStatus); } else { String path = file.getPresentableUrl(); setReadOnlyAttribute(path, readOnlyStatus); file.refresh(false, false); } }
Example #4
Source File: LoadAllVfsStoredContentsAction.java From consulo with Apache License 2.0 | 6 votes |
public boolean processFile(NewVirtualFile file) { if (file.isDirectory() || file.is(VFileProperty.SPECIAL)) { return true; } try { try (InputStream stream = PersistentFS.getInstance().getInputStream(file)) { // check if it's really cached in VFS if (!(stream instanceof DataInputStream)) return true; byte[] bytes = FileUtil.loadBytes(stream); totalSize.addAndGet(bytes.length); count.incrementAndGet(); ProgressManager.getInstance().getProgressIndicator().setText(file.getPresentableUrl()); } } catch (IOException e) { LOG.error(e); } return true; }
Example #5
Source File: PersistentFSTest.java From consulo with Apache License 2.0 | 6 votes |
public void testListChildrenOfTheRootOfTheRoot() { PersistentFS fs = PersistentFS.getInstance(); NewVirtualFile fakeRoot = fs.findRoot("", LocalFileSystem.getInstance()); assertNotNull(fakeRoot); int users = fs.getId(fakeRoot, "Users", LocalFileSystem.getInstance()); assertEquals(0, users); users = fs.getId(fakeRoot, "usr", LocalFileSystem.getInstance()); assertEquals(0, users); int win = fs.getId(fakeRoot, "Windows", LocalFileSystem.getInstance()); assertEquals(0, win); VirtualFile[] roots = fs.getRoots(LocalFileSystem.getInstance()); for (VirtualFile root : roots) { int rid = fs.getId(fakeRoot, root.getName(), LocalFileSystem.getInstance()); assertTrue(root.getPath()+"; Roots:"+ Arrays.toString(roots), 0 != rid); } NewVirtualFile c = fakeRoot.refreshAndFindChild("Users"); assertNull(c); c = fakeRoot.refreshAndFindChild("Users"); assertNull(c); c = fakeRoot.refreshAndFindChild("Windows"); assertNull(c); c = fakeRoot.refreshAndFindChild("Windows"); assertNull(c); }
Example #6
Source File: PersistentFSTest.java From consulo with Apache License 2.0 | 6 votes |
public void testFindRootShouldNotBeFooledByRelativePath() throws IOException { File tmp = createTempDirectory(); File x = new File(tmp, "x.jar"); x.createNewFile(); LocalFileSystem lfs = LocalFileSystem.getInstance(); VirtualFile vx = lfs.refreshAndFindFileByIoFile(x); assertNotNull(vx); ArchiveFileSystem jfs = (ArchiveFileSystem)StandardFileSystems.jar(); VirtualFile root = ArchiveVfsUtil.getArchiveRootForLocalFile(vx); PersistentFS fs = PersistentFS.getInstance(); String path = vx.getPath() + "/../" + vx.getName() + ArchiveFileSystem.ARCHIVE_SEPARATOR; NewVirtualFile root1 = fs.findRoot(path, (NewVirtualFileSystem)jfs); assertSame(root1, root); }
Example #7
Source File: VfsUtil.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static List<VirtualFile> markDirty(boolean recursive, boolean reloadChildren, @Nonnull VirtualFile... files) { List<VirtualFile> list = ContainerUtil.filter(files, Condition.NOT_NULL); if (list.isEmpty()) { return Collections.emptyList(); } for (VirtualFile file : list) { if (reloadChildren) { file.getChildren(); } if (file instanceof NewVirtualFile) { if (recursive) { ((NewVirtualFile)file).markDirtyRecursively(); } else { ((NewVirtualFile)file).markDirty(); } } } return list; }
Example #8
Source File: Util.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 6 votes |
public static void setModificationStamp(VirtualFile file) { // Store it in memory first if(file != null) { file.putUserData(Util.MODIFICATION_DATE_KEY, file.getTimeStamp()); if(file instanceof NewVirtualFile) { final DataOutputStream os = MODIFICATION_STAMP_FILE_ATTRIBUTE.writeAttribute(file); try { try { IOUtil.writeString(StringUtil.notNullize(file.getTimeStamp() + ""), os); } finally { os.close(); } } catch(IOException e) { // Ignore it but we might need to throw an exception String message = e.getMessage(); } } } }
Example #9
Source File: DesktopSaveAndSyncHandlerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void refreshOpenFiles() { List<VirtualFile> files = ContainerUtil.newArrayList(); for (Project project : ProjectManager.getInstance().getOpenProjects()) { for (VirtualFile file : FileEditorManager.getInstance(project).getSelectedFiles()) { if (file instanceof NewVirtualFile) { files.add(file); } } } if (!files.isEmpty()) { // refresh open files synchronously so it doesn't wait for potentially longish refresh request in the queue to finish RefreshQueue.getInstance().refresh(false, false, null, files); } }
Example #10
Source File: Util.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 6 votes |
@Override public boolean visitFile(VirtualFile file) { file.putUserData(MODIFICATION_DATE_KEY, null); if(file instanceof NewVirtualFile) { final DataOutputStream os = MODIFICATION_STAMP_FILE_ATTRIBUTE.writeAttribute(file); try { try { IOUtil.writeString(StringUtil.notNullize("0"), os); } finally { os.close(); } } catch(IOException e) { // Ignore it but we might need to throw an exception String message = e.getMessage(); } } return recursive; }
Example #11
Source File: FileUtil.java From jetbrains-plugin-graph-database-support with Apache License 2.0 | 6 votes |
public static String getParams(VirtualFile file) { String userData = file.getUserData(MY_KEY); if (userData != null) { return userData; } if (!(file instanceof NewVirtualFile)) { return "{}"; } try (DataInputStream is = QUERY_PARAMS_FILE_ATTRIBUTE.readAttribute(file)) { if (is == null || is.available() <= 0) { return "{}"; } String attributeData = IOUtil.readString(is); if (attributeData == null) { return "{}"; } else { file.putUserData(MY_KEY, attributeData); return attributeData; } } catch (IOException e) { return "{}"; } }
Example #12
Source File: VcsVFSListener.java From consulo with Apache License 2.0 | 6 votes |
private void addFileToDelete(VirtualFile file) { if (file.isDirectory() && file instanceof NewVirtualFile && !isDirectoryVersioningSupported()) { for (VirtualFile child : ((NewVirtualFile)file).getCachedChildren()) { addFileToDelete(child); } } else { final VcsDeleteType type = needConfirmDeletion(file); final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(new File(file.getPath()), file.isDirectory()); if (type == VcsDeleteType.CONFIRM) { myDeletedFiles.add(filePath); } else if (type == VcsDeleteType.SILENT) { myDeletedWithoutConfirmFiles.add(filePath); } } }
Example #13
Source File: CompositeCheckoutListener.java From consulo with Apache License 2.0 | 6 votes |
private static VirtualFile refreshVFS(final File directory) { final Ref<VirtualFile> result = new Ref<VirtualFile>(); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { final LocalFileSystem lfs = LocalFileSystem.getInstance(); final VirtualFile vDir = lfs.refreshAndFindFileByIoFile(directory); result.set(vDir); if (vDir != null) { final LocalFileSystem.WatchRequest watchRequest = lfs.addRootToWatch(vDir.getPath(), true); ((NewVirtualFile)vDir).markDirtyRecursively(); vDir.refresh(false, true); if (watchRequest != null) { lfs.removeWatchedRoot(watchRequest); } } } }); return result.get(); }
Example #14
Source File: LocalFileSystemRefreshWorker.java From consulo with Apache License 2.0 | 6 votes |
private void processFile(@Nonnull NewVirtualFile file, @Nonnull RefreshContext refreshContext) { if (!VfsEventGenerationHelper.checkDirty(file) || isCancelled(file, refreshContext)) { return; } if (file.isDirectory()) { boolean fullSync = ((VirtualDirectoryImpl)file).allChildrenLoaded(); if (fullSync) { fullDirRefresh((VirtualDirectoryImpl)file, refreshContext); } else { partialDirRefresh((VirtualDirectoryImpl)file, refreshContext); } } else { refreshFile(file, refreshContext); } if (isCancelled(file, refreshContext)) { return; } if (myIsRecursive || !file.isDirectory()) { file.markClean(); } }
Example #15
Source File: RefreshWorker.java From consulo with Apache License 2.0 | 6 votes |
private boolean checkAndScheduleFileTypeChange(@Nonnull NewVirtualFileSystem fs, @Nullable NewVirtualFile parent, @Nonnull NewVirtualFile child, @Nonnull FileAttributes childAttributes) { boolean currentIsDirectory = child.isDirectory(), upToDateIsDirectory = childAttributes.isDirectory(); boolean currentIsSymlink = child.is(VFileProperty.SYMLINK), upToDateIsSymlink = childAttributes.isSymLink(); boolean currentIsSpecial = child.is(VFileProperty.SPECIAL), upToDateIsSpecial = childAttributes.isSpecial(); if (currentIsDirectory != upToDateIsDirectory || currentIsSymlink != upToDateIsSymlink || currentIsSpecial != upToDateIsSpecial) { myHelper.scheduleDeletion(child); if (parent != null) { String symlinkTarget = upToDateIsSymlink ? fs.resolveSymLink(child) : null; myHelper.scheduleCreation(parent, child.getName(), childAttributes, symlinkTarget, () -> checkCancelled(parent)); } else { LOG.error("transgender orphan: " + child + ' ' + childAttributes); } return true; } return false; }
Example #16
Source File: LocalFileSystemRefreshWorker.java From consulo with Apache License 2.0 | 6 votes |
/** * @param fileOrDir * @param refreshContext * @param childrenToRefresh null means all * @param existingPersistentChildren */ RefreshingFileVisitor(@Nonnull NewVirtualFile fileOrDir, @Nonnull RefreshContext refreshContext, @Nullable Collection<String> childrenToRefresh, @Nonnull Collection<? extends VirtualFile> existingPersistentChildren) { myFileOrDir = fileOrDir; myRefreshContext = refreshContext; myPersistentChildren = new THashMap<>(existingPersistentChildren.size(), refreshContext.strategy); myChildrenWeAreInterested = childrenToRefresh == null ? null : new THashSet<>(childrenToRefresh, refreshContext.strategy); for (VirtualFile child : existingPersistentChildren) { String name = child.getName(); myPersistentChildren.put(name, child); if (myChildrenWeAreInterested != null) myChildrenWeAreInterested.add(name); } }
Example #17
Source File: LocalFileSystemImpl.java From consulo with Apache License 2.0 | 6 votes |
public void markSuspiciousFilesDirty(@Nonnull List<VirtualFile> files) { storeRefreshStatusToFiles(); if (myWatcher.isOperational()) { for (String root : myWatcher.getManualWatchRoots()) { VirtualFile suspiciousRoot = findFileByPathIfCached(root); if (suspiciousRoot != null) { ((NewVirtualFile)suspiciousRoot).markDirtyRecursively(); } } } else { for (VirtualFile file : files) { if (file.getFileSystem() == this) { ((NewVirtualFile)file).markDirtyRecursively(); } } } }
Example #18
Source File: LocalFileSystemImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void refreshWithoutFileWatcher(final boolean asynchronous) { Runnable heavyRefresh = () -> { for (VirtualFile root : myManagingFS.getRoots(this)) { ((NewVirtualFile)root).markDirtyRecursively(); } refresh(asynchronous); }; if (asynchronous && myWatcher.isOperational()) { RefreshQueue.getInstance().refresh(true, true, heavyRefresh, myManagingFS.getRoots(this)); } else { heavyRefresh.run(); } }
Example #19
Source File: VirtualFileSystemEntry.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean isRecursiveOrCircularSymLink() { if (!is(VFileProperty.SYMLINK)) return false; NewVirtualFile resolved = getCanonicalFile(); // invalid symlink if (resolved == null) return false; // if it's recursive if (VfsUtilCore.isAncestor(resolved, this, false)) return true; // check if it's circular - any symlink above resolves to my target too for (VirtualFileSystemEntry p = getParent(); p != null; p = p.getParent()) { // optimization: when the file has no symlinks up the hierarchy, it's not circular if (!p.getFlagInt(HAS_SYMLINK_FLAG)) return false; if (p.is(VFileProperty.SYMLINK)) { VirtualFile parentResolved = p.getCanonicalFile(); if (resolved.equals(parentResolved)) { return true; } } } return false; }
Example #20
Source File: ForcedBuildFileAttribute.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public static String getFrameworkIdOfBuildFile(VirtualFile file) { if (file instanceof NewVirtualFile) { final DataInputStream is = FRAMEWORK_FILE_ATTRIBUTE.readAttribute(file); if (is != null) { try { try { if (is.available() == 0) { return null; } return IOUtil.readString(is); } finally { is.close(); } } catch (IOException e) { LOG.error(file.getPath(), e); } } return ""; } return file.getUserData(FRAMEWORK_FILE_MARKER); }
Example #21
Source File: ForcedBuildFileAttribute.java From consulo with Apache License 2.0 | 6 votes |
private static void forceBuildFile(VirtualFile file, @Nullable String value) { if (file instanceof NewVirtualFile) { final DataOutputStream os = FRAMEWORK_FILE_ATTRIBUTE.writeAttribute(file); try { try { IOUtil.writeString(StringUtil.notNullize(value), os); } finally { os.close(); } } catch (IOException e) { LOG.error(e); } } else { file.putUserData(FRAMEWORK_FILE_MARKER, value); } }
Example #22
Source File: LocalFileSystemImpl.java From consulo with Apache License 2.0 | 5 votes |
private void markPathsDirty(Iterable<String> dirtyPaths) { for (String dirtyPath : dirtyPaths) { VirtualFile file = findFileByPathIfCached(dirtyPath); if (file instanceof NewVirtualFile) { ((NewVirtualFile)file).markDirty(); } } }
Example #23
Source File: LocalFileSystemRefreshWorker.java From consulo with Apache License 2.0 | 5 votes |
private boolean isCancelled(@Nonnull NewVirtualFile stopAt, @Nonnull RefreshContext refreshContext) { if (ourTestListener != null) { ourTestListener.accept(stopAt); } if (myCancelled) { refreshContext.filesToBecomeDirty.offer(stopAt); return true; } return false; }
Example #24
Source File: LocalFileSystemRefreshWorker.java From consulo with Apache License 2.0 | 5 votes |
final void waitForRefreshToFinish() { doWaitForRefreshToFinish(); for (NewVirtualFile file : filesToBecomeDirty) { forceMarkDirty(file); } }
Example #25
Source File: LocalFileSystemImpl.java From consulo with Apache License 2.0 | 5 votes |
private void markFlatDirsDirty(Iterable<String> dirtyPaths) { for (String dirtyPath : dirtyPaths) { Pair<NewVirtualFile, NewVirtualFile> pair = VfsImplUtil.findCachedFileByPath(this, dirtyPath); if (pair.first != null) { pair.first.markDirty(); for (VirtualFile child : pair.first.getCachedChildren()) { ((NewVirtualFile)child).markDirty(); } } else if (pair.second != null) { pair.second.markDirty(); } } }
Example #26
Source File: LocalFileSystemImpl.java From consulo with Apache License 2.0 | 5 votes |
private void markRecursiveDirsDirty(Iterable<String> dirtyPaths) { for (String dirtyPath : dirtyPaths) { Pair<NewVirtualFile, NewVirtualFile> pair = VfsImplUtil.findCachedFileByPath(this, dirtyPath); if (pair.first != null) { pair.first.markDirtyRecursively(); } else if (pair.second != null) { pair.second.markDirty(); } } }
Example #27
Source File: FileSystemTreeImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void treeExpanded(final TreeExpansionEvent event) { if (myTreeBuilder == null || !myTreeBuilder.isNodeBeingBuilt(event.getPath())) return; TreePath path = event.getPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); if (node.getUserObject() instanceof FileNodeDescriptor) { FileNodeDescriptor nodeDescriptor = (FileNodeDescriptor)node.getUserObject(); final FileElement fileDescriptor = nodeDescriptor.getElement(); final VirtualFile virtualFile = fileDescriptor.getFile(); if (virtualFile != null) { if (!myEverExpanded.contains(virtualFile)) { if (virtualFile instanceof NewVirtualFile) { ((NewVirtualFile)virtualFile).markDirty(); } myEverExpanded.add(virtualFile); } final boolean async = myTreeBuilder.isToBuildChildrenInBackground(virtualFile); if (virtualFile instanceof NewVirtualFile) { RefreshQueue.getInstance().refresh(async, false, null, ModalityState.stateForComponent(myTree), virtualFile); } else { virtualFile.refresh(async, false); } } } }
Example #28
Source File: ProjectRootManagerComponent.java From consulo with Apache License 2.0 | 5 votes |
@Override public void markRootsForRefresh() { Set<String> paths = ContainerUtil.newTroveSet(FileUtil.PATH_HASHING_STRATEGY); addRootsFromModules(false, paths, paths); LocalFileSystem fs = LocalFileSystem.getInstance(); for (String path : paths) { VirtualFile root = fs.findFileByPath(path); if (root instanceof NewVirtualFile) { ((NewVirtualFile)root).markDirtyRecursively(); } } }
Example #29
Source File: DirectoryIndexImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public DirectoryInfo getInfoForFile(@Nonnull VirtualFile file) { checkAvailability(); dispatchPendingEvents(); if (!(file instanceof NewVirtualFile)) return NonProjectDirectoryInfo.NOT_SUPPORTED_VIRTUAL_FILE_IMPLEMENTATION; return getRootIndex().getInfoForFile(file); }
Example #30
Source File: DirectoryIndexImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public String getPackageName(@Nonnull VirtualFile dir) { checkAvailability(); if (!(dir instanceof NewVirtualFile)) return null; return getRootIndex().getPackageName(dir); }