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 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 {
|
||||
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)
|
||||
|
||||
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 {
|
||||
override fun invoke(file: File): String {
|
||||
if (!file.startsWith(project.rootDirectory)) {
|
||||
return file.absolutePath
|
||||
return simplifyUserHomeDirPath(file.absolutePath)
|
||||
}
|
||||
|
||||
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.noReflect.option("noReflect")
|
||||
kotlinCompileOptions.moduleName.option("moduleName")
|
||||
kotlinCompileOptions.languageVersion.option("languageVersion")
|
||||
kotlinCompileOptions.apiVersion.option("apiVersion")
|
||||
xml("option", "name" to "jvmTarget", "value" to platformVersion)
|
||||
kotlinCompileOptions.addCompilerBuiltIns.option("addCompilerBuiltIns")
|
||||
kotlinCompileOptions.loadBuiltInsFromDependencies.option("loadBuiltInsFromDependencies")
|
||||
kotlinCompileOptions.languageVersion.option("languageVersion")
|
||||
kotlinCompileOptions.apiVersion.option("apiVersion")
|
||||
|
||||
xml("option", "name" to "pluginOptions") { 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) {
|
||||
val dependency = orderRoot.dependency
|
||||
|
||||
var args = when (dependency) {
|
||||
is PDependency.ModuleLibrary -> arrayOf(
|
||||
val args = when (dependency) {
|
||||
is PDependency.ModuleLibrary -> mutableListOf(
|
||||
"type" to "module-library"
|
||||
)
|
||||
is PDependency.Module -> arrayOf(
|
||||
is PDependency.Module -> mutableListOf(
|
||||
"type" to "module",
|
||||
"module-name" to dependency.name
|
||||
)
|
||||
is PDependency.Library -> arrayOf(
|
||||
is PDependency.Library -> mutableListOf(
|
||||
"type" to "library",
|
||||
"name" to dependency.name,
|
||||
"level" to "project"
|
||||
)
|
||||
}
|
||||
|
||||
if (orderRoot.scope != POrderRoot.Scope.COMPILE) {
|
||||
args.add(1, "scope" to orderRoot.scope.toString())
|
||||
}
|
||||
|
||||
if (dependency is PDependency.Module && orderRoot.isProductionOnTestDependency) {
|
||||
args += ("production-on-test" to "")
|
||||
}
|
||||
|
||||
args += ("scope" to orderRoot.scope.toString())
|
||||
if (orderRoot.isExported) {
|
||||
args += ("exported" to "")
|
||||
}
|
||||
|
||||
xml("orderEntry", *args) {
|
||||
xml("orderEntry", *args.toTypedArray()) {
|
||||
if (dependency is PDependency.ModuleLibrary) {
|
||||
add(renderLibraryToXml(dependency.library, pathContext, named = false))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user