diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/service/project/PlatformFacade.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/service/project/PlatformFacade.java index 404c2091b8a4..75c1405c8ded 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/service/project/PlatformFacade.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/service/project/PlatformFacade.java @@ -32,10 +32,7 @@ public interface PlatformFacade { @NotNull Collection getModules(@NotNull Project project); - - @NotNull - Collection getContentRoots(@NotNull Module module); - + @NotNull Collection getOrderEntries(@NotNull Module module); diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/IdeEntityVisitor.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/IdeEntityVisitor.java deleted file mode 100644 index ca2e7d37ee09..000000000000 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/IdeEntityVisitor.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.intellij.openapi.externalSystem.util; - -import com.intellij.openapi.externalSystem.service.project.ModuleAwareContentRoot; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.LibraryOrderEntry; -import com.intellij.openapi.roots.ModuleOrderEntry; -import com.intellij.openapi.roots.libraries.Library; -import org.jetbrains.annotations.NotNull; - -/** - * Dispatch callback for intellij project entities. - *

- * Implementations of this interface are not obliged to be thread-safe. - * - * @author Denis Zhdanov - * @since 2/14/12 1:48 PM - */ -public interface IdeEntityVisitor { - - void visit(@NotNull Project project); - - void visit(@NotNull Module module); - - void visit(@NotNull ModuleAwareContentRoot contentRoot); - - void visit(@NotNull LibraryOrderEntry libraryDependency); - - void visit(@NotNull ModuleOrderEntry moduleDependency); - - void visit(@NotNull Library library); -} diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/PlatformFacadeImpl.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/PlatformFacadeImpl.java index 34aae4e025d4..d3875f949237 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/PlatformFacadeImpl.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/PlatformFacadeImpl.java @@ -4,7 +4,6 @@ import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.ContentEntry; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable; @@ -32,23 +31,6 @@ public class PlatformFacadeImpl implements PlatformFacade { return Arrays.asList(ModuleManager.getInstance(project).getModules()); } - @NotNull - @Override - public Collection getContentRoots(@NotNull final Module module) { - final ContentEntry[] entries = ModuleRootManager.getInstance(module).getContentEntries(); - if (entries == null) { - return Collections.emptyList(); - } - List result = new ArrayList(); - for (ContentEntry entry : entries) { - final VirtualFile file = entry.getFile(); - if (file != null) { - result.add(new ModuleAwareContentRoot(module, entry)); - } - } - return result; - } - @NotNull @Override public Collection getOrderEntries(@NotNull Module module) { diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/ProjectStructureHelper.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/ProjectStructureHelper.java index 60b14574f4ca..729d16d0d9fc 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/ProjectStructureHelper.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/ProjectStructureHelper.java @@ -1,8 +1,5 @@ package com.intellij.openapi.externalSystem.service.project; -import com.intellij.openapi.externalSystem.model.DataNode; -import com.intellij.openapi.externalSystem.model.ProjectKeys; -import com.intellij.openapi.externalSystem.model.project.ContentRootData; import com.intellij.openapi.externalSystem.model.project.LibraryData; import com.intellij.openapi.externalSystem.model.project.ModuleData; import com.intellij.openapi.externalSystem.model.project.ModuleDependencyData; @@ -49,25 +46,6 @@ public class ProjectStructureHelper { return null; } - @Nullable - public ModuleAwareContentRoot findIdeContentRoot(@NotNull DataNode node, @NotNull Project ideProject) { - ModuleData moduleData = node.getData(ProjectKeys.MODULE); - if (moduleData == null) { - return null; - } - final Module module = findIdeModule(moduleData.getName(), ideProject); - if (module == null) { - return null; - } - for (ModuleAwareContentRoot contentRoot : myFacade.getContentRoots(module)) { - final VirtualFile file = contentRoot.getFile(); - if (node.getData().getRootPath().equals(file.getPath())) { - return contentRoot; - } - } - return null; - } - @Nullable public Library findIdeLibrary(@NotNull final LibraryData library, @NotNull Project ideProject) { return findIdeLibrary(library.getName(), ideProject); 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 e1bca6a3e88f..13965b1f0c7c 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 @@ -7,7 +7,6 @@ import com.intellij.openapi.externalSystem.model.ProjectKeys; import com.intellij.openapi.externalSystem.model.project.ContentRootData; import com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType; import com.intellij.openapi.externalSystem.model.project.ModuleData; -import com.intellij.openapi.externalSystem.service.project.ModuleAwareContentRoot; import com.intellij.openapi.externalSystem.service.project.ProjectStructureHelper; import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.openapi.externalSystem.util.ExternalSystemConstants; @@ -34,7 +33,7 @@ import java.util.Set; * @since 2/7/12 3:20 PM */ @Order(ExternalSystemConstants.BUILTIN_SERVICE_ORDER) -public class ContentRootDataService implements ProjectDataService { +public class ContentRootDataService implements ProjectDataService { private static final Logger LOG = Logger.getInstance("#" + ContentRootDataService.class.getName()); @@ -139,10 +138,7 @@ public class ContentRootDataService implements ProjectDataService toRemove, @NotNull Project project, boolean synchronous) { - Map> byModule = ContainerUtilRt.newHashMap(); - for (ModuleAwareContentRoot root : toRemove) { - Collection roots = byModule.get(root.getModule()); - if (roots == null) { - byModule.put(root.getModule(), roots = ContainerUtilRt.newArrayList()); - } - roots.add(root); - } - for (Map.Entry> entry : byModule.entrySet()) { - doRemoveData(entry.getValue(), synchronous); - } - } - - private static void doRemoveData(@NotNull final Collection contentRoots, boolean synchronous) { - ExternalSystemApiUtil.executeProjectChangeAction(synchronous, new Runnable() { - @Override - public void run() { - for (ModuleAwareContentRoot contentRoot : contentRoots) { - final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(contentRoot.getModule()); - ModifiableRootModel model = moduleRootManager.getModifiableModel(); - try { - model.removeContentEntry(contentRoot); - LOG.info(String.format("Removing content root '%s' from module %s", contentRoot.getUrl(), contentRoot.getModule().getName())); - } - finally { - model.commit(); - } - } - } - }); + public void removeData(@NotNull Collection toRemove, @NotNull Project project, boolean synchronous) { } private static String toVfsUrl(@NotNull String path) { diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/AbstractProjectBuilder.groovy b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/AbstractProjectBuilder.groovy deleted file mode 100644 index 56b250450810..000000000000 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/AbstractProjectBuilder.groovy +++ /dev/null @@ -1,145 +0,0 @@ -package org.jetbrains.plugins.gradle.testutil - -import com.intellij.pom.java.LanguageLevel -import com.intellij.openapi.util.text.StringUtil -import com.intellij.openapi.roots.DependencyScope - -/** - * @author Denis Zhdanov - * @since 1/25/12 4:06 PM - */ -public abstract class AbstractProjectBuilder extends BuilderSupport { - - public static final def SAME_TOKEN = "same" - private static int COUNTER - - def project - - /** [module name; module] */ - def modules = [:] - - /** [module; content roots] */ - def contentRoots = [:].withDefault { [] } - - /** Holds (library name; library) pairs for the active configuration. */ - def libraries = [:] - - /** [module; dependency list] */ - def libraryDependencies = [:].withDefault { [] } - - /** [module; dependency list] */ - def moduleDependencies = [:].withDefault { [] } - - /** - * Holds (library name; library) pairs for the whole test. I.e. there is a possible case that we define particular configuration - * initially and the adjust it. We need to use the same library instance then in order to pass hashCode()/equals() checks then. - * This map works as a test-wide storage. - */ - def librariesCache = [:] - - /** [module name; module] */ - def modulesCache = [:] - - @Override - protected void setParent(Object parent, Object child) { - } - - @Override - protected Object createNode(Object name) { - createNode(name, [:]) - } - - @Override - protected Object createNode(Object name, Object value) { - createNode(name, [name: value]) - } - - @Override - protected Object createNode(Object name, Map attributes, Object value) { - createNode(name, [name: value] + attributes) - } - - @SuppressWarnings("GroovyUnusedCatchParameter") - @Override - protected Object createNode(name, Map attributes) { - switch (name) { - case "dependencies": return current // Assuming that 'current' is a module object - case "project": - clear() - return project = createProject(attributes.name?: same, attributes.langLevel?: LanguageLevel.JDK_1_6) - case "contentRoot": - def contentRoot = createContentRoot(current, attributes.name, attributes) - contentRoots[current] << contentRoot - return contentRoot - case "module": - case "library": - def n = StringUtil.capitalize(name) - if (current == project) { - // Not a dependency. - return "get$n"(attributes) - } - def ownerModule = current - def scope - try { - scope = DependencyScope.valueOf(attributes.scope.toUpperCase()) - } - catch (Exception e) { - scope = DependencyScope.COMPILE - } - boolean exported = attributes.exported - def dep = "create${n}Dependency"(ownerModule, "get$n"(attributes), scope, exported) - "get${n}Dependencies"()[ownerModule] << dep - return dep - } - } - - protected abstract def createProject(String name, LanguageLevel languageLevel) - protected abstract def createModule(String name) - protected abstract def registerModule(module) - protected abstract def createContentRoot(module, rootPath, Map paths) - protected abstract def createLibrary(String name, Map paths) - protected abstract def applyLibraryPaths(library, Map paths) - protected abstract def createLibraryDependency(module, library, scope, boolean exported) - protected abstract def createModuleDependency(ownerModule, targetModule, scope, boolean exported) - protected abstract def reset(); - - protected String getUnique() { "./${COUNTER++}" } - protected String getSame() { SAME_TOKEN } - - private def getModule(Map attributes) { - def name = attributes.name?: same - def result = modules[name] - if (result) return result - result = modulesCache[name] - if (result) { - registerModule(result) - } - else { - result = createModule(name) - modulesCache[name] = result - } - modules[name] = result - result - } - - private def getLibrary(Map attributes) { - def name = attributes.name?: same - def result = libraries[name] - if (result) return result - result = librariesCache[name] - if (result) { - applyLibraryPaths(result, attributes) - } - else { - result = createLibrary(name, attributes.withDefault { /* empty paths*/ [] }) - librariesCache[name] = result - } - libraries[name] = result - result - } - - private def clear() { - reset() - [modules, contentRoots, libraryDependencies, libraries, moduleDependencies]*.clear() - } -} diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/GradleProjectBuilder.groovy b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/GradleProjectBuilder.groovy deleted file mode 100644 index 1a188cd0e8e4..000000000000 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/GradleProjectBuilder.groovy +++ /dev/null @@ -1,82 +0,0 @@ -package org.jetbrains.plugins.gradle.testutil - -import com.intellij.openapi.externalSystem.model.project.ProjectData -import com.intellij.openapi.externalSystem.model.project.ModuleData -import com.intellij.openapi.externalSystem.model.project.LibraryDependencyData -import com.intellij.openapi.externalSystem.model.project.LibraryData -import com.intellij.openapi.externalSystem.model.project.LibraryPathType -import com.intellij.pom.java.LanguageLevel -import com.intellij.openapi.externalSystem.model.project.ModuleDependencyData -import com.intellij.openapi.externalSystem.model.project.ContentRootData - -/** - * @author Denis Zhdanov - * @since 1/25/12 1:29 PM - */ -class GradleProjectBuilder extends AbstractProjectBuilder { - - @Override - protected createProject(String name, LanguageLevel languageLevel) { - def result = new ProjectData(same, same, id) - result.name = name - result.languageLevel = languageLevel - result - } - - @Override - protected createModule(String name) { - registerModule(new ModuleData(name, unique)) - } - - @Override - protected registerModule(module) { - project.addModule(module) - module - } - - @Override - protected createContentRoot(module, rootPath, Map paths) { - def result = new ContentRootData(module, rootPath) - module.addContentRoot(result) - return result - } - - @Override - protected createModuleDependency(ownerModule, targetModule, scope, boolean exported) { - def result = new ModuleDependencyData(ownerModule, targetModule) - ownerModule.addDependency(result) - result.setScope(scope) - result.setExported(exported) - result - } - - @Override - protected createLibrary(String name, Map paths) { - def result = new LibraryData(name) - applyLibraryPaths(result, paths) - result - } - - @Override - protected createLibraryDependency(module, library, scope, boolean exported) { - def result = new LibraryDependencyData(module, library) - module.addDependency(result) - result.setScope(scope) - result.setExported(exported) - result - } - - @Override - protected applyLibraryPaths(library, Map paths) { - library.forgetAllPaths() - ['bin': LibraryPathType.BINARY, 'src': LibraryPathType.SOURCE, 'doc': LibraryPathType.DOC].each { - key, type -> paths[key]?.each { library.addPath(type, it) } - } - project.addLibrary(library) - } - - @Override - protected reset() { - modulesCache.values().each { it.clearDependencies(); it.clearContentRoots() } - } -} diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/IntellijProjectBuilder.groovy b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/IntellijProjectBuilder.groovy deleted file mode 100644 index 177dd782190a..000000000000 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testutil/IntellijProjectBuilder.groovy +++ /dev/null @@ -1,117 +0,0 @@ -package org.jetbrains.plugins.gradle.testutil - -import com.intellij.openapi.fileTypes.FileTypes -import com.intellij.openapi.module.Module -import com.intellij.openapi.project.Project -import com.intellij.openapi.roots.ContentEntry -import com.intellij.openapi.roots.LibraryOrderEntry -import com.intellij.openapi.roots.ModuleOrderEntry -import com.intellij.openapi.roots.OrderRootType -import com.intellij.openapi.roots.libraries.Library -import com.intellij.openapi.roots.libraries.LibraryTable -import com.intellij.openapi.util.IconLoader -import com.intellij.openapi.vfs.VirtualFile -import com.intellij.pom.java.LanguageLevel -import com.intellij.openapi.externalSystem.service.project.ModuleAwareContentRoot -import org.jetbrains.plugins.gradle.util.GradleUtil - -/** - * @author Denis Zhdanov - * @since 1/25/12 3:09 PM - */ -class IntellijProjectBuilder extends AbstractProjectBuilder { - - static def LIBRARY_ENTRY_TYPES = [(OrderRootType.CLASSES) : "bin", (OrderRootType.SOURCES) : "src"] - static VirtualFile[] DUMMY_VIRTUAL_FILE_ARRAY = new VirtualFile[0] - - def projectStub = [getName: { same }] - def project = projectStub as Project - - def projectLibraryTableStub = [ getLibraries: { libraries.values() as Library[] } ] - def projectLibraryTable = projectLibraryTableStub as LibraryTable - - def platformFacade = [ - getModules: { modules.values() }, - getOrderEntries: { libraryDependencies[it] + moduleDependencies[it] }, - getProjectIcon: { IconLoader.getIcon("/nodes/ideaProject.png") }, - getLocalFileSystemPath: { it.path }, - getProjectLibraryTable: { projectLibraryTable }, - getContentRoots: { contentRoots[it] } - ] - /** (library name - (library root type - paths)). */ - def libraryPaths = [:].withDefault { [:] } - - @Override - protected createProject(String name, LanguageLevel languageLevel) { - projectStub.getName = { name } - platformFacade.getLanguageLevel = { languageLevel } as Closure - project - } - - @Override - protected createModule(String name) { - [ getName: { name } ] as Module - } - - @Override - protected registerModule(Object module) { } - - @Override - protected createContentRoot(module, rootPath, Map paths) { - new ModuleAwareContentRoot(module, [ getFile: {asVirtualFile(rootPath)} ] as ContentEntry) - } - - @Override - protected createModuleDependency(ownerModule, targetModule, scope, boolean exported) { - def stub = [:] - def result = stub as ModuleOrderEntry - stub.accept = { policy, defaultValue -> policy.visitModuleOrderEntry(result, defaultValue) } - stub.getModule = { targetModule } - stub.getOwnerModule = { ownerModule } - stub.getModuleName = { targetModule.name } - stub.getScope = { scope } - stub.isExported = { exported } - result - } - - @Override - protected createLibrary(String name, Map paths) { - libraryPaths[name] = paths - [ - getName: { name }, - getPresentableName: { name }, - getFiles: { - type -> - (libraryPaths[name])[LIBRARY_ENTRY_TYPES[type]].findAll { it }.collect { asVirtualFile(it) }.toArray(DUMMY_VIRTUAL_FILE_ARRAY) - } - ] as Library - } - - @Override - protected createLibraryDependency(module, library, scope, boolean exported) { - def stub = [:] - def result = stub as LibraryOrderEntry - stub.accept = { policy, defaultValue -> policy.visitLibraryOrderEntry(result, defaultValue) } - stub.getLibraryName = { library.name } - stub.getLibrary = { library } - stub.getOwnerModule = { module } - stub.getScope = { scope } - stub.isExported = { exported } - result - } - - @Override - protected applyLibraryPaths(library, Map paths) { - libraryPaths[library.name] = paths - } - - @Override - protected reset() { } - - private static def asVirtualFile(path) { - [ - getPath: { GradleUtil.toCanonicalPath(path) }, - getFileType: { FileTypes.UNKNOWN } - ] as VirtualFile - } -}