Last active
August 29, 2015 14:02
-
-
Save dkandalov/80d8d4f71bef54290a71 to your computer and use it in GitHub Desktop.
Find all transitive dependencies for modules in IDEA project (this is a mini plugin for https://github.com/dkandalov/live-plugin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.intellij.openapi.module.Module | |
import com.intellij.openapi.module.ModuleManager | |
import com.intellij.openapi.roots.CompilerModuleExtension | |
import com.intellij.openapi.roots.LibraryOrderEntry | |
import com.intellij.openapi.roots.ModifiableRootModel | |
import com.intellij.openapi.roots.ModuleRootManager | |
import com.intellij.openapi.roots.OrderRootType | |
import com.intellij.openapi.roots.libraries.Library | |
import com.intellij.openapi.roots.libraries.LibraryTable | |
import liveplugin.PluginUtil | |
import static liveplugin.PluginUtil.* | |
if (isIdeStartup) return | |
// Finds all transitive dependencies (modules and libraries) of specified modules in current project. | |
PluginUtil.runReadAction { | |
def moduleNames = ["openapi"] | |
def moduleManager = ModuleManager.getInstance(project) | |
def modules = moduleNames.collect{ moduleManager.findModuleByName(it) } | |
List<Module> dependantModules = [] | |
List<Library> dependantLibs = [] | |
while (!modules.empty) { | |
def module = modules.remove(0) | |
def rootManager = ModuleRootManager.getInstance(module) | |
dependantLibs.addAll(rootManager.orderEntries.findAll{ it instanceof LibraryOrderEntry }.collect{ it.library }) | |
dependantModules.add(module) | |
modules.addAll(rootManager.moduleDependencies.findAll{ !dependantModules.contains(it) }) | |
} | |
def moduleOutputPaths = dependantModules.collect{ CompilerModuleExtension.getInstance(it).compilerOutputPath.canonicalPath }.unique() | |
def libPaths = dependantLibs.collectAll{ it.getFiles(OrderRootType.CLASSES).collect{it.canonicalPath} }.flatten().unique() | |
show(moduleOutputPaths.join("\n")) | |
show(libPaths.join("\n")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment