Search in sources :

Example 1 with VirtualFileSystem

use of com.intellij.openapi.vfs.VirtualFileSystem in project kotlin by JetBrains.

the class LibrarySourcesConfig method checkLibFilesAndReportErrors.

private boolean checkLibFilesAndReportErrors(@NotNull JsConfig.Reporter report, @Nullable Function1<VirtualFile, Unit> action) {
    List<String> libraries = getLibraries();
    if (libraries.isEmpty()) {
        return false;
    }
    VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
    VirtualFileSystem jarFileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.JAR_PROTOCOL);
    Set<String> modules = new HashSet<String>();
    for (String path : libraries) {
        VirtualFile file;
        File filePath = new File(path);
        if (!filePath.exists()) {
            report.error("Path '" + path + "' does not exist");
            return true;
        }
        if (path.endsWith(".jar") || path.endsWith(".zip")) {
            file = jarFileSystem.findFileByPath(path + URLUtil.JAR_SEPARATOR);
        } else {
            file = fileSystem.findFileByPath(path);
        }
        if (file == null) {
            report.error("File '" + path + "' does not exist or could not be read");
            return true;
        }
        List<KotlinJavascriptMetadata> metadataList = KotlinJavascriptMetadataUtils.loadMetadata(filePath);
        if (metadataList.isEmpty()) {
            report.warning("'" + path + "' is not a valid Kotlin Javascript library");
            continue;
        }
        for (KotlinJavascriptMetadata metadata : metadataList) {
            if (!metadata.getVersion().isCompatible()) {
                report.error("File '" + path + "' was compiled with an incompatible version of Kotlin. " + "The binary version of its metadata is " + metadata.getVersion() + ", expected version is " + JsMetadataVersion.INSTANCE);
                return true;
            }
            if (!modules.add(metadata.getModuleName())) {
                report.warning("Module \"" + metadata.getModuleName() + "\" is defined in more, than one file");
            }
        }
        if (action != null) {
            action.invoke(file);
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) KotlinJavascriptMetadata(org.jetbrains.kotlin.utils.KotlinJavascriptMetadata) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with VirtualFileSystem

use of com.intellij.openapi.vfs.VirtualFileSystem in project kotlin by JetBrains.

the class BasicTest method createJetFileList.

private static List<KtFile> createJetFileList(@NotNull Project project, @NotNull List<String> list, @Nullable String root) {
    List<KtFile> libFiles = Lists.newArrayList();
    PsiManager psiManager = PsiManager.getInstance(project);
    VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
    VirtualFile rootFile = root == null ? null : fileSystem.findFileByPath(root);
    for (String libFileName : list) {
        VirtualFile virtualFile = rootFile == null ? fileSystem.findFileByPath(libFileName) : rootFile.findFileByRelativePath(libFileName);
        //TODO logging?
        assert virtualFile != null : "virtual file is missing, most likely the file doesn't exist: " + libFileName;
        PsiFile psiFile = psiManager.findFile(virtualFile);
        libFiles.add((KtFile) psiFile);
    }
    return libFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) PsiManager(com.intellij.psi.PsiManager) KtFile(org.jetbrains.kotlin.psi.KtFile) PsiFile(com.intellij.psi.PsiFile)

Example 3 with VirtualFileSystem

use of com.intellij.openapi.vfs.VirtualFileSystem in project intellij-elixir by KronicDeth.

the class ParsingTestCase method setProjectSdkFromSdkHome.

private void setProjectSdkFromSdkHome(@NotNull String sdkHome) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
    MessageBus messageBus = messageBus();
    registerProjectFileIndex(messageBus);
    ProjectRootManager projectRootManager = registerProjectRootManager();
    assertTrue(pathIsValidSdkHome(sdkHome));
    registerExtensionPoint(OrderRootType.EP_NAME, OrderRootType.class);
    registerExtension(OrderRootType.EP_NAME, new JavadocOrderRootType());
    getApplication().addComponent(VirtualFileManager.class, new VirtualFileManagerImpl(new VirtualFileSystem[] { new MockLocalFileSystem() }, messageBus));
    ProjectJdkTable projectJdkTable = new ProjectJdkTableImpl();
    registerApplicationService(ProjectJdkTable.class, projectJdkTable);
    registerExtensionPoint(com.intellij.openapi.projectRoots.SdkType.EP_NAME, com.intellij.openapi.projectRoots.SdkType.class);
    registerExtension(com.intellij.openapi.projectRoots.SdkType.EP_NAME, new ElixirSdkType());
    Sdk sdk = ElixirSdkType.createMockSdk(sdkHome, elixirSdkRelease());
    projectJdkTable.addJdk(sdk);
    ExtensionsArea area = Extensions.getArea(myProject);
    registerExtensionPoint(area, ProjectExtension.EP_NAME, ProjectExtension.class);
    registerExtensionPoint(FilePropertyPusher.EP_NAME, FilePropertyPusher.class);
    myProject.addComponent(PushedFilePropertiesUpdater.class, new PushedFilePropertiesUpdaterImpl(myProject));
    projectRootManager.setProjectSdk(sdk);
}
Also used : MockLocalFileSystem(com.intellij.mock.MockLocalFileSystem) ProjectJdkTableImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkTableImpl) ExtensionsArea(com.intellij.openapi.extensions.ExtensionsArea) MessageBus(com.intellij.util.messages.MessageBus) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) VirtualFileManagerImpl(com.intellij.openapi.vfs.impl.VirtualFileManagerImpl) Sdk(com.intellij.openapi.projectRoots.Sdk) ElixirSdkType(org.elixir_lang.sdk.ElixirSdkType)

