From cf829d8582b44af3cc02dea3295921d820ae7e78 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Wed, 6 Dec 2023 20:50:19 +0800 Subject: [PATCH] docs: thinking in language worker --- .../src/main/kotlin/cc/unitmesh/pick/picker/CodePicker.kt | 7 +++---- .../main/kotlin/cc/unitmesh/pick/worker/AbstractWorker.kt | 2 +- .../main/kotlin/cc/unitmesh/pick/worker/JavaFileWorker.kt | 5 +++-- .../main/kotlin/cc/unitmesh/pick/worker/WorkerDispatch.kt | 8 +++++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/CodePicker.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/CodePicker.kt index c43d793d..700a1a84 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/CodePicker.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/CodePicker.kt @@ -1,15 +1,14 @@ package cc.unitmesh.pick.picker +import cc.unitmesh.pick.worker.WorkerDispatch import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import org.archguard.action.checkout.GitSourceSettings import org.archguard.action.checkout.executeGitCheckout import java.nio.file.Files import java.nio.file.Path -import kotlin.coroutines.coroutineContext class CodePicker(val config: PickerConfig) { private val logger = org.slf4j.LoggerFactory.getLogger(javaClass) @@ -31,13 +30,13 @@ class CodePicker(val config: PickerConfig) { } launch { for (fileJob in walkdirChannel) { - // todo call by language worker - println(fileJob) + WorkerDispatch.worker(fileJob) } } } logger.info("stop picker") + // 3. generate tree to jsonl } } diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/AbstractWorker.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/AbstractWorker.kt index 33359277..e81c9f32 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/AbstractWorker.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/AbstractWorker.kt @@ -1,5 +1,5 @@ package cc.unitmesh.pick.worker abstract class AbstractWorker { - abstract suspend fun start(filePath: String) + abstract suspend fun start() } \ No newline at end of file diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/JavaFileWorker.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/JavaFileWorker.kt index 3eabbe70..8d0a1782 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/JavaFileWorker.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/JavaFileWorker.kt @@ -1,5 +1,6 @@ package cc.unitmesh.pick.worker +import cc.unitmesh.pick.picker.PickJob import kotlinx.coroutines.coroutineScope import org.archguard.scanner.analyser.count.FileJob @@ -17,11 +18,11 @@ import org.archguard.scanner.analyser.count.FileJob * - by Horizontal (with Import File): * - by Vertical (with History Change): */ -class JavaFileWorker : AbstractWorker() { +class JavaFileWorker(val job: PickJob) : AbstractWorker() { val packageTree: Map = mapOf() /// [Coco](https://github.com/inherd/coco) high change and long line, means is important file, and need to be checked. - override suspend fun start(filePath: String) = coroutineScope { + override suspend fun start() = coroutineScope { // 1. read directory to a collection of files for FileJob // 2. check package information from line 1? diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerDispatch.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerDispatch.kt index c818c53d..f8644b67 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerDispatch.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerDispatch.kt @@ -1,12 +1,14 @@ package cc.unitmesh.pick.worker +import cc.unitmesh.pick.picker.PickJob + object WorkerDispatch { /** * Dispatch language worker by language */ - fun worker(language: String): AbstractWorker? { - return when (language) { - "Java" -> JavaFileWorker() + fun worker(job: PickJob): AbstractWorker? { + return when (job.language.lowercase()) { + "java" -> JavaFileWorker(job) else -> null } }