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 d5bdd2c9..c43d793d 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 @@ -4,6 +4,7 @@ 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 @@ -13,7 +14,7 @@ import kotlin.coroutines.coroutineContext class CodePicker(val config: PickerConfig) { private val logger = org.slf4j.LoggerFactory.getLogger(javaClass) - suspend fun execute() { + fun execute() = runBlocking { val scope = CoroutineScope(coroutineContext) scope.launch { val codeDir = checkoutCode(config.url, config.branch, config.baseDir) @@ -24,12 +25,19 @@ class CodePicker(val config: PickerConfig) { logger.info("start picker") launch { - PickDirectoryWalker(walkdirChannel).start(codeDir.toString()) - walkdirChannel.close() + launch { + PickDirectoryWalker(walkdirChannel).start(codeDir.toString()) + walkdirChannel.close() + } + launch { + for (fileJob in walkdirChannel) { + // todo call by language worker + println(fileJob) + } + } } logger.info("stop picker") - // 3. generate tree to jsonl } } diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/DirectoryWalker.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/DirectoryWalker.kt index bde288ba..9386d07c 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/DirectoryWalker.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/DirectoryWalker.kt @@ -70,9 +70,14 @@ class PickDirectoryWalker( } private suspend fun walk(workdir: String) = coroutineScope { - val dirents = readDir(workdir) ?: return@coroutineScope + val files = readDir(workdir) + if (files == null) { + logger.error("Failed to read directory: $workdir") + return@coroutineScope + } + val directoryContents = files.toList() - dirents.map { + directoryContents.map { val name = it.name if (name == ".gitignore" || it.name == ".ignore") { @@ -82,12 +87,11 @@ class PickDirectoryWalker( } } - dirents.forEach { file -> + directoryContents.forEach { file -> val name = file.name val path = file.toString() val isDir = file.isDirectory - for (deny in PathDenyList) { if (path.contains(deny)) { return@forEach @@ -117,7 +121,7 @@ class PickDirectoryWalker( } } - if(dirChannels.size >= 1) { + if (dirChannels.isNotEmpty()) { dirChannels.removeAt(0).close() } } diff --git a/unit-picker/src/test/kotlin/cc/unitmesh/pick/picker/CodePickerTest.kt b/unit-picker/src/test/kotlin/cc/unitmesh/pick/picker/CodePickerTest.kt index a26085b7..4fa7ba15 100644 --- a/unit-picker/src/test/kotlin/cc/unitmesh/pick/picker/CodePickerTest.kt +++ b/unit-picker/src/test/kotlin/cc/unitmesh/pick/picker/CodePickerTest.kt @@ -64,8 +64,6 @@ class CodePickerTest { PickerConfig(url = "https://github.com/unit-mesh/unit-eval-testing") ) -// CoroutineScope(Dispatchers.IO).launch { -// picker.execute() -// } + picker.execute() } } \ No newline at end of file