Skip to content

Commit f4793f2

Browse files
authored
Merge pull request #64 from bnorm/exclude-sourcesets
Allow excluding Kotlin source sets from transformation
2 parents ee05aaa + ee13709 commit f4793f2

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,33 @@ kotlinPowerAssert {
119119
}
120120
```
121121

122+
You can also exclude Gradle source sets from being transformed by the plugin,
123+
where those source sets can be specified by name.
124+
125+
```kotlin
126+
// Kotlin DSL
127+
configure<com.bnorm.power.PowerAssertGradleExtension> {
128+
excludedSourceSets = listOf(
129+
"commonMain",
130+
"jvmMain",
131+
"jsMain",
132+
"nativeMain"
133+
)
134+
}
135+
```
136+
137+
```groovy
138+
// Groovy
139+
kotlinPowerAssert {
140+
excludedSourceSets = [
141+
"commonMain",
142+
"jvmMain",
143+
"jsMain",
144+
"nativeMain"
145+
]
146+
}
147+
```
148+
122149
## Compatibility
123150

124151
The Kotlin compiler plugin API is unstable and each new version of Kotlin can

kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleExtension.kt

+1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ package com.bnorm.power
1818

1919
open class PowerAssertGradleExtension {
2020
var functions: List<String> = listOf("kotlin.assert")
21+
var excludedSourceSets: List<String> = listOf()
2122
}

kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ class PowerAssertGradlePlugin : KotlinCompilerPluginSupportPlugin {
2828
extensions.create("kotlinPowerAssert", PowerAssertGradleExtension::class.java)
2929
}
3030

31-
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true
31+
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean {
32+
val project = kotlinCompilation.target.project
33+
val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java)
34+
return extension.excludedSourceSets.none { it == kotlinCompilation.defaultSourceSet.name }
35+
}
3236

3337
override fun getCompilerPluginId(): String = "com.bnorm.kotlin-power-assert"
3438

sample/build.gradle.kts

+6
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,10 @@ configure<com.bnorm.power.PowerAssertGradleExtension> {
6666
"com.bnorm.power.assert",
6767
"com.bnorm.power.dbg"
6868
)
69+
excludedSourceSets = listOf(
70+
"commonMain",
71+
"jvmMain",
72+
"jsMain",
73+
"nativeMain"
74+
)
6975
}

sample/src/commonMain/kotlin/com/bnorm/power/Person.kt

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ data class Person(
2020
val firstName: String,
2121
val lastName: String,
2222
) {
23+
init {
24+
require(firstName.isNotBlank())
25+
require(lastName.isNotBlank())
26+
}
27+
2328
companion object {
2429
val UNKNOWN = listOf(Person("John", "Doe"), Person("Jane", "Doe"))
2530
override fun toString() = "Person.Companion"

sample/src/commonTest/kotlin/com/bnorm/power/PowerAssertTest.kt

+9
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ class PowerAssertTest {
6363
)
6464
}
6565

66+
@Test
67+
fun excludedRequire() {
68+
val error = assertFailsWith<IllegalArgumentException> { Person("", "") }
69+
assertEquals(
70+
actual = error.message,
71+
expected = "Failed requirement."
72+
)
73+
}
74+
6675
@Test
6776
fun softAssert() {
6877
val unknown: List<Person>? = Person.UNKNOWN

0 commit comments

Comments
 (0)