Search in sources :

Example 71 with MavenProject

use of org.jetbrains.idea.maven.project.MavenProject 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)

Example 72 with MavenProject

use of org.jetbrains.idea.maven.project.MavenProject in project intellij-community by JetBrains.

the class MavenProjectsStructure method updateProjects.

public void updateProjects(List<MavenProject> updated, Collection<MavenProject> deleted) {
    for (MavenProject each : updated) {
        ProjectNode node = findNodeFor(each);
        if (node == null) {
            node = new ProjectNode(each);
            myProjectToNodeMapping.put(each, node);
        }
        doUpdateProject(node);
    }
    for (MavenProject each : deleted) {
        ProjectNode node = myProjectToNodeMapping.remove(each);
        if (node != null) {
            ProjectsGroupNode parent = node.getGroup();
            parent.remove(node);
        }
    }
    myRoot.updateProfiles();
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject)

Example 73 with MavenProject

use of org.jetbrains.idea.maven.project.MavenProject in project intellij-community by JetBrains.

the class MavenProjectsStructure method updateIgnored.

public void updateIgnored(List<MavenProject> projects) {
    for (MavenProject each : projects) {
        ProjectNode node = findNodeFor(each);
        if (node == null)
            continue;
        node.updateIgnored();
    }
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject)

Example 74 with MavenProject

use of org.jetbrains.idea.maven.project.MavenProject in project intellij-community by JetBrains.

the class MavenProjectsStructure method doUpdateProject.

private void doUpdateProject(ProjectNode node) {
    MavenProject project = node.getMavenProject();
    ProjectsGroupNode newParentNode = myRoot;
    if (myProjectsNavigator.getGroupModules()) {
        MavenProject aggregator = myProjectsManager.findAggregator(project);
        if (aggregator != null) {
            ProjectNode aggregatorNode = findNodeFor(aggregator);
            if (aggregatorNode != null && aggregatorNode.isVisible()) {
                newParentNode = aggregatorNode.getModulesNode();
            }
        }
    }
    node.updateProject();
    reconnectNode(node, newParentNode);
    ProjectsGroupNode newModulesParentNode = myProjectsNavigator.getGroupModules() && node.isVisible() ? node.getModulesNode() : myRoot;
    for (MavenProject each : myProjectsManager.getModules(project)) {
        ProjectNode moduleNode = findNodeFor(each);
        if (moduleNode != null && !moduleNode.getParent().equals(newModulesParentNode)) {
            reconnectNode(moduleNode, newModulesParentNode);
        }
    }
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject)

Example 75 with MavenProject

use of org.jetbrains.idea.maven.project.MavenProject in project intellij-community by JetBrains.

the class MavenFoldersImporter method updateProjectFolders.

public static void updateProjectFolders(final Project project, final boolean updateTargetFoldersOnly) {
    final MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
    final MavenImportingSettings settings = manager.getImportingSettings();
    WriteAction.run(() -> {
        List<ModifiableRootModel> rootModels = new ArrayList<>();
        for (Module each : ModuleManager.getInstance(project).getModules()) {
            MavenProject mavenProject = manager.findProject(each);
            if (mavenProject == null)
                continue;
            MavenRootModelAdapter a = new MavenRootModelAdapter(mavenProject, each, new IdeModifiableModelsProviderImpl(project));
            new MavenFoldersImporter(mavenProject, settings, a).config(updateTargetFoldersOnly);
            ModifiableRootModel model = a.getRootModel();
            if (model.isChanged()) {
                rootModels.add(model);
            } else {
                model.dispose();
            }
        }
        if (!rootModels.isEmpty()) {
            ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels.get((0)).getProject()).getModifiableModel());
        }
    });
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) ArrayList(java.util.ArrayList) MavenImportingSettings(org.jetbrains.idea.maven.project.MavenImportingSettings) Module(com.intellij.openapi.module.Module)

Aggregations

MavenProject (org.jetbrains.idea.maven.project.MavenProject)132 VirtualFile (com.intellij.openapi.vfs.VirtualFile)40 MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)20 MavenId (org.jetbrains.idea.maven.model.MavenId)16 Project (com.intellij.openapi.project.Project)10 Nullable (org.jetbrains.annotations.Nullable)9 Bombed (com.intellij.idea.Bombed)8 Module (com.intellij.openapi.module.Module)6 DataContext (com.intellij.openapi.actionSystem.DataContext)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 Result (com.intellij.openapi.application.Result)4 MavenArtifact (org.jetbrains.idea.maven.model.MavenArtifact)4 MavenEmbeddersManager (org.jetbrains.idea.maven.project.MavenEmbeddersManager)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 TextRange (com.intellij.openapi.util.TextRange)3 NotNull (org.jetbrains.annotations.NotNull)3 MavenRunnerParameters (org.jetbrains.idea.maven.execution.MavenRunnerParameters)3 MavenExplicitProfiles (org.jetbrains.idea.maven.model.MavenExplicitProfiles)3 MavenProjectsTree (org.jetbrains.idea.maven.project.MavenProjectsTree)3