Skip to content

Commit 97dfd29

Browse files
committed
try fixing case-sensitivity...
1 parent 7a51904 commit 97dfd29

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed

modules/bcv-gradle-plugin-functional-tests/src/functionalTest/kotlin/kotlinx/validation/test/MultipleJvmTargetsTest.kt

-9
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ internal class MultipleJvmTargetsTest : BaseKotlinGradleTest() {
5353

5454
runner.build {
5555
task(":apiCheck") shouldHaveOutcome SUCCESS
56-
// assertTaskSuccess(":jvmApiCheck")
57-
// assertTaskSuccess(":anotherJvmApiCheck")
5856
}
5957
}
6058

@@ -92,9 +90,6 @@ internal class MultipleJvmTargetsTest : BaseKotlinGradleTest() {
9290
}
9391

9492
runner.buildAndFail {
95-
// assertTaskNotRun(":apiCheck")
96-
// assertTaskFailure(":jvmApiCheck")
97-
// assertTaskFailure(":anotherJvmApiCheck")
9893
task(":apiCheck") shouldHaveOutcome FAILED
9994
output shouldContain "API check failed for project :testproject"
10095
shouldNotHaveRunTask(":check")
@@ -121,19 +116,15 @@ internal class MultipleJvmTargetsTest : BaseKotlinGradleTest() {
121116
}
122117
runner.build {
123118
task(":apiDump") shouldHaveOutcome SUCCESS
124-
// assertTaskSuccess(":jvmApiDump")
125-
// assertTaskSuccess(":anotherJvmApiDump")
126119

127120
System.err.println(output)
128121

129122
val anotherExpectedApi = readResourceFile("/examples/classes/Subsub1Class.dump")
130-
//assertThat(anotherApiDump.readText()).isEqualToIgnoringNewLines(anotherExpectedApi)
131123
anotherApiDump.shouldBeAFile()
132124
anotherApiDump.readText().invariantNewlines().shouldBe(anotherExpectedApi)
133125

134126
val mainExpectedApi =
135127
anotherExpectedApi + readResourceFile("/examples/classes/Subsub2Class.dump")
136-
//assertThat(jvmApiDump.readText()).isEqualToIgnoringNewLines(mainExpectedApi)
137128
jvmApiDump.shouldBeAFile()
138129
jvmApiDump.readText().invariantNewlines().shouldBe(mainExpectedApi)
139130
}

modules/bcv-gradle-plugin/src/main/kotlin/tasks/BCVApiCheckTask.kt

+40-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.github.difflib.UnifiedDiffUtils
55
import dev.adamko.kotlin.binary_compatibility_validator.internal.GradlePath
66
import dev.adamko.kotlin.binary_compatibility_validator.internal.fullPath
77
import java.io.*
8-
import java.util.TreeSet
8+
import java.util.TreeMap
99
import javax.inject.Inject
1010
import org.gradle.api.*
1111
import org.gradle.api.file.*
@@ -55,27 +55,31 @@ abstract class BCVApiCheckTask @Inject constructor(
5555
""".trimIndent()
5656
)
5757

58+
val apiBuildDir = apiBuildDir.get().asFile
59+
5860
val checkApiDeclarationPaths = projectApiDir.relativePathsOfContent { !isDirectory }
61+
val builtApiDeclarationPaths = apiBuildDir.relativePathsOfContent { !isDirectory }
5962
logger.info("checkApiDeclarationPaths: $checkApiDeclarationPaths")
6063

6164
checkApiDeclarationPaths.forEach { checkApiDeclarationPath ->
6265
logger.info("---------------------------")
6366
checkTarget(
6467
checkApiDeclaration = checkApiDeclarationPath.getFile(projectApiDir),
65-
builtApiDeclaration = checkApiDeclarationPath.getFile(apiBuildDir.get().asFile)
68+
// fetch the builtFile, using the case-insensitive map
69+
builtApiDeclaration = builtApiDeclarationPaths[checkApiDeclarationPath]?.getFile(apiBuildDir)
6670
)
6771
logger.info("---------------------------")
6872
}
6973
}
7074

7175
private fun checkTarget(
7276
checkApiDeclaration: File,
73-
builtApiDeclaration: File,
77+
builtApiDeclaration: File?,
7478
) {
7579
logger.info("checkApiDeclaration: $checkApiDeclaration")
7680
logger.info("builtApiDeclaration: $builtApiDeclaration")
7781

78-
val allBuiltFilePaths = builtApiDeclaration.parentFile.relativePathsOfContent()
82+
val allBuiltFilePaths = builtApiDeclaration?.parentFile.relativePathsOfContent()
7983
val allCheckFilePaths = checkApiDeclaration.parentFile.relativePathsOfContent()
8084

8185
logger.info("allBuiltPaths: $allBuiltFilePaths")
@@ -93,7 +97,7 @@ abstract class BCVApiCheckTask @Inject constructor(
9397

9498
val diff = compareFiles(
9599
checkFile = checkApiDeclaration,
96-
builtFile = builtApiDeclaration,
100+
builtFile = builtFilePath.getFile(builtApiDeclaration!!.parentFile!!),
97101
)
98102
val diffSet = mutableSetOf<String>()
99103
if (diff != null) diffSet.add(diff)
@@ -113,8 +117,8 @@ abstract class BCVApiCheckTask @Inject constructor(
113117
/** Get the relative paths of all files and folders inside a directory */
114118
private fun File?.relativePathsOfContent(
115119
filter: FileVisitDetails.() -> Boolean = { true },
116-
): TreeSet<RelativePath> {
117-
val contents = setOfRelativePaths()
120+
): RelativePaths {
121+
val contents = RelativePaths()
118122
if (this != null) {
119123
objects.fileTree().from(this).visit {
120124
if (filter()) contents += relativePath
@@ -145,16 +149,34 @@ abstract class BCVApiCheckTask @Inject constructor(
145149
}
146150

147151
companion object {
148-
/*
149-
* We use case-insensitive comparison to workaround issues with case-insensitive OSes
150-
* and Gradle behaving slightly different on different platforms.
151-
* We neither know original sensitivity of existing .api files, not
152-
* build ones, because projectName that is part of the path can have any sensitivity.
153-
* To work around that, we replace paths we are looking for the same paths that
154-
* actually exist on FS.
155-
*/
156-
private fun setOfRelativePaths() = TreeSet<RelativePath> { rp1, rp2 ->
157-
rp1.toString().compareTo(rp2.toString(), true)
158-
}
152+
// private fun setOfRelativePaths() = TreeSet<RelativePath> { rp1, rp2 ->
153+
// rp1.toString().compareTo(rp2.toString(), true)
154+
// }
155+
}
156+
}
157+
158+
/*
159+
* We use case-insensitive comparison to workaround issues with case-insensitive OSes
160+
* and Gradle behaving slightly different on different platforms.
161+
* We neither know original sensitivity of existing .api files, not
162+
* build ones, because projectName that is part of the path can have any sensitivity.
163+
* To work around that, we replace paths we are looking for the same paths that
164+
* actually exist on FS.
165+
*/
166+
private class RelativePaths(
167+
private val map: TreeMap<RelativePath, RelativePath> = caseInsensitiveMap()
168+
) : Set<RelativePath> by map.keys {
169+
170+
operator fun plusAssign(path: RelativePath) {
171+
map[path] = path
172+
}
173+
174+
operator fun get(path: RelativePath): RelativePath? = map[path]
175+
176+
companion object {
177+
private fun caseInsensitiveMap() =
178+
TreeMap<RelativePath, RelativePath> { path1, path2 ->
179+
path1.toString().compareTo(path2.toString(), true)
180+
}
159181
}
160182
}

0 commit comments

Comments
 (0)