Skip to content

Commit 262a2ac

Browse files
RBusarowkodiakhq[bot]
authored andcommitted
consolidated tree traversal and tree printing logic
1 parent e15bbdc commit 262a2ac

File tree

55 files changed

+1191
-317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1191
-317
lines changed

artifacts.json

+8
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,14 @@
279279
"packaging": "jar",
280280
"javaVersion": "11"
281281
},
282+
{
283+
"gradlePath": ":modulecheck-utils:traversal",
284+
"group": "com.rickbusarow.modulecheck",
285+
"artifactId": "modulecheck-utils-traversal",
286+
"description": "Fast dependency graph linting for Gradle projects",
287+
"packaging": "jar",
288+
"javaVersion": "11"
289+
},
282290
{
283291
"gradlePath": ":modulecheck-gradle:platforms:api",
284292
"group": "com.rickbusarow.modulecheck",

build-logic/artifacts-check/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ dependencies {
4242

4343
api(libs.square.moshi)
4444

45-
api(project(path = ":core"))
46-
4745
compileOnly(gradleApi())
4846

4947
compileOnly(libs.kotlin.gradle.plugin)
@@ -61,5 +59,7 @@ dependencies {
6159
implementation(libs.kotlin.stdlib.jdk8)
6260
implementation(libs.kotlinx.knit)
6361

62+
implementation(project(path = ":core"))
63+
6464
ksp(libs.square.moshi.codegen)
6565
}

build-logic/mcbuild/build.gradle.kts

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ dependencies {
4545

4646
api(libs.square.moshi)
4747

48-
api(project(path = ":artifacts-check"))
4948
api(project(path = ":conventions"))
5049
api(project(path = ":versions-matrix"))
5150

@@ -72,5 +71,7 @@ dependencies {
7271
implementation(libs.square.kotlinPoet)
7372
implementation(libs.vanniktech.publish)
7473

74+
implementation(project(path = ":artifacts-check"))
75+
7576
ksp(libs.square.moshi.codegen)
7677
}

dependency-guard-aggregate.txt

+10
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,16 @@
984984
:modulecheck-utils:trace-testing -- runtimeClasspath -- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4
985985
:modulecheck-utils:trace-testing -- runtimeClasspath -- org.jetbrains:annotations:13.0
986986

987+
:modulecheck-utils:traversal -- runtimeClasspath -- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.20
988+
:modulecheck-utils:traversal -- runtimeClasspath -- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.20
989+
:modulecheck-utils:traversal -- runtimeClasspath -- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20
990+
:modulecheck-utils:traversal -- runtimeClasspath -- org.jetbrains.kotlin:kotlin-stdlib:1.8.20
991+
:modulecheck-utils:traversal -- runtimeClasspath -- org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.4
992+
:modulecheck-utils:traversal -- runtimeClasspath -- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4
993+
:modulecheck-utils:traversal -- runtimeClasspath -- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4
994+
:modulecheck-utils:traversal -- runtimeClasspath -- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.6.4
995+
:modulecheck-utils:traversal -- runtimeClasspath -- org.jetbrains:annotations:13.0
996+
987997
:modulecheck-gradle:platforms:api -- runtimeClasspath -- javax.inject:javax.inject:1
988998
:modulecheck-gradle:platforms:api -- runtimeClasspath -- net.java.dev.jna:jna:5.6.0
989999
:modulecheck-gradle:platforms:api -- runtimeClasspath -- net.swiftzer.semver:semver:1.2.0

modulecheck-finding/api/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ dependencies {
2929
api(project(path = ":modulecheck-model:dependency:api"))
3030
api(project(path = ":modulecheck-parsing:gradle:dsl:api"))
3131
api(project(path = ":modulecheck-project:api"))
32-
api(project(path = ":modulecheck-utils:lazy"))
3332

3433
implementation(project(path = ":modulecheck-parsing:gradle:dsl:precompiled"))
34+
implementation(project(path = ":modulecheck-utils:lazy"))
3535
implementation(project(path = ":modulecheck-utils:stdlib"))
3636

3737
testImplementation(libs.bundles.hermit)

modulecheck-finding/impl-android/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ dependencies {
2828
api(project(path = ":modulecheck-finding:api"))
2929
api(project(path = ":modulecheck-finding:name"))
3030
api(project(path = ":modulecheck-model:dependency:api"))
31-
api(project(path = ":modulecheck-parsing:gradle:dsl:api"))
3231
api(project(path = ":modulecheck-project:api"))
33-
api(project(path = ":modulecheck-utils:lazy"))
3432

33+
implementation(project(path = ":modulecheck-parsing:gradle:dsl:api"))
34+
implementation(project(path = ":modulecheck-utils:lazy"))
3535
implementation(project(path = ":modulecheck-utils:stdlib"))
3636

3737
testImplementation(libs.bundles.hermit)

modulecheck-finding/impl-sort/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ dependencies {
3030
api(project(path = ":modulecheck-model:dependency:api"))
3131
api(project(path = ":modulecheck-parsing:gradle:dsl:api"))
3232
api(project(path = ":modulecheck-project:api"))
33-
api(project(path = ":modulecheck-utils:lazy"))
3433

34+
implementation(project(path = ":modulecheck-utils:lazy"))
3535
implementation(project(path = ":modulecheck-utils:stdlib"))
3636

3737
testImplementation(libs.bundles.hermit)

modulecheck-finding/impl/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ dependencies {
3030
api(project(path = ":modulecheck-model:dependency:api"))
3131
api(project(path = ":modulecheck-parsing:gradle:dsl:api"))
3232
api(project(path = ":modulecheck-project:api"))
33-
api(project(path = ":modulecheck-utils:lazy"))
3433

3534
implementation(project(path = ":modulecheck-parsing:gradle:dsl:precompiled"))
35+
implementation(project(path = ":modulecheck-utils:lazy"))
3636
implementation(project(path = ":modulecheck-utils:stdlib"))
3737

3838
testImplementation(libs.bundles.hermit)

modulecheck-gradle/platforms/api/build.gradle.kts

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ dependencies {
3030
api(libs.kotlin.compiler)
3131
api(libs.semVer)
3232

33-
api(project(path = ":modulecheck-dagger"))
3433
api(project(path = ":modulecheck-model:dependency:api"))
3534
api(project(path = ":modulecheck-model:sourceset:api"))
3635
api(project(path = ":modulecheck-parsing:gradle:model:api"))
@@ -47,6 +46,8 @@ dependencies {
4746

4847
implementation(libs.kotlin.reflect)
4948

49+
implementation(project(path = ":modulecheck-dagger"))
50+
5051
testImplementation(libs.bundles.hermit)
5152
testImplementation(libs.bundles.junit)
5253
testImplementation(libs.bundles.kotest)

modulecheck-gradle/platforms/impl/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ dependencies {
2828

2929
api(libs.javax.inject)
3030

31-
api(project(path = ":modulecheck-dagger"))
3231
api(project(path = ":modulecheck-gradle:platforms:api"))
3332
api(project(path = ":modulecheck-model:dependency:api"))
3433
api(project(path = ":modulecheck-parsing:gradle:model:api"))
@@ -38,6 +37,7 @@ dependencies {
3837
compileOnly(libs.kotlin.gradle.plugin)
3938
compileOnly(libs.kotlin.gradle.plugin.api)
4039

40+
implementation(project(path = ":modulecheck-dagger"))
4141
implementation(project(path = ":modulecheck-utils:stdlib"))
4242

4343
testImplementation(libs.bundles.hermit)

modulecheck-gradle/platforms/internal-android/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ dependencies {
3636

3737
api(libs.javax.inject)
3838

39-
api(project(path = ":modulecheck-dagger"))
4039
api(project(path = ":modulecheck-gradle:platforms:api"))
4140
api(project(path = ":modulecheck-model:dependency:api"))
4241
api(project(path = ":modulecheck-model:sourceset:api"))
@@ -54,6 +53,7 @@ dependencies {
5453

5554
implementation(libs.kotlin.compiler)
5655

56+
implementation(project(path = ":modulecheck-dagger"))
5757
implementation(project(path = ":modulecheck-utils:stdlib"))
5858

5959
testImplementation(libs.bundles.hermit)

modulecheck-gradle/plugin/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ dependencies {
103103
api(project(path = ":modulecheck-project:api"))
104104
api(project(path = ":modulecheck-reporting:logging:api"))
105105
api(project(path = ":modulecheck-rule:api"))
106-
api(project(path = ":modulecheck-rule:impl-factory"))
107106
api(project(path = ":modulecheck-runtime:api"))
108107

109108
compileOnly(gradleApi())
@@ -128,6 +127,7 @@ dependencies {
128127
implementation(project(path = ":modulecheck-parsing:source:api"))
129128
implementation(project(path = ":modulecheck-project:impl"))
130129
implementation(project(path = ":modulecheck-rule:impl"))
130+
implementation(project(path = ":modulecheck-rule:impl-factory"))
131131
implementation(project(path = ":modulecheck-utils:coroutines:impl"))
132132
implementation(project(path = ":modulecheck-utils:stdlib"))
133133

modulecheck-parsing/groovy-antlr/api/groovy-antlr.api

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
public final class modulecheck/parsing/groovy/antlr/ExtensionsKt {
2+
public static final fun children (Lgroovyjarjarantlr4/v4/runtime/tree/Tree;)Lkotlin/sequences/Sequence;
3+
public static final fun childrenBreadthFirst (Lgroovyjarjarantlr4/v4/runtime/tree/Tree;)Lkotlin/sequences/Sequence;
4+
public static final fun childrenBreadthFirst (Lgroovyjarjarantlr4/v4/runtime/tree/Tree;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
5+
public static final fun childrenDepthFirst (Lgroovyjarjarantlr4/v4/runtime/tree/Tree;)Lkotlin/sequences/Sequence;
6+
public static final fun childrenDepthFirst (Lgroovyjarjarantlr4/v4/runtime/tree/Tree;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
7+
}
8+
19
public final class modulecheck/parsing/groovy/antlr/GroovyAndroidGradleParser : modulecheck/parsing/gradle/dsl/AndroidGradleParser {
210
public fun <init> ()V
311
public fun parse (Ljava/io/File;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;

modulecheck-parsing/groovy-antlr/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ dependencies {
4040
implementation(libs.kotlin.reflect)
4141

4242
implementation(project(path = ":modulecheck-utils:stdlib"))
43+
implementation(project(path = ":modulecheck-utils:traversal"))
4344

4445
testImplementation(libs.bundles.hermit)
4546
testImplementation(libs.bundles.junit)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2021-2023 Rick Busarow
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package modulecheck.parsing.groovy.antlr
17+
18+
import groovyjarjarantlr4.v4.runtime.tree.ParseTree
19+
import groovyjarjarantlr4.v4.runtime.tree.Tree
20+
import modulecheck.utils.traversal.AbstractTreePrinter
21+
22+
internal class AntlrTreePrinter(
23+
whitespaceChar: Char = ' '
24+
) : AbstractTreePrinter<Tree>(whitespaceChar) {
25+
26+
override fun Tree.children(): Sequence<Tree> = sequence {
27+
(0 until childCount).forEach { yield(getChild(it)) }
28+
}
29+
30+
override fun Tree.text(): String = (this as ParseTree).text
31+
override fun Tree.typeName(): String = this::class.java.simpleName
32+
override fun Tree.parent(): Tree? = parent
33+
override fun Tree.simpleClassName(): String = this::class.java.simpleName
34+
35+
companion object {
36+
37+
internal fun <T : Tree> T.printEverything(
38+
whitespaceChar: Char = ' '
39+
): T = apply { AntlrTreePrinter(whitespaceChar).printTreeString(this) }
40+
}
41+
}

modulecheck-parsing/groovy-antlr/src/main/kotlin/modulecheck/parsing/groovy/antlr/EverythingPrinter.kt

-70
This file was deleted.

0 commit comments

Comments
 (0)