Skip to content

Commit

Permalink
fix: update kotlin-editor for better parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
autonomousapps committed Nov 1, 2024
1 parent 76c81ca commit 49a9e82
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dagp = "1.30.0"
java = "11"
junit5 = "5.7.2"
kotlin = "1.9.24"
kotlinEditor = "0.6"
kotlinEditor = "0.8"
mavenPublish = "0.28.0"
moshi = "1.14.0"
retrofit = "2.9.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ final class FunctionalSpec extends Specification {
implementation(platform('com.squareup.okhttp3:okhttp-bom:4.10.0'))
implementation('com.squareup.okhttp3:okhttp:4.10.0')
implementation('com.squareup.okio:okio:3.2.0')
}
""".stripIndent()
}""".stripIndent()
}

def "can sort build.gradle"() {
Expand All @@ -80,8 +79,7 @@ final class FunctionalSpec extends Specification {
implementation(platform('com.squareup.okhttp3:okhttp-bom:4.10.0'))
implementation('com.squareup.okhttp3:okhttp:4.10.0')
implementation('com.squareup.okio:okio:3.2.0')
}
""".stripIndent()
}""".stripIndent()
}

def "can sort build.gradle.kts"() {
Expand All @@ -108,8 +106,37 @@ final class FunctionalSpec extends Specification {
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("com.squareup.okio:okio:3.2.0")
}""".stripIndent()
}

def "can sort build.gradle.kts with string property declaration"() {
given: 'A build script with unsorted dependencies'
def buildScript = dir.resolve('build.gradle.kts')
Files.writeString(buildScript, BUILD_SCRIPT_KTS_STRING)

when: 'We sort dependencies'
build(dir, 'sortDependencies')

then: 'Dependencies are sorted'
buildScript.text == """\
plugins {
`java-library`
id("com.squareup.sort-dependencies")
}
repositories {
mavenCentral()
maven { url = uri("$REPO") }
}
""".stripIndent()
val okhttp3 = "com.squareup.okhttp3:okhttp:4.10.0"
val okhttp3Bom = "com.squareup.okhttp3:okhttp-bom:4.10.0"
dependencies {
implementation(platform(okhttp3Bom))
implementation("com.squareup.okio:okio:3.2.0")
implementation(okhttp3)
}""".stripIndent()
}

def "can check sort order"() {
Expand Down Expand Up @@ -149,8 +176,7 @@ final class FunctionalSpec extends Specification {
'''
sortDependencies {
check false
}
'''.stripIndent(),
}'''.stripIndent(),
StandardOpenOption.APPEND
)

Expand Down Expand Up @@ -244,8 +270,7 @@ final class FunctionalSpec extends Specification {
implementation('com.squareup.okio:okio:3.2.0')
implementation('com.squareup.okhttp3:okhttp:4.10.0')
implementation(platform('com.squareup.okhttp3:okhttp-bom:4.10.0'))
}
""".stripIndent()
}""".stripIndent()

private String buildScriptWithVersion(String version) {
"""\
Expand All @@ -267,8 +292,7 @@ final class FunctionalSpec extends Specification {
implementation('com.squareup.okio:okio:3.2.0')
implementation('com.squareup.okhttp3:okhttp:4.10.0')
implementation(platform('com.squareup.okhttp3:okhttp-bom:4.10.0'))
}
""".stripIndent()
}""".stripIndent()
}

private static final BUILD_SCRIPT_KTS = """\
Expand All @@ -286,6 +310,25 @@ final class FunctionalSpec extends Specification {
implementation("com.squareup.okio:okio:3.2.0")
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))
}""".stripIndent()

private static final BUILD_SCRIPT_KTS_STRING = """\
plugins {
`java-library`
id("com.squareup.sort-dependencies")
}
repositories {
mavenCentral()
maven { url = uri("$REPO") }
}
""".stripIndent()
val okhttp3 = "com.squareup.okhttp3:okhttp:4.10.0"
val okhttp3Bom = "com.squareup.okhttp3:okhttp-bom:4.10.0"
dependencies {
implementation("com.squareup.okio:okio:3.2.0")
implementation(okhttp3)
implementation(platform(okhttp3Bom))
}""".stripIndent()
}

0 comments on commit 49a9e82

Please sign in to comment.