Skip to content

Commit

Permalink
chore: Bump dependencies
Browse files Browse the repository at this point in the history
fix: Correctly consume channel as results are being emitted
  • Loading branch information
0ffz committed Oct 7, 2024
1 parent 5597f2c commit 00f86a3
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 74 deletions.
44 changes: 22 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
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 {
repositories {
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)
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
17 changes: 10 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<DownloadResult> = coroutineScope {
val channel = Channel<DownloadResult>(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<DownloadResult> = 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<Int> {
// repeat(20) {
// launch(Dispatchers.IO) {
// delay(Random.nextLong(3000))
// channel.send(1)
// }
// }
// }
// for(i in channel) {
// println(i)
// }
//}
4 changes: 2 additions & 2 deletions keepup-cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down Expand Up @@ -36,7 +36,7 @@ distributions {
tasks {
shadowJar {
minimize {
exclude { it.moduleGroup == "org.slf4j" }
exclude { it.moduleGroup == "org.slf4j" || it.moduleGroup == "com.github.ajalt.mordant" }
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -139,6 +141,7 @@ class PluginsCommand : CliktCommand(name = "plugins", help = "Syncs plugins from
progress?.advance(1)
result.printToConsole()
}

progress?.clear()
progress?.stop()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 00f86a3

Please sign in to comment.