Search in sources :

Example 6 with ScriptingLibraryModel

use of com.intellij.webcore.libraries.ScriptingLibraryModel in project intellij-plugins by JetBrains.

the class JstdLibraryUtil method doesCorrectJstdLibExist.

private static boolean doesCorrectJstdLibExist(@NotNull final Project project) {
    Boolean correctJstdLibExists = JSTD_LIBRARY_EXISTS;
    if (correctJstdLibExists == null) {
        correctJstdLibExists = ReadAction.compute(() -> {
            VirtualFile libVirtualFile = VfsUtil.findFileByURL(JstdDefaultAssertionFrameworkSrcMarker.class.getResource("TestCase.js"));
            if (libVirtualFile == null) {
                return false;
            }
            JSLibraryManager libraryManager = JSLibraryManager.getInstance(project);
            for (ScriptingLibraryModel libraryModel : libraryManager.getAllLibraries()) {
                if (libraryModel == null) {
                    continue;
                }
                String libraryName = libraryModel.getName();
                if (libraryName != null && libraryName.startsWith(LIBRARY_NAME)) {
                    Library library = libraryModel.getOriginalLibrary();
                    if (library instanceof LibraryEx) {
                        LibraryEx libraryEx = (LibraryEx) library;
                        if (libraryEx.isDisposed()) {
                            continue;
                        }
                    }
                    if (libraryModel.containsFile(libVirtualFile)) {
                        return true;
                    }
                }
            }
            return false;
        });
        JSTD_LIBRARY_EXISTS = correctJstdLibExists;
    }
    return correctJstdLibExists;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ScriptingLibraryModel(com.intellij.webcore.libraries.ScriptingLibraryModel) JSLibraryManager(com.intellij.lang.javascript.library.JSLibraryManager) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

ScriptingLibraryModel (com.intellij.webcore.libraries.ScriptingLibraryModel)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 JSLibraryManager (com.intellij.lang.javascript.library.JSLibraryManager)2 NotNull (org.jetbrains.annotations.NotNull)2 JSLibraryMappings (com.intellij.lang.javascript.library.JSLibraryMappings)1 Module (com.intellij.openapi.module.Module)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)1 Library (com.intellij.openapi.roots.libraries.Library)1 ScriptingLibraryManager (com.intellij.webcore.libraries.ScriptingLibraryManager)1 ScriptingLibraryMappings (com.intellij.webcore.libraries.ScriptingLibraryMappings)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Nullable (org.jetbrains.annotations.Nullable)1