Search in sources :

Example 1 with LibraryKind

use of com.intellij.openapi.roots.libraries.LibraryKind in project kotlin by JetBrains.

the class FrameworksCompatibilityUtils method suggestRemoveIncompatibleFramework.

public static void suggestRemoveIncompatibleFramework(@NotNull ModifiableRootModel rootModel, @NotNull Set<? extends LibraryKind> frameworkLibraryKinds, @NotNull FrameworkType frameworkType) {
    List<OrderEntry> existingEntries = new ArrayList<OrderEntry>();
    for (OrderEntry entry : rootModel.getOrderEntries()) {
        if (!(entry instanceof LibraryOrderEntry))
            continue;
        Library library = ((LibraryOrderEntry) entry).getLibrary();
        if (library == null)
            continue;
        for (LibraryKind kind : frameworkLibraryKinds) {
            if (LibraryPresentationManager.getInstance().isLibraryOfKind(Arrays.asList(library.getFiles(OrderRootType.CLASSES)), kind)) {
                existingEntries.add(entry);
            }
        }
    }
    removeWithConfirm(rootModel, existingEntries, String.format("Current module is already configured with '%s' framework.\nDo you want to remove it?", frameworkType.getPresentableName()), "Framework Conflict");
}
Also used : LibraryKind(com.intellij.openapi.roots.libraries.LibraryKind) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) ArrayList(java.util.ArrayList) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library)

Example 2 with LibraryKind

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

the class LibraryUsageCollector method getProjectUsages.

@NotNull
@Override
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
    final Set<LibraryKind> usedKinds = new HashSet<>();
    final Processor<Library> processor = library -> {
        usedKinds.addAll(LibraryPresentationManagerImpl.getLibraryKinds(library, null));
        return true;
    };
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        ModuleRootManager.getInstance(module).orderEntries().librariesOnly().forEachLibrary(processor);
    }
    final HashSet<UsageDescriptor> usageDescriptors = new HashSet<>();
    for (LibraryKind kind : usedKinds) {
        usageDescriptors.add(new UsageDescriptor(kind.getKindId(), 1));
    }
    return usageDescriptors;
}
Also used : GroupDescriptor(com.intellij.internal.statistic.beans.GroupDescriptor) ModuleManager(com.intellij.openapi.module.ModuleManager) UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) AbstractApplicationUsagesCollector(com.intellij.internal.statistic.AbstractApplicationUsagesCollector) NonNls(org.jetbrains.annotations.NonNls) Set(java.util.Set) LibraryKind(com.intellij.openapi.roots.libraries.LibraryKind) HashSet(java.util.HashSet) Library(com.intellij.openapi.roots.libraries.Library) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Processor(com.intellij.util.Processor) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) LibraryKind(com.intellij.openapi.roots.libraries.LibraryKind) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LibraryKind

use of com.intellij.openapi.roots.libraries.LibraryKind in project intellij-plugins by JetBrains.

the class Flexmojos3Configurator method handleDependencies.

