Skip to content

Commit 4678a62

Browse files
authored
Merge pull request #163 from AnimatedLEDStrip/dependencies
Update Dependencies and Fix Tests
2 parents 5c08355 + d3abd0e commit 4678a62

28 files changed

Lines changed: 294 additions & 208 deletions

File tree

.github/workflows/test.yml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,17 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4.1.6
1616
- name: Set up JDK
17-
uses: actions/setup-java@v3.1.0
17+
uses: actions/setup-java@v4.2.1
1818
with:
1919
distribution: "temurin"
20-
java-version: 17
20+
java-version: 21
2121
cache: "gradle"
22-
# - name: Cache Gradle packages
23-
# uses: actions/cache@v2.1.4
24-
# with:
25-
# path: |
26-
# ~/.gradle/caches
27-
# ~/.gradle/wrapper
28-
# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
29-
# restore-keys: |
30-
# ${{ runner.os }}-gradle-
3122
- name: Create test classes for testing
3223
run: ./gradlew jvmTestClasses
3324

34-
# - name: Test
35-
# run: ./gradlew jvmTest
3625
- name: Test
3726
run: ./gradlew koverXmlReport
3827
- name: Upload coverage
39-
uses: codecov/codecov-action@v1.3.1
40-
41-
# - name: Cleanup Gradle Cache
42-
# run: |
43-
# rm -f ~/.gradle/caches/modules-2/modules-2.lock
44-
# rm -f ~/.gradle/caches/modules-2/gc.properties
28+
uses: codecov/codecov-action@v3

build.gradle.kts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@
2121
*/
2222

2323
tasks.wrapper {
24-
gradleVersion = "7.4.2"
24+
gradleVersion = "8.7"
2525
}
2626

2727
plugins {
28-
kotlin("multiplatform") version "1.6.21"
29-
kotlin("plugin.serialization") version "1.6.21"
30-
id("org.jetbrains.dokka") version "1.6.21"
28+
kotlin("multiplatform") version "1.9.23"
29+
kotlin("plugin.serialization") version "1.9.23"
30+
id("org.jetbrains.dokka") version "1.9.20"
3131
id("io.kotest") version "0.3.9"
32-
id("org.jetbrains.kotlinx.kover") version "0.6.1"
32+
id("org.jetbrains.kotlinx.kover") version "0.7.6"
3333
id("java-library")
3434
signing
35-
id("de.marcphilipp.nexus-publish") version "0.4.0"
36-
id("io.codearte.nexus-staging") version "0.30.0"
35+
id("maven-publish")
36+
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
3737
}
3838

