use of com.intellij.ide.highlighter.ArchiveFileType in project intellij-community by JetBrains.
the class FacetLibraryConfigurator method fillLibrary.
private static void fillLibrary(Project project, Library lib, List<String> paths) {
Library.ModifiableModel modifiableModel = lib.getModifiableModel();
for (String root : lib.getUrls(OrderRootType.CLASSES)) {
modifiableModel.removeRoot(root, OrderRootType.CLASSES);
}
Set<VirtualFile> roots = new HashSet<>();
ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
Collections.addAll(roots, rootManager.getContentRoots());
Collections.addAll(roots, rootManager.getContentSourceRoots());
if (paths != null) {
for (String dir : paths) {
VirtualFile pathEntry = LocalFileSystem.getInstance().findFileByPath(dir);
if (pathEntry != null && !pathEntry.isDirectory() && pathEntry.getFileType() instanceof ArchiveFileType) {
pathEntry = JarFileSystem.getInstance().getJarRootForLocalFile(pathEntry);
}
// buildout includes source root of project in paths; don't add it as library home
if (pathEntry != null && roots.contains(pathEntry)) {
continue;
}
if (pathEntry != null) {
modifiableModel.addRoot(pathEntry, OrderRootType.CLASSES);
} else {
modifiableModel.addRoot("file://" + dir, OrderRootType.CLASSES);
}
}
}
modifiableModel.commit();
}
use of com.intellij.ide.highlighter.ArchiveFileType in project intellij-community by JetBrains.
the class PyRemoteLibrariesNode method create.
@Nullable
public static PyRemoteLibrariesNode create(@NotNull Project project, @NotNull Sdk sdk, ViewSettings settings) {
if (sdk.getSdkAdditionalData() instanceof PyRemoteSdkAdditionalDataBase) {
VirtualFile remoteLibrary = PySdkUtil.findAnyRemoteLibrary(sdk);
if (remoteLibrary != null && remoteLibrary.getFileType() instanceof ArchiveFileType) {
remoteLibrary = JarFileSystem.getInstance().getLocalVirtualFileFor(remoteLibrary);
}
if (remoteLibrary != null) {
final VirtualFile remoteLibraries = remoteLibrary.getParent();
final PsiDirectory remoteLibrariesDirectory = PsiManager.getInstance(project).findDirectory(remoteLibraries);
return new PyRemoteLibrariesNode(sdk, project, remoteLibrariesDirectory, settings);
}
}
return null;
}
use of com.intellij.ide.highlighter.ArchiveFileType in project intellij-community by JetBrains.
the class BaseAnalysisAction method getInspectionScopeImpl.
@Nullable
private AnalysisScope getInspectionScopeImpl(@NotNull DataContext dataContext) {
//Possible scopes: file, directory, package, project, module.
Project projectContext = PlatformDataKeys.PROJECT_CONTEXT.getData(dataContext);
if (projectContext != null) {
return new AnalysisScope(projectContext);
}
final AnalysisScope analysisScope = AnalysisScopeUtil.KEY.getData(dataContext);
if (analysisScope != null) {
return analysisScope;
}
final PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataContext);
if (psiFile != null && psiFile.getManager().isInProject(psiFile)) {
final VirtualFile file = psiFile.getVirtualFile();
if (file != null && file.isValid() && file.getFileType() instanceof ArchiveFileType && acceptNonProjectDirectories()) {
final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(file);
if (jarRoot != null) {
PsiDirectory psiDirectory = psiFile.getManager().findDirectory(jarRoot);
if (psiDirectory != null) {
return new AnalysisScope(psiDirectory);
}
}
}
return new AnalysisScope(psiFile);
}
VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (virtualFiles != null && project != null) {
//analyze on selection
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
if (virtualFiles.length == 1) {
PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(virtualFiles[0]);
if (psiDirectory != null && (acceptNonProjectDirectories() || psiDirectory.getManager().isInProject(psiDirectory))) {
return new AnalysisScope(psiDirectory);
}
}
Set<VirtualFile> files = new HashSet<>();
for (VirtualFile vFile : virtualFiles) {
if (fileIndex.isInContent(vFile)) {
files.add(vFile);
}
}
return new AnalysisScope(project, files);
}
Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
if (moduleContext != null) {
return new AnalysisScope(moduleContext);
}
Module[] modulesArray = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
if (modulesArray != null) {
return new AnalysisScope(modulesArray);
}
return project == null ? null : new AnalysisScope(project);
}
use of com.intellij.ide.highlighter.ArchiveFileType in project android by JetBrains.
the class AndroidRootUtil method fillExternalLibrariesAndModules.
private static void fillExternalLibrariesAndModules(@NotNull final Module module, @NotNull final Set<VirtualFile> outputDirs, @NotNull final Set<Module> visited, @Nullable final Set<VirtualFile> libraries, final boolean exportedLibrariesOnly, final boolean recursive) {
if (!visited.add(module)) {
return;
}
ApplicationManager.getApplication().runReadAction(() -> {
ModuleRootManager manager = ModuleRootManager.getInstance(module);
for (OrderEntry entry : manager.getOrderEntries()) {
if (!(entry instanceof ExportableOrderEntry) || ((ExportableOrderEntry) entry).getScope() != DependencyScope.COMPILE) {
continue;
}
if (libraries != null && entry instanceof LibraryOrderEntry) {
LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
Library library = libraryOrderEntry.getLibrary();
if (library != null && (!exportedLibrariesOnly || libraryOrderEntry.isExported())) {
for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
if (!file.exists()) {
continue;
}
if (file.getFileType() instanceof ArchiveFileType) {
if (file.getFileSystem() instanceof JarFileSystem) {
VirtualFile localFile = JarFileSystem.getInstance().getVirtualFileForJar(file);
if (localFile != null) {
libraries.add(localFile);
}
} else {
libraries.add(file);
}
} else if (file.isDirectory() && !(file.getFileSystem() instanceof JarFileSystem)) {
collectClassFilesAndJars(file, libraries, new HashSet<>());
}
}
}
} else if (entry instanceof ModuleOrderEntry) {
Module depModule = ((ModuleOrderEntry) entry).getModule();
if (depModule == null) {
continue;
}
AndroidFacet facet = AndroidFacet.getInstance(depModule);
boolean libraryProject = facet != null && facet.isLibraryProject();
CompilerModuleExtension extension = CompilerModuleExtension.getInstance(depModule);
if (extension != null) {
VirtualFile classDir = extension.getCompilerOutputPath();
if (libraryProject) {
VirtualFile tmpArtifactsDir = AndroidDexCompiler.getOutputDirectoryForDex(depModule);
if (tmpArtifactsDir != null) {
VirtualFile packedClassesJar = tmpArtifactsDir.findChild(CLASSES_JAR_FILE_NAME);
if (packedClassesJar != null) {
outputDirs.add(packedClassesJar);
}
}
} else // do not support android-app->android-app compile dependencies
if (facet == null && !outputDirs.contains(classDir) && classDir != null && classDir.exists()) {
outputDirs.add(classDir);
}
}
if (recursive) {
fillExternalLibrariesAndModules(depModule, outputDirs, visited, libraries, !libraryProject || exportedLibrariesOnly, true);
}
}
}
});
}
use of com.intellij.ide.highlighter.ArchiveFileType in project intellij-community by JetBrains.
the class LibraryDataService method registerPaths.
static void registerPaths(boolean unresolved, @NotNull Map<OrderRootType, Collection<File>> libraryFiles, @NotNull Library.ModifiableModel model, @NotNull String libraryName) {
for (Map.Entry<OrderRootType, Collection<File>> entry : libraryFiles.entrySet()) {
for (File file : entry.getValue()) {
VirtualFile virtualFile = unresolved ? null : ExternalSystemUtil.refreshAndFindFileByIoFile(file);
if (virtualFile == null) {
if (!unresolved && ExternalSystemConstants.VERBOSE_PROCESSING && entry.getKey() == OrderRootType.CLASSES) {
LOG.warn(String.format("Can't find %s of the library '%s' at path '%s'", entry.getKey(), libraryName, file.getAbsolutePath()));
}
String url = VfsUtil.getUrlForLibraryRoot(file);
String[] urls = model.getUrls(entry.getKey());
if (!ArrayUtil.contains(url, urls)) {
model.addRoot(url, entry.getKey());
}
continue;
}
if (virtualFile.isDirectory()) {
VirtualFile[] files = model.getFiles(entry.getKey());
if (!ArrayUtil.contains(virtualFile, files)) {
model.addRoot(virtualFile, entry.getKey());
}
} else {
VirtualFile root = virtualFile;
if (virtualFile.getFileType() instanceof ArchiveFileType) {
root = JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile);
if (root == null) {
LOG.warn(String.format("Can't parse contents of the JAR file at path '%s' for the library '%s''", file.getAbsolutePath(), libraryName));
continue;
}
}
VirtualFile[] files = model.getFiles(entry.getKey());
if (!ArrayUtil.contains(root, files)) {
model.addRoot(root, entry.getKey());
}
}
}
}
}
Aggregations