/** * Collects all files which are located in the passed directory. * * @throws IllegalArgumentException if <code>dir</code> isn't a directory. */ public static void collectFiles( final VirtualFile dir, final List<VirtualFile> files, final boolean recursive, final boolean addDirectories) { if (!dir.isDirectory()) { throw new IllegalArgumentException( VcsBundle.message("exception.text.file.should.be.directory", dir.getPresentableUrl())); } final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); VfsUtilCore.visitChildrenRecursively( dir, new VirtualFileVisitor() { @Override public boolean visitFile(@NotNull VirtualFile file) { if (file.isDirectory()) { if (addDirectories) { files.add(file); } if (!recursive && !Comparing.equal(file, dir)) { return false; } } else if (fileTypeManager == null || file.getFileType() != FileTypes.UNKNOWN) { files.add(file); } return true; } }); }
public static void refreshFiles(Project project, HashSet<FilePath> paths) { for (FilePath path : paths) { VirtualFile vFile = path.getVirtualFile(); if (vFile != null) { if (vFile.isDirectory()) { markFileAsDirty(project, vFile); } else { vFile.refresh(true, vFile.isDirectory()); } } } }
@NotNull public static Collection<VcsDirectoryMapping> findRoots( @NotNull VirtualFile rootDir, @NotNull Project project) throws IllegalArgumentException { if (!rootDir.isDirectory()) { throw new IllegalArgumentException( "Can't find VCS at the target file system path. Reason: expected to find a directory there but it's not. The path: " + rootDir.getParent()); } Collection<VcsRoot> roots = ServiceManager.getService(project, VcsRootDetector.class).detect(rootDir); Collection<VcsDirectoryMapping> result = ContainerUtilRt.newArrayList(); for (VcsRoot vcsRoot : roots) { VirtualFile vFile = vcsRoot.getPath(); AbstractVcs rootVcs = vcsRoot.getVcs(); if (rootVcs != null && vFile != null) { result.add(new VcsDirectoryMapping(vFile.getPath(), rootVcs.getName())); } } return result; }