diff options
Diffstat (limited to 'platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java')
-rw-r--r-- | platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java | 134 |
1 files changed, 71 insertions, 63 deletions
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java index e0c52255fb58..60cc2411191d 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 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.service.project.manage; import com.intellij.openapi.diagnostic.Logger; @@ -18,11 +33,10 @@ import com.intellij.openapi.externalSystem.util.Order; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.*; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.util.Consumer; import com.intellij.util.containers.ContainerUtilRt; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; @@ -31,12 +45,10 @@ import org.jetbrains.jps.model.java.JavaSourceRootProperties; import org.jetbrains.jps.model.java.JavaSourceRootType; import org.jetbrains.jps.model.module.JpsModuleSourceRootType; -import java.io.File; import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Set; /** * Thread-safe. @@ -64,8 +76,7 @@ public class ContentRootDataService implements ProjectDataService<ContentRootDat @Override public void importData(@NotNull final Collection<DataNode<ContentRootData>> toImport, @NotNull final Project project, - boolean synchronous) - { + boolean synchronous) { if (toImport.isEmpty()) { return; } @@ -84,72 +95,69 @@ public class ContentRootDataService implements ProjectDataService<ContentRootDat } } - private static void importData(@NotNull final Collection<DataNode<ContentRootData>> datas, + private static void importData(@NotNull final Collection<DataNode<ContentRootData>> data, @NotNull final Module module, - boolean synchronous) - { + boolean synchronous) { ExternalSystemApiUtil.executeProjectChangeAction(synchronous, new DisposeAwareProjectChange(module) { @Override public void execute() { - final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); - final ModifiableRootModel model = moduleRootManager.getModifiableModel(); - final ContentEntry[] contentEntries = model.getContentEntries(); - final Map<String, ContentEntry> contentEntriesMap = ContainerUtilRt.newHashMap(); - for(ContentEntry contentEntry : contentEntries) { - contentEntriesMap.put(contentEntry.getUrl(), contentEntry); - } - - boolean createEmptyContentRootDirectories = false; - if (!datas.isEmpty()) { - ProjectSystemId projectSystemId = datas.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(); - } - } - - try { - for (final DataNode<ContentRootData> data : datas) { - final ContentRootData contentRoot = data.getData(); - - final ContentEntry contentEntry = findOrCreateContentRoot(model, contentRoot.getRootPath()); - contentEntry.clearExcludeFolders(); - contentEntry.clearSourceFolders(); - LOG.info(String.format("Importing content root '%s' for module '%s'", contentRoot.getRootPath(), module.getName())); - for (String path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE)) { - createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, false, createEmptyContentRootDirectories); - } - for (String path : contentRoot.getPaths(ExternalSystemSourceType.TEST)) { - createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, false, createEmptyContentRootDirectories); + ModuleRootModificationUtil.updateModel(module, new Consumer<ModifiableRootModel>() { + @Override + public void consume(ModifiableRootModel model) { + final ContentEntry[] contentEntries = model.getContentEntries(); + final Map<String, ContentEntry> contentEntriesMap = ContainerUtilRt.newHashMap(); + for(ContentEntry contentEntry : contentEntries) { + contentEntriesMap.put(contentEntry.getUrl(), contentEntry); } - for (String path : contentRoot.getPaths(ExternalSystemSourceType.RESOURCE)) { - createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.RESOURCE, false, createEmptyContentRootDirectories); - } - for (String path : contentRoot.getPaths(ExternalSystemSourceType.TEST_RESOURCE)) { - createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.TEST_RESOURCE, false, createEmptyContentRootDirectories); - } - for (String path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE_GENERATED)) { - createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, true, createEmptyContentRootDirectories); + + boolean createEmptyContentRootDirectories = false; + if (!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(); + } } - for (String path : contentRoot.getPaths(ExternalSystemSourceType.TEST_GENERATED)) { - createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, true, createEmptyContentRootDirectories); + + for (final DataNode<ContentRootData> node : data) { + final ContentRootData contentRoot = node.getData(); + + final ContentEntry contentEntry = findOrCreateContentRoot(model, contentRoot.getRootPath()); + contentEntry.clearExcludeFolders(); + contentEntry.clearSourceFolders(); + LOG.info(String.format("Importing content root '%s' for module '%s'", contentRoot.getRootPath(), module.getName())); + for (String path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE)) { + createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, false, createEmptyContentRootDirectories); + } + for (String path : contentRoot.getPaths(ExternalSystemSourceType.TEST)) { + createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, false, createEmptyContentRootDirectories); + } + for (String path : contentRoot.getPaths(ExternalSystemSourceType.RESOURCE)) { + createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.RESOURCE, false, createEmptyContentRootDirectories); + } + for (String path : contentRoot.getPaths(ExternalSystemSourceType.TEST_RESOURCE)) { + createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.TEST_RESOURCE, false, createEmptyContentRootDirectories); + } + for (String path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE_GENERATED)) { + createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, true, createEmptyContentRootDirectories); + } + for (String path : contentRoot.getPaths(ExternalSystemSourceType.TEST_GENERATED)) { + createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, true, createEmptyContentRootDirectories); + } + for (String path : contentRoot.getPaths(ExternalSystemSourceType.EXCLUDED)) { + createExcludedRootIfAbsent(contentEntry, path, module.getName()); + } + contentEntriesMap.remove(contentEntry.getUrl()); } - for (String path : contentRoot.getPaths(ExternalSystemSourceType.EXCLUDED)) { - createExcludedRootIfAbsent(contentEntry, path, module.getName()); + for(ContentEntry contentEntry : contentEntriesMap.values()) { + model.removeContentEntry(contentEntry); } - contentEntriesMap.remove(contentEntry.getUrl()); - } - for(ContentEntry contentEntry : contentEntriesMap.values()) { - model.removeContentEntry(contentEntry); } - } - finally { - model.commit(); - } + }); } }); } |