Skip to content

Commit

Permalink
Look for .api file in a case-insensitive manner
Browse files Browse the repository at this point in the history
Fixes #76
  • Loading branch information
qwwdfsad committed Apr 11, 2022
1 parent eb3d599 commit cccf209
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -89,6 +89,29 @@ internal class DefaultConfigTests : BaseKotlinGradleTest() {
}
}

@Test
fun `apiCheck should succeed when public classes match api file ignoring case`() {
val runner = test {
buildGradleKts {
resolve("examples/gradle/base/withPlugin.gradle.kts")
}
kotlin("AnotherBuildConfig.kt") {
resolve("examples/classes/AnotherBuildConfig.kt")
}
apiFile(projectName = rootProjectDir.name.toUpperCase()) {
resolve("examples/classes/AnotherBuildConfig.dump")
}

runner {
arguments.add(":apiCheck")
}
}

runner.build().apply {
assertTaskSuccess(":apiCheck")
}
}

@Test
fun `apiCheck should fail, when a public class is not in api-File`() {
val runner = test {
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/ApiCompareCompareTask.kt
Expand Up @@ -11,6 +11,7 @@ import org.gradle.api.file.*
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.*
import java.io.*
import java.util.TreeSet
import javax.inject.Inject

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

val subject = projectName
val apiBuildDirFiles = mutableSetOf<RelativePath>()
val expectedApiFiles = mutableSetOf<RelativePath>()
// We use case-insensitive comparison to workaround issues with case-insensitive OSes
// and Gradle behaving slightly different on different platforms
val expectedApiFiles = TreeSet<RelativePath> { rp, rp2 ->
rp.toString().compareTo(rp2.toString(), true)
}
objects.fileTree().from(apiBuildDir).visit { file ->
apiBuildDirFiles.add(file.relativePath)
}
Expand Down

0 comments on commit cccf209

Please sign in to comment.