Search in sources :

Example 11 with AbstractExternalSystemSettings

use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.

the class AbstractExternalProjectImportBuilder method executeAndRestoreDefaultProjectSettings.

@SuppressWarnings("unchecked")
private void executeAndRestoreDefaultProjectSettings(@NotNull Project project, @NotNull Runnable task) {
    AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId);
    Object systemStateToRestore = null;
    if (systemSettings instanceof PersistentStateComponent) {
        systemStateToRestore = ((PersistentStateComponent) systemSettings).getState();
    }
    systemSettings.copyFrom(myControl.getSystemSettings());
    Collection projectSettingsToRestore = systemSettings.getLinkedProjectsSettings();
    Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
    projects.add(getCurrentExternalProjectSettings());
    systemSettings.setLinkedProjectsSettings(projects);
    try {
        task.run();
    } finally {
        if (systemStateToRestore != null) {
            ((PersistentStateComponent) systemSettings).loadState(systemStateToRestore);
        } else {
            systemSettings.setLinkedProjectsSettings(projectSettingsToRestore);
        }
    }
}
Also used : AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) PersistentStateComponent(com.intellij.openapi.components.PersistentStateComponent) Collection(java.util.Collection) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)

Example 12 with AbstractExternalSystemSettings

use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.

the class ExternalSystemViewDefaultContributor method addModuleNodes.

private static void addModuleNodes(@NotNull ExternalProjectsView externalProjectsView, @NotNull MultiMap<Key<?>, DataNode<?>> dataNodes, @NotNull List<ExternalSystemNode<?>> result) {
    final Collection<DataNode<?>> moduleDataNodes = dataNodes.get(ProjectKeys.MODULE);
    if (!moduleDataNodes.isEmpty()) {
        final AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(externalProjectsView.getProject(), externalProjectsView.getSystemId());
        for (DataNode<?> dataNode : moduleDataNodes) {
            final ModuleData data = (ModuleData) dataNode.getData();
            final ExternalProjectSettings projectSettings = systemSettings.getLinkedProjectSettings(data.getLinkedExternalProjectPath());
            DataNode<ProjectData> projectDataNode = ExternalSystemApiUtil.findParent(dataNode, PROJECT);
            final boolean isRoot = projectSettings != null && data.getLinkedExternalProjectPath().equals(projectSettings.getExternalProjectPath()) && projectDataNode != null && projectDataNode.getData().getInternalName().equals(data.getInternalName());
            //noinspection unchecked
            final ModuleNode moduleNode = new ModuleNode(externalProjectsView, (DataNode<ModuleData>) dataNode, isRoot);
            result.add(moduleNode);
        }
    }
}
Also used : AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)

Example 13 with AbstractExternalSystemSettings

use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.

the class ProjectNode method doUpdate.

@Override
protected void doUpdate() {
    String autoImportHint = null;
    final ProjectData projectData = getData();
    if (projectData != null) {
        final AbstractExternalSystemSettings externalSystemSettings = ExternalSystemApiUtil.getSettings(getExternalProjectsView().getProject(), getData().getOwner());
        final ExternalProjectSettings projectSettings = externalSystemSettings.getLinkedProjectSettings(projectData.getLinkedExternalProjectPath());
        if (projectSettings != null && projectSettings.isUseAutoImport())
            autoImportHint = "auto-import enabled";
    }
    setNameAndTooltip(getName(), myTooltipCache, autoImportHint);
}
Also used : AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)

Example 14 with AbstractExternalSystemSettings

use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.

the class ContentRootDataService method importData.

