Example usage for com.intellij.openapi.vfs JarFileSystem getInstance

List of usage examples for com.intellij.openapi.vfs JarFileSystem getInstance

Introduction

In this page you can find the example usage for com.intellij.openapi.vfs JarFileSystem getInstance.

Prototype

public static JarFileSystem getInstance() 

Source Link

Usage

From source file:com.android.tools.idea.actions.annotations.InferSupportAnnotationsTest.java

License:Apache License

private void doTest(boolean annotateLocalVariables, String summary, VirtualFile... files) throws Exception {
    if (!InferSupportAnnotationsAction.ENABLED) {
        System.out.println("Ignoring " + this.getClass().getSimpleName() + ": Functionality disabled");
        return;//from w  w w . j ava2 s.  c  o m
    }

    String annotationsJar = getTestDataPath() + "/infer/data.jar";
    VirtualFile aLib = LocalFileSystem.getInstance().findFileByPath(annotationsJar);
    if (aLib != null) {
        final VirtualFile file = JarFileSystem.getInstance().getJarRootForLocalFile(aLib);
        if (file != null) {
            ModuleRootModificationUtil.addModuleLibrary(myModule, file.getUrl());
        }
    }

    InferSupportAnnotations inference = new InferSupportAnnotations(annotateLocalVariables, getProject());
    AnalysisScope scope;
    if (files.length > 0) {
        configureByFiles(null, files);
        scope = new AnalysisScope(getProject(), Arrays.asList(files));

        for (int i = 0; i < InferSupportAnnotationsAction.MAX_PASSES; i++) {
            for (VirtualFile virtualFile : files) {
                PsiFile psiFile = getPsiManager().findFile(virtualFile);
                assertNotNull(psiFile);
                inference.collect(psiFile);
            }
        }
    } else {
        configureByFile(INFER_PATH + "before" + getTestName(false) + ".java");
        inference.collect(getFile());
        scope = new AnalysisScope(getFile());
    }

    if (summary != null) {
        List<UsageInfo> infos = Lists.newArrayList();
        inference.collect(infos, scope);
        String s = InferSupportAnnotations.generateReport(infos.toArray(UsageInfo.EMPTY_ARRAY));
        s = StringUtil.trimStart(s,
                "INFER SUPPORT ANNOTATIONS REPORT\n" + "================================\n" + "\n");
        assertEquals(summary, s.trim());
    }

    if (files.length == 0) {
        inference.apply(getProject());
        checkResultByFile(INFER_PATH + "after" + getTestName(false) + ".java");
    }
}

From source file:com.android.tools.idea.actions.CreateLibraryFromFilesAction.java

License:Apache License

@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();
    }//from   w  w w .j ava 2 s  . c  om

    List<VirtualFile> roots = new ArrayList<>();
    for (VirtualFile file : files) {
        VirtualFile root = JarFileSystem.getInstance().getJarRootForLocalFile(file);
        if (root != null) {
            roots.add(root);
        }
    }
    return roots;
}

From source file:com.android.tools.idea.gradle.customizer.DependenciesModuleCustomizer.java

License:Apache License

private static void registerPaths(@NotNull OrderRootType type, @NotNull Map<File, Library> libraries) {
    for (Map.Entry<File, Library> entry : libraries.entrySet()) {
        Library library = entry.getValue();
        Library.ModifiableModel model = library.getModifiableModel();
        try {/*from ww w .j  a v a  2 s. c  o m*/
            File file = entry.getKey();
            VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
            if (virtualFile == null) {
                String msg = String.format("Unable to find file at path '%1$s', library '%2$s'", file.getPath(),
                        library.getName());
                LOG.warn(msg);
                continue;
            }
            if (virtualFile.isDirectory()) {
                model.addRoot(virtualFile, type);
                continue;
            }
            VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile);
            if (jarRoot == null) {
                String msg = String.format("Unable to parse contents of jar file '%1$s', library '%2$s'",
                        file.getPath(), library.getName());
                LOG.warn(msg);
                continue;
            }
            model.addRoot(jarRoot, type);
        } finally {
            model.commit();
        }
    }
}

From source file:com.android.tools.idea.sdk.AndroidSdks.java

License:Apache License

