-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gradle] New Compose Compiler gradle plugin checks. (#4604)
If KGP >= 2.0.0-RC2 new Compose gradle plugin has to be applied. To throw a configuration error if it's not.
- Loading branch information
Showing
13 changed files
with
162 additions
and
32 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
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
32 changes: 32 additions & 0 deletions
32
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/internal/IdeaImportTask.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,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() | ||
} |
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
27 changes: 1 addition & 26 deletions
27
...e-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/GenerateResClassTask.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
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")) | ||
} | ||
} |