-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapiComparison.gradle.kts
More file actions
51 lines (41 loc) · 1.85 KB
/
Copy pathapiComparison.gradle.kts
File metadata and controls
51 lines (41 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
tasks.register("compareSentinelApis") {
doFirst {
val sentinelApi = file("${project.rootDir}/sentinel/api/sentinel.api")
val noOpApi = file("${project.rootDir}/sentinel-no-op/api/sentinel-no-op.api")
if (!sentinelApi.exists() || !noOpApi.exists()) {
throw GradleException("API dump files not found. Run `apiDump` task first.")
}
val targetBlocks = listOf(
"public final class com/infinum/sentinel/Sentinel {",
"public final class com/infinum/sentinel/SentinelInitializer {",
"public abstract interface class com/infinum/sentinel/Sentinel\$Tool {"
)
fun extractRelevantLines(apiFile: File): Set<String> {
val relevantLines = mutableSetOf<String>()
var insideTargetBlock = false
apiFile.forEachLine { line ->
val trimmed = line.trim()
if (targetBlocks.contains(trimmed)) {
insideTargetBlock = true
}
if (insideTargetBlock) {
relevantLines.add(line)
}
if (trimmed.isEmpty()) {
insideTargetBlock = false
}
}
return relevantLines
}
val sentinelRelevant = extractRelevantLines(sentinelApi)
val noOpRelevant = extractRelevantLines(noOpApi)
val missingLines = sentinelRelevant - noOpRelevant
if (missingLines.isNotEmpty()) {
println("🚨 API mismatch detected! The following APIs in `Sentinel` are missing in `Sentinel no-op`:")
missingLines.forEach { println("❌ $it") }
throw GradleException("API mismatch detected between Sentinel and Sentinel no-op!")
} else {
println("✅ API is identical between Sentinel and Sentinel no-op!")
}
}
}