Search in sources :

Example 31 with LibraryTable

use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.

the class SimpleClasspathElementFactory method createElements.

public static List<SimpleClasspathElement> createElements(@Nullable Project project, @NotNull Element element) {
    final String name = element.getAttributeValue(GlobalLibraryReferenceElement.NAME_ATTRIBUTE);
    final String level = element.getAttributeValue(GlobalLibraryReferenceElement.LEVEL_ATTRIBUTE);
    final String url = element.getChildText(SingleRootClasspathElement.URL_ELEMENT);
    if (!StringUtil.isEmpty(url)) {
        return Collections.<SimpleClasspathElement>singletonList(new SingleRootClasspathElement(url));
    }
    if (name == null || level == null) {
        return Collections.emptyList();
    }
    if (LibraryTablesRegistrar.APPLICATION_LEVEL.equals(level)) {
        return Collections.<SimpleClasspathElement>singletonList(new GlobalLibraryReferenceElement(name));
    }
    //this is needed only for backward compatibility with version before 8
    if (project != null) {
        final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(level, project);
        if (libraryTable != null) {
            final Library library = libraryTable.getLibraryByName(name);
            if (library != null) {
                return createElements(library);
            }
        }
    }
    return Collections.emptyList();
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library)

Example 32 with LibraryTable

use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.

the class LibraryTest method testNativePathSerialization.

public void testNativePathSerialization() {
    LibraryTable table = getLibraryTable();
    Library library = new WriteAction<Library>() {

        @Override
        protected void run(@NotNull Result<Library> result) throws Throwable {
            Library res = table.createLibrary("native");
            result.setResult(res);
        }
    }.execute().throwException().getResultObject();
    Library.ModifiableModel model = library.getModifiableModel();
    model.addRoot("file://native-lib-root", NativeLibraryOrderRootType.getInstance());
    commit(model);
    Element element = serialize(library);
    PlatformTestUtil.assertElementEquals("<root><library name=\"native\"><CLASSES /><JAVADOC />" + "<NATIVE><root url=\"file://native-lib-root\" /></NATIVE>" + "<SOURCES /></library></root>", element);
}
Also used : ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Element(org.jdom.Element) Library(com.intellij.openapi.roots.libraries.Library)

Example 33 with LibraryTable

use of com.intellij.openapi.roots.libraries.LibraryTable 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 34 with LibraryTable

use of com.intellij.openapi.roots.libraries.LibraryTable in project android by JetBrains.

the class ArtifactsByConfigurationModuleSetupStepTest method testDoSetUpModuleWithCompiledJar.

public void testDoSetUpModuleWithCompiledJar() throws IOException {
    Module module = getModule();
    String moduleName = module.getName();
    File buildFolderPath = createTempDir("build");
    File jarFilePath = new File(buildFolderPath, moduleName + ".jar");
    createIfDoesntExist(jarFilePath);
    Project project = getProject();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
    Map<String, Set<File>> artifactsByConfiguration = new HashMap<>();
    artifactsByConfiguration.put("default", Collections.singleton(jarFilePath));
    JavaModuleModel model = new JavaModuleModel(moduleName, Collections.emptyList(), Collections.emptyList(), artifactsByConfiguration, null, buildFolderPath, null, true, false);
    mySetupStep.doSetUpModule(module, modelsProvider, model, null, null);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
    Library[] libraries = libraryTable.getLibraries();
    assertThat(libraries).isEmpty();
    assertAbout(libraryDependencies()).that(module).isEmpty();
    // No libraries were created, nothing should be marked as "used".
    verify(myLibraryRegistry, never()).markAsUsed(any(), any());
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) Project(com.intellij.openapi.project.Project) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) File(java.io.File)

Example 35 with LibraryTable

use of com.intellij.openapi.roots.libraries.LibraryTable in project android by JetBrains.

the class ArtifactsByConfigurationModuleSetupStepTest method assertJarIsLibrary.

private void assertJarIsLibrary(@NotNull File jarFilePath) {
    LibraryTable libraryTable = ProjectLibraryTable.getInstance(getProject());
    Library[] libraries = libraryTable.getLibraries();
    assertThat(libraries).hasLength(1);
    Library library = libraries[0];
    String libraryName = library.getName();
    assertNotNull(libraryName);
    assertEquals(createLibraryName(jarFilePath), libraryName);
    String[] urls = library.getUrls(CLASSES);
    assertThat(urls).hasLength(1);
    assertEquals(pathToUrl(jarFilePath.getPath()), urls[0]);
    assertAbout(libraryDependencies()).that(getModule()).contains(libraryName);
}
Also used : ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library)

Aggregations

LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)65 Library (com.intellij.openapi.roots.libraries.Library)44 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)16 Module (com.intellij.openapi.module.Module)10 NotNull (org.jetbrains.annotations.NotNull)7 Project (com.intellij.openapi.project.Project)5 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)5 LibraryTablesRegistrar (com.intellij.openapi.roots.libraries.LibraryTablesRegistrar)4 File (java.io.File)4 Element (org.jdom.Element)4 LibraryImpl (com.intellij.openapi.roots.impl.libraries.LibraryImpl)3 ArrayList (java.util.ArrayList)3 FlexLibraryProperties (com.intellij.lang.javascript.flex.library.FlexLibraryProperties)2 Application (com.intellij.openapi.application.Application)2 Result (com.intellij.openapi.application.Result)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 OrderEntry (com.intellij.openapi.roots.OrderEntry)2 ModuleLibraryTable (com.intellij.openapi.roots.impl.ModuleLibraryTable)2