Search in sources :

Example 16 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry 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 17 with LibraryOrderEntry

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

the class FrameworksCompatibilityUtils method suggestRemoveOldJsLibrary.

public static void suggestRemoveOldJsLibrary(@NotNull ModifiableRootModel rootModel) {
    List<OrderEntry> oldJsLibraries = new ArrayList<OrderEntry>();
    for (OrderEntry entry : rootModel.getOrderEntries()) {
        if (!(entry instanceof LibraryOrderEntry))
            continue;
        Library library = ((LibraryOrderEntry) entry).getLibrary();
        if (library == null)
            continue;
        if (JSLibraryStdPresentationProvider.detectOld(library)) {
            oldJsLibraries.add(entry);
        }
    }
    removeWithConfirm(rootModel, oldJsLibraries, "Current module is configured with old js library.\nDo you want to remove it?", "Old JS Library");
}
Also used : 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 18 with LibraryOrderEntry

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

the class AndroidMavenUtil method isMavenAarDependency.

public static boolean isMavenAarDependency(@NotNull Module module, @NotNull OrderEntry entry) {
    if (ApplicationManager.getApplication().isUnitTestMode() && entry.getPresentableName().equals("maven_aar_dependency")) {
        return true;
    }
    if (!(entry instanceof LibraryOrderEntry) || !isMavenizedModule(module)) {
        return false;
    }
    final Library library = ((LibraryOrderEntry) entry).getLibrary();
    if (library == null) {
        return false;
    }
    final MavenProject mavenProject = MavenProjectsManager.getInstance(module.getProject()).findProject(module);
    if (mavenProject == null) {
        return false;
    }
    final MavenArtifact artifact = MavenRootModelAdapter.findArtifact(mavenProject, library);
    return artifact != null && AAR_DEPENDENCY_AND_PACKAGING_TYPE.equals(artifact.getType());
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact)

Example 19 with LibraryOrderEntry

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

the class ModuleDependenciesSetup method addLibraryAsDependency.

protected void addLibraryAsDependency(@NotNull Library library, @NotNull String libraryName, @NotNull DependencyScope scope, @NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider) {
    for (OrderEntry orderEntry : modelsProvider.getModifiableRootModel(module).getOrderEntries()) {
        if (orderEntry instanceof LibraryOrderEntry) {
            Library entryLibrary = ((LibraryOrderEntry) orderEntry).getLibrary();
            if (entryLibrary != null && libraryName.equals(entryLibrary.getName())) {
                // Dependency already set up.
                return;
            }
        }
    }
    LibraryOrderEntry orderEntry = modelsProvider.getModifiableRootModel(module).addLibraryEntry(library);
    orderEntry.setScope(scope);
    orderEntry.setExported(true);
}
Also used : LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library)

Example 20 with LibraryOrderEntry

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

the class ArtifactsByConfigurationModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
    for (Map.Entry<String, Set<File>> entry : javaModuleModel.getArtifactsByConfiguration().entrySet()) {
        Set<File> artifacts = entry.getValue();
        if (artifacts != null && !artifacts.isEmpty()) {
            for (File artifact : artifacts) {
                if (!artifact.isFile() || !endsWithIgnoreCase(artifact.getName(), DOT_JAR)) {
                    // We only expose artifacts that are jar files.
                    continue;
                }
                File buildFolderPath = javaModuleModel.getBuildFolderPath();
                String artifactName = getNameWithoutExtension(artifact);
                if (buildFolderPath != null && buildFolderPath.isDirectory() && isAncestor(buildFolderPath, artifact, true) && module.getName().equals(artifactName)) {
                    // This is the jar obtained by compiling the module, no need to add it as dependency.
                    continue;
                }
                String libraryName = module.getName() + "." + artifactName;
                Library library = ideModelsProvider.getLibraryByName(libraryName);
                if (library == null) {
                    // Create library.
                    library = ideModelsProvider.createLibrary(libraryName);
                    Library.ModifiableModel libraryModel = ideModelsProvider.getModifiableLibraryModel(library);
                    String url = pathToIdeaUrl(artifact);
                    libraryModel.addRoot(url, CLASSES);
                } else {
                    SyncLibraryRegistry.getInstance(module.getProject()).markAsUsed(library, artifact);
                }
                LibraryOrderEntry orderEntry = moduleModel.addLibraryEntry(library);
                orderEntry.setScope(COMPILE);
                orderEntry.setExported(true);
            }
        }
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Set(java.util.Set) Library(com.intellij.openapi.roots.libraries.Library) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Map(java.util.Map) File(java.io.File)

Aggregations

LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)40 Library (com.intellij.openapi.roots.libraries.Library)27 OrderEntry (com.intellij.openapi.roots.OrderEntry)17 Module (com.intellij.openapi.module.Module)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)7 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)6 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)5 Nullable (org.jetbrains.annotations.Nullable)5 Project (com.intellij.openapi.project.Project)4 File (java.io.File)4 NotNull (org.jetbrains.annotations.NotNull)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)3 ActionCallback (com.intellij.openapi.util.ActionCallback)3 THashSet (gnu.trove.THashSet)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Notification (com.intellij.notification.Notification)2 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)2 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)2