Skip to content

Commit fc376fb

Browse files
authored
Look for .api file in a case-insensitive manner (#79)
Fixes #76
1 parent eb3d599 commit fc376fb

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/functionalTest/kotlin/kotlinx/validation/test/DefaultConfigTests.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,29 @@ internal class DefaultConfigTests : BaseKotlinGradleTest() {
8989
}
9090
}
9191

92+
@Test
93+
fun `apiCheck should succeed when public classes match api file ignoring case`() {
94+
val runner = test {
95+
buildGradleKts {
96+
resolve("examples/gradle/base/withPlugin.gradle.kts")
97+
}
98+
kotlin("AnotherBuildConfig.kt") {
99+
resolve("examples/classes/AnotherBuildConfig.kt")
100+
}
101+
apiFile(projectName = rootProjectDir.name.toUpperCase()) {
102+
resolve("examples/classes/AnotherBuildConfig.dump")
103+
}
104+
105+
runner {
106+
arguments.add(":apiCheck")
107+
}
108+
}
109+
110+
runner.build().apply {
111+
assertTaskSuccess(":apiCheck")
112+
}
113+
}
114+
92115
@Test
93116
fun `apiCheck should fail, when a public class is not in api-File`() {
94117
val runner = test {

src/main/kotlin/ApiCompareCompareTask.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.gradle.api.file.*
1111
import org.gradle.api.model.ObjectFactory
1212
import org.gradle.api.tasks.*
1313
import java.io.*
14+
import java.util.TreeSet
1415
import javax.inject.Inject
1516

1617
open class ApiCompareCompareTask @Inject constructor(private val objects: ObjectFactory): DefaultTask() {
@@ -53,7 +54,11 @@ open class ApiCompareCompareTask @Inject constructor(private val objects: Object
5354

5455
val subject = projectName
5556
val apiBuildDirFiles = mutableSetOf<RelativePath>()
56-
val expectedApiFiles = mutableSetOf<RelativePath>()
57+
// We use case-insensitive comparison to workaround issues with case-insensitive OSes
58+
// and Gradle behaving slightly different on different platforms
59+
val expectedApiFiles = TreeSet<RelativePath> { rp, rp2 ->
60+
rp.toString().compareTo(rp2.toString(), true)
61+
}
5762
objects.fileTree().from(apiBuildDir).visit { file ->
5863
apiBuildDirFiles.add(file.relativePath)
5964
}

0 commit comments

Comments
 (0)