Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix [#38](https://github.com/bernaferrari/GradleKotlinConverter/issues/38) #42

Merged
merged 2 commits into from
Jun 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions gradlekotlinconverter.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if (!args.contains("skipintro")) {
println(intro)
}


var isInClipBoardMode = args.isEmpty()

val input = if (!isInClipBoardMode) args.first() else ""
Expand Down Expand Up @@ -420,15 +421,15 @@ fun String.addParentheses(): String {
// becomes
// id("io.gitlab.arturbosch.detekt") version "1.0.0.RC8"
fun String.addParenthesisToId(): String {

// this will only catch id "..." version ..., should skip id("...")
// should get the id "..."
val idExp = "id\\s*\".*?\"".toRegex()
val idExp = "(id)\\s*\"(.*?)\"".toRegex()

return this.replace(idExp) {
// remove the "id " before the real id
val idValue = it.value.replace("id\\s*".toRegex(), "")
"id($idValue)"
val (id, value) = it.destructured
"""$id("$value")"""
}
}

Expand All @@ -438,13 +439,14 @@ fun String.addParenthesisToId(): String {
// versionCode = 4
fun String.addEquals(): String {

val compileSdk = "compileSdk"
val signing = "keyAlias|keyPassword|storeFile|storePassword"
val other = "multiDexEnabled|correctErrorTypes|javaMaxHeapSize|jumboMode|dimension|useSupportLibrary"
val databinding = "dataBinding|viewBinding"
val defaultConfig = "applicationId|versionCode|versionName|testInstrumentationRunner"
val defaultConfig = "applicationId|minSdk|targetSdk|versionCode|versionName|testInstrumentationRunner"
val negativeLookAhead = "(?!\\{)[^\\s]" // Don't want '{' as next word character

val versionExp = """($defaultConfig|$signing|$other|$databinding)\s*${negativeLookAhead}.*""".toRegex()
val versionExp = """($compileSdk|$defaultConfig|$signing|$other|$databinding)\s*${negativeLookAhead}.*""".toRegex()

return this.replace(versionExp) {
val split = it.value.split(" ")
Expand Down