Search in sources :

Example 21 with VirtualFileVisitor

use of com.intellij.openapi.vfs.VirtualFileVisitor in project intellij-plugins by JetBrains.

the class FilesToPackageUtil method initNodes.

private static void initNodes(final VirtualFile rootFolder, final FolderNode rootFolderNode, final Collection<String> pathsExcludedFromPackaging) {
    final Map<VirtualFile, Node> map = new THashMap<>();
    map.put(rootFolder, rootFolderNode);
    VfsUtilCore.visitChildrenRecursively(rootFolder, new VirtualFileVisitor() {

        @NotNull
        public Result visitFileEx(@NotNull final VirtualFile file) {
            if (file.equals(rootFolder))
                return CONTINUE;
            final VirtualFile parentFile = file.getParent();
            final Node parentNode = map.get(parentFile);
            LOG.assertTrue(parentNode instanceof FolderNode, file.getPath());
            if (pathsExcludedFromPackaging.contains(((FolderNode) parentNode).getChildRelativePath(file.getName())) || file.getPath().endsWith("-app.xml") || !canBeAddedToPackage(file)) {
                ((FolderNode) parentNode).setHasExcludedChildren();
                return SKIP_CHILDREN;
            } else {
                if (file.isDirectory()) {
                    final FolderNode childFolderNode = ((FolderNode) parentNode).addChildFolderNode(file.getPath());
                    map.put(file, childFolderNode);
                } else {
                    ((FolderNode) parentNode).addChildFileNode(file.getPath());
                }
                return CONTINUE;
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with VirtualFileVisitor

use of com.intellij.openapi.vfs.VirtualFileVisitor in project intellij-plugins by JetBrains.

the class KarmaWatchPattern method watchRoot.

@Nullable
private LocalFileSystem.WatchRequest watchRoot(@NotNull final VirtualFile dir, final boolean reportChildren) {
    VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() {

        @Override
        public boolean visitFile(@NotNull VirtualFile file) {
            if (reportChildren && !file.isDirectory()) {
                myChangedFileManager.onFileAdded(file.getPath());
            }
            file.getChildren();
            return true;
        }
    });
    LocalFileSystem.WatchRequest watchRequest = myFileSystem.addRootToWatch(dir.getPath(), true);
    if (watchRequest == null) {
        LOG.warn("Can not watch valid directory " + dir.getPath());
    }
    return watchRequest;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with VirtualFileVisitor

use of com.intellij.openapi.vfs.VirtualFileVisitor in project intellij-plugins by JetBrains.

the class KarmaWatchPattern method update.

public void update(boolean rescan) {
    boolean noRootBefore = false;
    boolean rootValid = myRoot != null && myRoot.isValid();
    if (rootValid) {
        String path = myRoot.getPath();
        if (!path.equals(myRootPath)) {
            rootValid = false;
            if (myRootPath != null) {
                VfsUtilCore.visitChildrenRecursively(myRoot, new VirtualFileVisitor() {

                    @Override
                    public boolean visitFile(@NotNull VirtualFile file) {
                        if (!file.isDirectory()) {
                            String subPath = VfsUtilCore.getRelativePath(file, myRoot, KarmaWatchSession.SEPARATOR_CHAR);
                            if (subPath != null) {
                                myChangedFileManager.onFileRemoved(KarmaWatchSession.join(myRootPath, subPath));
                            }
                        }
                        return true;
                    }
                });
            }
        }
    }
    if (!rootValid) {
        noRootBefore = true;
        myRoot = null;
        myRootPath = null;
        stopWatching();
        final VirtualFile file = myFileSystem.findFileByPath(myVfsPath);
        if (file != null && file.isValid()) {
            myRoot = file;
        } else if (myCheckBasePathDir) {
            final VirtualFile baseDir = myFileSystem.findFileByPath(myBasePathDir);
            if (baseDir != null && baseDir.isValid()) {
                myRoot = baseDir;
            }
        }
        if (myRoot != null) {
            myRootPath = myRoot.getPath();
        }
    }
    if (myRoot == null) {
        LOG.warn("[Karma watch] Can not find vfs root for " + myBasePathDir);
        return;
    }
    if (myWatchRequest == null) {
        myWatchRequest = watchRoot(myRoot, rescan && noRootBefore);
        LOG.info("Watching " + myRoot.getPath());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 VirtualFileVisitor (com.intellij.openapi.vfs.VirtualFileVisitor)23 NotNull (org.jetbrains.annotations.NotNull)12 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)4 File (java.io.File)4 FileType (com.intellij.openapi.fileTypes.FileType)3 IOException (java.io.IOException)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 Result (com.intellij.openapi.application.Result)1 PatchApplier (com.intellij.openapi.diff.impl.patch.formove.PatchApplier)1 FileTypeRegistry (com.intellij.openapi.fileTypes.FileTypeRegistry)1 Module (com.intellij.openapi.module.Module)1 ModuleImpl (com.intellij.openapi.module.impl.ModuleImpl)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)1 ContentIterator (com.intellij.openapi.roots.ContentIterator)1 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)1