From b3d49a438a4be0da0b3e56b7ef347cbf16577c4d Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Wed, 18 Sep 2013 15:59:05 +0400 Subject: [PATCH] IDEA-113775 External System: new 'Refresh external project' action for single module refresh --- .../i18n/ExternalSystemBundle.properties | 2 + .../action/DetachExternalProjectAction.java | 56 +---------- .../action/ExternalActionUtil.java | 88 +++++++++++++++++ .../action/OpenExternalConfigAction.java | 7 +- .../RefreshAllExternalProjectsAction.java | 5 +- .../action/RefreshExternalProjectAction.java | 97 +++++++++++++++++++ .../src/idea/ExternalSystemActions.xml | 9 +- 7 files changed, 202 insertions(+), 62 deletions(-) create mode 100644 platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalActionUtil.java create mode 100644 platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/RefreshExternalProjectAction.java diff --git a/platform/external-system-api/resources/i18n/ExternalSystemBundle.properties b/platform/external-system-api/resources/i18n/ExternalSystemBundle.properties index d56ce39c6924..17078c097875 100644 --- a/platform/external-system-api/resources/i18n/ExternalSystemBundle.properties +++ b/platform/external-system-api/resources/i18n/ExternalSystemBundle.properties @@ -34,6 +34,8 @@ tool.window.title.tasks=tasks # Action. action.refresh.all.projects.text=Refresh all {0} projects action.refresh.all.projects.description=Force refresh all linked {0} projects +action.refresh.project.text=Refresh {0} project +action.refresh.project.description=Force refresh selected linked {0} project action.attach.external.project.text=Attach {0} project action.attach.external.project.description=Attach {0} project to the current ide project action.detach.external.project.text=Detach {0} project diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/DetachExternalProjectAction.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/DetachExternalProjectAction.java index dbc5766cd989..88f2c26a68a1 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/DetachExternalProjectAction.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/DetachExternalProjectAction.java @@ -59,13 +59,13 @@ public class DetachExternalProjectAction extends AnAction implements DumbAware { @Override public void update(AnActionEvent e) { - MyInfo info = getProcessingInfo(e.getDataContext()); + ExternalActionUtil.MyInfo info = ExternalActionUtil.getProcessingInfo(e.getDataContext()); e.getPresentation().setEnabled(info.externalProject != null); } @Override public void actionPerformed(AnActionEvent e) { - MyInfo info = getProcessingInfo(e.getDataContext()); + ExternalActionUtil.MyInfo info = ExternalActionUtil.getProcessingInfo(e.getDataContext()); if (info.settings == null || info.localSettings == null || info.externalProject == null || info.ideProject == null || info.externalSystemId == null) { @@ -108,56 +108,4 @@ public class DetachExternalProjectAction extends AnAction implements DumbAware { ExternalSystemUtil.ruleOrphanModules(orphanModules, info.ideProject, info.externalSystemId); } } - - @NotNull - private static MyInfo getProcessingInfo(@NotNull DataContext context) { - ExternalProjectPojo externalProject = ExternalSystemDataKeys.SELECTED_PROJECT.getData(context); - if (externalProject == null) { - return MyInfo.EMPTY; - } - - ProjectSystemId externalSystemId = ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID.getData(context); - if (externalSystemId == null) { - return MyInfo.EMPTY; - } - - Project ideProject = PlatformDataKeys.PROJECT.getData(context); - if (ideProject == null) { - return MyInfo.EMPTY; - } - - AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(ideProject, externalSystemId); - ExternalProjectSettings externalProjectSettings = settings.getLinkedProjectSettings(externalProject.getPath()); - AbstractExternalSystemLocalSettings localSettings = ExternalSystemApiUtil.getLocalSettings(ideProject, externalSystemId); - - return new MyInfo(externalProjectSettings == null ? null : settings, - localSettings == null ? null : localSettings, - externalProjectSettings == null ? null : externalProject, - ideProject, - externalSystemId); - } - - private static class MyInfo { - - public static final MyInfo EMPTY = new MyInfo(null, null, null, null, null); - - @Nullable public final AbstractExternalSystemSettings settings; - @Nullable public final AbstractExternalSystemLocalSettings localSettings; - @Nullable public final ExternalProjectPojo externalProject; - @Nullable public final Project ideProject; - @Nullable public final ProjectSystemId externalSystemId; - - MyInfo(@Nullable AbstractExternalSystemSettings settings, - @Nullable AbstractExternalSystemLocalSettings localSettings, - @Nullable ExternalProjectPojo externalProject, - @Nullable Project ideProject, - @Nullable ProjectSystemId externalSystemId) - { - this.settings = settings; - this.localSettings = localSettings; - this.externalProject = externalProject; - this.ideProject = ideProject; - this.externalSystemId = externalSystemId; - } - } } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalActionUtil.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalActionUtil.java new file mode 100644 index 000000000000..772ce688a2e5 --- /dev/null +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalActionUtil.java @@ -0,0 +1,88 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.externalSystem.action; + +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys; +import com.intellij.openapi.externalSystem.model.ProjectSystemId; +import com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo; +import com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings; +import com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings; +import com.intellij.openapi.externalSystem.settings.ExternalProjectSettings; +import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Vladislav.Soroka + * @since 9/18/13 + */ +public class ExternalActionUtil { + @NotNull + public static MyInfo getProcessingInfo(@NotNull DataContext context) { + ExternalProjectPojo externalProject = ExternalSystemDataKeys.SELECTED_PROJECT.getData(context); + if (externalProject == null) { + return MyInfo.EMPTY; + } + + ProjectSystemId externalSystemId = ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID.getData(context); + if (externalSystemId == null) { + return MyInfo.EMPTY; + } + + Project ideProject = PlatformDataKeys.PROJECT.getData(context); + if (ideProject == null) { + return MyInfo.EMPTY; + } + + AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(ideProject, externalSystemId); + ExternalProjectSettings externalProjectSettings = settings.getLinkedProjectSettings(externalProject.getPath()); + AbstractExternalSystemLocalSettings localSettings = ExternalSystemApiUtil.getLocalSettings(ideProject, externalSystemId); + + return new MyInfo(externalProjectSettings == null ? null : settings, + localSettings == null ? null : localSettings, + externalProjectSettings == null ? null : externalProject, + ideProject, + externalSystemId); + } + + public static class MyInfo { + + public static final MyInfo EMPTY = new MyInfo(null, null, null, null, null); + + @Nullable public final AbstractExternalSystemSettings settings; + @Nullable public final AbstractExternalSystemLocalSettings localSettings; + @Nullable public final ExternalProjectPojo externalProject; + @Nullable public final Project ideProject; + @Nullable public final ProjectSystemId externalSystemId; + + MyInfo(@Nullable AbstractExternalSystemSettings settings, + @Nullable AbstractExternalSystemLocalSettings localSettings, + @Nullable ExternalProjectPojo externalProject, + @Nullable Project ideProject, + @Nullable ProjectSystemId externalSystemId) + { + this.settings = settings; + this.localSettings = localSettings; + this.externalProject = externalProject; + this.ideProject = ideProject; + this.externalSystemId = externalSystemId; + } + } +} + diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/OpenExternalConfigAction.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/OpenExternalConfigAction.java index 8e62f72b5917..acc5aa4f08b4 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/OpenExternalConfigAction.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/OpenExternalConfigAction.java @@ -1,9 +1,6 @@ package com.intellij.openapi.externalSystem.action; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys; import com.intellij.openapi.externalSystem.model.ProjectSystemId; import com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo; @@ -48,7 +45,7 @@ public class OpenExternalConfigAction extends AnAction implements DumbAware { @Override public void actionPerformed(AnActionEvent e) { - Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); + Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) { return; } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/RefreshAllExternalProjectsAction.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/RefreshAllExternalProjectsAction.java index 268cb6a33bac..166a46aed037 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/RefreshAllExternalProjectsAction.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/RefreshAllExternalProjectsAction.java @@ -2,6 +2,7 @@ package com.intellij.openapi.externalSystem.action; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys; @@ -39,7 +40,7 @@ public class RefreshAllExternalProjectsAction extends AnAction implements DumbAw e.getPresentation().setText(ExternalSystemBundle.message("action.refresh.all.projects.text", name)); e.getPresentation().setDescription(ExternalSystemBundle.message("action.refresh.all.projects.description", name)); - Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); + Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) { e.getPresentation().setEnabled(false); return; @@ -56,7 +57,7 @@ public class RefreshAllExternalProjectsAction extends AnAction implements DumbAw return; } - Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); + Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project == null) { e.getPresentation().setEnabled(false); return; diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/RefreshExternalProjectAction.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/RefreshExternalProjectAction.java new file mode 100644 index 000000000000..69d2aa51f525 --- /dev/null +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/RefreshExternalProjectAction.java @@ -0,0 +1,97 @@ +package com.intellij.openapi.externalSystem.action; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.externalSystem.model.DataNode; +import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys; +import com.intellij.openapi.externalSystem.model.ProjectSystemId; +import com.intellij.openapi.externalSystem.model.project.ProjectData; +import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType; +import com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager; +import com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback; +import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager; +import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; +import com.intellij.openapi.externalSystem.util.ExternalSystemBundle; +import com.intellij.openapi.externalSystem.util.ExternalSystemUtil; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ex.ProjectRootManagerEx; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; + +/** + * * Forces the ide to retrieve the most up-to-date info about the linked external project and updates project state if necessary + * (e.g. imports missing libraries). + * + * @author Vladislav.Soroka + * @since 9/18/13 + */ +public class RefreshExternalProjectAction extends AnAction implements DumbAware, AnAction.TransparentUpdate { + + public RefreshExternalProjectAction() { + getTemplatePresentation().setText(ExternalSystemBundle.message("action.refresh.project.text", "external")); + getTemplatePresentation().setDescription(ExternalSystemBundle.message("action.refresh.project.description", "external")); + } + + @Override + public void update(AnActionEvent e) { + ExternalActionUtil.MyInfo info = ExternalActionUtil.getProcessingInfo(e.getDataContext()); + e.getPresentation().setEnabled(info.externalProject != null); + } + + @Override + public void actionPerformed(AnActionEvent e) { + ExternalActionUtil.MyInfo info = ExternalActionUtil.getProcessingInfo(e.getDataContext()); + if (info.settings == null || info.localSettings == null || info.externalProject == null || info.ideProject == null + || info.externalSystemId == null) + { + return; + } + ProjectSystemId externalSystemId = ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID.getData(e.getDataContext()); + if (externalSystemId == null) { + return; + } + + final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); + if (project == null) { + e.getPresentation().setEnabled(false); + return; + } + + // We save all documents because there is a possible case that there is an external system config file changed inside the ide. + FileDocumentManager.getInstance().saveAllDocuments(); + + final ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class); + ExternalSystemUtil.refreshProject( + project, externalSystemId, info.externalProject.getPath(), + new ExternalProjectRefreshCallback() { + @Override + public void onSuccess(@Nullable final DataNode externalProject) { + if (externalProject == null) { + return; + } + ExternalSystemApiUtil.executeProjectChangeAction(true, new Runnable() { + @Override + public void run() { + ProjectRootManagerEx.getInstanceEx(project).mergeRootsChangesDuring(new Runnable() { + @Override + public void run() { + projectDataManager.importData(externalProject.getKey(), Collections.singleton(externalProject), project, true); + } + }); + } + }); + } + + @Override + public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) { + } + }, true, false); + } +} diff --git a/platform/platform-resources/src/idea/ExternalSystemActions.xml b/platform/platform-resources/src/idea/ExternalSystemActions.xml index 555856acc309..48028edbf607 100644 --- a/platform/platform-resources/src/idea/ExternalSystemActions.xml +++ b/platform/platform-resources/src/idea/ExternalSystemActions.xml @@ -5,10 +5,16 @@ + + + + class="com.intellij.openapi.externalSystem.action.DetachExternalProjectAction" + use-shortcut-of="$Delete"/> @@ -23,6 +29,7 @@ +