Search in sources :

Example 16 with JarFileSystem

use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.

the class EPathUtil method collapse2EclipsePath.

static String collapse2EclipsePath(final String url, final ModuleRootModel model) {
    final Project project = model.getModule().getProject();
    final VirtualFile contentRoot = getContentRoot(model);
    VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);
    if (file != null) {
        LOG.assertTrue(file.isValid());
        if (file.getFileSystem() instanceof JarFileSystem) {
            final VirtualFile jarFile = JarFileSystem.getInstance().getVirtualFileForJar(file);
            if (jarFile == null) {
                LOG.error("Url: \'" + url + "\'; file: " + file);
                return ProjectRootManagerImpl.extractLocalPath(url);
            }
            file = jarFile;
        }
        if (contentRoot != null && VfsUtilCore.isAncestor(contentRoot, file, false)) {
            //inside current project
            return VfsUtilCore.getRelativePath(file, contentRoot, '/');
        } else {
            //relative to other project
            final String path = collapse2eclipseRelative2OtherModule(project, file);
            if (path != null) {
                return path;
            }
        }
        //absolute path
        return ProjectRootManagerImpl.extractLocalPath(url);
    } else {
        //try to avoid absolute path for deleted file
        if (contentRoot != null) {
            final String rootUrl = contentRoot.getUrl();
            if (url.startsWith(rootUrl) && url.length() > rootUrl.length()) {
                //without leading /
                return url.substring(rootUrl.length() + 1);
            }
        }
        final VirtualFile projectBaseDir = contentRoot != null ? contentRoot.getParent() : project.getBaseDir();
        assert projectBaseDir != null;
        final String projectUrl = projectBaseDir.getUrl();
        if (url.startsWith(projectUrl)) {
            //leading /
            return url.substring(projectUrl.length());
        }
        final String path = VfsUtilCore.urlToPath(url);
        final String projectPath = projectBaseDir.getPath();
        if (path.startsWith(projectPath)) {
            return ProjectRootManagerImpl.extractLocalPath(path.substring(projectPath.length()));
        }
        return ProjectRootManagerImpl.extractLocalPath(url);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem)

Example 17 with JarFileSystem

use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.

the class EclipseUserLibrariesHelper method writeUserLibrary.

private static void writeUserLibrary(final Library library, final Element libElement) {
    final VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
    for (VirtualFile file : files) {
        Element archElement = new Element("archive");
        if (file.getFileSystem() instanceof JarFileSystem) {
            final VirtualFile localFile = JarFileSystem.getInstance().getVirtualFileForJar(file);
            if (localFile != null) {
                file = localFile;
            }
        }
        archElement.setAttribute("path", file.getPath());
        libElement.addContent(archElement);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Element(org.jdom.Element)

Example 18 with JarFileSystem

use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.

the class FileTreeStructure method getParentElement.

@Nullable
public Object getParentElement(Object element) {
    if (element instanceof FileElement) {
        final FileElement fileElement = (FileElement) element;
        final VirtualFile elementFile = getValidFile(fileElement);
        if (elementFile != null && myRootElement.getFile() != null && myRootElement.getFile().equals(elementFile)) {
            return null;
        }
        final VirtualFile parentElementFile = getValidFile(fileElement.getParent());
        if (elementFile != null && parentElementFile != null) {
            final VirtualFile parentFile = elementFile.getParent();
            if (parentElementFile.equals(parentFile))
                return fileElement.getParent();
        }
        VirtualFile file = fileElement.getFile();
        if (file == null)
            return null;
        VirtualFile parent = file.getParent();
        if (parent != null && parent.getFileSystem() instanceof JarFileSystem && parent.getParent() == null) {
            // parent of jar contents should be local jar file
            String localPath = parent.getPath().substring(0, parent.getPath().length() - JarFileSystem.JAR_SEPARATOR.length());
            parent = LocalFileSystem.getInstance().findFileByPath(localPath);
        }
        if (parent != null && parent.isValid() && parent.equals(myRootElement.getFile())) {
            return myRootElement;
        }
        if (parent == null) {
            return myRootElement;
        }
        return new FileElement(parent, parent.getName());
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) FileElement(com.intellij.openapi.fileChooser.FileElement) RootFileElement(com.intellij.openapi.fileChooser.ex.RootFileElement) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with JarFileSystem

use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.

the class AbstractModuleNode method contains.

@Override
public boolean contains(@NotNull VirtualFile file) {
    Module module = getValue();
    if (module == null || module.isDisposed())
        return false;
    if (file.getFileSystem() instanceof JarFileSystem) {
        VirtualFile local = JarFileSystem.getInstance().getVirtualFileForJar(file);
        if (local == null)
            return false;
        file = local;
    }
    for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) {
        if (VfsUtilCore.isAncestor(root, file, false))
            return true;
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Module(com.intellij.openapi.module.Module)

Example 20 with JarFileSystem

use of com.intellij.openapi.vfs.JarFileSystem in project intellij-community by JetBrains.

the class IdeaJdk method addSources.

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 {
                String homePath = javaSdk.getHomePath();
                if (homePath == null)
                    return;
                final File jdkHome = new File(homePath).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);
                }
            }
        }
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

JarFileSystem (com.intellij.openapi.vfs.JarFileSystem)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 Nullable (org.jetbrains.annotations.Nullable)7 Module (com.intellij.openapi.module.Module)6 Project (com.intellij.openapi.project.Project)5 File (java.io.File)4 NonNls (org.jetbrains.annotations.NonNls)4 NotNull (org.jetbrains.annotations.NotNull)4 ArrayList (java.util.ArrayList)3 FileElement (com.intellij.openapi.fileChooser.FileElement)2 RootFileElement (com.intellij.openapi.fileChooser.ex.RootFileElement)2 VirtualFileSystem (com.intellij.openapi.vfs.VirtualFileSystem)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 ZipFile (java.util.zip.ZipFile)2 ArchiveFileType (com.intellij.ide.highlighter.ArchiveFileType)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 ParamValue (com.intellij.javaee.model.xml.ParamValue)1 Filter (com.intellij.javaee.model.xml.web.Filter)1 WebApp (com.intellij.javaee.model.xml.web.WebApp)1