[imltogradle] Add additional check for absence of snapshot version in JpsLikeJarDependency

This commit is contained in:
Nikita Bobko
2021-08-10 14:22:11 +02:00
parent 493fdbd418
commit 784273ac5b
3 changed files with 15 additions and 4 deletions
@@ -26,6 +26,13 @@ data class JpsLikeJarDependency(
val dependencyConfiguration: String?,
val exported: Boolean
) : JpsLikeDependency {
init {
require(!dependencyNotation.contains(DEFAULT_KOTLIN_SNAPSHOT_VERSION)) {
"JpsLikeJarDependency dependency notation ($dependencyNotation) cannot contain Kotlin snapshot version. " +
"Most likely you want to configure JpsLikeModuleDependency"
}
}
override fun convertToGradleCall(): String {
val scopeArg = "JpsDepScope.$scope"
val exportedArg = "exported = true".takeIf { exported }
@@ -22,6 +22,7 @@ import kotlin.system.measureNanoTime
private lateinit var intellijModuleNameToGradleDependencyNotationsMapping: Map<String, List<GradleDependencyNotation>>
private val KOTLIN_REPO_ROOT = File(".").canonicalFile
val DEFAULT_KOTLIN_SNAPSHOT_VERSION = KOTLIN_REPO_ROOT.resolve("gradle.properties").readProperty("defaultSnapshotVersion")
private val INTELLIJ_REPO_ROOT = KOTLIN_REPO_ROOT.resolve("intellij").resolve("community").takeIf { it.exists() }
?: KOTLIN_REPO_ROOT.resolve("intellij")
@@ -63,10 +64,7 @@ fun main() {
}
.toList()
val ideaMajorVersion = KOTLIN_REPO_ROOT.resolve("local.properties").takeIf { it.exists() }
?.inputStream()
?.use { Properties().apply { load(it) }.getProperty("attachedIntellijVersion") }
?: error("Can't find 'attachedIntellijVersion' in 'local.properties'")
val ideaMajorVersion = KOTLIN_REPO_ROOT.resolve("local.properties").readProperty("attachedIntellijVersion")
intellijModuleNameToGradleDependencyNotationsMapping = fetchJsonsFromBuildserver(ideaMajorVersion)
.flatMap { jsonStr ->
@@ -18,6 +18,7 @@ import org.jetbrains.jps.model.module.JpsModuleDependency
import org.jetbrains.jps.model.serialization.JpsProjectLoader
import java.io.File
import java.net.URL
import java.util.*
fun String.trimMarginWithInterpolations(): String {
val regex = Regex("""^(\s*\|)(\s*).*$""")
@@ -98,3 +99,8 @@ fun fetchJsonsFromBuildserver(ideaMajorVersion: String): List<String> {
}
}
}
fun File.readProperty(propertyName: String): String {
return inputStream().use { Properties().apply { load(it) }.getProperty(propertyName) }
?: error("Can't find '$propertyName' in '${this.canonicalPath}'")
}