@Nullable
private static VirtualFile findFileInJarFileSystem(@NotNull File path) {
    String canonicalPath = toCanonicalPath(path.getPath());
    return JarFileSystem.getInstance().findFileByPath(canonicalPath + JAR_SEPARATOR);
}

From source file:com.cfsoft.ofbiz.facet.ui.OfbizVersionDetector.java

License:Apache License

@Nullable
private static JarFile getStrutsJar(final Module module) throws IOException {
    final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
    final JavaPsiFacade psiManager = JavaPsiFacade.getInstance(module.getProject());

    final VirtualFile virtualFile = getStrutsClass(scope, psiManager);
    if (virtualFile == null || !(virtualFile.getFileSystem() instanceof JarFileSystem)) {
        return null;
    }//from  w w w  . j  av  a 2  s . c om

    return JarFileSystem.getInstance().getJarFile(virtualFile);
}

From source file:com.eightbitmage.moonscript.lang.documentor.KahluaPluginDocumentationProvider.java

License:Apache License

@LuaMethod(name = "getBaseJarUrl", global = true)
public String getBaseJarUrl() {
    String url = VfsUtil.pathToUrl(PathUtil.getJarPathForClass(MoonPsiFile.class));
    VirtualFile sdkFile = VirtualFileManager.getInstance().findFileByUrl(url);
    if (sdkFile != null) {
        VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(sdkFile);
        if (jarFile != null) {
            return jarFile.getUrl();
        } else {/*from  ww  w. j  a va 2 s . com*/
            return sdkFile.getUrl();
        }
    }

    return null;
}

From source file:com.eightbitmage.moonscript.sdk.StdLibrary.java

License:Apache License

public static VirtualFile getStdFileLocation() {
    VirtualFile dir = MoonFileUtil.getPluginVirtualDirectory();
    if (dir != null) {
        dir = dir.findChild(STDLIBRARY);

        if (dir != null)
            return dir;
    }//from  w w w  . j  a  va  2 s  . co m

    String url = VfsUtil.pathToUrl(PathUtil.getJarPathForClass(MoonPsiFile.class));
    VirtualFile sdkFile = VirtualFileManager.getInstance().findFileByUrl(url);
    if (sdkFile != null) {
        VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(sdkFile);
        if (jarFile != null) {
            return jarFile.findChild(STDLIBRARY);
        } else if (sdkFile instanceof VirtualDirectoryImpl) {
            return sdkFile.findChild(STDLIBRARY);
        }
    }

    return null;
}

From source file:com.github.intelliguard.util.ObfuscatorUtils.java

License:Apache License

@Nullable
private static VirtualFile findJarFile(@NotNull final String jarPath) {
    return JarFileSystem.getInstance()
            .refreshAndFindFileByPath(FileUtil.toSystemIndependentName(jarPath) + JarFileSystem.JAR_SEPARATOR);
}

From source file:com.google.idea.blaze.android.sync.model.idea.BlazeClassJarProvider.java

License:Open Source License

@Nullable
private static VirtualFile findClassInJar(final VirtualFile classJar, String classNamePath) {
    VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(classJar);
    if (jarRoot == null) {
        return null;
    }//from   w  w w. j  av  a  2 s. c o m
    return jarRoot.findFileByRelativePath(classNamePath);
}

From source file:com.intellij.coldFusion.model.psi.CfmlJavaLoaderClassType.java

License:Apache License

public CfmlJavaLoaderClassType(PsiComment comment, Project project) {
    super(PsiAnnotation.EMPTY_ARRAY);
    final String text = comment.getText();

    myProject = project;//from www  . j a v a 2 s  . c o m
    Matcher javaLoaderMatcher = CfmlFile.LOADER_DECL_PATTERN_TEMP.matcher(text);
    mySearchScope = GlobalSearchScope.allScope(project);//EMPTY_SCOPE;

    if (javaLoaderMatcher.matches()) {
        Collection<String> collection = CfmlPsiUtil.findBetween(text, "loadPaths=\"", "\"");
        if (collection != null) {
            for (String str : collection) {
                VirtualFile file = JarFileSystem.getInstance()
                        .findFileByPath(str + JarFileSystem.JAR_SEPARATOR);
                if (file != null) {
                    mySearchScope = mySearchScope.uniteWith(new JarFileScope(file));
                }
            }
        }
    }
}