1
0
Fork 0

setup jvm target, move koin modules to components

master
Florian Schrofner 2022-02-26 23:10:55 +01:00
parent 40c0d8dd5e
commit 3cd728756a
8 changed files with 168 additions and 12 deletions

23
.github/workflows/jar.yml vendored Normal file
View File

@ -0,0 +1,23 @@
name: Build jar release on tag
on:
push:
tags:
- '*'
jobs:
gradle:
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 11
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Execute Gradle build
run: ./gradlew shadowJar

View File

@ -4,6 +4,11 @@ Change your light settings easily inside scripts or use configuration files to a
Please report issues, bugs or feature requests [here](https://codeberg.org/schrofi/happy-cat/issues). Please report issues, bugs or feature requests [here](https://codeberg.org/schrofi/happy-cat/issues).
## Running
Download the newest release for your system from the [releases page](https://codeberg.org/schrofi/happy-cat/releases).
On Linux and Mac OS you can run the native binaries by simply executing `./hc`.
On all other systems you have to resort to java by running the jar like `java -jar ./hc.jar`
## Usage ## Usage
Happy cat is split up into multiple subcommands, each of which have their own parameters. Happy cat is split up into multiple subcommands, each of which have their own parameters.
To find out more about each command, check out the help pages by appending `--help` after the command. To find out more about each command, check out the help pages by appending `--help` after the command.
@ -79,11 +84,19 @@ Timeframes can cross midnight, but *must not* overlap. If there are overlapping
Probably one could automate the setup using systemd and/or cronjobs, but so far I didn't get to that. Probably one could automate the setup using systemd and/or cronjobs, but so far I didn't get to that.
## Building ## Building
It should be enough to do a simple: ### Linux and Mac OS
To build native binaries run:
```bash ```bash
./gradlew nativeBinaries ./gradlew nativeBinaries
``` ```
You can then find the executable in `build/bin/native/hcReleaseExecutable`. You can then find the executable in `build/bin/native/hcReleaseExecutable`.
### Windows and others
To build the Java package run:
```bash
./gradlew shadowJar
```
You can then find the jar in `build/libs`.
## License ## License
This software is licensed under the MPL 2.0, see the [LICENSE](LICENSE) file. This software is licensed under the MPL 2.0, see the [LICENSE](LICENSE) file.

View File

@ -9,16 +9,28 @@ val ktorVersion: String by project
plugins { plugins {
kotlin("multiplatform") version "1.6.10" kotlin("multiplatform") version "1.6.10"
kotlin("plugin.serialization") version "1.6.10" kotlin("plugin.serialization") version "1.6.10"
id("com.github.johnrengelman.shadow") version "7.1.2"
application
} }
group = "fi.schro" group = "fi.schro"
version = toolVersion version = toolVersion
application {
mainClass.set("fi.schro.Main")
}
repositories { repositories {
mavenCentral() mavenCentral()
} }
kotlin { kotlin {
//java compilation
jvm {
withJava()
}
//native compilation
val hostOs = System.getProperty("os.name") val hostOs = System.getProperty("os.name")
val nativeTarget = when { val nativeTarget = when {
@ -53,9 +65,11 @@ kotlin {
implementation("org.jetbrains.kotlinx:kotlinx-datetime:$datetimeVersion") implementation("org.jetbrains.kotlinx:kotlinx-datetime:$datetimeVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion") implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion") implementation("io.ktor:ktor-client-cio:$ktorVersion")
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
} }
} }
val commonTest by getting val commonTest by getting
val nativeMain by getting val nativeMain by getting
val jvmMain by getting
} }
} }

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2022 Florian Schrofner
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package fi.schro
import fi.schro.di.jvmModules
import fi.schro.ui.HappyCatCommand
import org.koin.core.context.startKoin
object Main {
@JvmStatic
fun main(args: Array<String>) {
startKoin {
modules(jvmModules)
}
HappyCatCommand()
.main(args)
}
}

View File

