From 00f86a3c2944f27633435703f424ae3cc6e7a5f1 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Sun, 6 Oct 2024 22:11:01 -0400 Subject: [PATCH] chore: Bump dependencies fix: Correctly consume channel as results are being emitted --- build.gradle.kts | 44 ++++++------- gradle.properties | 2 +- gradle/libs.versions.toml | 17 +++-- .../keepup/api/KeepupDownloader.kt | 65 +++++++++++-------- keepup-cli/build.gradle.kts | 4 +- .../mineinabyss/keepup/cli/ConfigCommand.kt | 5 +- .../kotlin/com/mineinabyss/keepup/cli/Main.kt | 5 +- .../mineinabyss/keepup/cli/PluginsCommand.kt | 27 ++++---- .../mineinabyss/keepup/cli/TemplateCommand.kt | 5 +- 9 files changed, 100 insertions(+), 74 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 51654a4..46ba1ca 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ plugins { alias(libs.plugins.kotlinJvm) -// id("com.github.ben-manes.versions") version "0.41.0" -// id("nl.littlerobots.version-catalog-update") version "0.8.4" + alias(libs.plugins.versions) + alias(libs.plugins.versionCatalogUpdate) } allprojects { @@ -9,23 +9,23 @@ allprojects { mavenCentral() } } -// -//versionCatalogUpdate { -// this.keep { -// keepUnusedPlugins = true -// keepUnusedVersions = true -// keepUnusedLibraries = true -// } -//} -// -//tasks.dependencyUpdates { -// fun isNonStable(version: String): Boolean { -// val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) } -// val regex = "^[0-9,.v-]+(-r)?$".toRegex() -// val isStable = stableKeyword || regex.matches(version) -// return isStable.not() -// } -// rejectVersionIf { -// isNonStable(candidate.version) -// } -//} + +versionCatalogUpdate { + this.keep { + keepUnusedPlugins = true + keepUnusedVersions = true + keepUnusedLibraries = true + } +} + +tasks.dependencyUpdates { + fun isNonStable(version: String): Boolean { + val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) } + val regex = "^[0-9,.v-]+(-r)?$".toRegex() + val isStable = stableKeyword || regex.matches(version) + return isStable.not() + } + rejectVersionIf { + isNonStable(candidate.version) + } +} diff --git a/gradle.properties b/gradle.properties index fc41066..eff2a10 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ kotlin.code.style=official group=com.mineinabyss -version=3.1.0-alpha.1 +version=3.1.0-alpha.2 idofrontVersion=0.25.6 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 011c27b..0654b48 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,13 +1,13 @@ [versions] -clikt = "4.4.0" +clikt = "5.0.1" hocon = "1.4.3" -kaml = "0.59.0" +kaml = "0.61.0" kotlin = "2.0.20" -kotlinx-coroutines = "1.8.1" -kotlinx-serialization = "1.6.3" -ktor = "2.3.11" -mordant = "2.6.0" -slf4j = "2.0.13" +kotlinx-coroutines = "1.9.0" +kotlinx-serialization = "1.7.3" +ktor = "2.3.12" +mordant = "3.0.0" +slf4j = "2.0.16" turtle = "0.10.0" [libraries] @@ -25,3 +25,6 @@ turtle = { module = "com.lordcodes.turtle:turtle", version.ref = "turtle" } [plugins] kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } +shadow = "com.github.johnrengelman.shadow:8.1.1" +versionCatalogUpdate = "nl.littlerobots.version-catalog-update:0.8.4" +versions = "com.github.ben-manes.versions:0.51.0" diff --git a/keepup-api/src/main/kotlin/com/mineinabyss/keepup/api/KeepupDownloader.kt b/keepup-api/src/main/kotlin/com/mineinabyss/keepup/api/KeepupDownloader.kt index eecacf6..4d47eae 100644 --- a/keepup-api/src/main/kotlin/com/mineinabyss/keepup/api/KeepupDownloader.kt +++ b/keepup-api/src/main/kotlin/com/mineinabyss/keepup/api/KeepupDownloader.kt @@ -6,11 +6,11 @@ import com.mineinabyss.keepup.downloads.parsing.DownloadParser import com.mineinabyss.keepup.downloads.parsing.DownloadSource import com.mineinabyss.keepup.similarfiles.SimilarFileChecker import io.ktor.client.* +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.joinAll +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.channels.ReceiveChannel +import kotlinx.coroutines.channels.produce import kotlinx.coroutines.launch import java.nio.file.Path import kotlin.io.path.absolute @@ -22,33 +22,44 @@ class KeepupDownloader( val config: KeepupDownloaderConfig, val githubConfig: GithubConfig, ) { - suspend fun download( + @OptIn(ExperimentalCoroutinesApi::class) + fun download( vararg sources: DownloadSource, dest: Path, - ): Channel = coroutineScope { - val channel = Channel(UNLIMITED) - launch(Dispatchers.IO) { - http.use { client -> - val similarFileChecker = if (config.ignoreSimilar) SimilarFileChecker(dest) else null - val downloader = DownloadParser( - failAllDownloads = config.failAllDownloads, - client = client, - githubConfig = githubConfig, - similarFileChecker = similarFileChecker, - ) + scope: CoroutineScope, + ): ReceiveChannel = scope.produce(Dispatchers.IO) { + val similarFileChecker = if (config.ignoreSimilar) SimilarFileChecker(dest) else null + val downloader = DownloadParser( + failAllDownloads = config.failAllDownloads, + client = http, + githubConfig = githubConfig, + similarFileChecker = similarFileChecker, + ) - sources.map { source -> - val downloadPathForKey = (config.downloadCache / source.keyInConfig).absolute() - downloadPathForKey.createDirectories() - launch { - downloader - .download(source, downloadPathForKey) - .forEach { channel.trySend(it) } - } - }.joinAll() - channel.close() + sources.map { source -> + val downloadPathForKey = (config.downloadCache / source.keyInConfig).absolute() + downloadPathForKey.createDirectories() + launch { + downloader + .download(source, downloadPathForKey) + .forEach { channel.send(it) } } } - channel } } + +// +//@OptIn(ExperimentalCoroutinesApi::class) +//suspend fun main() = coroutineScope { +// val channel = produce { +// repeat(20) { +// launch(Dispatchers.IO) { +// delay(Random.nextLong(3000)) +// channel.send(1) +// } +// } +// } +// for(i in channel) { +// println(i) +// } +//} diff --git a/keepup-cli/build.gradle.kts b/keepup-cli/build.gradle.kts index 4cd1cd3..3b2c55b 100644 --- a/keepup-cli/build.gradle.kts +++ b/keepup-cli/build.gradle.kts @@ -1,7 +1,7 @@ plugins { alias(libs.plugins.kotlinJvm) alias(libs.plugins.kotlinx.serialization) - id("com.github.johnrengelman.shadow") version "8.1.1" + alias(libs.plugins.shadow) application } @@ -36,7 +36,7 @@ distributions { tasks { shadowJar { minimize { - exclude { it.moduleGroup == "org.slf4j" } + exclude { it.moduleGroup == "org.slf4j" || it.moduleGroup == "com.github.ajalt.mordant" } } } } diff --git a/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/ConfigCommand.kt b/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/ConfigCommand.kt index 8277a2c..78ee5a0 100644 --- a/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/ConfigCommand.kt +++ b/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/ConfigCommand.kt @@ -1,6 +1,7 @@ package com.mineinabyss.keepup.cli import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.core.Context import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.options.defaultLazy import com.github.ajalt.clikt.parameters.options.option @@ -12,7 +13,9 @@ import com.mineinabyss.keepup.helpers.MSG import com.mineinabyss.keepup.t import kotlin.io.path.inputStream -class ConfigCommand : CliktCommand(name = "config", help = "Syncs local config files to appropriate destinations") { +class ConfigCommand : CliktCommand(name = "config") { + override fun help(context: Context) = "Syncs local config files to appropriate destinations" + val include by argument( "include", help = "The config defined in inventory to sync" diff --git a/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/Main.kt b/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/Main.kt index 5b893b8..d1d1fe0 100644 --- a/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/Main.kt +++ b/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/Main.kt @@ -3,9 +3,12 @@ package com.mineinabyss.keepup.cli import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.core.main import com.github.ajalt.clikt.core.subcommands -class KeepupCommand : CliktCommand(allowMultipleSubcommands = true) { +class KeepupCommand : CliktCommand() { + override val allowMultipleSubcommands = true + override fun run() { } } diff --git a/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/PluginsCommand.kt b/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/PluginsCommand.kt index b5fe708..dedc496 100644 --- a/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/PluginsCommand.kt +++ b/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/PluginsCommand.kt @@ -1,6 +1,7 @@ package com.mineinabyss.keepup.cli import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.core.Context import com.github.ajalt.clikt.core.context import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.options.convert @@ -10,10 +11,11 @@ import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.types.enum import com.github.ajalt.clikt.parameters.types.inputStream import com.github.ajalt.clikt.parameters.types.path -import com.github.ajalt.mordant.animation.progressAnimation +import com.github.ajalt.mordant.animation.progress.advance +import com.github.ajalt.mordant.animation.progress.animateOnThread +import com.github.ajalt.mordant.animation.progress.execute import com.github.ajalt.mordant.rendering.TextColors -import com.github.ajalt.mordant.widgets.progress.progressBar -import com.github.ajalt.mordant.widgets.progress.progressBarLayout +import com.github.ajalt.mordant.widgets.progress.* import com.mineinabyss.keepup.api.* import com.mineinabyss.keepup.downloads.DownloadResult import com.mineinabyss.keepup.downloads.github.GithubConfig @@ -23,14 +25,15 @@ import com.mineinabyss.keepup.helpers.clearSymlinks import com.mineinabyss.keepup.helpers.linkToDest import com.mineinabyss.keepup.helpers.printToConsole import com.mineinabyss.keepup.t -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking import kotlin.time.Duration import kotlin.time.Duration.Companion.minutes import kotlin.time.DurationUnit import kotlin.time.TimeSource -class PluginsCommand : CliktCommand(name = "plugins", help = "Syncs plugins from a hocon/json config") { +class PluginsCommand : CliktCommand(name = "plugins") { + override fun help(context: Context): String = "Syncs plugins from a hocon/json config" + init { context { autoEnvvarPrefix = "KEEPUP" @@ -113,24 +116,23 @@ class PluginsCommand : CliktCommand(name = "plugins", help = "Syncs plugins from progressBarLayout { progressBar() } - val progress = if (hideProgressBar) null else t.progressAnimation { + val progress = if (hideProgressBar) null else progressBarLayout { text("Keepup!") percentage() progressBar() completed() timeRemaining() - } - progress?.updateTotal(sources.size.toLong()) - progress?.start() + }.animateOnThread(t) + progress?.update { total = (sources.size.toLong()) } + progress?.execute() if (githubConfig.overrideGithubRelease != GithubReleaseOverride.NONE) t.println("${TextColors.yellow("[!]")} Overriding GitHub release versions to ${githubConfig.overrideGithubRelease}") val startTime = TimeSource.Monotonic.markNow() - runBlocking(Dispatchers.IO) { - val downloadResults = downloader.download(sources = sources.toTypedArray(), dest = dest) - + runBlocking { + val downloadResults = downloader.download(sources = sources.toTypedArray(), dest = dest, this) for (result in downloadResults) { if (result is DownloadResult.HasFiles) { linkToDest(dest, result) @@ -139,6 +141,7 @@ class PluginsCommand : CliktCommand(name = "plugins", help = "Syncs plugins from progress?.advance(1) result.printToConsole() } + progress?.clear() progress?.stop() diff --git a/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/TemplateCommand.kt b/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/TemplateCommand.kt index ed4476d..4503734 100644 --- a/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/TemplateCommand.kt +++ b/keepup-cli/src/main/kotlin/com/mineinabyss/keepup/cli/TemplateCommand.kt @@ -2,12 +2,15 @@ package com.mineinabyss.keepup.cli import com.charleskorn.kaml.Yaml import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.core.Context import com.github.ajalt.clikt.parameters.arguments.argument import com.mineinabyss.keepup.config_sync.VariablesSerializer import com.mineinabyss.keepup.config_sync.templating.Templater import com.mineinabyss.keepup.t -class TemplateCommand : CliktCommand(help = "Previews Pebble template result") { +class TemplateCommand : CliktCommand() { + override fun help(context: Context) = "Previews Pebble template result" + val input by argument(help = "Input stream to template") val variables by argument(help = "Yaml formatted variables to template with")