private TargetPlatform handleDependencies(final ModifiableFlexBuildConfiguration bc) {
    bc.getDependencies().getModifiableEntries().clear();
    boolean playerglobal = false;
    boolean airglobal = false;
    boolean mobilecomponents = false;
    final ModifiableRootModel rootModel = myModelsProvider.getModifiableRootModel(myModule);
    for (OrderEntry entry : rootModel.getOrderEntries()) {
        final DependencyScope scope = entry instanceof ExportableOrderEntry ? ((ExportableOrderEntry) entry).getScope() : DependencyScope.COMPILE;
        final boolean isExported = entry instanceof ExportableOrderEntry && ((ExportableOrderEntry) entry).isExported();
        if (entry instanceof ModuleOrderEntry) {
            rootModel.removeOrderEntry(entry);
            final String dependencyModuleName = ((ModuleOrderEntry) entry).getModuleName();
            final MavenProject dependencyMavenProject = findMavenProjectByModuleName(dependencyModuleName);
            if (dependencyMavenProject == null) {
                MavenLog.LOG.warn("Maven project not found, module dependency skipped: " + myModule.getName() + " on " + dependencyModuleName);
                continue;
            }
            if (!ArrayUtil.contains(dependencyMavenProject.getPackaging(), FlexmojosImporter.SUPPORTED_PACKAGINGS)) {
                MavenLog.LOG.info("Unexpected packaging (" + dependencyMavenProject.getPackaging() + "), module dependency skipped: " + myModule.getName() + " on " + dependencyModuleName);
                continue;
            }
            final ModifiableDependencyEntry existingEntry = ContainerUtil.find(bc.getDependencies().getModifiableEntries(), entry1 -> (entry1 instanceof BuildConfigurationEntry) && ((BuildConfigurationEntry) entry1).getModuleName().equals(dependencyModuleName) && ((BuildConfigurationEntry) entry1).getBcName().equals(dependencyModuleName));
            final LinkageType linkageType = "swc".equals(dependencyMavenProject.getPackaging()) ? FlexUtils.convertLinkageType(scope, isExported) : LinkageType.LoadInRuntime;
            if (existingEntry != null) {
                if (existingEntry.getDependencyType().getLinkageType() == LinkageType.Test) {
                    existingEntry.getDependencyType().setLinkageType(linkageType);
                }
                continue;
            }
            final ModifiableBuildConfigurationEntry bcEntry = myFlexEditor.createBcEntry(bc.getDependencies(), dependencyModuleName, dependencyModuleName);
            bcEntry.getDependencyType().setLinkageType(linkageType);
            bc.getDependencies().getModifiableEntries().add(0, bcEntry);
            continue;
        }
        if (entry instanceof JdkOrderEntry) {
            rootModel.removeOrderEntry(entry);
        }
        if (!(entry instanceof LibraryOrderEntry))
            continue;
        rootModel.removeOrderEntry(entry);
        if (!LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry) entry).getLibraryLevel()))
            continue;
        final Library library = ((LibraryOrderEntry) entry).getLibrary();
        if (library == null || !MavenRootModelAdapter.isMavenLibrary(library))
            continue;
        final String libraryName = library.getName();
        if (libraryName.contains(":rb.swc:") || libraryName.contains(":resource-bundle:")) {
            // fix rb.swc placeholders to real SWCs according to used locales
            final Library.ModifiableModel libraryModifiableModel = myModelsProvider.getModifiableLibraryModel(library);
            for (final String rbSwcPlaceholdersUrl : findRbSwcPlaceholderUrls(libraryModifiableModel)) {
                final Collection<String> rootsToAdd = getRbSwcUrlsForCompiledLocales(rbSwcPlaceholdersUrl);
                libraryModifiableModel.removeRoot(rbSwcPlaceholdersUrl, OrderRootType.CLASSES);
                for (final String rootToAdd : rootsToAdd) {
                    if (!ArrayUtil.contains(rootToAdd, libraryModifiableModel.getUrls(OrderRootType.CLASSES))) {
                        libraryModifiableModel.addRoot(rootToAdd, OrderRootType.CLASSES);
                    }
                }
            // sources and docs could be updated as well, but currently they are always senseless, because they do not exist
            }
        }
        if (libraryName.contains(":swc:") || libraryName.contains(":rb.swc:") || libraryName.contains(":resource-bundle:") || libraryName.contains(":ane:")) {
            playerglobal |= libraryName.contains("playerglobal");
            airglobal |= libraryName.contains("airglobal");
            mobilecomponents |= libraryName.contains("mobilecomponents");
            final boolean ane = libraryName.contains(":ane:") && !libraryName.contains(":swc:");
            final LibraryKind kind = ((LibraryEx) library).getKind();
            if (kind != FlexLibraryType.FLEX_LIBRARY) {
                if (kind == null) {
                    final LibraryEx.ModifiableModelEx libraryModel = (LibraryEx.ModifiableModelEx) myModelsProvider.getModifiableLibraryModel(library);
                    libraryModel.setKind(FlexLibraryType.FLEX_LIBRARY);
                }
            }
            final ModifiableDependencyEntry sharedLibraryEntry = myFlexEditor.createSharedLibraryEntry(bc.getDependencies(), ((LibraryOrderEntry) entry).getLibraryName(), ((LibraryOrderEntry) entry).getLibraryLevel());
            final LinkageType linkageType = ane ? DependencyType.DEFAULT_LINKAGE : FlexUtils.convertLinkageType(scope, isExported);
            sharedLibraryEntry.getDependencyType().setLinkageType(linkageType);
            bc.getDependencies().getModifiableEntries().add(sharedLibraryEntry);
        } else {
            MavenLog.LOG.info("Non-swc dependency for flexmojos project '" + myModule.getName() + "': " + libraryName);
        }
    }
    // todo better target platform detection if both airglobal and playerglobal present?
    return mobilecomponents && airglobal ? TargetPlatform.Mobile : airglobal && !playerglobal ? TargetPlatform.Desktop : TargetPlatform.Web;
}
Also used : LibraryKind(com.intellij.openapi.roots.libraries.LibraryKind) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Library(com.intellij.openapi.roots.libraries.Library)

Aggregations

Library (com.intellij.openapi.roots.libraries.Library)3 LibraryKind (com.intellij.openapi.roots.libraries.LibraryKind)3 AbstractApplicationUsagesCollector (com.intellij.internal.statistic.AbstractApplicationUsagesCollector)1 GroupDescriptor (com.intellij.internal.statistic.beans.GroupDescriptor)1 UsageDescriptor (com.intellij.internal.statistic.beans.UsageDescriptor)1 Module (com.intellij.openapi.module.Module)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 Project (com.intellij.openapi.project.Project)1 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 OrderEntry (com.intellij.openapi.roots.OrderEntry)1 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)1 Processor (com.intellij.util.Processor)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 NonNls (org.jetbrains.annotations.NonNls)1 NotNull (org.jetbrains.annotations.NotNull)1 MavenProject (org.jetbrains.idea.maven.project.MavenProject)1