File tree Expand file tree Collapse file tree 6 files changed +52
-4
lines changed
main/kotlin/com/squareup/sort
test/groovy/com/squareup/sort Expand file tree Collapse file tree 6 files changed +52
-4
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ dagp = "1.30.0"
4
4
java = " 11"
5
5
junit5 = " 5.7.2"
6
6
kotlin = " 1.9.24"
7
- kotlinEditor = " 0.4 "
7
+ kotlinEditor = " 0.5 "
8
8
mavenPublish = " 0.28.0"
9
9
moshi = " 1.14.0"
10
10
retrofit = " 2.9.0"
Original file line number Diff line number Diff line change @@ -28,12 +28,17 @@ internal class DependencyComparator : Comparator<DependencyDeclaration> {
28
28
right : DependencyDeclaration ,
29
29
): Int {
30
30
if (left.isProjectDependency() && right.isProjectDependency()) return compareDependencies(
31
- left,
32
- right
31
+ left, right
33
32
)
34
33
if (left.isProjectDependency()) return - 1
35
34
if (right.isProjectDependency()) return 1
36
35
36
+ if (left.isGradleDistributionDependency() && right.isGradleDistributionDependency()) return compareDependencies(
37
+ left, right
38
+ )
39
+ if (left.isGradleDistributionDependency()) return - 1
40
+ if (right.isGradleDistributionDependency()) return 1
41
+
37
42
if (left.isFileDependency() && right.isFileDependency()) return compareDependencies(left, right)
38
43
if (left.isFileDependency()) return - 1
39
44
if (right.isFileDependency()) return - 1
Original file line number Diff line number Diff line change @@ -8,7 +8,11 @@ internal interface DependencyDeclaration {
8
8
fun isPlatformDeclaration (): Boolean
9
9
fun isTestFixturesDeclaration (): Boolean
10
10
11
+ /* * TODO(tsr): what about files and fileTree? */
11
12
fun isFileDependency (): Boolean
13
+
14
+ fun isGradleDistributionDependency (): Boolean
15
+
12
16
fun isProjectDependency (): Boolean
13
17
14
18
/* *
Original file line number Diff line number Diff line change @@ -47,9 +47,13 @@ internal class GroovyDependencyDeclaration(
47
47
override fun isPlatformDeclaration () = declarationKind == DeclarationKind .PLATFORM
48
48
override fun isTestFixturesDeclaration () = declarationKind == DeclarationKind .TEST_FIXTURES
49
49
50
- override fun isProjectDependency () = dependencyKind == DependencyKind .PROJECT
51
50
override fun isFileDependency () = dependencyKind == DependencyKind .FILE
52
51
52
+ /* * TODO(tsr): implement DependencyKind.GRADLE_DISTRIBUTION */
53
+ override fun isGradleDistributionDependency (): Boolean = false
54
+
55
+ override fun isProjectDependency () = dependencyKind == DependencyKind .PROJECT
56
+
53
57
override fun hasQuotes (): Boolean {
54
58
val i = declaration.children.indexOf(dependency)
55
59
return declaration.getChild(i - 1 ) is QuoteContext && declaration.getChild(i + 1 ) is QuoteContext
Original file line number Diff line number Diff line change @@ -27,6 +27,10 @@ internal class KotlinDependencyDeclaration(
27
27
return base.type == Type .FILE
28
28
}
29
29
30
+ override fun isGradleDistributionDependency (): Boolean {
31
+ return base.type == Type .GRADLE_DISTRIBUTION
32
+ }
33
+
30
34
override fun isProjectDependency (): Boolean {
31
35
return base.type == Type .PROJECT
32
36
}
Original file line number Diff line number Diff line change @@ -115,6 +115,37 @@ class KotlinSorterSpec extends Specification {
115
115
)). inOrder()
116
116
}
117
117
118
+ def "can sort build script with gradleApi () dep" () {
119
+ given:
120
+ def buildScript = dir.resolve('build.gradle.kts')
121
+ Files.writeString(buildScript,
122
+ '''\
123
+ dependencies {
124
+ implementation(" heart :of- gold :1.0 " )
125
+ api(project(" :marvin" ))
126
+
127
+ implementation(" sad :robot :1.0 " )
128
+ api(gradleApi())
129
+ implementation(testFixtures(libs.magic))
130
+ implementation(platform(project(" :platform" )))
131
+ }'''.stripIndent())
132
+ def sorter = KotlinSorter.of(buildScript)
133
+
134
+ expect:
135
+ assertThat(trimmedLinesOf(sorter.rewritten())).containsExactlyElementsIn(trimmedLinesOf(
136
+ '''\
137
+ dependencies {
138
+ api(project(" :marvin" ))
139
+ api(gradleApi())
140
+
141
+ implementation(platform(project(" :platform" )))
142
+ implementation(testFixtures(libs.magic))
143
+ implementation(" heart :of- gold :1.0 " )
144
+ implementation(" sad :robot :1.0 " )
145
+ }'''.stripIndent()
146
+ )).inOrder()
147
+ }
148
+
118
149
def " can sort build script with four- space tabs" () {
119
150
given:
120
151
def buildScript = dir.resolve('build.gradle.kts')
You can’t perform that action at this time.
0 commit comments