use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class ModuleHighlightUtil method getModuleDescriptor.
@Nullable
static PsiJavaModule getModuleDescriptor(@NotNull PsiFileSystemItem fsItem) {
VirtualFile file = fsItem.getVirtualFile();
if (file == null)
return null;
Project project = fsItem.getProject();
ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project);
if (index.isInLibraryClasses(file)) {
VirtualFile classRoot = index.getClassRootForFile(file);
if (classRoot != null) {
VirtualFile descriptorFile = classRoot.findChild(PsiJavaModule.MODULE_INFO_CLS_FILE);
if (descriptorFile == null) {
descriptorFile = classRoot.findFileByRelativePath("META-INF/versions/9/" + PsiJavaModule.MODULE_INFO_CLS_FILE);
}
if (descriptorFile != null) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(descriptorFile);
if (psiFile instanceof PsiJavaFile) {
return ((PsiJavaFile) psiFile).getModuleDeclaration();
}
} else if (classRoot.getFileSystem() instanceof JarFileSystem && "jar".equalsIgnoreCase(classRoot.getExtension())) {
return LightJavaModule.getModule(PsiManager.getInstance(project), classRoot);
}
}
return null;
} else {
return getModuleDescriptor(index.getModuleForFile(file));
}
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class JavaDocumentationProvider method findUrlForVirtualFile.
@Nullable
public static List<String> findUrlForVirtualFile(@NotNull Project project, @NotNull VirtualFile virtualFile, @NotNull String relPath) {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
Module module = fileIndex.getModuleForFile(virtualFile);
if (module == null) {
final VirtualFileSystem fs = virtualFile.getFileSystem();
if (fs instanceof JarFileSystem) {
final VirtualFile jar = ((JarFileSystem) fs).getVirtualFileForJar(virtualFile);
if (jar != null) {
module = fileIndex.getModuleForFile(jar);
}
}
}
if (module != null) {
String[] javadocPaths = JavaModuleExternalPaths.getInstance(module).getJavadocUrls();
final List<String> httpRoots = PlatformDocumentationUtil.getHttpRoots(javadocPaths, relPath);
// if found nothing and the file is from library classes, fall back to order entries
if (httpRoots != null || !fileIndex.isInLibraryClasses(virtualFile)) {
return httpRoots;
}
}
for (OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(virtualFile)) {
for (VirtualFile root : orderEntry.getFiles(JavadocOrderRootType.getInstance())) {
if (root.getFileSystem() == JarFileSystem.getInstance()) {
VirtualFile file = root.findFileByRelativePath(relPath);
List<Url> urls = file == null ? null : BuiltInWebBrowserUrlProviderKt.getBuiltInServerUrls(file, project, null);
if (!ContainerUtil.isEmpty(urls)) {
List<String> result = new SmartList<>();
for (Url url : urls) {
result.add(url.toExternalForm());
}
return result;
}
}
}
List<String> httpRoot = PlatformDocumentationUtil.getHttpRoots(JavadocOrderRootType.getUrls(orderEntry), relPath);
if (httpRoot != null) {
return httpRoot;
}
}
return null;
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class GradleBuildClasspathManager method reload.
public void reload() {
ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(GradleConstants.SYSTEM_ID);
assert manager != null;
AbstractExternalSystemLocalSettings localSettings = manager.getLocalSettingsProvider().fun(myProject);
Map<String, List<VirtualFile>> /*module build classpath*/
map = ContainerUtil.newHashMap();
final JarFileSystem jarFileSystem = JarFileSystem.getInstance();
for (final ExternalProjectBuildClasspathPojo projectBuildClasspathPojo : localSettings.getProjectBuildClasspath().values()) {
final List<VirtualFile> projectBuildClasspath = ContainerUtil.newArrayList();
for (String path : projectBuildClasspathPojo.getProjectBuildClasspath()) {
final VirtualFile virtualFile = ExternalSystemUtil.findLocalFileByPath(path);
ContainerUtil.addIfNotNull(projectBuildClasspath, virtualFile == null || virtualFile.isDirectory() ? virtualFile : jarFileSystem.getJarRootForLocalFile(virtualFile));
}
for (final ExternalModuleBuildClasspathPojo moduleBuildClasspathPojo : projectBuildClasspathPojo.getModulesBuildClasspath().values()) {
final List<VirtualFile> moduleBuildClasspath = ContainerUtil.newArrayList(projectBuildClasspath);
for (String path : moduleBuildClasspathPojo.getEntries()) {
final VirtualFile virtualFile = ExternalSystemUtil.findLocalFileByPath(path);
ContainerUtil.addIfNotNull(moduleBuildClasspath, virtualFile == null || virtualFile.isDirectory() ? virtualFile : jarFileSystem.getJarRootForLocalFile(virtualFile));
}
map.put(moduleBuildClasspathPojo.getPath(), moduleBuildClasspath);
}
}
myClasspathMap.set(map);
Set<VirtualFile> set = new LinkedHashSet<>();
for (List<VirtualFile> virtualFiles : myClasspathMap.get().values()) {
set.addAll(virtualFiles);
}
allFilesCache = ContainerUtil.newArrayList(set);
Extensions.findExtension(PsiElementFinder.EP_NAME, myProject, GradleClassFinder.class).clearCache();
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class MvcFramework method addAvailableSystemScripts.
public static void addAvailableSystemScripts(final Collection<String> result, @NotNull Module module) {
VirtualFile scriptRoot = null;
GlobalSearchScope searchScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
for (PsiClass aClass : JavaPsiFacade.getInstance(module.getProject()).findClasses("CreateApp_", searchScope)) {
PsiClass superClass = aClass.getSuperClass();
if (superClass != null && GroovyCommonClassNames.GROOVY_LANG_SCRIPT.equals(superClass.getQualifiedName())) {
PsiFile psiFile = aClass.getContainingFile();
if (psiFile != null) {
VirtualFile file = psiFile.getVirtualFile();
if (file != null && file.getFileSystem() instanceof JarFileSystem) {
VirtualFile parent = file.getParent();
if (parent != null && parent.findChild("Console.class") != null) {
scriptRoot = parent;
break;
}
}
}
}
}
if (scriptRoot == null)
return;
Pattern scriptPattern = Pattern.compile("([A-Za-z0-9]+)_?\\.class");
for (VirtualFile file : scriptRoot.getChildren()) {
Matcher matcher = scriptPattern.matcher(file.getName());
if (matcher.matches()) {
result.add(GroovyNamesUtil.camelToSnake(matcher.group(1)));
}
}
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class EPathUtil method collapse2EclipseVariabledPath.
@Nullable
static String collapse2EclipseVariabledPath(final LibraryOrderEntry libraryOrderEntry, OrderRootType type) {
final VirtualFile[] virtualFiles = libraryOrderEntry.getRootFiles(type);
if (virtualFiles.length > 0) {
VirtualFile jarFile = virtualFiles[0];
if (jarFile.getFileSystem() instanceof JarFileSystem) {
jarFile = JarFileSystem.getInstance().getVirtualFileForJar(jarFile);
}
if (jarFile == null) {
return null;
}
final Project project = libraryOrderEntry.getOwnerModule().getProject();
final VirtualFile baseDir = project.getBaseDir();
final String filePath = jarFile.getPath();
if (baseDir != null && !VfsUtilCore.isAncestor(baseDir, jarFile, false)) {
final String ideaCollapsed = PathMacroManager.getInstance(project).collapsePath(filePath);
if (ideaCollapsed.contains(".."))
return null;
final int index = ideaCollapsed.indexOf('$');
if (index < 0)
return null;
return ideaCollapsed.substring(index).replace("$", "");
}
}
for (String url : libraryOrderEntry.getRootUrls(type)) {
//check if existing eclipse variable points inside project or doesn't exist
String filePath = VirtualFileManager.extractPath(url);
final int jarSeparatorIdx = filePath.indexOf(JarFileSystem.JAR_SEPARATOR);
if (jarSeparatorIdx > -1) {
filePath = filePath.substring(0, jarSeparatorIdx);
}
final PathMacros pathMacros = PathMacros.getInstance();
final Set<String> names = pathMacros.getUserMacroNames();
for (String name : names) {
final String path = FileUtil.toSystemIndependentName(pathMacros.getValue(name));
if (filePath.startsWith(path + "/")) {
final String substr = filePath.substring(path.length());
return name + (substr.startsWith("/") || substr.length() == 0 ? substr : "/" + substr);
}
}
}
return null;
}
Aggregations