-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gradle] If KGP >= 2.0.0-RC1 new Compose gradle plugin has to be appl…
…ied. To throw a configuration error if it's not, and to fail the build
- Loading branch information
Showing
8 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/Version.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jetbrains.compose.internal | ||
|
||
internal data class Version( | ||
val major: Int, | ||
val minor: Int, | ||
val patch: Int, | ||
val meta: String | ||
): 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) | ||
} | ||
} | ||
|
||
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 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 | ||
val meta: String = matchResult.groups[4]?.value ?: "" | ||
return Version(major, minor, patch, meta) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/unit/SemVerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.jetbrains.compose.test.tests.unit | ||
|
||
import org.jetbrains.compose.internal.Version | ||
import kotlin.test.Test | ||
|
||
class SemVerTest { | ||
@Test | ||
fun testSemVersionParser() { | ||
assert(Version.fromString("0") < Version.fromString("1.2.3")) | ||
assert(Version.fromString("2") > Version.fromString("1.2.3")) | ||
assert(Version.fromString("1.1") > Version.fromString("1-abc")) | ||
assert(Version.fromString("1.1") > Version.fromString("1")) | ||
assert(Version.fromString("2.0.0-RC1") > Version.fromString("2.0.0-Beta5")) | ||
assert(Version.fromString("2.0.0-RC2") > Version.fromString("2.0.0-RC1")) | ||
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")) | ||
} | ||
} |