Search in sources :

Example 1 with ScriptingLibraryModel

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

the class ChooseScopeAndCreateLibraryDialog method createLibraryAndAssociate.

@Nullable
private ErrorMessage createLibraryAndAssociate() {
    String libraryName = myLibraryNameTextField.getText();
    ScriptingLibraryModel libraryModel = myLibraryHelper.getOrCreateJsLibraryModel(libraryName);
    try {
        ScriptingLibraryMappings libraryMappings = ServiceManager.getService(myProject, JSLibraryMappings.class);
        if (myModuleSelector.isAssociateWithProjectView()) {
            if (myModuleSelector.isAssociateWithProjectRequested()) {
                libraryMappings.associateWithProject(libraryModel.getName());
                LOG.info("Library '" + libraryModel.getName() + "' has been successfully associated with the project");
            } else {
                libraryMappings.disassociateWithProject(libraryModel.getName());
            }
        } else {
            for (Module module : myModuleSelector.getSelectedModules()) {
                ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
                VirtualFile[] roots = moduleRootManager.getContentRoots();
                for (VirtualFile root : roots) {
                    libraryMappings.associate(root, libraryModel.getName(), false);
                    LOG.info("Library '" + libraryModel.getName() + "' has been associated with " + root);
                }
            }
        }
        myLibraryHelper.commit();
        return null;
    } catch (Exception ex) {
        return new ErrorMessage("Unable to associate '" + libraryName + "' JavaScript library", ex);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ScriptingLibraryModel(com.intellij.webcore.libraries.ScriptingLibraryModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) ScriptingLibraryMappings(com.intellij.webcore.libraries.ScriptingLibraryMappings) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ScriptingLibraryModel

use of com.intellij.webcore.libraries.ScriptingLibraryModel 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 3 with ScriptingLibraryModel

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

the class JsLibraryHelper method getOrCreateJsLibraryModel.

@NotNull
public ScriptingLibraryModel getOrCreateJsLibraryModel(@NotNull String libraryName) {
    if (myReusableJsLibraryModel != null) {
        return myReusableJsLibraryModel;
    }
    ScriptingLibraryModel libraryModel = myJsLibraryManager.createLibrary(libraryName, VfsUtilCore.toVirtualFileArray(myLibraryFiles), VirtualFile.EMPTY_ARRAY, ArrayUtil.EMPTY_STRING_ARRAY, ScriptingLibraryModel.LibraryLevel.GLOBAL, false);
    LOG.info("JavaScript library '" + libraryModel.getName() + "' has been successfully created.");
    return libraryModel;
}
Also used : ScriptingLibraryModel(com.intellij.webcore.libraries.ScriptingLibraryModel) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ScriptingLibraryModel

use of com.intellij.webcore.libraries.ScriptingLibraryModel in project oxy-template-support-plugin by mutant-industries.

the class InnerJsPredefinedLibrary method getPredefinedLibraries.

@NotNull
@Override
public ScriptingLibraryModel[] getPredefinedLibraries(@NotNull Project project) {
    Set<VirtualFile> virtualFiles = getVirtualFiles();
    ScriptingLibraryModel scriptingLibraryModel = ScriptingLibraryModel.createPredefinedLibrary(LIBRARY_NAME, virtualFiles.toArray(new VirtualFile[virtualFiles.size()]), true);
    return new ScriptingLibraryModel[] { scriptingLibraryModel };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ScriptingLibraryModel(com.intellij.webcore.libraries.ScriptingLibraryModel) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ScriptingLibraryModel

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

the class JstdResolveTest method removeLibrary.

private static void removeLibrary(@NotNull final Project project) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        ScriptingLibraryManager libraryManager = ServiceManager.getService(project, JSLibraryManager.class);
        ScriptingLibraryModel model = libraryManager.getLibraryByName(JstdLibraryUtil.LIBRARY_NAME);
        assert model != null;
        libraryManager.removeLibrary(model);
        libraryManager.commitChanges();
    });
}
Also used : ScriptingLibraryModel(com.intellij.webcore.libraries.ScriptingLibraryModel) ScriptingLibraryManager(com.intellij.webcore.libraries.ScriptingLibraryManager)

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