From bc78d2c41750a94ca2460d8f399a0ce9cc8414ef Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Fri, 16 Feb 2018 03:07:29 +0300 Subject: [PATCH] Pill: Move .iml files out of the module structure --- buildSrc/src/main/kotlin/pill/parser.kt | 25 +++++++++++++++++--- buildSrc/src/main/kotlin/pill/pathContext.kt | 7 +++++- buildSrc/src/main/kotlin/pill/plugin.kt | 5 ++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/buildSrc/src/main/kotlin/pill/parser.kt b/buildSrc/src/main/kotlin/pill/parser.kt index 066a618a057..f6dfe607023 100644 --- a/buildSrc/src/main/kotlin/pill/parser.kt +++ b/buildSrc/src/main/kotlin/pill/parser.kt @@ -25,6 +25,7 @@ data class PModule( val name: String, val bundleName: String, val rootDirectory: File, + val moduleFile: File, val contentRoots: List, val orderRoots: List, val moduleForProductionSources: PModule? = null, @@ -78,11 +79,15 @@ data class PLibrary( } fun parse(project: Project, context: ParserContext): PProject = with (context) { + if (project != project.rootProject) { + error("$project is not a root project") + } + val modules = project.allprojects .filter { it.plugins.hasPlugin(JpsCompatiblePlugin::class.java) } .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 { 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()) { continue } @@ -134,9 +146,10 @@ private fun ParserContext.parseModules(project: Project): List { } val module = PModule( - project.name + "." + nameSuffix, + project.name + nameSuffix, project.name, mainRoot.path, + getModuleFile(nameSuffix), roots, dependencies, productionSourcesModule @@ -149,10 +162,16 @@ private fun ParserContext.parseModules(project: Project): List { } } + val mainModuleFileRelativePath = when { + project == project.rootProject -> File(project.rootProject.projectDir, project.name + ".iml") + else -> getModuleFile() + } + modules += PModule( project.name, project.name, project.projectDir, + mainModuleFileRelativePath, listOf(PContentRoot(project.projectDir, false, emptyList(), allExcludedDirs)), if (modules.isEmpty()) parseDependencies(project, false) else emptyList() ) diff --git a/buildSrc/src/main/kotlin/pill/pathContext.kt b/buildSrc/src/main/kotlin/pill/pathContext.kt index a9a67fbd211..be1557a44b7 100644 --- a/buildSrc/src/main/kotlin/pill/pathContext.kt +++ b/buildSrc/src/main/kotlin/pill/pathContext.kt @@ -29,6 +29,11 @@ class ModuleContext(val project: PProject, val module: PModule) : PathContext { 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) } } \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/pill/plugin.kt b/buildSrc/src/main/kotlin/pill/plugin.kt index 57e551ef2c0..2962f239aa9 100644 --- a/buildSrc/src/main/kotlin/pill/plugin.kt +++ b/buildSrc/src/main/kotlin/pill/plugin.kt @@ -125,7 +125,7 @@ class JpsCompatibleRootPlugin : Plugin { val files = render(jpsProject, getProjectLibraries(jpsProject)) - removeExistingIdeaLibraries() + removeExistingIdeaLibrariesAndModules() removeJpsRunConfigurations() copyRunConfigurations() @@ -145,8 +145,9 @@ class JpsCompatibleRootPlugin : Plugin { removeJpsRunConfigurations() } - private fun removeExistingIdeaLibraries() { + private fun removeExistingIdeaLibrariesAndModules() { File(projectDir, ".idea/libraries").deleteRecursively() + File(projectDir, ".idea/modules").deleteRecursively() } private fun removeJpsRunConfigurations() {