From f2f16ab0021be7ba92e38be9a314a61f0610e620 Mon Sep 17 00:00:00 2001 From: Rick Busarow Date: Sun, 21 Aug 2022 07:58:25 -0500 Subject: [PATCH 1/3] WIP --- .../modulecheck/runtime/ModuleCheckRunner.kt | 22 ++++++- .../modulecheck/runtime/test/RunnerTest.kt | 12 +++- .../utils/trace/test/runTestTraced.kt | 12 ++-- modulecheck-utils/trace/build.gradle.kts | 1 + .../kotlin/modulecheck/utils/trace/Trace.kt | 60 +++++++++++++++++++ .../modulecheck/utils/trace/TraceCollector.kt | 36 +++++++++++ 6 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 modulecheck-utils/trace/src/main/kotlin/modulecheck/utils/trace/TraceCollector.kt diff --git a/modulecheck-runtime/api/src/main/kotlin/modulecheck/runtime/ModuleCheckRunner.kt b/modulecheck-runtime/api/src/main/kotlin/modulecheck/runtime/ModuleCheckRunner.kt index bde1c1c3ef..9fecce1ed7 100644 --- a/modulecheck-runtime/api/src/main/kotlin/modulecheck/runtime/ModuleCheckRunner.kt +++ b/modulecheck-runtime/api/src/main/kotlin/modulecheck/runtime/ModuleCheckRunner.kt @@ -15,6 +15,9 @@ package modulecheck.runtime +import com.squareup.anvil.annotations.ContributesTo +import dagger.Module +import dagger.Provides import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject @@ -25,6 +28,7 @@ import modulecheck.api.context.ProjectDepth import modulecheck.config.ModuleCheckSettings import modulecheck.dagger.DaggerLazy import modulecheck.dagger.DaggerList +import modulecheck.dagger.TaskScope import modulecheck.finding.Finding import modulecheck.finding.Finding.FindingResult import modulecheck.finding.FindingResultFactory @@ -42,16 +46,24 @@ import modulecheck.rule.FindingFactory import modulecheck.rule.ModuleCheckRule import modulecheck.utils.createSafely import modulecheck.utils.trace.Trace +import modulecheck.utils.trace.TraceCollector import java.io.File import kotlin.system.measureTimeMillis +@Module +@ContributesTo(TaskScope::class) +object TraceCollectorModule { + @Provides + fun provideTraceCollector(): TraceCollector = TraceCollector(mutableListOf()) +} + /** * Proxy for a Gradle task, without all the Gradle framework * stuff. Most logic is delegated to its various dependencies. * * @property findingFactory handles parsing of the projects in order to generate the findings * @property findingResultFactory attempts to apply fixes to the findings and - * returns a list of [FindingResult][modulecheck.finding.Finding.FindingResult] + * returns a list of [FindingResult][modulecheck.finding.Finding.FindingResult] * @property reportFactory handles console output of the main results * @property depthLogFactoryLazy handles console output of the depth results * @since 0.12.0 @@ -69,13 +81,14 @@ data class ModuleCheckRunner @AssistedInject constructor( val depthLogFactoryLazy: DaggerLazy, val projectProvider: ProjectProvider, val rules: DaggerList>, + val traceCollector: TraceCollector, @Assisted val autoCorrect: Boolean ) { fun run(projects: List): Result = runBlocking( if (settings.trace) { - dispatcherProvider.default + Trace.start(ModuleCheckRunner::class) + dispatcherProvider.default + Trace.start(ModuleCheckRunner::class)+ traceCollector } else { dispatcherProvider.default } @@ -154,6 +167,11 @@ data class ModuleCheckRunner @AssistedInject constructor( ) } + File("TRACE.txt").writeText( + traceCollector.all() + .joinToString("\n\n") { it.asString() } + ) + if (totalUnfixedIssues > 0) { val wasPlural = if (totalFindings == 1) "was" else "were" diff --git a/modulecheck-runtime/testing/src/main/kotlin/modulecheck/runtime/test/RunnerTest.kt b/modulecheck-runtime/testing/src/main/kotlin/modulecheck/runtime/test/RunnerTest.kt index cdd39cc3ac..5dfd407078 100644 --- a/modulecheck-runtime/testing/src/main/kotlin/modulecheck/runtime/test/RunnerTest.kt +++ b/modulecheck-runtime/testing/src/main/kotlin/modulecheck/runtime/test/RunnerTest.kt @@ -50,6 +50,7 @@ import modulecheck.rule.test.AllRulesComponent import modulecheck.runtime.ModuleCheckRunner import modulecheck.testing.assertions.TrimmedAsserts import modulecheck.utils.mapToSet +import modulecheck.utils.trace.TraceCollector @Suppress("UnnecessaryAbstractClass") abstract class RunnerTest : @@ -131,6 +132,10 @@ abstract class RunnerTest : } } + val traceCollector = TraceCollector(mutableListOf()) + + settings.trace = true + val result = ModuleCheckRunner( settings = settings, findingFactory = findingFactory, @@ -147,10 +152,15 @@ abstract class RunnerTest : depthLogFactoryLazy = { DepthLogFactory(terminal) }, projectProvider = projectProvider, rules = rules, - autoCorrect = autoCorrect + autoCorrect = autoCorrect, + traceCollector = traceCollector ) .run(allProjects()) + traceCollector.all() + .joinToString("\n\n") { it.asString() } + .also(::println) + if (autoCorrect) { // Re-parse everything from scratch to ensure that auto-correct didn't break anything. diff --git a/modulecheck-utils/trace-testing/src/main/kotlin/modulecheck/utils/trace/test/runTestTraced.kt b/modulecheck-utils/trace-testing/src/main/kotlin/modulecheck/utils/trace/test/runTestTraced.kt index cfb8ed4c18..0caf316c95 100644 --- a/modulecheck-utils/trace-testing/src/main/kotlin/modulecheck/utils/trace/test/runTestTraced.kt +++ b/modulecheck-utils/trace-testing/src/main/kotlin/modulecheck/utils/trace/test/runTestTraced.kt @@ -18,12 +18,14 @@ package modulecheck.utils.trace.test import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.runBlocking import modulecheck.utils.trace.Trace - -fun runTestTraced(action: suspend CoroutineScope.() -> Unit) { - runBlocking(Trace.start("test-start"), action) -} +import modulecheck.utils.trace.TraceCollector @Suppress("UnusedReceiverParameter") inline fun T.runTestTraced(noinline action: suspend CoroutineScope.() -> Unit) { - runBlocking(Trace.start(T::class), action) + val traceCollector = TraceCollector(mutableListOf()) + runBlocking(Trace.start(T::class) + traceCollector, action) + + traceCollector.all() + .joinToString("\n") { it.asString() } + .also(::println) } diff --git a/modulecheck-utils/trace/build.gradle.kts b/modulecheck-utils/trace/build.gradle.kts index 7dd9d19255..6ec7c23f3f 100644 --- a/modulecheck-utils/trace/build.gradle.kts +++ b/modulecheck-utils/trace/build.gradle.kts @@ -25,6 +25,7 @@ mcbuild { dependencies { + api(libs.benManes.caffeine) api(libs.kotlinx.coroutines.core) api(libs.kotlinx.coroutines.jvm) api(libs.rickBusarow.dispatch.core) diff --git a/modulecheck-utils/trace/src/main/kotlin/modulecheck/utils/trace/Trace.kt b/modulecheck-utils/trace/src/main/kotlin/modulecheck/utils/trace/Trace.kt index fa69a10e3b..37d0b222f9 100644 --- a/modulecheck-utils/trace/src/main/kotlin/modulecheck/utils/trace/Trace.kt +++ b/modulecheck-utils/trace/src/main/kotlin/modulecheck/utils/trace/Trace.kt @@ -58,6 +58,17 @@ sealed class Trace( } } + abstract fun parentOrNull(): Trace? + + val parents: Sequence = generateSequence { + when (this) { + is Child -> parent + is Root -> null + } + } + val parentsWithSelf: Sequence + get() = sequenceOf(this) + parents + override val key: CoroutineContext.Key<*> get() = Key abstract val depth: Int @@ -93,10 +104,24 @@ sealed class Trace( private class Root(tags: List) : Trace(tags) { override val depth = 0 + override fun parentOrNull(): Trace? = null override fun asString(): String = buildString { appendLine("") append("tags: $tags") } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is Root) return false + + if (tags != other.tags) return false + + return true + } + + override fun hashCode(): Int { + return tags.hashCode() + } } private class Child( @@ -106,6 +131,8 @@ sealed class Trace( val args: List ) : Trace(tags) { + override fun parentOrNull() = parent + override fun asString(): String = StringBuilder(parent.asString()) .apply { val indent = " ".repeat(depth - 1) @@ -113,6 +140,26 @@ sealed class Trace( append("\n$indent└─ tags: $tags -- args: $args") } .toString() + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is Child) return false + + if (parent != other.parent) return false + if (depth != other.depth) return false + if (args != other.args) return false + if (tags != other.tags) return false + + return true + } + + override fun hashCode(): Int { + var result = parent.hashCode() + result = 31 * result + depth + result = 31 * result + args.hashCode() + result = 31 * result + tags.hashCode() + return result + } } companion object Key : CoroutineContext.Key { @@ -123,6 +170,16 @@ sealed class Trace( */ fun start(vararg tags: Any): Trace = Root(tags.traceStrings()) + /** + * Creates a new [Trace] root. Prefer adding to an existing trace via a [traced] extension. + * + * @since 0.12.0 + */ + suspend fun start( + vararg tags: Any, + action: suspend CoroutineScope.() -> T + ): T = withContext(start(tags), action) + private fun Array.traceStrings(): List = map { it.traceString() } private fun Iterable.traceStrings(): List = map { it.traceString() } private fun Any.traceString() = when (this) { @@ -235,6 +292,9 @@ private suspend fun tracedInternal( ?: return coroutineScope { block() } val newTrace = oldTrace.child(tags, args) + + currentCoroutineContext()[TraceCollector]?.add(newTrace) + return withContext(newTrace, block) } diff --git a/modulecheck-utils/trace/src/main/kotlin/modulecheck/utils/trace/TraceCollector.kt b/modulecheck-utils/trace/src/main/kotlin/modulecheck/utils/trace/TraceCollector.kt new file mode 100644 index 0000000000..572e47f8ee --- /dev/null +++ b/modulecheck-utils/trace/src/main/kotlin/modulecheck/utils/trace/TraceCollector.kt @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2021-2022 Rick Busarow + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package modulecheck.utils.trace + +import kotlin.coroutines.AbstractCoroutineContextElement +import kotlin.coroutines.CoroutineContext + +class TraceCollector( + private val cache: MutableList +) : AbstractCoroutineContextElement(Key) { + + fun add(trace: Trace) = synchronized(cache) { + cache.add(trace) + + trace.parentOrNull()?.let { parent -> + cache.remove(parent) + } + } + + fun all() = cache + + companion object Key : CoroutineContext.Key +} From bdd71dfda37c9f7630666e1b48a504d5d07cd41c Mon Sep 17 00:00:00 2001 From: Rick Busarow Date: Sat, 27 Apr 2024 09:00:53 -0500 Subject: [PATCH 2/3] WIP? --- .gitignore | 2 ++ .../main/kotlin/modulecheck/utils/trace/Trace.kt | 13 ++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 00b04c5bdd..aa7107d413 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,5 @@ java_pid1690.hprof build-logic/.editorconfig **/node_modules/ + +!/.idea/runConfigurations/all_tests.xml diff --git a/modulecheck-utils/trace/src/main/kotlin/modulecheck/utils/trace/Trace.kt b/modulecheck-utils/trace/src/main/kotlin/modulecheck/utils/trace/Trace.kt index 37d0b222f9..5ee7aea321 100644 --- a/modulecheck-utils/trace/src/main/kotlin/modulecheck/utils/trace/Trace.kt +++ b/modulecheck-utils/trace/src/main/kotlin/modulecheck/utils/trace/Trace.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Rick Busarow + * Copyright (C) 2021-2024 Rick Busarow * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -58,14 +58,7 @@ sealed class Trace( } } - abstract fun parentOrNull(): Trace? - - val parents: Sequence = generateSequence { - when (this) { - is Child -> parent - is Root -> null - } - } + val parents: Sequence = generateSequence({ parentOrNull() }) { it.parentOrNull() } val parentsWithSelf: Sequence get() = sequenceOf(this) + parents @@ -73,6 +66,8 @@ sealed class Trace( abstract val depth: Int + abstract fun parentOrNull(): Trace? + /** * ``` * From e0b4058760a77b9dfc740c3fb50d3878ab9e2d0e Mon Sep 17 00:00:00 2001 From: Rick Busarow Date: Sat, 27 Apr 2024 09:50:06 -0500 Subject: [PATCH 3/3] WIP? --- dependency-guard-aggregate.txt | 9 +++++ modulecheck-gradle/plugin/build.gradle.kts | 3 +- modulecheck-project/testing/api/testing.api | 10 +++-- modulecheck-runtime/api/api/api.api | 38 ++++++++++++++----- modulecheck-runtime/api/build.gradle.kts | 4 +- .../modulecheck/runtime/ModuleCheckRunner.kt | 6 +-- modulecheck-runtime/testing/api/testing.api | 10 +++-- modulecheck-runtime/testing/build.gradle.kts | 3 +- .../trace-testing/api/trace-testing.api | 4 -- .../trace-testing/build.gradle.kts | 4 +- modulecheck-utils/trace/api/trace.api | 14 +++++++ 11 files changed, 77 insertions(+), 28 deletions(-) diff --git a/dependency-guard-aggregate.txt b/dependency-guard-aggregate.txt index 14f993c6c1..dd472c047e 100644 --- a/dependency-guard-aggregate.txt +++ b/dependency-guard-aggregate.txt @@ -1194,7 +1194,10 @@ :modulecheck-utils:stdlib -- runtimeClasspath -- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0 :modulecheck-utils:stdlib -- runtimeClasspath -- org.jetbrains:annotations:23.0.0 +:modulecheck-utils:trace -- runtimeClasspath -- com.github.ben-manes.caffeine:caffeine:3.1.8 +:modulecheck-utils:trace -- runtimeClasspath -- com.google.errorprone:error_prone_annotations:2.21.1 :modulecheck-utils:trace -- runtimeClasspath -- com.rickbusarow.dispatch:dispatch-core:1.0.0-beta10 +:modulecheck-utils:trace -- runtimeClasspath -- org.checkerframework:checker-qual:3.37.0 :modulecheck-utils:trace -- runtimeClasspath -- org.jetbrains.kotlin:kotlin-bom:1.9.22 :modulecheck-utils:trace -- runtimeClasspath -- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.22 :modulecheck-utils:trace -- runtimeClasspath -- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.22 @@ -1204,7 +1207,10 @@ :modulecheck-utils:trace -- runtimeClasspath -- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0 :modulecheck-utils:trace -- runtimeClasspath -- org.jetbrains:annotations:23.0.0 +:modulecheck-utils:trace-testing -- runtimeClasspath -- com.github.ben-manes.caffeine:caffeine:3.1.8 +:modulecheck-utils:trace-testing -- runtimeClasspath -- com.google.errorprone:error_prone_annotations:2.21.1 :modulecheck-utils:trace-testing -- runtimeClasspath -- com.rickbusarow.dispatch:dispatch-core:1.0.0-beta10 +:modulecheck-utils:trace-testing -- runtimeClasspath -- org.checkerframework:checker-qual:3.37.0 :modulecheck-utils:trace-testing -- runtimeClasspath -- org.jetbrains.kotlin:kotlin-bom:1.9.22 :modulecheck-utils:trace-testing -- runtimeClasspath -- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.22 :modulecheck-utils:trace-testing -- runtimeClasspath -- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.22 @@ -1419,7 +1425,9 @@ :modulecheck-parsing:source:api -- runtimeClasspath -- org.jetbrains.kotlinx:kotlinx-serialization-core:1.6.3 :modulecheck-parsing:source:api -- runtimeClasspath -- org.jetbrains:annotations:23.0.0 +:modulecheck-parsing:source:testing -- runtimeClasspath -- com.github.ben-manes.caffeine:caffeine:3.1.8 :modulecheck-parsing:source:testing -- runtimeClasspath -- com.github.curious-odd-man:rgxgen:1.4 +:modulecheck-parsing:source:testing -- runtimeClasspath -- com.google.errorprone:error_prone_annotations:2.21.1 :modulecheck-parsing:source:testing -- runtimeClasspath -- com.rickbusarow.dispatch:dispatch-core:1.0.0-beta10 :modulecheck-parsing:source:testing -- runtimeClasspath -- com.rickbusarow.kase:kase-gradle:0.11.1 :modulecheck-parsing:source:testing -- runtimeClasspath -- com.rickbusarow.kase:kase:0.11.1 @@ -1436,6 +1444,7 @@ :modulecheck-parsing:source:testing -- runtimeClasspath -- io.kotest:kotest-property-jvm:5.8.1 :modulecheck-parsing:source:testing -- runtimeClasspath -- net.swiftzer.semver:semver-jvm:2.0.0 :modulecheck-parsing:source:testing -- runtimeClasspath -- net.swiftzer.semver:semver:2.0.0 +:modulecheck-parsing:source:testing -- runtimeClasspath -- org.checkerframework:checker-qual:3.37.0 :modulecheck-parsing:source:testing -- runtimeClasspath -- org.jetbrains.intellij.deps:trove4j:1.0.20200330 :modulecheck-parsing:source:testing -- runtimeClasspath -- org.jetbrains.kotlin:kotlin-bom:1.9.22 :modulecheck-parsing:source:testing -- runtimeClasspath -- org.jetbrains.kotlin:kotlin-compiler-embeddable:1.9.22 diff --git a/modulecheck-gradle/plugin/build.gradle.kts b/modulecheck-gradle/plugin/build.gradle.kts index b220b97c56..edc5354aa2 100644 --- a/modulecheck-gradle/plugin/build.gradle.kts +++ b/modulecheck-gradle/plugin/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Rick Busarow + * Copyright (C) 2021-2024 Rick Busarow * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -151,6 +151,7 @@ dependencies { "integrationTestImplementation"(project(path = ":modulecheck-rule:api")) "integrationTestImplementation"(project(path = ":modulecheck-rule:impl")) "integrationTestImplementation"(project(path = ":modulecheck-rule:impl-factory")) + "integrationTestImplementation"(project(path = ":modulecheck-runtime:api")) "integrationTestImplementation"(project(path = ":modulecheck-utils:coroutines:impl")) "integrationTestImplementation"(project(path = ":modulecheck-utils:stdlib")) diff --git a/modulecheck-project/testing/api/testing.api b/modulecheck-project/testing/api/testing.api index 3c49357cd8..b30d5ecb85 100644 --- a/modulecheck-project/testing/api/testing.api +++ b/modulecheck-project/testing/api/testing.api @@ -2,7 +2,11 @@ public abstract class modulecheck/project/test/ProjectTest : com/rickbusarow/kas public fun ()V public synthetic fun getTestEnvironmentFactory ()Lcom/rickbusarow/kase/TestEnvironmentFactory; public fun getTestEnvironmentFactory ()Lmodulecheck/project/test/ProjectTestEnvironmentFactory; + public fun test (Lcom/rickbusarow/kase/HasTestEnvironmentFactory;Ljava/lang/Object;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;Lkotlin/jvm/functions/Function2;)V + public fun test (Lcom/rickbusarow/kase/HasTestEnvironmentFactory;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;Lkotlin/jvm/functions/Function2;)V + public fun test (Lcom/rickbusarow/kase/NoParamTestEnvironmentFactory;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;Lkotlin/jvm/functions/Function2;)V public final fun test (Lcom/rickbusarow/kase/files/TestLocation;Lkotlin/jvm/functions/Function2;)V + public fun test (Ljava/lang/Object;Lcom/rickbusarow/kase/TestEnvironmentFactory;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;Lkotlin/jvm/functions/Function2;)V public static synthetic fun test$default (Lmodulecheck/project/test/ProjectTest;Lcom/rickbusarow/kase/files/TestLocation;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V public final fun writeText (Ljava/io/File;Ljava/lang/String;)V } @@ -27,10 +31,10 @@ public class modulecheck/project/test/ProjectTestEnvironment : modulecheck/testi public fun getRoot ()Ljava/io/File; } -public final class modulecheck/project/test/ProjectTestEnvironmentFactory : com/rickbusarow/kase/TestEnvironmentFactory { +public final class modulecheck/project/test/ProjectTestEnvironmentFactory : com/rickbusarow/kase/ParamTestEnvironmentFactory { public fun ()V - public synthetic fun createEnvironment (Ljava/lang/Object;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;)Lcom/rickbusarow/kase/TestEnvironment; - public fun createEnvironment (Lmodulecheck/project/test/ProjectTestEnvironmentParams;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;)Lmodulecheck/project/test/ProjectTestEnvironment; + public synthetic fun create (Ljava/lang/Object;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;)Lcom/rickbusarow/kase/TestEnvironment; + public fun create (Lmodulecheck/project/test/ProjectTestEnvironmentParams;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;)Lmodulecheck/project/test/ProjectTestEnvironment; } public final class modulecheck/project/test/ProjectTestEnvironmentParams : modulecheck/testing/TestEnvironmentParams { diff --git a/modulecheck-runtime/api/api/api.api b/modulecheck-runtime/api/api/api.api index cc44076d64..9e45c4f6cb 100644 --- a/modulecheck-runtime/api/api/api.api +++ b/modulecheck-runtime/api/api/api.api @@ -1,10 +1,16 @@ +public final class anvil/hint/merge/modulecheck/runtime/TraceCollectorModuleKt { + public static final fun getModulecheck_runtime_TraceCollectorModule_reference ()Lkotlin/reflect/KClass; + public static final fun getModulecheck_runtime_TraceCollectorModule_scope0 ()Lkotlin/reflect/KClass; +} + public final class modulecheck/runtime/ModuleCheckRunner { - public fun (Lmodulecheck/config/ModuleCheckSettings;Lmodulecheck/rule/FindingFactory;Lmodulecheck/reporting/logging/McLogger;Lmodulecheck/finding/FindingResultFactory;Lmodulecheck/reporting/console/ReportFactory;Lmodulecheck/reporting/checkstyle/CheckstyleReporter;Lmodulecheck/reporting/graphviz/GraphvizFileWriter;Ldispatch/core/DispatcherProvider;Lmodulecheck/reporting/sarif/SarifReportFactory;Ldagger/Lazy;Lmodulecheck/project/ProjectProvider;Ljava/util/List;Z)V + public fun (Lmodulecheck/config/ModuleCheckSettings;Lmodulecheck/rule/FindingFactory;Lmodulecheck/reporting/logging/McLogger;Lmodulecheck/finding/FindingResultFactory;Lmodulecheck/reporting/console/ReportFactory;Lmodulecheck/reporting/checkstyle/CheckstyleReporter;Lmodulecheck/reporting/graphviz/GraphvizFileWriter;Ldispatch/core/DispatcherProvider;Lmodulecheck/reporting/sarif/SarifReportFactory;Ldagger/Lazy;Lmodulecheck/project/ProjectProvider;Ljava/util/List;Lmodulecheck/utils/trace/TraceCollector;Z)V public final fun component1 ()Lmodulecheck/config/ModuleCheckSettings; public final fun component10 ()Ldagger/Lazy; public final fun component11 ()Lmodulecheck/project/ProjectProvider; public final fun component12 ()Ljava/util/List; - public final fun component13 ()Z + public final fun component13 ()Lmodulecheck/utils/trace/TraceCollector; + public final fun component14 ()Z public final fun component2 ()Lmodulecheck/rule/FindingFactory; public final fun component3 ()Lmodulecheck/reporting/logging/McLogger; public final fun component4 ()Lmodulecheck/finding/FindingResultFactory; @@ -13,8 +19,8 @@ public final class modulecheck/runtime/ModuleCheckRunner { public final fun component7 ()Lmodulecheck/reporting/graphviz/GraphvizFileWriter; public final fun component8 ()Ldispatch/core/DispatcherProvider; public final fun component9 ()Lmodulecheck/reporting/sarif/SarifReportFactory; - public final fun copy (Lmodulecheck/config/ModuleCheckSettings;Lmodulecheck/rule/FindingFactory;Lmodulecheck/reporting/logging/McLogger;Lmodulecheck/finding/FindingResultFactory;Lmodulecheck/reporting/console/ReportFactory;Lmodulecheck/reporting/checkstyle/CheckstyleReporter;Lmodulecheck/reporting/graphviz/GraphvizFileWriter;Ldispatch/core/DispatcherProvider;Lmodulecheck/reporting/sarif/SarifReportFactory;Ldagger/Lazy;Lmodulecheck/project/ProjectProvider;Ljava/util/List;Z)Lmodulecheck/runtime/ModuleCheckRunner; - public static synthetic fun copy$default (Lmodulecheck/runtime/ModuleCheckRunner;Lmodulecheck/config/ModuleCheckSettings;Lmodulecheck/rule/FindingFactory;Lmodulecheck/reporting/logging/McLogger;Lmodulecheck/finding/FindingResultFactory;Lmodulecheck/reporting/console/ReportFactory;Lmodulecheck/reporting/checkstyle/CheckstyleReporter;Lmodulecheck/reporting/graphviz/GraphvizFileWriter;Ldispatch/core/DispatcherProvider;Lmodulecheck/reporting/sarif/SarifReportFactory;Ldagger/Lazy;Lmodulecheck/project/ProjectProvider;Ljava/util/List;ZILjava/lang/Object;)Lmodulecheck/runtime/ModuleCheckRunner; + public final fun copy (Lmodulecheck/config/ModuleCheckSettings;Lmodulecheck/rule/FindingFactory;Lmodulecheck/reporting/logging/McLogger;Lmodulecheck/finding/FindingResultFactory;Lmodulecheck/reporting/console/ReportFactory;Lmodulecheck/reporting/checkstyle/CheckstyleReporter;Lmodulecheck/reporting/graphviz/GraphvizFileWriter;Ldispatch/core/DispatcherProvider;Lmodulecheck/reporting/sarif/SarifReportFactory;Ldagger/Lazy;Lmodulecheck/project/ProjectProvider;Ljava/util/List;Lmodulecheck/utils/trace/TraceCollector;Z)Lmodulecheck/runtime/ModuleCheckRunner; + public static synthetic fun copy$default (Lmodulecheck/runtime/ModuleCheckRunner;Lmodulecheck/config/ModuleCheckSettings;Lmodulecheck/rule/FindingFactory;Lmodulecheck/reporting/logging/McLogger;Lmodulecheck/finding/FindingResultFactory;Lmodulecheck/reporting/console/ReportFactory;Lmodulecheck/reporting/checkstyle/CheckstyleReporter;Lmodulecheck/reporting/graphviz/GraphvizFileWriter;Ldispatch/core/DispatcherProvider;Lmodulecheck/reporting/sarif/SarifReportFactory;Ldagger/Lazy;Lmodulecheck/project/ProjectProvider;Ljava/util/List;Lmodulecheck/utils/trace/TraceCollector;ZILjava/lang/Object;)Lmodulecheck/runtime/ModuleCheckRunner; public fun equals (Ljava/lang/Object;)Z public final fun getAutoCorrect ()Z public final fun getCheckstyleReporter ()Lmodulecheck/reporting/checkstyle/CheckstyleReporter; @@ -29,6 +35,7 @@ public final class modulecheck/runtime/ModuleCheckRunner { public final fun getRules ()Ljava/util/List; public final fun getSarifReportFactory ()Lmodulecheck/reporting/sarif/SarifReportFactory; public final fun getSettings ()Lmodulecheck/config/ModuleCheckSettings; + public final fun getTraceCollector ()Lmodulecheck/utils/trace/TraceCollector; public fun hashCode ()I public final fun run-IoAF18A (Ljava/util/List;)Ljava/lang/Object; public fun toString ()Ljava/lang/String; @@ -53,15 +60,15 @@ public final class modulecheck/runtime/ModuleCheckRunner$TimedResults { public final class modulecheck/runtime/ModuleCheckRunner_Factory { public static final field Companion Lmodulecheck/runtime/ModuleCheckRunner_Factory$Companion; - public fun (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)V - public static final fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lmodulecheck/runtime/ModuleCheckRunner_Factory; + public fun (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)V + public static final fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lmodulecheck/runtime/ModuleCheckRunner_Factory; public final fun get (Z)Lmodulecheck/runtime/ModuleCheckRunner; - public static final fun newInstance (Lmodulecheck/config/ModuleCheckSettings;Lmodulecheck/rule/FindingFactory;Lmodulecheck/reporting/logging/McLogger;Lmodulecheck/finding/FindingResultFactory;Lmodulecheck/reporting/console/ReportFactory;Lmodulecheck/reporting/checkstyle/CheckstyleReporter;Lmodulecheck/reporting/graphviz/GraphvizFileWriter;Ldispatch/core/DispatcherProvider;Lmodulecheck/reporting/sarif/SarifReportFactory;Ldagger/Lazy;Lmodulecheck/project/ProjectProvider;Ljava/util/List;Z)Lmodulecheck/runtime/ModuleCheckRunner; + public static final fun newInstance (Lmodulecheck/config/ModuleCheckSettings;Lmodulecheck/rule/FindingFactory;Lmodulecheck/reporting/logging/McLogger;Lmodulecheck/finding/FindingResultFactory;Lmodulecheck/reporting/console/ReportFactory;Lmodulecheck/reporting/checkstyle/CheckstyleReporter;Lmodulecheck/reporting/graphviz/GraphvizFileWriter;Ldispatch/core/DispatcherProvider;Lmodulecheck/reporting/sarif/SarifReportFactory;Ldagger/Lazy;Lmodulecheck/project/ProjectProvider;Ljava/util/List;Lmodulecheck/utils/trace/TraceCollector;Z)Lmodulecheck/runtime/ModuleCheckRunner; } public final class modulecheck/runtime/ModuleCheckRunner_Factory$Companion { - public final fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lmodulecheck/runtime/ModuleCheckRunner_Factory; - public final fun newInstance (Lmodulecheck/config/ModuleCheckSettings;Lmodulecheck/rule/FindingFactory;Lmodulecheck/reporting/logging/McLogger;Lmodulecheck/finding/FindingResultFactory;Lmodulecheck/reporting/console/ReportFactory;Lmodulecheck/reporting/checkstyle/CheckstyleReporter;Lmodulecheck/reporting/graphviz/GraphvizFileWriter;Ldispatch/core/DispatcherProvider;Lmodulecheck/reporting/sarif/SarifReportFactory;Ldagger/Lazy;Lmodulecheck/project/ProjectProvider;Ljava/util/List;Z)Lmodulecheck/runtime/ModuleCheckRunner; + public final fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lmodulecheck/runtime/ModuleCheckRunner_Factory; + public final fun newInstance (Lmodulecheck/config/ModuleCheckSettings;Lmodulecheck/rule/FindingFactory;Lmodulecheck/reporting/logging/McLogger;Lmodulecheck/finding/FindingResultFactory;Lmodulecheck/reporting/console/ReportFactory;Lmodulecheck/reporting/checkstyle/CheckstyleReporter;Lmodulecheck/reporting/graphviz/GraphvizFileWriter;Ldispatch/core/DispatcherProvider;Lmodulecheck/reporting/sarif/SarifReportFactory;Ldagger/Lazy;Lmodulecheck/project/ProjectProvider;Ljava/util/List;Lmodulecheck/utils/trace/TraceCollector;Z)Lmodulecheck/runtime/ModuleCheckRunner; } public final class modulecheck/runtime/ModuleCheckRunner_Factory_Impl : modulecheck/runtime/ModuleCheckRunner$Factory { @@ -79,3 +86,16 @@ public abstract interface class modulecheck/runtime/RunnerComponent { public abstract fun getRunnerFactory ()Lmodulecheck/runtime/ModuleCheckRunner$Factory; } +public final class modulecheck/runtime/TraceCollectorModule { + public static final field INSTANCE Lmodulecheck/runtime/TraceCollectorModule; + public final fun provideTraceCollector ()Lmodulecheck/utils/trace/TraceCollector; +} + +public final class modulecheck/runtime/TraceCollectorModule_ProvideTraceCollectorFactory : dagger/internal/Factory { + public static final field INSTANCE Lmodulecheck/runtime/TraceCollectorModule_ProvideTraceCollectorFactory; + public static final fun create ()Lmodulecheck/runtime/TraceCollectorModule_ProvideTraceCollectorFactory; + public synthetic fun get ()Ljava/lang/Object; + public fun get ()Lmodulecheck/utils/trace/TraceCollector; + public static final fun provideTraceCollector ()Lmodulecheck/utils/trace/TraceCollector; +} + diff --git a/modulecheck-runtime/api/build.gradle.kts b/modulecheck-runtime/api/build.gradle.kts index ef4d13ad27..b521ec87f2 100644 --- a/modulecheck-runtime/api/build.gradle.kts +++ b/modulecheck-runtime/api/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Rick Busarow + * Copyright (C) 2021-2024 Rick Busarow * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -38,8 +38,8 @@ dependencies { api(project(path = ":modulecheck-reporting:logging:api")) api(project(path = ":modulecheck-reporting:sarif")) api(project(path = ":modulecheck-rule:api")) + api(project(path = ":modulecheck-utils:trace")) implementation(project(path = ":modulecheck-api")) implementation(project(path = ":modulecheck-utils:stdlib")) - implementation(project(path = ":modulecheck-utils:trace")) } diff --git a/modulecheck-runtime/api/src/main/kotlin/modulecheck/runtime/ModuleCheckRunner.kt b/modulecheck-runtime/api/src/main/kotlin/modulecheck/runtime/ModuleCheckRunner.kt index 9fecce1ed7..cf9a7c8a3d 100644 --- a/modulecheck-runtime/api/src/main/kotlin/modulecheck/runtime/ModuleCheckRunner.kt +++ b/modulecheck-runtime/api/src/main/kotlin/modulecheck/runtime/ModuleCheckRunner.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Rick Busarow + * Copyright (C) 2021-2024 Rick Busarow * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -63,7 +63,7 @@ object TraceCollectorModule { * * @property findingFactory handles parsing of the projects in order to generate the findings * @property findingResultFactory attempts to apply fixes to the findings and - * returns a list of [FindingResult][modulecheck.finding.Finding.FindingResult] + * returns a list of [FindingResult][modulecheck.finding.Finding.FindingResult] * @property reportFactory handles console output of the main results * @property depthLogFactoryLazy handles console output of the depth results * @since 0.12.0 @@ -88,7 +88,7 @@ data class ModuleCheckRunner @AssistedInject constructor( fun run(projects: List): Result = runBlocking( if (settings.trace) { - dispatcherProvider.default + Trace.start(ModuleCheckRunner::class)+ traceCollector + dispatcherProvider.default + Trace.start(ModuleCheckRunner::class) + traceCollector } else { dispatcherProvider.default } diff --git a/modulecheck-runtime/testing/api/testing.api b/modulecheck-runtime/testing/api/testing.api index dc9e0612f2..63eeca7c10 100644 --- a/modulecheck-runtime/testing/api/testing.api +++ b/modulecheck-runtime/testing/api/testing.api @@ -225,7 +225,11 @@ public abstract class modulecheck/runtime/test/RunnerTest : com/rickbusarow/kase public final fun run-5dDjBWM (Lmodulecheck/runtime/test/RunnerTestEnvironment;ZZLmodulecheck/rule/FindingFactory;Lmodulecheck/config/ModuleCheckSettings;Lmodulecheck/reporting/logging/McLogger;Lmodulecheck/project/ProjectProvider;Lmodulecheck/finding/FindingResultFactory;Lcom/github/ajalt/mordant/terminal/Terminal;Lmodulecheck/reporting/console/ReportFactory;Lmodulecheck/reporting/checkstyle/CheckstyleReporter;Lmodulecheck/reporting/graphviz/GraphvizFileWriter;Ldispatch/core/DispatcherProvider;Ljava/util/List;)Ljava/lang/Object; public static synthetic fun run-5dDjBWM$default (Lmodulecheck/runtime/test/RunnerTest;Lmodulecheck/runtime/test/RunnerTestEnvironment;ZZLmodulecheck/rule/FindingFactory;Lmodulecheck/config/ModuleCheckSettings;Lmodulecheck/reporting/logging/McLogger;Lmodulecheck/project/ProjectProvider;Lmodulecheck/finding/FindingResultFactory;Lcom/github/ajalt/mordant/terminal/Terminal;Lmodulecheck/reporting/console/ReportFactory;Lmodulecheck/reporting/checkstyle/CheckstyleReporter;Lmodulecheck/reporting/graphviz/GraphvizFileWriter;Ldispatch/core/DispatcherProvider;Ljava/util/List;ILjava/lang/Object;)Ljava/lang/Object; public final fun shouldBe (Ljava/util/List;Ljava/util/List;)V + public fun test (Lcom/rickbusarow/kase/HasTestEnvironmentFactory;Ljava/lang/Object;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;Lkotlin/jvm/functions/Function2;)V + public fun test (Lcom/rickbusarow/kase/HasTestEnvironmentFactory;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;Lkotlin/jvm/functions/Function2;)V + public fun test (Lcom/rickbusarow/kase/NoParamTestEnvironmentFactory;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;Lkotlin/jvm/functions/Function2;)V public final fun test (Lcom/rickbusarow/kase/files/TestLocation;Lkotlin/jvm/functions/Function2;)V + public fun test (Ljava/lang/Object;Lcom/rickbusarow/kase/TestEnvironmentFactory;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;Lkotlin/jvm/functions/Function2;)V public static synthetic fun test$default (Lmodulecheck/runtime/test/RunnerTest;Lcom/rickbusarow/kase/files/TestLocation;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V } @@ -241,10 +245,10 @@ public class modulecheck/runtime/test/RunnerTestEnvironment : modulecheck/projec public final fun parsedReport (Lmodulecheck/reporting/logging/test/ReportingLogger;)Ljava/util/List; } -public final class modulecheck/runtime/test/RunnerTestEnvironmentFactory : com/rickbusarow/kase/TestEnvironmentFactory { +public final class modulecheck/runtime/test/RunnerTestEnvironmentFactory : com/rickbusarow/kase/ParamTestEnvironmentFactory { public fun ()V - public synthetic fun createEnvironment (Ljava/lang/Object;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;)Lcom/rickbusarow/kase/TestEnvironment; - public fun createEnvironment (Lmodulecheck/runtime/test/RunnerTestEnvironmentParams;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;)Lmodulecheck/runtime/test/RunnerTestEnvironment; + public synthetic fun create (Ljava/lang/Object;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;)Lcom/rickbusarow/kase/TestEnvironment; + public fun create (Lmodulecheck/runtime/test/RunnerTestEnvironmentParams;Ljava/util/List;Lcom/rickbusarow/kase/files/TestLocation;)Lmodulecheck/runtime/test/RunnerTestEnvironment; } public final class modulecheck/runtime/test/RunnerTestEnvironmentParams : modulecheck/testing/TestEnvironmentParams { diff --git a/modulecheck-runtime/testing/build.gradle.kts b/modulecheck-runtime/testing/build.gradle.kts index f88ecc2edc..8728e3ec1d 100644 --- a/modulecheck-runtime/testing/build.gradle.kts +++ b/modulecheck-runtime/testing/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Rick Busarow + * Copyright (C) 2021-2024 Rick Busarow * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -41,6 +41,7 @@ dependencies { api(project(path = ":modulecheck-reporting:logging:testing")) api(project(path = ":modulecheck-rule:api")) api(project(path = ":modulecheck-rule:impl-factory")) + api(project(path = ":modulecheck-utils:trace")) implementation(project(path = ":modulecheck-config:fake")) implementation(project(path = ":modulecheck-config:impl")) diff --git a/modulecheck-utils/trace-testing/api/trace-testing.api b/modulecheck-utils/trace-testing/api/trace-testing.api index 1582cb2068..e69de29bb2 100644 --- a/modulecheck-utils/trace-testing/api/trace-testing.api +++ b/modulecheck-utils/trace-testing/api/trace-testing.api @@ -1,4 +0,0 @@ -public final class modulecheck/utils/trace/test/RunTestTracedKt { - public static final fun runTestTraced (Lkotlin/jvm/functions/Function2;)V -} - diff --git a/modulecheck-utils/trace-testing/build.gradle.kts b/modulecheck-utils/trace-testing/build.gradle.kts index 9e9708af17..b4b86c4f06 100644 --- a/modulecheck-utils/trace-testing/build.gradle.kts +++ b/modulecheck-utils/trace-testing/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Rick Busarow + * Copyright (C) 2021-2024 Rick Busarow * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -29,7 +29,7 @@ dependencies { api(libs.kotlinx.coroutines.jvm) api(libs.rickBusarow.dispatch.core) - implementation(project(path = ":modulecheck-utils:trace")) + api(project(path = ":modulecheck-utils:trace")) testImplementation(libs.bundles.junit) testImplementation(libs.bundles.kotest) diff --git a/modulecheck-utils/trace/api/trace.api b/modulecheck-utils/trace/api/trace.api index 9e3caba938..2870cfeed7 100644 --- a/modulecheck-utils/trace/api/trace.api +++ b/modulecheck-utils/trace/api/trace.api @@ -10,13 +10,27 @@ public abstract class modulecheck/utils/trace/Trace : kotlin/coroutines/Coroutin public fun get (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext$Element; public abstract fun getDepth ()I public fun getKey ()Lkotlin/coroutines/CoroutineContext$Key; + public final fun getParents ()Lkotlin/sequences/Sequence; + public final fun getParentsWithSelf ()Lkotlin/sequences/Sequence; public final fun getTags ()Ljava/util/List; public fun minusKey (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext; + public abstract fun parentOrNull ()Lmodulecheck/utils/trace/Trace; public fun plus (Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext; } public final class modulecheck/utils/trace/Trace$Key : kotlin/coroutines/CoroutineContext$Key { public final fun start ([Ljava/lang/Object;)Lmodulecheck/utils/trace/Trace; + public final fun start ([Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + +public final class modulecheck/utils/trace/TraceCollector : kotlin/coroutines/AbstractCoroutineContextElement { + public static final field Key Lmodulecheck/utils/trace/TraceCollector$Key; + public fun (Ljava/util/List;)V + public final fun add (Lmodulecheck/utils/trace/Trace;)Ljava/lang/Boolean; + public final fun all ()Ljava/util/List; +} + +public final class modulecheck/utils/trace/TraceCollector$Key : kotlin/coroutines/CoroutineContext$Key { } public final class modulecheck/utils/trace/TraceKt {