@Nullable private VirtualFile getSourceCodeRoot(final @NotNull HybrisModuleDescriptor moduleDescriptor) { final VirtualFile sourceCodeRoot; final File sourceCodeFile = moduleDescriptor.getRootProjectDescriptor().getSourceCodeFile(); if (null != sourceCodeFile) { final VirtualFile sourceVFile = VfsUtil.findFileByIoFile(sourceCodeFile, true); if (null == sourceVFile) { sourceCodeRoot = null; } else if (sourceVFile.isDirectory()) { sourceCodeRoot = sourceVFile; } else { sourceCodeRoot = JarFileSystem.getInstance().getJarRootForLocalFile(sourceVFile); } } else { sourceCodeRoot = null; } return sourceCodeRoot; }
@Override public void initComponent() { VirtualFile pluginVirtualDirectory = LuaFileUtil.getPluginVirtualDirectory(); if (pluginVirtualDirectory != null) { VirtualFile lib = pluginVirtualDirectory.findChild("lib"); if (lib != null) { VirtualFile pluginJar = lib.findChild("IDLua.jar"); JarFileSystem jfs = JarFileSystem.getInstance(); VirtualFile std = jfs.findLocalVirtualFileByPath("include/stdlibrary"); try { VfsUtil.copyDirectory(this, std, pluginVirtualDirectory, null); } catch (IOException e) { e.printStackTrace(); } } } }
protected static void commitLibraryModel(ModifiableRootModel model, String testDataPath, @NotNull String... libraryPath) { LibraryTable libraryTable = model.getModuleLibraryTable(); Library library = libraryTable.createLibrary("test"); Library.ModifiableModel libraryModel = library.getModifiableModel(); for (String annotationsDir : libraryPath) { String path = testDataPath + "/libs/" + annotationsDir; VirtualFile libJarLocal = LocalFileSystem.getInstance().findFileByPath(path); assertNotNull(libJarLocal); VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(libJarLocal); assertNotNull(jarRoot); libraryModel.addRoot(jarRoot, jarRoot.getName().contains("-sources") ? OrderRootType.SOURCES : OrderRootType.CLASSES); } libraryModel.commit(); }
public void testAllInPackageForProject() throws IOException, ExecutionException { // module1 -> module2 -> module3 // module5 addModule("module5"); addDependency(getModule1(), getModule2()); addDependency(getModule2(), getModule3()); String[][] outputs = new String[4][]; for (int i = 0; i < 4; i++) { outputs[i] = addOutputs(getModule(i), i + 1); } PsiPackage defaultPackage = JavaPsiFacade.getInstance(myProject).findPackage(""); JUnitConfiguration configuration = createJUnitConfiguration(defaultPackage, AllInPackageConfigurationProducer.class, new MapDataContext()); configuration.getPersistentData().setScope(TestSearchScope.WHOLE_PROJECT); JavaParameters javaParameters = checkCanRun(configuration); String classPath = javaParameters.getClassPath().getPathsString(); assertEquals(-1, classPath.indexOf(JarFileSystem.PROTOCOL_PREFIX)); assertEquals(-1, classPath.indexOf(LocalFileSystem.PROTOCOL_PREFIX)); for (int i = 0; i < 4; i++) { checkContains(classPath, outputs[i][0]); checkContains(classPath, outputs[i][1]); } }
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); } } }
@NotNull @Override public CellAppearanceEx forLibrary(Project project, @NotNull final Library library, final boolean hasInvalidRoots) { final StructureConfigurableContext context = ProjectStructureConfigurable.getInstance(project).getContext(); final Icon icon = LibraryPresentationManager.getInstance().getCustomIcon(library, context); final String name = library.getName(); if (name != null) { return normalOrRedWaved(name, (icon != null ? icon : PlatformIcons.LIBRARY_ICON), hasInvalidRoots); } final String[] files = library.getUrls(OrderRootType.CLASSES); if (files.length == 0) { return SimpleTextCellAppearance.invalid(ProjectBundle.message("library.empty.library.item"), PlatformIcons.LIBRARY_ICON); } else if (files.length == 1) { return forVirtualFilePointer(new LightFilePointer(files[0])); } final String url = StringUtil.trimEnd(files[0], JarFileSystem.JAR_SEPARATOR); return SimpleTextCellAppearance.regular(PathUtil.getFileName(url), PlatformIcons.LIBRARY_ICON); }
@Override @Nullable public VirtualFile getExistingRootDirectory() { for (OrderRootType orderRootType : OrderRootType.getAllPersistentTypes()) { final VirtualFile[] existingRoots = getLibraryEditor().getFiles(orderRootType); if (existingRoots.length > 0) { VirtualFile existingRoot = existingRoots[0]; if (existingRoot.getFileSystem() instanceof JarFileSystem) { existingRoot = JarFileSystem.getInstance().getVirtualFileForJar(existingRoot); } if (existingRoot != null) { if (existingRoot.isDirectory()) { return existingRoot; } else { return existingRoot.getParent(); } } } } return null; }
@Nullable private Module findModule(List<OrderRoot> roots) { for (OrderRoot root : roots) { Module module = null; final VirtualFile local = JarFileSystem.getInstance().getVirtualFileForJar(root.getFile()); if (local != null) { module = ModuleUtil.findModuleForFile(local, myProject); } if (module == null) { module = ModuleUtil.findModuleForFile(root.getFile(), myProject); } if (module != null) { return module; } } return null; }
@NotNull private static List<VirtualFile> getRoots(AnActionEvent e) { final Project project = getEventProject(e); final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); if (project == null || files == null || files.length == 0) return Collections.emptyList(); List<VirtualFile> roots = new ArrayList<VirtualFile>(); for (VirtualFile file : files) { if (file.isDirectory()) { roots.add(file); } else { final VirtualFile root = JarFileSystem.getInstance().getJarRootForLocalFile(file); if (root != null) { roots.add(root); } } } return roots; }
@Override public VirtualFile getSdkRoot(@Nullable Module module) { if (module == null) return null; final VirtualFile[] classRoots = ModuleRootManager.getInstance(module).orderEntries().librariesOnly().getClassesRoots(); for (VirtualFile file : classRoots) { if (GriffonLibraryPresentationProvider.isGriffonCoreJar(file)) { final VirtualFile localFile = JarFileSystem.getInstance().getVirtualFileForJar(file); if (localFile != null) { final VirtualFile parent = localFile.getParent(); if (parent != null) { return parent.getParent(); } } return null; } } return null; }
@Nullable public final VirtualFile getFileToSelect(VirtualFile file) { if (file.isDirectory() && (myChooseFolders || isFileSelectable(file))) { return file; } boolean isJar = file.getFileType() == FileTypes.ARCHIVE; if (!isJar) { return acceptAsGeneralFile(file) ? file : null; } if (myChooseJarsAsFiles) { return file; } if (!acceptAsJarFile(file)) { return null; } String path = file.getPath(); return JarFileSystem.getInstance().findFileByPath(path + JarFileSystem.JAR_SEPARATOR); }
public WatchRequestImpl(String rootPath, boolean watchRecursively) throws FileNotFoundException { int index = rootPath.indexOf(JarFileSystem.JAR_SEPARATOR); if (index >= 0) rootPath = rootPath.substring(0, index); File rootFile = new File(FileUtil.toSystemDependentName(rootPath)); if (index > 0 || !(FileUtil.isRootPath(rootFile) || rootFile.isDirectory())) { File parentFile = rootFile.getParentFile(); if (parentFile == null) { throw new FileNotFoundException(rootPath); } if (!parentFile.getPath().equals(PathManager.getSystemPath()) || !rootFile.mkdir()) { rootFile = parentFile; } } myFSRootPath = rootFile.getAbsolutePath(); myWatchRecursively = watchRecursively; }
@NotNull @Override public CellAppearanceEx forVirtualFile(@NotNull final VirtualFile file) { if (!file.isValid()) { return forInvalidUrl(file.getPresentableUrl()); } final VirtualFileSystem fileSystem = file.getFileSystem(); if (fileSystem.getProtocol().equals(JarFileSystem.PROTOCOL)) { return new JarSubfileCellAppearance(file); } if (fileSystem instanceof HttpFileSystem) { return new HttpUrlCellAppearance(file); } if (file.isDirectory()) { return SimpleTextCellAppearance.regular(file.getPresentableUrl(), PlatformIcons.FOLDER_ICON); } return new ValidFileCellAppearance(file); }
@Nullable private static FileElement getFileElementFor(@NotNull VirtualFile file) { VirtualFile selectFile; if ((file.getFileSystem() instanceof JarFileSystem) && file.getParent() == null) { selectFile = JarFileSystem.getInstance().getVirtualFileForJar(file); if (selectFile == null) { return null; } } else { selectFile = file; } return new FileElement(selectFile, selectFile.getName()); }
public void testFindFile() throws IOException { String rtJarPath = PlatformTestUtil.getRtJarPath(); VirtualFile jarRoot = findByPath(rtJarPath + JarFileSystem.JAR_SEPARATOR); assertTrue(jarRoot.isDirectory()); VirtualFile file2 = findByPath(rtJarPath + JarFileSystem.JAR_SEPARATOR + "java"); assertTrue(file2.isDirectory()); VirtualFile file3 = jarRoot.findChild("java"); assertEquals(file2, file3); VirtualFile file4 = findByPath(rtJarPath + JarFileSystem.JAR_SEPARATOR + "java/lang/Object.class"); assertTrue(!file4.isDirectory()); byte[] bytes = file4.contentsToByteArray(); assertNotNull(bytes); assertTrue(bytes.length > 10); assertEquals(0xCAFEBABE, ByteBuffer.wrap(bytes).getInt()); }
private void checkMove(File jar, VirtualFile vFile, final PsiFile file) { VirtualFile jarRoot; File libDir = new File(jar.getParent(), "lib"); assertTrue(libDir.mkdir()); final VirtualFile vLibDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libDir); assertNotNull(vLibDir); jarRoot = findByPath(vFile.getPath() + JarFileSystem.JAR_SEPARATOR); assertTrue(jarRoot.isValid()); PsiDirectory directory = getPsiManager().findDirectory(vLibDir); final DataContext psiDataContext = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT.getName(), directory); new WriteCommandAction.Simple(myProject) { @Override protected void run() throws Throwable { new MoveHandler().invoke(myProject, new PsiElement[] {file}, psiDataContext); } }.execute(); assertFalse(jarRoot.isValid()); jarRoot = findByPath(vFile.getPath() + JarFileSystem.JAR_SEPARATOR); assertTrue(jarRoot.isValid()); rename(directory, "lib2"); assertFalse(jarRoot.isValid()); }
private static void appendIdeaLibrary(final String libDirPath, final ArrayList<VirtualFile> result, @NonNls final String... forbidden) { Arrays.sort(forbidden); final String path = libDirPath + File.separator + LIB_DIR_NAME; final JarFileSystem jfs = JarFileSystem.getInstance(); final File lib = new File(path); if (lib.isDirectory()) { File[] jars = lib.listFiles(); if (jars != null) { for (File jar : jars) { @NonNls String name = jar.getName(); if (jar.isFile() && Arrays.binarySearch(forbidden, name) < 0 && (name.endsWith(".jar") || name.endsWith(".zip"))) { VirtualFile file = jfs.findFileByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR); LOG.assertTrue(file != null, jar.getPath() + " not found"); result.add(file); } } } } }
/** * @return the specified attribute of the JDK (examines rt.jar) or null if cannot determine the value */ @Nullable public static String getJdkMainAttribute(@NotNull Sdk jdk, Attributes.Name attribute) { VirtualFile homeDirectory = jdk.getHomeDirectory(); if (homeDirectory == null) return null; VirtualFile rtJar = homeDirectory.findFileByRelativePath("jre/lib/rt.jar"); // JDK if (rtJar == null) rtJar = homeDirectory.findFileByRelativePath("lib/rt.jar"); // JRE if (rtJar == null) rtJar = homeDirectory.findFileByRelativePath("jre/lib/vm.jar"); // IBM JDK if (rtJar == null) rtJar = homeDirectory.findFileByRelativePath("../Classes/classes.jar"); // Apple JDK if (rtJar == null) { String versionString = jdk.getVersionString(); if (versionString != null) { final int start = versionString.indexOf("\""); final int end = versionString.lastIndexOf("\""); versionString = start >= 0 && (end > start)? versionString.substring(start + 1, end) : null; } return versionString; } VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(rtJar); return jarRoot != null ? getJarMainAttribute(jarRoot, attribute) : null; }
@Override public boolean isAccepted(@NotNull VirtualFile rootCandidate, @NotNull final ProgressIndicator progressIndicator) { if (isJarDirectory()) { if (!rootCandidate.isDirectory() || !rootCandidate.isInLocalFileSystem()) { return false; } for (VirtualFile child : rootCandidate.getChildren()) { if (!child.isDirectory() && child.getFileType().equals(FileTypes.ARCHIVE)) { final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(child); if (jarRoot != null && containsFileOfType(jarRoot, progressIndicator)) { return true; } } } return false; } else { return containsFileOfType(rootCandidate, progressIndicator); } }
@Override public boolean contains(@NotNull VirtualFile file) { Module module = getValue(); if (module == null || module.isDisposed()) return false; final VirtualFile testee; if (file.getFileSystem() instanceof JarFileSystem) { testee = JarFileSystem.getInstance().getVirtualFileForJar(file); if (testee == null) return false; } else { testee = file; } for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) { if (VfsUtilCore.isAncestor(root, testee, false)) return true; } return false; }
private VirtualFile findEggEntry(String file) { int ind = -1; for (String ext : EGG_EXTENSIONS) { ind = file.indexOf(ext); if (ind != -1) break; } if (ind != -1) { String jarPath = file.substring(0, ind + 4); VirtualFile jarFile = getLocalFileSystem().findFileByPath(jarPath); if (jarFile != null) { String innerPath = file.substring(ind + 4); final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(jarFile); if (jarRoot != null) { return jarRoot.findFileByRelativePath(innerPath); } } } return null; }
private static void addSources(SdkModificator sdkModificator, final Sdk javaSdk) { if (javaSdk != null) { if (!addOrderEntries(OrderRootType.SOURCES, javaSdk, sdkModificator)){ if (SystemInfo.isMac) { Sdk[] jdks = ProjectJdkTable.getInstance().getAllJdks(); for (Sdk jdk : jdks) { if (jdk.getSdkType() instanceof JavaSdk) { addOrderEntries(OrderRootType.SOURCES, jdk, sdkModificator); break; } } } else { final File jdkHome = new File(javaSdk.getHomePath()).getParentFile(); @NonNls final String srcZip = "src.zip"; final File jarFile = new File(jdkHome, srcZip); if (jarFile.exists()){ JarFileSystem jarFileSystem = JarFileSystem.getInstance(); String path = jarFile.getAbsolutePath().replace(File.separatorChar, '/') + JarFileSystem.JAR_SEPARATOR; jarFileSystem.setNoCopyJarForPath(path); sdkModificator.addRoot(jarFileSystem.findFileByPath(path), OrderRootType.SOURCES); } } } } }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component rendererComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value != null) { String loc = value.toString().replace('\\', '/'); final int jarDelimIndex = loc.indexOf(JarFileSystem.JAR_SEPARATOR); final VirtualFile path; if (jarDelimIndex != -1) { path = JarFileSystem.getInstance().findFileByPath(loc); } else { path = LocalFileSystem.getInstance().findFileByPath(loc); } setForeground(path != null ? isSelected ? UIUtil.getTableSelectionForeground() : Color.black : new Color(210, 0, 0)); } return rendererComponent; }
public void search() { myFiles.clear(); myJars.clear(); PsiManager psiManager = PsiManager.getInstance(myProject); for (PsiFile file : search(myModule, myProject)) { VirtualFile jar = JarFileSystem.getInstance().getVirtualFileForJar(file.getVirtualFile()); if (jar != null) { myJars.putValue(jar, file); } else { Module module = ModuleUtilCore.findModuleForPsiElement(file); if (module != null) { myFiles.putValue(module, file); } else { VirtualFile virtualFile = file.getVirtualFile(); myVirtualFiles.putValue(virtualFile.getParent(), psiManager.findFile(virtualFile)); } } } }
private static void collectClassFilesAndJars(@NotNull VirtualFile root, @NotNull Set<VirtualFile> result, @NotNull Set<VirtualFile> visited) { if (!visited.add(root)) { return; } for (VirtualFile child : root.getChildren()) { if (child.exists()) { if (child.isDirectory()) { collectClassFilesAndJars(child, result, visited); } else if ("jar".equals(child.getExtension()) || "class".equals(child.getExtension())) { if (child.getFileSystem() instanceof JarFileSystem) { VirtualFile localFile = JarFileSystem.getInstance().getVirtualFileForJar(child); if (localFile != null) { result.add(localFile); } } else { result.add(child); } } } } }
private static boolean isMyContext(@NotNull final PsiElement element, @NotNull final Project project) { if (element instanceof PsiClass) { return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() { @Override public Boolean compute() { PsiFile file = element.getContainingFile(); if (file == null) { return false; } VirtualFile vFile = file.getVirtualFile(); if (vFile == null) { return false; } String path = FileUtil.toSystemIndependentName(vFile.getPath()); if (path.toLowerCase(Locale.US).contains("/" + SdkConstants.FN_FRAMEWORK_LIBRARY + "!/")) { if (ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID).size() > 0) { VirtualFile jarFile = JarFileSystem.getInstance().getVirtualFileForJar(vFile); return jarFile != null && SdkConstants.FN_FRAMEWORK_LIBRARY.equals(jarFile.getName()); } } return false; } }); } return false; }
@NotNull private static List<VirtualFile> getRoots(@NotNull AnActionEvent e) { final Project project = getEventProject(e); final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); if (project == null || files == null || files.length == 0) { return Collections.emptyList(); } List<VirtualFile> roots = new ArrayList<VirtualFile>(); for (VirtualFile file : files) { VirtualFile root = JarFileSystem.getInstance().getJarRootForLocalFile(file); if (root != null) { roots.add(root); } } return roots; }
@Nullable public static VirtualFile doResolveSuperPomFile(@NotNull File mavenHome) { File[] files = mavenHome.listFiles(); if (files == null) return null; for (File library : files) { for (Pair<Pattern, String> path : SUPER_POM_PATHS) { if (path.first.matcher(library.getName()).matches()) { VirtualFile libraryVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(library); if (libraryVirtualFile == null) continue; VirtualFile root = JarFileSystem.getInstance().getJarRootForLocalFile(libraryVirtualFile); if (root == null) continue; VirtualFile pomFile = root.findFileByRelativePath(path.second); if (pomFile != null) { return pomFile; } } } } return null; }
public static String getStorageRoot(String[] urls, Project project) { if (urls.length == 0) { return null; } final String localRepositoryPath = FileUtil.toSystemIndependentName(MavenProjectsManager.getInstance(project).getLocalRepository().getPath()); List<String> roots = JBIterable.of(urls).transform(new Function<String, String>() { @Override public String fun(String urlWithPrefix) { String url = StringUtil.trimStart(urlWithPrefix, JarFileSystem.PROTOCOL_PREFIX); return url.startsWith(localRepositoryPath) ? null : FileUtil.toSystemDependentName(PathUtil.getParentPath(url)); } }).toList(); Map<String, Integer> counts = new HashMap<String, Integer>(); for (String root : roots) { int count = counts.get(root) != null ? counts.get(root) : 0; counts.put(root, count + 1); } return Collections.max(counts.entrySet(), new Comparator<Map.Entry<String, Integer>>() { @Override public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { return o1.getValue().compareTo(o2.getValue()); } }).getKey(); }
public static VirtualFile getContainerFile(VirtualFile fileContainer) { if (fileContainer.getFileType() == ARCHIVE) { return requireNonNull(JarFileSystem.getInstance().getLocalVirtualFileFor(fileContainer)); } else { return fileContainer; } }
private static String removeJarSeparator( String path ) { if( path.endsWith( JarFileSystem.JAR_SEPARATOR ) ) { path = path.substring( 0, path.length() - JarFileSystem.JAR_SEPARATOR.length() ); } return path; }
IDirectory getIDirectory( String pathString ) { VirtualFile file = LocalFileSystemImpl.getInstance().findFileByPath( pathString ); if( file != null && pathString.endsWith( ".jar" ) ) { file = JarFileSystem.getInstance().getJarRootForLocalFile( file ); if( file == null ) { throw new RuntimeException( "Cannot load Jar file for: " + pathString ); } return new IjJarDirectory( this, file ); } return file != null ? new IjDirectory( this, file ) : new IjDirectory( this, pathString ); }
public static VirtualFile getFileFromArchive(String name) { String[] subPath = name.split("/"); try { URL def = ArchiveUtil.class.getClassLoader().getResource("/"); if (def != null) { String path = URLDecoder.decode(def.getPath(), "utf-8").replace("file:", ""); String[] temp = path.split("!"); if (temp.length > 1 && path.toLowerCase().contains(".jar")) { path = temp[0]; } VirtualFile root = JarFileSystem.getInstance().findLocalVirtualFileByPath(path); if (root == null) { root = LocalFileSystem.getInstance().refreshAndFindFileByPath(path); } VirtualFile target = root; for (String s : subPath) { if (target != null) { target = target.findChild(s); } } return target; } } catch (Exception e) { e.printStackTrace(); } return null; }
@Nullable public static String detectJarVersion(@NotNull String detectionClass, @NotNull Module module) { for (OrderEntry library : ModuleRootManager.getInstance(module).getOrderEntries()) { if (library instanceof LibraryOrderEntry) { VirtualFile jar = LibrariesHelper.getInstance().findJarByClass(((LibraryOrderEntry)library).getLibrary(), detectionClass); if (jar != null && jar.getFileSystem() instanceof JarFileSystem) { return JdkUtil.getJarMainAttribute(jar, Attributes.Name.IMPLEMENTATION_VERSION); } } } return null; }
@Override public boolean isClassAvailable(final String[] urls, String fqn) { for (String url : urls) { VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); if (file == null) continue; if (!(file.getFileSystem() instanceof JarFileSystem) && !file.isDirectory()) { file = JarFileSystem.getInstance().getJarRootForLocalFile(file); } if (file == null) continue; if (findInFile(file, new StringTokenizer(fqn, "."))) return true; } return false; }
@NotNull @Override public Set<UsageDescriptor> getProjectUsages(@NotNull final Project project) throws CollectUsagesException { final LibraryJarDescriptor[] descriptors = LibraryJarStatisticsService.getInstance().getTechnologyDescriptors(); final Set<UsageDescriptor> result = new HashSet<UsageDescriptor>(descriptors.length); ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { for (LibraryJarDescriptor descriptor : descriptors) { String className = descriptor.myClass; if (className == null) continue; PsiClass[] psiClasses = JavaPsiFacade.getInstance(project).findClasses(className, ProjectScope.getLibrariesScope(project)); for (PsiClass psiClass : psiClasses) { if (psiClass == null) continue; VirtualFile localFile = JarFileSystem.getInstance().getLocalVirtualFileFor(psiClass.getContainingFile().getVirtualFile()); if (localFile == null) continue; String version = getVersionByJarManifest(localFile); if (version == null) version = getVersionByJarFileName(localFile.getName()); if (version == null) continue; result.add(new UsageDescriptor(descriptor.myName + "_" + version, 1)); } } } }); return result; }
private static void addModuleLibraryRoots(ModuleRootManager moduleRootManager, List<VirtualFile> roots) { final VirtualFile[] files = moduleRootManager.orderEntries().withoutModuleSourceEntries().withoutDepModules().classes().getRoots(); for (final VirtualFile file : files) { if (file.getFileSystem() instanceof JarFileSystem && file.getParent() != null) { // skip entries inside jars continue; } roots.add(file); } }
@NotNull public static VirtualFile getJarFile(String name) { VirtualFile file = getVirtualFile(getDataFile(name)); assertNotNull(file); VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(file); assertNotNull(jarFile); return jarFile; }
@Nullable protected static VirtualFile getJarByPsiFile(PsiFile psiFile) { VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null) return null; VirtualFile jar = JarFileSystem.getInstance().getVirtualFileForJar(psiFile.getVirtualFile()); if (jar == null || !jar.getName().endsWith(".jar")) return null; return jar; }
protected VirtualFile getJarFromLibDir(final String name) { final VirtualFile file = getVirtualFile(PathManager.findFileInLibDirectory(name)); assertNotNull(name + " not found", file); final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(file); assertNotNull(name + " is not jar", jarFile); return jarFile; }