@ -8,6 +8,9 @@
package fi.schro.di package fi.schro.di
import fi.schro.util.FileUtil
import fi.schro.util.FileUtilImpl
import org.koin.dsl.module
import fi.schro.data.ConfigurationRepository import fi.schro.data.ConfigurationRepository
import fi.schro.data.ConfigurationRepositoryImpl import fi.schro.data.ConfigurationRepositoryImpl
import fi.schro.data.ElgatoLightRepository import fi.schro.data.ElgatoLightRepository
@ -16,11 +19,9 @@ import fi.schro.ui.ApplyCommand
import fi.schro.ui.DaemonCommand import fi.schro.ui.DaemonCommand
import fi.schro.ui.GetCommand import fi.schro.ui.GetCommand
import fi.schro.ui.SetCommand import fi.schro.ui.SetCommand
import fi.schro.util.FileUtil
import fi.schro.util.FileUtilImpl
import io.ktor.client.* import io.ktor.client.*
import io.ktor.client.engine.cio.* import io.ktor.client.engine.cio.*
import org.koin.dsl.module import io.ktor.client.features.json.*
val commandModule = module { val commandModule = module {
single { ApplyCommand(get()) } single { ApplyCommand(get()) }
@ -36,14 +37,18 @@ val dataModule = module {
val networkModule = module { val networkModule = module {
//HttpClient has to be recreated every time it is used //HttpClient has to be recreated every time it is used
factory<HttpClient> { HttpClient(CIO)} factory<HttpClient> {
HttpClient(CIO) {
install(JsonFeature)
}
}
} }
val fileModule = module { val fileModule = module {
single<FileUtil> { FileUtilImpl() } single<FileUtil> { FileUtilImpl() }
} }
val mainModule = listOf( val jvmModules = listOf(
commandModule, commandModule,
dataModule, dataModule,
networkModule, networkModule,

View File

@ -0,0 +1,19 @@
/*
* Copyright (c) 2022 Florian Schrofner
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package fi.schro.util
import java.io.File
class FileUtilImpl: FileUtil {
override fun readAllText(filePath: String): String {
return File(filePath).inputStream().use {
it.readBytes().toString(Charsets.UTF_8)
}
}
}

View File

@ -8,13 +8,13 @@
package fi.schro package fi.schro
import fi.schro.di.mainModule import fi.schro.di.nativeModules
import fi.schro.ui.HappyCatCommand import fi.schro.ui.HappyCatCommand
import org.koin.core.context.startKoin import org.koin.core.context.startKoin
fun main(args: Array<String>) { fun main(args: Array<String>) {
startKoin { startKoin {
modules(mainModule) modules(nativeModules)
} }
HappyCatCommand() HappyCatCommand()

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2022 Florian Schrofner
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package fi.schro.di
import fi.schro.util.FileUtil
import fi.schro.util.FileUtilImpl
import org.koin.dsl.module
import fi.schro.data.ConfigurationRepository
import fi.schro.data.ConfigurationRepositoryImpl
import fi.schro.data.ElgatoLightRepository
import fi.schro.data.LightRepository
import fi.schro.ui.ApplyCommand
import fi.schro.ui.DaemonCommand
import fi.schro.ui.GetCommand
import fi.schro.ui.SetCommand
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.features.json.*
import org.koin.dsl.module
val commandModule = module {
single { ApplyCommand(get()) }
single { DaemonCommand(get()) }
single { SetCommand(get()) }
single { GetCommand(get()) }
}
val dataModule = module {
single<LightRepository> { ElgatoLightRepository() }
single<ConfigurationRepository> { ConfigurationRepositoryImpl(get(), get()) }
}
val networkModule = module {
//HttpClient has to be recreated every time it is used
factory<HttpClient> {
HttpClient(CIO) {
install(JsonFeature)
}
}
}
val fileModule = module {
single<FileUtil> { FileUtilImpl() }
}
val nativeModules = listOf(
commandModule,
dataModule,
networkModule,
fileModule
)