use of com.intellij.openapi.vfs.VirtualFileVisitor in project intellij-community by JetBrains.
the class JavaVfsSourceRootDetectionUtil method suggestRoots.
/**
* Scan directory and detect java source roots within it. The source root is detected as the following:
* <ol>
* <li>It contains at least one Java file.</li>
* <li>Java file is located in the sub-folder that matches package statement in the file.</li>
* </ol>
*
* @param dir a directory to scan
* @param progressIndicator
* @return a list of found source roots within directory. If no source roots are found, a empty list is returned.
*/
@NotNull
public static List<VirtualFile> suggestRoots(@NotNull VirtualFile dir, @NotNull final ProgressIndicator progressIndicator) {
if (!dir.isDirectory()) {
return ContainerUtil.emptyList();
}
final FileTypeManager typeManager = FileTypeManager.getInstance();
final ArrayList<VirtualFile> foundDirectories = new ArrayList<>();
try {
VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() {
@NotNull
@Override
public Result visitFileEx(@NotNull VirtualFile file) {
progressIndicator.checkCanceled();
if (file.isDirectory()) {
if (typeManager.isFileIgnored(file) || StringUtil.startsWithIgnoreCase(file.getName(), "testData")) {
return SKIP_CHILDREN;
}
} else {
FileType type = typeManager.getFileTypeByFileName(file.getName());
if (StdFileTypes.JAVA == type) {
VirtualFile root = suggestRootForJavaFile(file);
if (root != null) {
foundDirectories.add(root);
return skipTo(root);
}
}
}
return CONTINUE;
}
});
} catch (ProcessCanceledException ignore) {
}
return foundDirectories;
}
use of com.intellij.openapi.vfs.VirtualFileVisitor in project intellij-community by JetBrains.
the class FrameworkDetectionProcessor method collectSuitableFiles.
private void collectSuitableFiles(@NotNull VirtualFile file) {
try {
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
// Since this code is invoked from New Project Wizard it's very possible that VFS isn't loaded to memory yet, so we need to do it
// manually, otherwise refresh will do nothing
myProgressIndicator.checkCanceled();
return true;
}
});
file.refresh(false, true);
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
myProgressIndicator.checkCanceled();
if (!myProcessedFiles.add(file)) {
return false;
}
if (!file.isDirectory()) {
final FileType fileType = file.getFileType();
if (myDetectorsByFileType.containsKey(fileType)) {
myProgressIndicator.setText2(file.getPresentableUrl());
try {
final FileContent fileContent = new FileContentImpl(file, file.contentsToByteArray(false));
for (FrameworkDetectorData detector : myDetectorsByFileType.get(fileType)) {
if (detector.myFilePattern.accepts(fileContent)) {
detector.mySuitableFiles.add(file);
}
}
} catch (IOException e) {
LOG.info(e);
}
}
}
return true;
}
});
} catch (ProcessCanceledException ignored) {
}
}
use of com.intellij.openapi.vfs.VirtualFileVisitor in project intellij-community by JetBrains.
the class AbstractConvertLineSeparatorsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
final DataContext dataContext = event.getDataContext();
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return;
}
final VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
if (virtualFiles == null) {
return;
}
VirtualFile projectVirtualDirectory = ProjectKt.getStateStore(project).getDirectoryStoreFile();
final FileTypeRegistry fileTypeManager = FileTypeRegistry.getInstance();
for (VirtualFile file : virtualFiles) {
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
@NotNull
@Override
public Result visitFileEx(@NotNull VirtualFile file) {
if (shouldProcess(file, project)) {
changeLineSeparators(project, file, mySeparator);
}
return file.isDirectory() && (file.equals(projectVirtualDirectory) || fileTypeManager.isFileIgnored(file)) ? SKIP_CHILDREN : CONTINUE;
}
});
}
}
use of com.intellij.openapi.vfs.VirtualFileVisitor in project intellij-plugins by JetBrains.
the class FlexSwcFoldersRootDetector method collectRoots.
private static void collectRoots(VirtualFile file, final List<VirtualFile> result, final ProgressIndicator progressIndicator) {
if (!file.isDirectory() || file.getFileSystem() instanceof JarFileSystem)
return;
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
@NotNull
@Override
public Result visitFileEx(@NotNull VirtualFile child) {
progressIndicator.checkCanceled();
if (child.isDirectory()) {
progressIndicator.setText2(child.getPresentableUrl());
} else if ("swc".equalsIgnoreCase(child.getExtension()) || "ane".equalsIgnoreCase(child.getExtension())) {
final VirtualFile dir = child.getParent();
result.add(dir);
return skipTo(dir);
}
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;
}
Aggregations