Example 4 with VirtualFileSystem

use of com.intellij.openapi.vfs.VirtualFileSystem in project intellij-plugins by JetBrains.

the class FlexDocumentationProvider method findUrlForVirtualFile.

@NotNull
private static List<String> findUrlForVirtualFile(final Project project, final VirtualFile virtualFile, final 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();
        List<String> httpRoots = PlatformDocumentationUtil.getHttpRoots(correctHttpRoots(javadocPaths), relPath);
        if (httpRoots != null)
            return httpRoots;
    }
    final List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(virtualFile);
    for (OrderEntry orderEntry : orderEntries) {
        final String[] files = JavadocOrderRootType.getUrls(orderEntry);
        final List<String> httpRoot = PlatformDocumentationUtil.getHttpRoots(correctHttpRoots(files), relPath);
        if (httpRoot != null)
            return httpRoot;
    }
    return Collections.emptyList();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with VirtualFileSystem

use of com.intellij.openapi.vfs.VirtualFileSystem 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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Module(com.intellij.openapi.module.Module) SmartList(com.intellij.util.SmartList) Url(com.intellij.util.Url) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

VirtualFileSystem (com.intellij.openapi.vfs.VirtualFileSystem)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)4 Module (com.intellij.openapi.module.Module)2 JarFileSystem (com.intellij.openapi.vfs.JarFileSystem)2 PsiFile (com.intellij.psi.PsiFile)2 KtFile (org.jetbrains.kotlin.psi.KtFile)2 MockLocalFileSystem (com.intellij.mock.MockLocalFileSystem)1 ExtensionsArea (com.intellij.openapi.extensions.ExtensionsArea)1 ProjectJdkTable (com.intellij.openapi.projectRoots.ProjectJdkTable)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 ProjectJdkTableImpl (com.intellij.openapi.projectRoots.impl.ProjectJdkTableImpl)1 Condition (com.intellij.openapi.util.Condition)1 VirtualFileManagerImpl (com.intellij.openapi.vfs.impl.VirtualFileManagerImpl)1 com.intellij.psi (com.intellij.psi)1 PsiManager (com.intellij.psi.PsiManager)1 FileReferenceSet (com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet)1 PsiUtilCore (com.intellij.psi.util.PsiUtilCore)1 ProcessingContext (com.intellij.util.ProcessingContext)1 SmartList (com.intellij.util.SmartList)1