use of com.intellij.openapi.roots.OrderEnumerator in project intellij-community by JetBrains.
the class SearchScope method iterateContent.
public void iterateContent(@NotNull final Project project, final Processor<VirtualFile> processor) {
switch(getScopeType()) {
case PROJECT:
//noinspection unchecked
ProjectRootManager.getInstance(project).getFileIndex().iterateContent(new MyFileIterator(processor, Conditions.<VirtualFile>alwaysTrue()));
break;
case MODULE:
final Module module = ModuleManager.getInstance(project).findModuleByName(getModuleName());
assert module != null;
ModuleRootManager.getInstance(module).getFileIndex().iterateContent(new MyFileIterator(processor, Conditions.<VirtualFile>alwaysTrue()));
break;
case DIRECTORY:
final String dirName = getPath();
assert dirName != null;
final VirtualFile virtualFile = findFile(dirName);
if (virtualFile != null) {
iterateRecursively(virtualFile, processor, isRecursive());
}
break;
case CUSTOM:
assert myCustomScope != null;
final ContentIterator iterator;
if (myCustomScope instanceof GlobalSearchScope) {
final GlobalSearchScope searchScope = (GlobalSearchScope) myCustomScope;
iterator = new MyFileIterator(processor, virtualFile13 -> searchScope.contains(virtualFile13));
if (searchScope.isSearchInLibraries()) {
final OrderEnumerator enumerator = OrderEnumerator.orderEntries(project).withoutModuleSourceEntries().withoutDepModules();
final Collection<VirtualFile> libraryFiles = new THashSet<>();
Collections.addAll(libraryFiles, enumerator.getClassesRoots());
Collections.addAll(libraryFiles, enumerator.getSourceRoots());
final Processor<VirtualFile> adapter = virtualFile1 -> iterator.processFile(virtualFile1);
for (final VirtualFile file : libraryFiles) {
iterateRecursively(file, adapter, true);
}
}
} else {
final PsiManager manager = PsiManager.getInstance(project);
iterator = new MyFileIterator(processor, virtualFile12 -> {
final PsiFile element = manager.findFile(virtualFile12);
return element != null && PsiSearchScopeUtil.isInScope(myCustomScope, element);
});
}
ProjectRootManager.getInstance(project).getFileIndex().iterateContent(iterator);
}
}
use of com.intellij.openapi.roots.OrderEnumerator in project intellij-community by JetBrains.
the class JarFromModulesTemplate method doCreateArtifact.
@Nullable
public NewArtifactConfiguration doCreateArtifact(final Module[] modules, final String mainClassName, final String directoryForManifest, final boolean extractLibrariesToJar, final boolean includeTests) {
VirtualFile manifestFile = null;
final Project project = myContext.getProject();
if (mainClassName != null && !mainClassName.isEmpty() || !extractLibrariesToJar) {
final VirtualFile directory;
try {
directory = ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<VirtualFile, IOException>() {
@Override
public VirtualFile compute() throws IOException {
return VfsUtil.createDirectoryIfMissing(directoryForManifest);
}
});
} catch (IOException e) {
LOG.info(e);
Messages.showErrorDialog(project, "Cannot create directory '" + directoryForManifest + "': " + e.getMessage(), CommonBundle.getErrorTitle());
return null;
}
if (directory == null)
return null;
manifestFile = ManifestFileUtil.createManifestFile(directory, project);
if (manifestFile == null) {
return null;
}
ManifestFileUtil.updateManifest(manifestFile, mainClassName, null, true);
}
String name = modules.length == 1 ? modules[0].getName() : project.getName();
final PackagingElementFactory factory = PackagingElementFactory.getInstance();
final CompositePackagingElement<?> archive = factory.createArchive(ArtifactUtil.suggestArtifactFileName(name) + ".jar");
OrderEnumerator orderEnumerator = ProjectRootManager.getInstance(project).orderEntries(Arrays.asList(modules));
final Set<Library> libraries = new THashSet<>();
if (!includeTests) {
orderEnumerator = orderEnumerator.productionOnly();
}
final ModulesProvider modulesProvider = myContext.getModulesProvider();
final OrderEnumerator enumerator = orderEnumerator.using(modulesProvider).withoutSdk().runtimeOnly().recursively();
enumerator.forEachLibrary(new CommonProcessors.CollectProcessor<>(libraries));
enumerator.forEachModule(module -> {
if (ProductionModuleOutputElementType.ELEMENT_TYPE.isSuitableModule(modulesProvider, module)) {
archive.addOrFindChild(factory.createModuleOutput(module));
}
if (includeTests && TestModuleOutputElementType.ELEMENT_TYPE.isSuitableModule(modulesProvider, module)) {
archive.addOrFindChild(factory.createTestModuleOutput(module));
}
return true;
});
final JarArtifactType jarArtifactType = JarArtifactType.getInstance();
if (manifestFile != null && !manifestFile.equals(ManifestFileUtil.findManifestFile(archive, myContext, jarArtifactType))) {
archive.addFirstChild(factory.createFileCopyWithParentDirectories(manifestFile.getPath(), ManifestFileUtil.MANIFEST_DIR_NAME));
}
final String artifactName = name + ":jar";
if (extractLibrariesToJar) {
addExtractedLibrariesToJar(archive, factory, libraries);
return new NewArtifactConfiguration(archive, artifactName, jarArtifactType);
} else {
final ArtifactRootElement<?> root = factory.createArtifactRootElement();
List<String> classpath = new ArrayList<>();
root.addOrFindChild(archive);
addLibraries(libraries, root, archive, classpath);
ManifestFileUtil.updateManifest(manifestFile, mainClassName, classpath, true);
return new NewArtifactConfiguration(root, artifactName, PlainArtifactType.getInstance());
}
}
use of com.intellij.openapi.roots.OrderEnumerator in project intellij-community by JetBrains.
the class VfsRootAccess method getAllRoots.
@NotNull
private static VirtualFile[] getAllRoots(@NotNull Project project) {
insideGettingRoots = true;
final Set<VirtualFile> roots = new THashSet<>();
final OrderEnumerator enumerator = ProjectRootManager.getInstance(project).orderEntries();
ContainerUtil.addAll(roots, enumerator.getClassesRoots());
ContainerUtil.addAll(roots, enumerator.getSourceRoots());
insideGettingRoots = false;
return VfsUtilCore.toVirtualFileArray(roots);
}
use of com.intellij.openapi.roots.OrderEnumerator in project intellij-community by JetBrains.
the class JspSpiUtil method processClassPathItems.
public static void processClassPathItems(final VirtualFile virtualFile, final Module module, final Consumer<VirtualFile> consumer, boolean includeModuleOutput) {
if (isJarFile(virtualFile)) {
consumer.consume(virtualFile);
}
if (module != null) {
OrderEnumerator enumerator = ModuleRootManager.getInstance(module).orderEntries().recursively();
if (!includeModuleOutput) {
enumerator = enumerator.withoutModuleSourceEntries();
}
for (VirtualFile root : enumerator.getClassesRoots()) {
final VirtualFile file;
if (root.getFileSystem().getProtocol().equals(JarFileSystem.PROTOCOL)) {
file = JarFileSystem.getInstance().getVirtualFileForJar(root);
} else {
file = root;
}
consumer.consume(file);
}
}
}
use of com.intellij.openapi.roots.OrderEnumerator in project intellij-community by JetBrains.
the class ManifestFileUtil method suggestManifestFileDirectory.
@Nullable
public static VirtualFile suggestManifestFileDirectory(@NotNull Project project, @Nullable Module module) {
OrderEnumerator enumerator = module != null ? OrderEnumerator.orderEntries(module) : OrderEnumerator.orderEntries(project);
final VirtualFile[] files = enumerator.withoutDepModules().withoutLibraries().withoutSdk().productionOnly().sources().getRoots();
if (files.length > 0) {
return files[0];
}
return suggestBaseDir(project, null);
}
Aggregations