Browse Source
If KGP >= 2.0.0-RC2 new Compose gradle plugin has to be applied. To throw a configuration error if it's not.pull/4705/head
Konstantin
7 months ago
committed by
GitHub
13 changed files with 162 additions and 32 deletions
@ -0,0 +1,32 @@
|
||||
package org.jetbrains.compose.internal |
||||
|
||||
import org.gradle.api.DefaultTask |
||||
import org.gradle.api.Project |
||||
import org.gradle.api.provider.Provider |
||||
import org.gradle.api.tasks.Input |
||||
import org.gradle.api.tasks.TaskAction |
||||
|
||||
internal fun Project.ideaIsInSyncProvider(): Provider<Boolean> = provider { |
||||
System.getProperty("idea.sync.active", "false").toBoolean() |
||||
} |
||||
|
||||
/** |
||||
* This task should be FAST and SAFE! Because it is being run during IDE import. |
||||
*/ |
||||
internal abstract class IdeaImportTask : DefaultTask() { |
||||
@get:Input |
||||
val ideaIsInSync: Provider<Boolean> = project.ideaIsInSyncProvider() |
||||
|
||||
@TaskAction |
||||
fun run() { |
||||
try { |
||||
safeAction() |
||||
} catch (e: Exception) { |
||||
//message must contain two ':' symbols to be parsed by IDE UI! |
||||
logger.error("e: $name task was failed:", e) |
||||
if (!ideaIsInSync.get()) throw e |
||||
} |
||||
} |
||||
|
||||
abstract fun safeAction() |
||||
} |
@ -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) |
||||
} |
||||
} |
||||
} |
@ -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")) |
||||
} |
||||
} |
Loading…
Reference in new issue