Search in sources :

Example 1 with LibraryEx

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

the class RepositoryLibraryDependencyScopeSuggester method getDefaultDependencyScope.

@Nullable
@Override
public DependencyScope getDefaultDependencyScope(@NotNull Library library) {
    if (!(library instanceof LibraryEx)) {
        return null;
    }
    LibraryEx libraryEx = (LibraryEx) library;
    LibraryProperties libraryProperties = libraryEx.getProperties();
    if (libraryProperties == null || !(libraryProperties instanceof RepositoryLibraryProperties)) {
        return null;
    }
    RepositoryLibraryProperties repositoryLibraryProperties = (RepositoryLibraryProperties) libraryProperties;
    RepositoryLibraryDescription libraryDescription = RepositoryLibraryDescription.findDescription(repositoryLibraryProperties);
    return libraryDescription.getSuggestedScope();
}
Also used : LibraryProperties(com.intellij.openapi.roots.libraries.LibraryProperties) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with LibraryEx

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

the class RepositoryLibrarySupport method createNewLibrary.

private LibraryEx createNewLibrary(@NotNull final Module module, final LibraryTable.ModifiableModel modifiableModel) {
    RepositoryLibraryProperties libraryProperties = new RepositoryLibraryProperties(libraryDescription.getGroupId(), libraryDescription.getArtifactId(), model.getVersion());
    final LibraryEx library = (LibraryEx) modifiableModel.createLibrary(LibraryEditingUtil.suggestNewLibraryName(modifiableModel, RepositoryLibraryType.getInstance().getDescription(libraryProperties)), RepositoryLibraryType.REPOSITORY_LIBRARY_KIND);
    RepositoryLibraryProperties realLibraryProperties = (RepositoryLibraryProperties) library.getProperties();
    realLibraryProperties.setMavenId(libraryProperties.getMavenId());
    ApplicationManager.getApplication().runWriteAction(() -> modifiableModel.commit());
    RepositoryUtils.loadDependencies(module.getProject(), library, model.isDownloadSources(), model.isDownloadJavaDocs(), null);
    return library;
}
Also used : LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx)

Example 3 with LibraryEx

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

the class RepositoryLibrarySynchronizer method runActivity.

@Override
public void runActivity(@NotNull final Project project) {
    StartupManager.getInstance(project).registerPostStartupActivity(new DumbAwareRunnable() {

        @Override
        public void run() {
            ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() {

                @Override
                public void run() {
                    final Collection<Library> libraries = collectLibraries(project, new Predicate<Library>() {

                        @Override
                        public boolean apply(Library library) {
                            if (!(library instanceof LibraryEx)) {
                                return false;
                            }
                            LibraryEx libraryEx = (LibraryEx) library;
                            return libraryEx.getKind() == RepositoryLibraryType.REPOSITORY_LIBRARY_KIND && libraryEx.getProperties() instanceof RepositoryLibraryProperties && isLibraryNeedToBeReloaded(libraryEx, (RepositoryLibraryProperties) libraryEx.getProperties());
                        }
                    });
                    for (Library library : libraries) {
                        final LibraryEx libraryEx = (LibraryEx) library;
                        RepositoryUtils.reloadDependencies(project, libraryEx);
                    }
                }
            }, project.getDisposed());
        }
    });
}
Also used : LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable)

Example 4 with LibraryEx

use of com.intellij.openapi.roots.impl.libraries.LibraryEx in project azure-tools-for-java by Microsoft.

the class SparkLibraryOptionsPanel method calculateSuitableLibraries.

private List<Library> calculateSuitableLibraries() {
    ArrayList suitableLibraries = new ArrayList();
    Library[] libraries = this.librariesContainer.getAllLibraries();
    for (int i = 0; i < libraries.length; ++i) {
        Library library = libraries[i];
        PersistentLibraryKind type = ((LibraryEx) library).getKind();
        if (type != null && type instanceof SparkLibraryKind) {
            suitableLibraries.add(library);
        }
    }
    return suitableLibraries;
}
Also used : PersistentLibraryKind(com.intellij.openapi.roots.libraries.PersistentLibraryKind) ArrayList(java.util.ArrayList) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library)

Example 5 with LibraryEx

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

the class ModuleRootModificationUtil method addModuleLibrary.

public static void addModuleLibrary(@NotNull Module module, @Nullable String libName, @NotNull List<String> classesRoots, @NotNull List<String> sourceRoots, @NotNull List<String> excludedRoots, @NotNull DependencyScope scope, boolean exported) {
    updateModel(module, model -> {
        LibraryEx library = (LibraryEx) model.getModuleLibraryTable().createLibrary(libName);
        LibraryEx.ModifiableModelEx libraryModel = library.getModifiableModel();
        for (String root : classesRoots) {
            libraryModel.addRoot(root, OrderRootType.CLASSES);
        }
        for (String root : sourceRoots) {
            libraryModel.addRoot(root, OrderRootType.SOURCES);
        }
        for (String excluded : excludedRoots) {
            libraryModel.addExcludedRoot(excluded);
        }
        LibraryOrderEntry entry = model.findLibraryOrderEntry(library);
        assert entry != null : library;
        entry.setScope(scope);
        entry.setExported(exported);
        ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(libraryModel::commit));
    });
}
Also used : LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx)

Aggregations

LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)38 Library (com.intellij.openapi.roots.libraries.Library)19 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)8 Nullable (org.jetbrains.annotations.Nullable)8 Module (com.intellij.openapi.module.Module)6 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)6 Project (com.intellij.openapi.project.Project)5 FlexLibraryProperties (com.intellij.lang.javascript.flex.library.FlexLibraryProperties)4 Logger (com.intellij.openapi.diagnostic.Logger)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4 Disposable (com.intellij.openapi.Disposable)3 OrderRootType (com.intellij.openapi.roots.OrderRootType)3 LibraryProperties (com.intellij.openapi.roots.libraries.LibraryProperties)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 List (java.util.List)3 FlexCommonUtils (com.intellij.flex.FlexCommonUtils)2 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)2 OutputType (com.intellij.flex.model.bc.OutputType)2