3939
repositories {
@@ -46,6 +46,8 @@ version = "1.2.0-SNAPSHOT"
4646
description = "A library for creating an AnimatedLEDStrip server"
4747

4848
kotlin {
49+
jvmToolchain(8)
50+
4951
jvm {
5052
// compilations.all {
5153
// kotlinOptions.jvmTarget = "1.8"
@@ -75,38 +77,38 @@ kotlin {
7577
val commonMain by getting {
7678
dependencies {
7779
api(kotlin("reflect"))
78-
api("io.github.animatedledstrip:animatedledstrip-core:1.1.0-SNAPSHOT")
80+
api("io.github.animatedledstrip:animatedledstrip-core:1.0.5")
7981
}
8082
}
8183
val commonTest by getting {
8284
dependencies {
8385
implementation(kotlin("test-common"))
8486
implementation(kotlin("test-annotations-common"))
85-
implementation("io.kotest:kotest-assertions-core:5.3.0")
86-
implementation("io.kotest:kotest-property:5.3.0")
87+
implementation("io.kotest:kotest-assertions-core:5.9.0")
88+
implementation("io.kotest:kotest-property:5.9.0")
8789
}
8890
}
8991
val jvmMain by getting {
9092
dependencies {
91-
api("io.github.animatedledstrip:animatedledstrip-core-jvm:1.1.0-SNAPSHOT")
93+
api("io.github.animatedledstrip:animatedledstrip-core-jvm:1.0.5")
9294

93-
api("commons-cli:commons-cli:1.4")
95+
api("commons-cli:commons-cli:1.8.0")
9496
implementation("io.github.maxnz:interactive-command-parser:0.1")
95-
implementation("com.github.doyaaaaaken:kotlin-csv-jvm:0.15.0")
97+
implementation("com.github.doyaaaaaken:kotlin-csv-jvm:1.9.3")
9698

9799
api("io.ktor:ktor-server-core:1.6.8")
98100
api("io.ktor:ktor-server-netty:1.6.8")
99101
api("io.ktor:ktor-serialization:1.6.8")
100102
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.20.0")
101-
api("ch.qos.logback:logback-classic:1.4.3")
103+
// api("ch.qos.logback:logback-classic:1.5.6")
102104
}
103105
}
104106
val jvmTest by getting {
105107
dependencies {
106108
implementation(kotlin("test-junit"))
107-
implementation("io.mockk:mockk:1.12.4")
108-
implementation("io.kotest:kotest-runner-junit5:5.3.0")
109-
implementation("io.kotest:kotest-framework-engine-jvm:4.3.2")
109+
implementation("io.mockk:mockk:1.13.11")
110+
implementation("io.kotest:kotest-runner-junit5:5.9.0")
111+
implementation("io.kotest:kotest-framework-engine-jvm:5.9.0")
110112
}
111113
}
112114
// val jsMain by getting
@@ -135,7 +137,7 @@ tasks.named<Test>("jvmTest") {
135137
org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED)
136138
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
137139
}
138-
systemProperties = System.getProperties().map { it.key.toString() to it.value }.toMap()
140+
// systemProperties = System.getProperties().map { it.key.toString() to it.value }.toMap()
139141
}
140142

141143
//tasks.jacocoTestReport {
@@ -211,6 +213,11 @@ signing {
211213
sign(publishing.publications)
212214
}
213215

216+
tasks.withType<AbstractPublishToMaven>().configureEach {
217+
val signingTasks = tasks.withType<Sign>()
218+
mustRunAfter(signingTasks)
219+
}
220+
214221
nexusPublishing {
215222
repositories {
216223
sonatype {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/jvmMain/kotlin/animatedledstrip/server/AnimatedLEDStripServer.kt

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
package animatedledstrip.server
2424

2525
import animatedledstrip.communication.decodeJson
26-
import animatedledstrip.communication.toUTF8String
2726
import animatedledstrip.leds.animationmanagement.AnimationToRunParams
2827
import animatedledstrip.leds.animationmanagement.RunningAnimationParams
2928
import animatedledstrip.leds.animationmanagement.startAnimation
@@ -32,11 +31,11 @@ import animatedledstrip.leds.locationmanagement.Location
3231
import animatedledstrip.leds.stripmanagement.LEDStrip
3332
import animatedledstrip.leds.stripmanagement.NativeLEDStrip
3433
import animatedledstrip.leds.stripmanagement.StripInfo
35-
import co.touchlab.kermit.Logger
36-
import kotlinx.coroutines.*
34+
import animatedledstrip.utils.Logger
35+
import kotlinx.coroutines.CoroutineScope
36+
import kotlinx.coroutines.Dispatchers
37+
import kotlinx.coroutines.launch
3738
import java.io.File
38-
import java.io.FileInputStream
39-
import java.io.FileNotFoundException
4039
import java.io.FileOutputStream
4140
import java.nio.file.Files
4241
import java.nio.file.Paths
@@ -50,6 +49,9 @@ class AnimatedLEDStripServer<T : NativeLEDStrip>(
5049
ledClass: KClass<T>,
5150
internal val pixelLocations: List<Location>? = null,
5251
) {
52+
private val logger = Logger.withTag("LED Server")
53+
54+
private val fileOpsScope = CoroutineScope(EmptyCoroutineContext)
5355

5456
/** Is the server running */
5557
internal var running: Boolean = false
@@ -110,82 +112,76 @@ class AnimatedLEDStripServer<T : NativeLEDStrip>(
110112
}
111113

112114
internal fun savePersistentAnimation(newAnim: RunningAnimationParams) {
113-
val scope = CoroutineScope(EmptyCoroutineContext)
114-
scope.launch(Dispatchers.IO) {
115+
fileOpsScope.launch(Dispatchers.IO) {
115116
FileOutputStream("$persistentAnimationDirectory/${newAnim.fileName}").apply {
116117
write(newAnim.sourceParams.json())
117118
close()
118119
}
119120
}
120-
scope.cancel()
121121
}
122122

123123
internal fun deletePersistentAnimation(anim: RunningAnimationParams) {
124124
if (File("$persistentAnimationDirectory/${anim.fileName}").exists())
125-
Files.delete(Paths.get("$persistentAnimationDirectory/${anim.fileName}"))
125+
fileOpsScope.launch(Dispatchers.IO) {
126+
Files.delete(Paths.get("$persistentAnimationDirectory/${anim.fileName}"))
127+
}
126128
}
127129

128130
internal fun loadPersistentAnimations() {
129131
val dir = File(persistentAnimationDirectory)
130-
val scope = CoroutineScope(EmptyCoroutineContext)
131132
when {
132-
!dir.exists() -> dir.mkdirs()
133-
!dir.isDirectory -> Logger.w("$persistentAnimationDirectory should be a directory")
134-
else -> scope.launch {
135-
File(persistentAnimationDirectory).walk().forEach {
133+
!dir.exists() -> fileOpsScope.launch(Dispatchers.IO) { dir.mkdirs() }
134+
!dir.isDirectory -> logger.w("$persistentAnimationDirectory should be a directory")
135+
else -> fileOpsScope.launch(Dispatchers.IO) {
136+
dir.walk().forEach {
136137
if (!it.isDirectory && it.name.endsWith(".json"))
137138
try {
138-
FileInputStream(it).apply {
139-
val obj = readAllBytes().toUTF8String().decodeJson() as AnimationToRunParams
140-
leds.animationManager.startAnimation(obj, obj.id)
141-
close()
142-
}
143-
} catch (_: FileNotFoundException) {
139+
val obj = it.readText().decodeJson() as AnimationToRunParams
140+
leds.animationManager.startAnimation(obj, obj.id)
141+
} catch (e: Exception) {
142+
logger.w("Failed to decode ${it.name}: $e")
144143
}
145144
}
146145
}
147146
}
148-
scope.cancel()
149147
}
150148

151149
fun addSavedAnimation(newAnim: AnimationToRunParams) {
152-
Logger.i(newAnim.toString())
150+
logger.i("Saved ${newAnim.id}: $newAnim")
153151
savedAnimations[newAnim.id] = newAnim
154-
FileOutputStream("$savedAnimationDirectory/${newAnim.fileName}").apply {
155-
write(newAnim.json())
156-
close()
152+
fileOpsScope.launch(Dispatchers.IO) {
153+
FileOutputStream("$savedAnimationDirectory/${newAnim.fileName}").apply {
154+
write(newAnim.json())
155+
close()
156+
}
157157
}
158158
}
159159

160160
fun deleteSavedAnimation(id: String) {
161161
savedAnimations.remove(id)
162162
if (File("$savedAnimationDirectory/$id.json").exists())
163-
Files.delete(Paths.get("$savedAnimationDirectory/$id.json"))
163+
fileOpsScope.launch(Dispatchers.IO) {
164+
Files.delete(Paths.get("$savedAnimationDirectory/$id.json"))
165+
}
164166
}
165167

166168
internal fun loadSavedAnimations() {
167169
val dir = File(savedAnimationDirectory)
168-
val scope = CoroutineScope(EmptyCoroutineContext)
169170
when {
170-
!dir.exists() -> dir.mkdirs()
171-
!dir.isDirectory -> Logger.w("$savedAnimationDirectory should be a directory")
172-
else -> scope.launch {
173-
File(savedAnimationDirectory).walk().forEach {
171+
!dir.exists() -> fileOpsScope.launch(Dispatchers.IO) { dir.mkdirs() }
172+
!dir.isDirectory -> logger.w("$savedAnimationDirectory should be a directory")
173+
else -> fileOpsScope.launch(Dispatchers.IO) {
174+
dir.walk().forEach {
174175
if (!it.isDirectory && it.name.endsWith(".json"))
175176
try {
176-
FileInputStream(it).apply {
177-
val obj = readAllBytes().toUTF8String().decodeJson() as AnimationToRunParams
178-
savedAnimations[obj.id] = obj
179-
close()
180-
}
181-
} catch (_: FileNotFoundException) {
177+
val obj = it.readText().decodeJson() as AnimationToRunParams
178+
savedAnimations[obj.id] = obj
182179
} catch (e: Exception) {
183-
Logger.e("Failed to decode ${it.name}: $e")
180+
logger.w("Failed to decode ${it.name}: $e")
184181
}
185182
}
186183
}
187184
}
188-
scope.cancel()
189185
}
190186

191187
val httpServer = httpServer(this)

0 commit comments

Comments
 (0)