use of com.intellij.openapi.roots.FileIndex in project intellij-community by JetBrains.
the class FileIndexCompileScope method getFiles.
@NotNull
public VirtualFile[] getFiles(final FileType fileType, final boolean inSourceOnly) {
final List<VirtualFile> files = new ArrayList<>();
final FileIndex[] fileIndices = getFileIndices();
for (final FileIndex fileIndex : fileIndices) {
fileIndex.iterateContent(new CompilerContentIterator(fileType, fileIndex, inSourceOnly, files));
}
return VfsUtil.toVirtualFileArray(files);
}
use of com.intellij.openapi.roots.FileIndex in project intellij-community by JetBrains.
the class PackageChooserDialog method createTreeModel.
private void createTreeModel() {
final PsiManager psiManager = PsiManager.getInstance(myProject);
final FileIndex fileIndex = myModule != null ? ModuleRootManager.getInstance(myModule).getFileIndex() : ProjectRootManager.getInstance(myProject).getFileIndex();
fileIndex.iterateContent(new ContentIterator() {
public boolean processFile(VirtualFile fileOrDir) {
if (fileOrDir.isDirectory() && fileIndex.isUnderSourceRootOfType(fileOrDir, JavaModuleSourceRootTypes.SOURCES)) {
final PsiDirectory psiDirectory = psiManager.findDirectory(fileOrDir);
LOG.assertTrue(psiDirectory != null);
PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
if (aPackage != null) {
addPackage(aPackage);
}
}
return true;
}
});
TreeUtil.sort(myModel, (o1, o2) -> {
DefaultMutableTreeNode n1 = (DefaultMutableTreeNode) o1;
DefaultMutableTreeNode n2 = (DefaultMutableTreeNode) o2;
PsiNamedElement element1 = (PsiNamedElement) n1.getUserObject();
PsiNamedElement element2 = (PsiNamedElement) n2.getUserObject();
return element1.getName().compareToIgnoreCase(element2.getName());
});
}
use of com.intellij.openapi.roots.FileIndex in project intellij-community by JetBrains.
the class GlobalInspectionContextImpl method startIterateScopeInBackground.
@NotNull
private Future<?> startIterateScopeInBackground(@NotNull final AnalysisScope scope, @Nullable final Collection<VirtualFile> localScopeFiles, final boolean headlessEnvironment, @NotNull final BlockingQueue<PsiFile> outFilesToInspect, @NotNull final ProgressIndicator progressIndicator) {
Task.Backgroundable task = new Task.Backgroundable(getProject(), "Scanning Files to Inspect") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
final FileIndex fileIndex = ProjectRootManager.getInstance(getProject()).getFileIndex();
scope.accept(file -> {
indicator.checkCanceled();
if (ProjectUtil.isProjectOrWorkspaceFile(file) || !fileIndex.isInContent(file))
return true;
PsiFile psiFile = ReadAction.compute(() -> {
if (getProject().isDisposed())
throw new ProcessCanceledException();
PsiFile psi = PsiManager.getInstance(getProject()).findFile(file);
Document document = psi == null ? null : shouldProcess(psi, headlessEnvironment, localScopeFiles);
if (document != null) {
return psi;
}
return null;
});
if (psiFile != null) {
try {
LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed());
outFilesToInspect.put(psiFile);
} catch (InterruptedException e) {
LOG.error(e);
}
}
indicator.checkCanceled();
return true;
});
} catch (ProcessCanceledException e) {
// ignore, but put tombstone
} finally {
try {
outFilesToInspect.put(TOMBSTONE);
} catch (InterruptedException e) {
LOG.error(e);
}
}
}
};
return ((CoreProgressManager) ProgressManager.getInstance()).runProcessWithProgressAsynchronously(task, progressIndicator, null);
}
use of com.intellij.openapi.roots.FileIndex in project intellij-community by JetBrains.
the class SaveProjectAsTemplateAction method saveProject.
public static void saveProject(final Project project, @NotNull Path zipFile, Module moduleToSave, final String description, boolean replaceParameters, final ProgressIndicator indicator, boolean shouldEscape) {
final Map<String, String> parameters = computeParameters(project, replaceParameters);
indicator.setText("Saving project...");
ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(project::save));
indicator.setText("Processing project files...");
ZipOutputStream stream = null;
try {
stream = new ZipOutputStream(PathKt.outputStream(zipFile));
final VirtualFile dir = getDirectoryToSave(project, moduleToSave);
List<LocalArchivedTemplate.RootDescription> roots = collectStructure(project, moduleToSave);
LocalArchivedTemplate.RootDescription basePathRoot = findOrAddBaseRoot(roots, dir);
writeFile(LocalArchivedTemplate.DESCRIPTION_PATH, description, project, basePathRoot.myRelativePath, stream, true);
if (replaceParameters) {
String text = getInputFieldsText(parameters);
writeFile(LocalArchivedTemplate.TEMPLATE_DESCRIPTOR, text, project, basePathRoot.myRelativePath, stream, false);
}
String metaDescription = getTemplateMetaText(shouldEscape, roots);
writeFile(LocalArchivedTemplate.META_TEMPLATE_DESCRIPTOR_PATH, metaDescription, project, basePathRoot.myRelativePath, stream, true);
FileIndex index = moduleToSave == null ? ProjectRootManager.getInstance(project).getFileIndex() : ModuleRootManager.getInstance(moduleToSave).getFileIndex();
final ZipOutputStream finalStream = stream;
MyContentIterator iterator = new MyContentIterator(indicator, finalStream, project, parameters, shouldEscape);
for (LocalArchivedTemplate.RootDescription root : roots) {
String prefix = LocalArchivedTemplate.ROOT_FILE_NAME + root.myIndex;
VirtualFile rootFile = root.myFile;
iterator.setRootAndPrefix(rootFile, prefix);
index.iterateContentUnderDirectory(rootFile, iterator);
}
} catch (ProcessCanceledException ex) {
//ignore
} catch (Exception ex) {
LOG.error(ex);
UIUtil.invokeLaterIfNeeded(() -> Messages.showErrorDialog(project, "Can't save project as template", "Internal Error"));
} finally {
StreamUtil.closeStream(stream);
}
}
Aggregations