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;
}
}
});
}
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;
}
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());
}
}
Aggregations