Skip to content

Commit

Permalink
Upgrade semver checks and set dev version with new compiler plugin. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
terrakok committed Apr 26, 2024
1 parent bce5dec commit 0c886be
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
Expand Up @@ -35,10 +35,10 @@ internal fun Project.configureComposeCompilerPlugin() {
}
}

internal const val newCompilerIsAvailableVersion = "2.0.0-RC2"
internal const val newCompilerIsAvailableVersion = "2.0.0-RC2-238"
internal const val newComposeCompilerKotlinSupportPluginId = "org.jetbrains.kotlin.plugin.compose"
internal const val newComposeCompilerError =
"Since Kotlin $newCompilerIsAvailableVersion to use Compose Multiplatform " +
"Since Kotlin 2.0.0-RC2 to use Compose Multiplatform " +
"you must apply \"$newComposeCompilerKotlinSupportPluginId\" plugin." +
"\nSee the migration guide https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-compiler/compose-compiler.html#migrating-a-compose-multiplatform-project"

Expand Down
@@ -1,26 +1,47 @@
package org.jetbrains.compose.internal

import kotlin.math.min

internal data class Version(
val major: Int,
val minor: Int,
val patch: Int,
val meta: String
): Comparable<Version> {
) : Comparable<Version> {
override fun compareTo(other: Version): Int = when {
major != other.major -> major - other.major
minor != other.minor -> minor - other.minor
patch != other.patch -> patch - other.patch
else -> {
if (meta.isEmpty()) 1
else if (other.meta.isEmpty()) -1
else meta.compareTo(other.meta)
else {
val metaParts = meta.split("-")
val otherMetaParts = other.meta.split("-")

var result = 0
for (i in 0 until min(metaParts.size, otherMetaParts.size)) {
val metaPart = metaParts[i]
val otherMetaPart = otherMetaParts[i]
if (metaPart != otherMetaPart) {
result = metaPart.compareTo(otherMetaPart)
break
}
}
if (result != 0) result
else {
if (metaParts.size < otherMetaParts.size) 1
else if (metaParts.size > otherMetaParts.size) -1
else 0
}
}
}
}

companion object {
private val SEMVER_REGEXP = """^(\d+)(?:\.(\d*))?(?:\.(\d*))?(?:-(.*))?${'$'}""".toRegex()
fun fromString(versionString: String): Version {
val matchResult: MatchResult = SEMVER_REGEXP.matchEntire(versionString) ?: return Version(0,0,0, "")
val matchResult: MatchResult = SEMVER_REGEXP.matchEntire(versionString) ?: return Version(0, 0, 0, "")
val major: Int = matchResult.groups[1]?.value?.toInt() ?: 0
val minor: Int = matchResult.groups[2]?.value?.toInt() ?: 0
val patch: Int = matchResult.groups[3]?.value?.toInt() ?: 0
Expand Down
Expand Up @@ -49,15 +49,16 @@ class KotlinCompatibilityTest : GradlePluginTestBase() {
}
}

/* TODO uncomment the test when Kotlin RC2 will be published
@Test
fun testNewCompilerPluginError() {
// TODO replace by this after Kotlin 2.0 release
// testEnvironment = defaultTestEnvironment.copy(kotlinVersion = "2.0")
val testProject = testProject(
TestProjects.mpp,
testEnvironment = defaultTestEnvironment.copy(kotlinVersion = newCompilerIsAvailableVersion)
)
testProject.gradleFailure("tasks").checks {
check.logContains(newComposeCompilerError)
}
}*/
}
}
Expand Up @@ -15,5 +15,13 @@ class SemVerTest {
assert(Version.fromString("2.0.0-RC1") > Version.fromString("1.9.23"))
assert(Version.fromString("2.0.0") > Version.fromString("2.0.0-RC1"))
assert(Version.fromString("2.0.0-RC1") == Version.fromString("2.0.0-RC1"))
assert(Version.fromString("2.0.0-RC2") > Version.fromString("2.0.0-RC2-238"))
assert(Version.fromString("2.0.0-RC2-239") > Version.fromString("2.0.0-RC2-238"))
assert(Version.fromString("2.0.0-RC3-111") > Version.fromString("2.0.0-RC2-999"))
assert(Version.fromString("2.0.0-RC3-111") > Version.fromString("2.0.0-RC3-111-9"))
assert(Version.fromString("2.0.0-RC3-112-9") > Version.fromString("2.0.0-RC3-111-9"))
assert(Version.fromString("2.0.0") > Version.fromString("2.0.0-RC3-111-9"))
assert(Version.fromString("2.0.0-RC1") > Version.fromString("2.0.0--"))
assert(Version.fromString("2.0.0-RC3-112-9") == Version.fromString("2.0.0-RC3-112-9"))
}
}
Expand Up @@ -12,6 +12,9 @@ pluginManagement {
maven {
url 'https://maven.pkg.jetbrains.space/public/p/compose/dev'
}
maven {
url 'https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/'
}
}
}
dependencyResolutionManagement {
Expand All @@ -22,6 +25,9 @@ dependencyResolutionManagement {
maven {
url 'https://maven.pkg.jetbrains.space/public/p/compose/dev'
}
maven {
url 'https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/'
}
}
}
rootProject.name = "mpp"

0 comments on commit 0c886be

Please sign in to comment.