diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ModuleDataService.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ModuleDataService.java index 7fcbc601acb5..94e61cdd6077 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ModuleDataService.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ModuleDataService.java @@ -6,6 +6,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.externalSystem.model.DataNode; import com.intellij.openapi.externalSystem.model.Key; import com.intellij.openapi.externalSystem.model.ProjectKeys; +import com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType; import com.intellij.openapi.externalSystem.model.project.ModuleData; import com.intellij.openapi.externalSystem.model.project.ProjectData; import com.intellij.openapi.externalSystem.service.project.ProjectStructureHelper; @@ -75,67 +76,15 @@ public class ModuleDataService implements ProjectDataService @Override public void run() { final Collection> toCreate = filterExistingModules(toImport, project); - if (toCreate.isEmpty()) { - return; + if (!toCreate.isEmpty()) { + createModules(toCreate, project); } - removeExistingModulesConfigs(toCreate); - Application application = ApplicationManager.getApplication(); - final Map, Module> moduleMappings = ContainerUtilRt.newHashMap(); - application.runWriteAction(new Runnable() { - @Override - public void run() { - final ModuleManager moduleManager = ModuleManager.getInstance(project); - final ProjectEntityChangeListener publisher - = project.getMessageBus().syncPublisher(ProjectEntityChangeListener.TOPIC); - for (DataNode module : toCreate) { - publisher.onChangeStart(module, module.getData().getOwner()); - try { - importModule(moduleManager, module); - } - finally { - publisher.onChangeEnd(module, module.getData().getOwner()); - } - } + for (DataNode node : toImport) { + Module module = myProjectStructureHelper.findIdeModule(node.getData(), project); + if (module != null) { + syncPaths(module, node.getData()); } - - private void importModule(@NotNull ModuleManager moduleManager, @NotNull DataNode module) { - ModuleData data = module.getData(); - final Module created = moduleManager.newModule(data.getModuleFilePath(), data.getModuleTypeId()); - - // Ensure that the dependencies are clear (used to be not clear when manually removing the module and importing it via gradle) - ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(created); - final ModifiableRootModel moduleRootModel = moduleRootManager.getModifiableModel(); - moduleRootModel.inheritSdk(); - created.setOption(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY, data.getOwner().toString()); - ProjectData projectData = module.getData(ProjectKeys.PROJECT); - if (projectData != null) { - created.setOption(ExternalSystemConstants.LINKED_PROJECT_PATH_KEY, projectData.getLinkedExternalProjectPath()); - } - - RootPolicy visitor = new RootPolicy() { - @Override - public Object visitLibraryOrderEntry(LibraryOrderEntry libraryOrderEntry, Object value) { - moduleRootModel.removeOrderEntry(libraryOrderEntry); - return value; - } - - @Override - public Object visitModuleOrderEntry(ModuleOrderEntry moduleOrderEntry, Object value) { - moduleRootModel.removeOrderEntry(moduleOrderEntry); - return value; - } - }; - try { - for (OrderEntry orderEntry : moduleRootModel.getOrderEntries()) { - orderEntry.accept(visitor, null); - } - } - finally { - moduleRootModel.commit(); - } - moduleMappings.put(module, created); - } - }); + } } }; if (synchronous) { @@ -145,6 +94,59 @@ public class ModuleDataService implements ProjectDataService UIUtil.invokeLaterIfNeeded(task); } } + + private void createModules(@NotNull final Collection> toCreate, @NotNull final Project project) { + removeExistingModulesConfigs(toCreate); + Application application = ApplicationManager.getApplication(); + final Map, Module> moduleMappings = ContainerUtilRt.newHashMap(); + application.runWriteAction(new Runnable() { + @Override + public void run() { + final ModuleManager moduleManager = ModuleManager.getInstance(project); + for (DataNode module : toCreate) { + importModule(moduleManager, module); + } + } + + private void importModule(@NotNull ModuleManager moduleManager, @NotNull DataNode module) { + ModuleData data = module.getData(); + final Module created = moduleManager.newModule(data.getModuleFilePath(), data.getModuleTypeId()); + + // Ensure that the dependencies are clear (used to be not clear when manually removing the module and importing it via gradle) + ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(created); + final ModifiableRootModel moduleRootModel = moduleRootManager.getModifiableModel(); + moduleRootModel.inheritSdk(); + created.setOption(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY, data.getOwner().toString()); + ProjectData projectData = module.getData(ProjectKeys.PROJECT); + if (projectData != null) { + created.setOption(ExternalSystemConstants.LINKED_PROJECT_PATH_KEY, projectData.getLinkedExternalProjectPath()); + } + + RootPolicy visitor = new RootPolicy() { + @Override + public Object visitLibraryOrderEntry(LibraryOrderEntry libraryOrderEntry, Object value) { + moduleRootModel.removeOrderEntry(libraryOrderEntry); + return value; + } + + @Override + public Object visitModuleOrderEntry(ModuleOrderEntry moduleOrderEntry, Object value) { + moduleRootModel.removeOrderEntry(moduleOrderEntry); + return value; + } + }; + try { + for (OrderEntry orderEntry : moduleRootModel.getOrderEntries()) { + orderEntry.accept(visitor, null); + } + } + finally { + moduleRootModel.commit(); + } + moduleMappings.put(module, created); + } + }); + } @NotNull private Collection> filterExistingModules(@NotNull Collection> modules, @@ -184,6 +186,31 @@ public class ModuleDataService implements ProjectDataService }); } + private static void syncPaths(@NotNull Module module, @NotNull ModuleData data) { + CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module); + if (extension == null) { + LOG.warn(String.format("Can't sync paths for module '%s'. Reason: no compiler extension is found for it", module.getName())); + return; + } + CompilerModuleExtension model = (CompilerModuleExtension)extension.getModifiableModel(true); + try { + String compileOutputPath = data.getCompileOutputPath(ExternalSystemSourceType.SOURCE); + if (compileOutputPath != null) { + model.setCompilerOutputPath(compileOutputPath); + } + + String testCompileOutputPath = data.getCompileOutputPath(ExternalSystemSourceType.TEST); + if (testCompileOutputPath != null) { + model.setCompilerOutputPathForTests(testCompileOutputPath); + } + + model.inheritCompilerOutputPath(data.isInheritProjectCompileOutputPath()); + } + finally { + model.commit(); + } + } + @Override public void removeData(@NotNull final Collection modules, @NotNull Project project, boolean synchronous) { if (modules.isEmpty()) { diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ProjectEntityChangeListener.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ProjectEntityChangeListener.java deleted file mode 100644 index 589cbf279283..000000000000 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ProjectEntityChangeListener.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.intellij.openapi.externalSystem.service.project.manage; - -import com.intellij.openapi.externalSystem.model.ProjectSystemId; -import com.intellij.util.messages.Topic; -import org.jetbrains.annotations.NotNull; - -/** - * Defines contract for the callback to be notified on project structure changes triggered by external system integrations. - *

- * Implementations of this interface are not obliged to be thread-safe. - * - * @author Denis Zhdanov - * @since 2/24/12 1:05 PM - */ -public interface ProjectEntityChangeListener { - - Topic TOPIC = Topic.create("External system project change", ProjectEntityChangeListener.class); - - /** - * Is called before the given entity is changed. - * - * @param entity target entity being changed - * @param externalSystemId id of the target external system which integration triggered project change - */ - void onChangeStart(@NotNull Object entity, @NotNull ProjectSystemId externalSystemId); - - /** - * Is called after the given entity has been changed. - * - * @param entity target entity that has been changed - * @param externalSystemId id of the target external system which integration triggered project change - */ - void onChangeEnd(@NotNull Object entity, @NotNull ProjectSystemId externalSystemId); -}