unused code removed

This commit is contained in:
nik
2013-08-30 13:36:54 +04:00
parent 4f49ed7570
commit b56c3aab7b
8 changed files with 4 additions and 462 deletions
@@ -32,10 +32,7 @@ public interface PlatformFacade {
@NotNull
Collection<Module> getModules(@NotNull Project project);
@NotNull
Collection<ModuleAwareContentRoot> getContentRoots(@NotNull Module module);
@NotNull
Collection<OrderEntry> getOrderEntries(@NotNull Module module);
@@ -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.
* <p/>
* 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);
}
@@ -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<ModuleAwareContentRoot> getContentRoots(@NotNull final Module module) {
final ContentEntry[] entries = ModuleRootManager.getInstance(module).getContentEntries();
if (entries == null) {
return Collections.emptyList();
}
List<ModuleAwareContentRoot> result = new ArrayList<ModuleAwareContentRoot>();
for (ContentEntry entry : entries) {
final VirtualFile file = entry.getFile();
if (file != null) {
result.add(new ModuleAwareContentRoot(module, entry));
}
}
return result;
}
@NotNull
@Override
public Collection<OrderEntry> getOrderEntries(@NotNull Module module) {
@@ -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<ContentRootData> 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);
@@ -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<ContentRootData, ModuleAwareContentRoot> {
public class ContentRootDataService implements ProjectDataService<ContentRootData, ContentEntry> {
private static final Logger LOG = Logger.getInstance("#" + ContentRootDataService.class.getName());
@@ -139,10 +138,7 @@ public class ContentRootDataService implements ProjectDataService<ContentRootDat
@NotNull
private static ContentEntry findOrCreateContentRoot(@NotNull ModifiableRootModel model, @NotNull String path) {
ContentEntry[] entries = model.getContentEntries();
if (entries == null) {
return model.addContentEntry(toVfsUrl(path));
}
for (ContentEntry entry : entries) {
VirtualFile file = entry.getFile();
if (file == null) {
@@ -172,11 +168,6 @@ public class ContentRootDataService implements ProjectDataService<ContentRootDat
private static void createExcludedRootIfAbsent(@NotNull ContentEntry entry, @NotNull String path, @NotNull String moduleName) {
ExcludeFolder[] folders = entry.getExcludeFolders();
if (folders == null) {
LOG.info(String.format("Importing excluded root '%s' for content root '%s' of module '%s'", path, entry.getUrl(), moduleName));
entry.addExcludeFolder(toVfsUrl(path));
return;
}
for (ExcludeFolder folder : folders) {
VirtualFile file = folder.getFile();
if (file == null) {
@@ -206,37 +197,7 @@ public class ContentRootDataService implements ProjectDataService<ContentRootDat
}
@Override
public void removeData(@NotNull Collection<? extends ModuleAwareContentRoot> toRemove, @NotNull Project project, boolean synchronous) {
Map<Module, Collection<ModuleAwareContentRoot>> byModule = ContainerUtilRt.newHashMap();
for (ModuleAwareContentRoot root : toRemove) {
Collection<ModuleAwareContentRoot> roots = byModule.get(root.getModule());
if (roots == null) {
byModule.put(root.getModule(), roots = ContainerUtilRt.newArrayList());
}
roots.add(root);
}
for (Map.Entry<Module, Collection<ModuleAwareContentRoot>> entry : byModule.entrySet()) {
doRemoveData(entry.getValue(), synchronous);
}
}
private static void doRemoveData(@NotNull final Collection<ModuleAwareContentRoot> 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<? extends ContentEntry> toRemove, @NotNull Project project, boolean synchronous) {
}
private static String toVfsUrl(@NotNull String path) {
@@ -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()
}
}
@@ -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() }
}
}
@@ -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
}
}