Search in sources :

Example 1 with JSLibraryManager

use of com.intellij.lang.javascript.library.JSLibraryManager in project intellij-plugins by JetBrains.

the class JstdResolveTest method addJstdLibrary.

private static void addJstdLibrary(@NotNull final Project project, @NotNull final Collection<VirtualFile> libSourceFiles) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        JSLibraryManager jsLibraryManager = ServiceManager.getService(project, JSLibraryManager.class);
        ScriptingLibraryModel libraryModel = jsLibraryManager.createLibrary(JstdLibraryUtil.LIBRARY_NAME, VfsUtilCore.toVirtualFileArray(libSourceFiles), VirtualFile.EMPTY_ARRAY, ArrayUtil.EMPTY_STRING_ARRAY, ScriptingLibraryModel.LibraryLevel.GLOBAL, false);
        JSLibraryMappings jsLibraryMappings = ServiceManager.getService(project, JSLibraryMappings.class);
        jsLibraryMappings.associate(null, libraryModel.getName());
        jsLibraryManager.commitChanges();
    });
}
Also used : ScriptingLibraryModel(com.intellij.webcore.libraries.ScriptingLibraryModel) JSLibraryManager(com.intellij.lang.javascript.library.JSLibraryManager) JSLibraryMappings(com.intellij.lang.javascript.library.JSLibraryMappings)

Example 2 with JSLibraryManager

use of com.intellij.lang.javascript.library.JSLibraryManager in project intellij-plugins by JetBrains.

the class JstdLibraryUtil method doInit.

private static void doInit(@NotNull final Project project) {
    ApplicationManager.getApplication().runReadAction(() -> {
        JSLibraryManager libraryManager = JSLibraryManager.getInstance(project);
        LibraryTable libraryTable = libraryManager.getLibraryTable(ScriptingLibraryModel.LibraryLevel.GLOBAL);
        libraryTable.addListener(new MyLibraryChangeWatcher());
    });
}
Also used : JSLibraryManager(com.intellij.lang.javascript.library.JSLibraryManager) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable)

Example 3 with JSLibraryManager

use of com.intellij.lang.javascript.library.JSLibraryManager 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

JSLibraryManager (com.intellij.lang.javascript.library.JSLibraryManager)3 ScriptingLibraryModel (com.intellij.webcore.libraries.ScriptingLibraryModel)2 JSLibraryMappings (com.intellij.lang.javascript.library.JSLibraryMappings)1 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)1 Library (com.intellij.openapi.roots.libraries.Library)1 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1