use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class PathEditor method isJarFile.
private static boolean isJarFile(final VirtualFile file) {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
VirtualFile tempFile = file;
if ((file.getFileSystem() instanceof JarFileSystem) && file.getParent() == null) {
//[myakovlev] It was bug - directories with *.jar extensions was saved as files of JarFileSystem.
// so we can not just return true, we should filter such directories.
String path = file.getPath().substring(0, file.getPath().length() - JarFileSystem.JAR_SEPARATOR.length());
tempFile = LocalFileSystem.getInstance().findFileByPath(path);
}
if (tempFile != null && !tempFile.isDirectory()) {
return Boolean.valueOf(tempFile.getFileType().equals(FileTypes.ARCHIVE));
}
return Boolean.FALSE;
}
}).booleanValue();
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class ShowFilePathAction method show.
private static void show(@NotNull VirtualFile file, @NotNull Consumer<ListPopup> action) {
if (!isSupported())
return;
List<VirtualFile> files = new ArrayList<>();
List<String> fileUrls = new ArrayList<>();
VirtualFile eachParent = file;
while (eachParent != null) {
int index = files.size();
files.add(index, eachParent);
fileUrls.add(index, getPresentableUrl(eachParent));
if (eachParent.getParent() == null && eachParent.getFileSystem() instanceof JarFileSystem) {
eachParent = JarFileSystem.getInstance().getVirtualFileForJar(eachParent);
if (eachParent == null)
break;
}
eachParent = eachParent.getParent();
}
ApplicationManager.getApplication().executeOnPooledThread(() -> {
List<Icon> icons = new ArrayList<>();
for (String url : fileUrls) {
File ioFile = new File(url);
icons.add(ioFile.exists() ? FileSystemView.getFileSystemView().getSystemIcon(ioFile) : EmptyIcon.ICON_16);
}
ApplicationManager.getApplication().invokeLater(() -> action.consume(createPopup(files, icons)));
});
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class FileTreeStructure method getChildElements.
public Object[] getChildElements(Object nodeElement) {
if (!(nodeElement instanceof FileElement)) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
FileElement element = (FileElement) nodeElement;
VirtualFile file = element.getFile();
if (file == null || !file.isValid()) {
if (element == myRootElement) {
return myRootElement.getChildren();
}
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
VirtualFile[] children = null;
if (element.isArchive() && myChooserDescriptor.isChooseJarContents()) {
String path = file.getPath();
if (!(file.getFileSystem() instanceof JarFileSystem)) {
file = JarFileSystem.getInstance().findFileByPath(path + JarFileSystem.JAR_SEPARATOR);
}
if (file != null) {
children = file.getChildren();
}
} else {
children = file.getChildren();
}
if (children == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
Set<FileElement> childrenSet = new HashSet<>();
for (VirtualFile child : children) {
if (myChooserDescriptor.isFileVisible(child, myShowHidden)) {
final FileElement childElement = new FileElement(child, child.getName());
childElement.setParent(element);
childrenSet.add(childElement);
}
}
return ArrayUtil.toObjectArray(childrenSet);
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class IdeaSpecificSettings method appendModuleRelatedRoot.
public static void appendModuleRelatedRoot(Element element, String classesUrl, final String rootName, ModuleRootModel model) {
VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(classesUrl);
if (file == null) {
return;
}
final Project project = model.getModule().getProject();
if (file.getFileSystem() instanceof JarFileSystem) {
file = JarFileSystem.getInstance().getVirtualFileForJar(file);
assert file != null;
}
final Module module = ModuleUtilCore.findModuleForFile(file, project);
if (module != null) {
appendRelatedToModule(element, classesUrl, rootName, file, module);
} else if (ProjectRootManager.getInstance(project).getFileIndex().isExcluded(file)) {
for (Module aModule : ModuleManager.getInstance(project).getModules()) {
if (appendRelatedToModule(element, classesUrl, rootName, file, aModule)) {
return;
}
}
}
}
use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.
the class IdeaJdk method addSources.
private static void addSources(File file, SdkModificator sdkModificator) {
final File src = new File(new File(file, LIB_DIR_NAME), SRC_DIR_NAME);
if (!src.exists())
return;
File[] srcs = src.listFiles(pathname -> {
@NonNls final String path = pathname.getPath();
if (path.contains("generics"))
return false;
return path.endsWith(".jar") || path.endsWith(".zip");
});
for (int i = 0; srcs != null && i < srcs.length; i++) {
File jarFile = srcs[i];
if (jarFile.exists()) {
JarFileSystem jarFileSystem = JarFileSystem.getInstance();
String path = jarFile.getAbsolutePath().replace(File.separatorChar, '/') + JarFileSystem.JAR_SEPARATOR;
jarFileSystem.setNoCopyJarForPath(path);
VirtualFile vFile = jarFileSystem.findFileByPath(path);
sdkModificator.addRoot(vFile, OrderRootType.SOURCES);
}
}
}
Aggregations