Pill: Move .iml files out of the module structure

This commit is contained in:
Yan Zhulanow
2018-02-16 03:07:29 +03:00
parent 4c12a4cb11
commit bc78d2c417
3 changed files with 31 additions and 6 deletions
+22 -3
View File
@@ -25,6 +25,7 @@ data class PModule(
val name: String, val name: String,
val bundleName: String, val bundleName: String,
val rootDirectory: File, val rootDirectory: File,
val moduleFile: File,
val contentRoots: List<PContentRoot>, val contentRoots: List<PContentRoot>,
val orderRoots: List<POrderRoot>, val orderRoots: List<POrderRoot>,
val moduleForProductionSources: PModule? = null, val moduleForProductionSources: PModule? = null,
@@ -78,11 +79,15 @@ data class PLibrary(
} }
fun parse(project: Project, context: ParserContext): PProject = with (context) { fun parse(project: Project, context: ParserContext): PProject = with (context) {
if (project != project.rootProject) {
error("$project is not a root project")
}
val modules = project.allprojects val modules = project.allprojects
.filter { it.plugins.hasPlugin(JpsCompatiblePlugin::class.java) } .filter { it.plugins.hasPlugin(JpsCompatiblePlugin::class.java) }
.flatMap { parseModules(it) } .flatMap { parseModules(it) }
return PProject("Kotlin", project.rootProject.projectDir, modules, emptyList()) return PProject("Kotlin", project.projectDir, modules, emptyList())
} }
/* /*
@@ -120,7 +125,14 @@ private fun ParserContext.parseModules(project: Project): List<PModule> {
var productionSourcesModule: PModule? = null var productionSourcesModule: PModule? = null
for ((nameSuffix, roots) in mapOf("src" to productionContentRoots, "test" to testContentRoots)) { fun getModuleFile(suffix: String = ""): File {
val relativePath = File(project.projectDir, project.name + suffix + ".iml")
.toRelativeString(project.rootProject.projectDir)
return File(project.rootProject.projectDir, ".idea/modules/$relativePath")
}
for ((nameSuffix, roots) in mapOf(".src" to productionContentRoots, ".test" to testContentRoots)) {
if (roots.isEmpty()) { if (roots.isEmpty()) {
continue continue
} }
@@ -134,9 +146,10 @@ private fun ParserContext.parseModules(project: Project): List<PModule> {
} }
val module = PModule( val module = PModule(
project.name + "." + nameSuffix, project.name + nameSuffix,
project.name, project.name,
mainRoot.path, mainRoot.path,
getModuleFile(nameSuffix),
roots, roots,
dependencies, dependencies,
productionSourcesModule productionSourcesModule
@@ -149,10 +162,16 @@ private fun ParserContext.parseModules(project: Project): List<PModule> {
} }
} }
val mainModuleFileRelativePath = when {
project == project.rootProject -> File(project.rootProject.projectDir, project.name + ".iml")
else -> getModuleFile()
}
modules += PModule( modules += PModule(
project.name, project.name,
project.name, project.name,
project.projectDir, project.projectDir,
mainModuleFileRelativePath,
listOf(PContentRoot(project.projectDir, false, emptyList(), allExcludedDirs)), listOf(PContentRoot(project.projectDir, false, emptyList(), allExcludedDirs)),
if (modules.isEmpty()) parseDependencies(project, false) else emptyList() if (modules.isEmpty()) parseDependencies(project, false) else emptyList()
) )
+6 -1
View File
@@ -29,6 +29,11 @@ class ModuleContext(val project: PProject, val module: PModule) : PathContext {
return file.absolutePath return file.absolutePath
} }
return "\$MODULE_DIR\$/" + file.toRelativeString(module.rootDirectory) fun String.withSlash() = if (this.endsWith("/")) this else (this + "/")
return "\$MODULE_DIR\$/" +
project.rootDirectory.toRelativeString(module.moduleFile.parentFile).withSlash() +
module.rootDirectory.toRelativeString(project.rootDirectory).withSlash() +
file.toRelativeString(module.rootDirectory)
} }
} }
+3 -2
View File
@@ -125,7 +125,7 @@ class JpsCompatibleRootPlugin : Plugin<Project> {
val files = render(jpsProject, getProjectLibraries(jpsProject)) val files = render(jpsProject, getProjectLibraries(jpsProject))
removeExistingIdeaLibraries() removeExistingIdeaLibrariesAndModules()
removeJpsRunConfigurations() removeJpsRunConfigurations()
copyRunConfigurations() copyRunConfigurations()
@@ -145,8 +145,9 @@ class JpsCompatibleRootPlugin : Plugin<Project> {
removeJpsRunConfigurations() removeJpsRunConfigurations()
} }
private fun removeExistingIdeaLibraries() { private fun removeExistingIdeaLibrariesAndModules() {
File(projectDir, ".idea/libraries").deleteRecursively() File(projectDir, ".idea/libraries").deleteRecursively()
File(projectDir, ".idea/modules").deleteRecursively()
} }
private fun removeJpsRunConfigurations() { private fun removeJpsRunConfigurations() {