private static void importData(@NotNull IdeModifiableModelsProvider modelsProvider, @NotNull final Collection<DataNode<ContentRootData>> data, @NotNull final Module module, boolean forceDirectoriesCreation) {
    final ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
    final ContentEntry[] contentEntries = modifiableRootModel.getContentEntries();
    final Map<String, ContentEntry> contentEntriesMap = ContainerUtilRt.newHashMap();
    for (ContentEntry contentEntry : contentEntries) {
        contentEntriesMap.put(contentEntry.getUrl(), contentEntry);
    }
    boolean createEmptyContentRootDirectories = forceDirectoriesCreation;
    if (!forceDirectoriesCreation && !data.isEmpty()) {
        ProjectSystemId projectSystemId = data.iterator().next().getData().getOwner();
        AbstractExternalSystemSettings externalSystemSettings = ExternalSystemApiUtil.getSettings(module.getProject(), projectSystemId);
        String path = module.getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
        if (path != null) {
            ExternalProjectSettings projectSettings = externalSystemSettings.getLinkedProjectSettings(path);
            createEmptyContentRootDirectories = projectSettings != null && projectSettings.isCreateEmptyContentRootDirectories();
        }
    }
    final Set<ContentEntry> importedContentEntries = ContainerUtil.newIdentityTroveSet();
    for (final DataNode<ContentRootData> node : data) {
        final ContentRootData contentRoot = node.getData();
        final ContentEntry contentEntry = findOrCreateContentRoot(modifiableRootModel, contentRoot.getRootPath());
        if (!importedContentEntries.contains(contentEntry)) {
            // clear source folders but do not remove existing excluded folders
            contentEntry.clearSourceFolders();
            importedContentEntries.add(contentEntry);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Importing content root '%s' for module '%s'", contentRoot.getRootPath(), module.getName()));
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, false, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.TEST)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, false, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE_GENERATED)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, true, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.TEST_GENERATED)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, true, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.RESOURCE)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.RESOURCE, false, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.TEST_RESOURCE)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.TEST_RESOURCE, false, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.EXCLUDED)) {
            createExcludedRootIfAbsent(contentEntry, path, module.getName(), module.getProject());
        }
        contentEntriesMap.remove(contentEntry.getUrl());
    }
    for (ContentEntry contentEntry : contentEntriesMap.values()) {
        modifiableRootModel.removeContentEntry(contentEntry);
    }
}
Also used : ContentRootData(com.intellij.openapi.externalSystem.model.project.ContentRootData) SourceRoot(com.intellij.openapi.externalSystem.model.project.ContentRootData.SourceRoot) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Example 15 with AbstractExternalSystemSettings

use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.

the class ExternalModuleStructureExtension method disposeUIResources.

@Override
public void disposeUIResources() {
    try {
        if (isExternalSystemsInvolved) {
            assert myOrphanProjectsCandidates != null;
            assert myProject != null;
            if (myExternalProjectsToRestore != null) {
                for (Pair<ProjectSystemId, ExternalProjectSettings> settingsPair : myExternalProjectsToRestore.values()) {
                    AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(myProject, settingsPair.first);
                    String rootProjectPath = settingsPair.second.getExternalProjectPath();
                    if (settings.getLinkedProjectSettings(rootProjectPath) == null) {
                        //noinspection unchecked
                        settings.linkProject(settingsPair.second);
                    }
                    myOrphanProjectsCandidates.remove(rootProjectPath);
                }
            }
            ModulesConfigurator modulesConfigurator = getModulesConfigurator(myProject);
            if (modulesConfigurator != null) {
                for (Map.Entry<String, ProjectSystemId> entry : myOrphanProjectsCandidates.entrySet()) {
                    String rootProjectPath = entry.getKey();
                    if (StringUtil.isNotEmpty(rootProjectPath)) {
                        unlinkProject(myProject, entry.getValue(), rootProjectPath);
                    }
                }
            }
        }
    } catch (Throwable e) {
        LOG.warn(e);
    } finally {
        myProject = null;
        myExternalProjectsToRestore = null;
        myOrphanProjectsCandidates = null;
    }
}
Also used : AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) ModulesConfigurator(com.intellij.openapi.roots.ui.configuration.ModulesConfigurator) HashMap(java.util.HashMap) Map(java.util.Map) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)

Aggregations

AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)18 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)13 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)4 Collection (java.util.Collection)4 ImportSpecBuilder (com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)3 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)3 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)3 ExternalSystemSettingsListenerAdapter (com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter)3 Module (com.intellij.openapi.module.Module)2 ModulesConfigurator (com.intellij.openapi.roots.ui.configuration.ModulesConfigurator)2 Couple (com.intellij.openapi.util.Couple)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 HashMap (java.util.HashMap)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 PersistentStateComponent (com.intellij.openapi.components.PersistentStateComponent)1 ImportSpec (com.intellij.openapi.externalSystem.importing.ImportSpec)1 DataNode (com.intellij.openapi.externalSystem.model.DataNode)1 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)1