Pill: Generate iml files more consistently with IDEA
This commit is contained in:
@@ -4,6 +4,20 @@ package org.jetbrains.kotlin.pill
|
|||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
private val USER_HOME_DIR_PATH = System.getProperty("user.home").withSlash()
|
||||||
|
|
||||||
|
private fun replacePrefix(path: String, prefix: String, variableName: String): String {
|
||||||
|
if (path.startsWith(prefix)) {
|
||||||
|
return "$" + variableName + "$/" + path.drop(prefix.length)
|
||||||
|
}
|
||||||
|
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun simplifyUserHomeDirPath(path: String): String {
|
||||||
|
return replacePrefix(path, USER_HOME_DIR_PATH, "USER_HOME")
|
||||||
|
}
|
||||||
|
|
||||||
interface PathContext {
|
interface PathContext {
|
||||||
operator fun invoke(file: File): String
|
operator fun invoke(file: File): String
|
||||||
|
|
||||||
@@ -22,14 +36,14 @@ class ProjectContext private constructor(private val projectDir: File) : PathCon
|
|||||||
constructor(project: Project) : this(project.projectDir)
|
constructor(project: Project) : this(project.projectDir)
|
||||||
|
|
||||||
override fun invoke(file: File): String {
|
override fun invoke(file: File): String {
|
||||||
return file.absolutePath.replace(projectDir.absolutePath, "\$PROJECT_DIR\$")
|
return simplifyUserHomeDirPath(replacePrefix(file.absolutePath, projectDir.absolutePath.withSlash(), "PROJECT_DIR"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ModuleContext(val project: PProject, val module: PModule) : PathContext {
|
class ModuleContext(val project: PProject, val module: PModule) : PathContext {
|
||||||
override fun invoke(file: File): String {
|
override fun invoke(file: File): String {
|
||||||
if (!file.startsWith(project.rootDirectory)) {
|
if (!file.startsWith(project.rootDirectory)) {
|
||||||
return file.absolutePath
|
return simplifyUserHomeDirPath(file.absolutePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return "\$MODULE_DIR\$/" + file.toRelativeString(module.moduleFile.parentFile)
|
return "\$MODULE_DIR\$/" + file.toRelativeString(module.moduleFile.parentFile)
|
||||||
|
|||||||
@@ -86,10 +86,11 @@ private fun renderModule(project: PProject, module: PModule) = PFile(
|
|||||||
kotlinCompileOptions.noStdlib.option("noStdlib")
|
kotlinCompileOptions.noStdlib.option("noStdlib")
|
||||||
kotlinCompileOptions.noReflect.option("noReflect")
|
kotlinCompileOptions.noReflect.option("noReflect")
|
||||||
kotlinCompileOptions.moduleName.option("moduleName")
|
kotlinCompileOptions.moduleName.option("moduleName")
|
||||||
kotlinCompileOptions.languageVersion.option("languageVersion")
|
xml("option", "name" to "jvmTarget", "value" to platformVersion)
|
||||||
kotlinCompileOptions.apiVersion.option("apiVersion")
|
|
||||||
kotlinCompileOptions.addCompilerBuiltIns.option("addCompilerBuiltIns")
|
kotlinCompileOptions.addCompilerBuiltIns.option("addCompilerBuiltIns")
|
||||||
kotlinCompileOptions.loadBuiltInsFromDependencies.option("loadBuiltInsFromDependencies")
|
kotlinCompileOptions.loadBuiltInsFromDependencies.option("loadBuiltInsFromDependencies")
|
||||||
|
kotlinCompileOptions.languageVersion.option("languageVersion")
|
||||||
|
kotlinCompileOptions.apiVersion.option("apiVersion")
|
||||||
|
|
||||||
xml("option", "name" to "pluginOptions") { xml("array") }
|
xml("option", "name" to "pluginOptions") { xml("array") }
|
||||||
xml("option", "name" to "pluginClasspaths") { xml("array") }
|
xml("option", "name" to "pluginClasspaths") { xml("array") }
|
||||||
@@ -134,31 +135,34 @@ private fun renderModule(project: PProject, module: PModule) = PFile(
|
|||||||
for (orderRoot in module.orderRoots) {
|
for (orderRoot in module.orderRoots) {
|
||||||
val dependency = orderRoot.dependency
|
val dependency = orderRoot.dependency
|
||||||
|
|
||||||
var args = when (dependency) {
|
val args = when (dependency) {
|
||||||
is PDependency.ModuleLibrary -> arrayOf(
|
is PDependency.ModuleLibrary -> mutableListOf(
|
||||||
"type" to "module-library"
|
"type" to "module-library"
|
||||||
)
|
)
|
||||||
is PDependency.Module -> arrayOf(
|
is PDependency.Module -> mutableListOf(
|
||||||
"type" to "module",
|
"type" to "module",
|
||||||
"module-name" to dependency.name
|
"module-name" to dependency.name
|
||||||
)
|
)
|
||||||
is PDependency.Library -> arrayOf(
|
is PDependency.Library -> mutableListOf(
|
||||||
"type" to "library",
|
"type" to "library",
|
||||||
"name" to dependency.name,
|
"name" to dependency.name,
|
||||||
"level" to "project"
|
"level" to "project"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (orderRoot.scope != POrderRoot.Scope.COMPILE) {
|
||||||
|
args.add(1, "scope" to orderRoot.scope.toString())
|
||||||
|
}
|
||||||
|
|
||||||
if (dependency is PDependency.Module && orderRoot.isProductionOnTestDependency) {
|
if (dependency is PDependency.Module && orderRoot.isProductionOnTestDependency) {
|
||||||
args += ("production-on-test" to "")
|
args += ("production-on-test" to "")
|
||||||
}
|
}
|
||||||
|
|
||||||
args += ("scope" to orderRoot.scope.toString())
|
|
||||||
if (orderRoot.isExported) {
|
if (orderRoot.isExported) {
|
||||||
args += ("exported" to "")
|
args += ("exported" to "")
|
||||||
}
|
}
|
||||||
|
|
||||||
xml("orderEntry", *args) {
|
xml("orderEntry", *args.toTypedArray()) {
|
||||||
if (dependency is PDependency.ModuleLibrary) {
|
if (dependency is PDependency.ModuleLibrary) {
|
||||||
add(renderLibraryToXml(dependency.library, pathContext, named = false))
|
add(renderLibraryToXml(dependency.library, pathContext, named = false))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user