Skip to content

Commit c102b74

Browse files
authored
Refactor generated API post-processing (#291)
Reduce code duplication after #288. Also add `.kotlin` to .gitignore, a new compiler-internal dir from K2.
1 parent 8f6dc8a commit c102b74

File tree

2 files changed

+19
-39
lines changed

2 files changed

+19
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.gradle
2+
.kotlin
23
out
34
!*/src/**/out
45

build-logic/src/main/kotlin/com/gabrielfeo/task/PostProcessGeneratedApi.kt

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,47 +39,26 @@ abstract class PostProcessGeneratedApi @Inject constructor(
3939

4040
private fun postProcess(srcDir: File, modelsPackage: String) {
4141
// Replace Response<X> with X in every method return type of DevelocityApi.kt
42-
ant.withGroovyBuilder {
43-
"replaceregexp"(
44-
"match" to ": Response<(.*?)>$",
45-
"replace" to """: \1""",
46-
"flags" to "gm",
47-
) {
48-
"fileset"(
49-
"dir" to srcDir,
50-
"includes" to "com/gabrielfeo/develocity/api/*Api.kt",
51-
)
52-
}
53-
}
42+
replaceAll(
43+
match = ": Response<(.*?)>$",
44+
replace = """: \1""",
45+
dir = srcDir,
46+
includes = "com/gabrielfeo/develocity/api/*Api.kt",
47+
)
5448
// Add @JvmSuppressWildcards to avoid square/retrofit#3275
55-
ant.withGroovyBuilder {
56-
"replaceregexp"(
57-
"match" to "interface",
58-
"replace" to """
59-
@JvmSuppressWildcards
60-
interface
61-
""".trimIndent(),
62-
"flags" to "m",
63-
) {
64-
"fileset"(
65-
"dir" to srcDir,
66-
"includes" to "com/gabrielfeo/develocity/api/*Api.kt",
67-
)
68-
}
69-
}
49+
replaceAll(
50+
match = "interface",
51+
replace = "@JvmSuppressWildcards\ninterface",
52+
dir = srcDir,
53+
includes = "com/gabrielfeo/develocity/api/*Api.kt",
54+
)
7055
// Fix mapping of BuildModelName: gradle-attributes -> gradleAttributes
71-
ant.withGroovyBuilder {
72-
"replaceregexp"(
73-
"match" to "Minus",
74-
"replace" to "",
75-
"flags" to "mg",
76-
) {
77-
"fileset"(
78-
"dir" to srcDir,
79-
"includes" to "com/gabrielfeo/develocity/api/model/BuildModelName.kt",
80-
)
81-
}
82-
}
56+
replaceAll(
57+
match = "Minus",
58+
replace = "",
59+
dir = srcDir,
60+
includes = "com/gabrielfeo/develocity/api/model/BuildModelName.kt",
61+
)
8362
// Fix mapping of GradleConfigurationCacheResult.Outcome: hIT -> hit
8463
val file = "com/gabrielfeo/develocity/api/model/GradleConfigurationCacheResult.kt"
8564
replaceAll("hIT", "hit", dir = srcDir, includes = file)

0 commit comments

Comments
 (0)