Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available
distribution: 'zulu'
java-version: 21
- name: Cache SonarQube packages
uses: actions/cache@v4
with:
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/publish_nvplib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Publish NvpLib
on:
push:
tags:
- 'nvplib-*'
jobs:
publish:
name: Release build and publish
runs-on: macOS-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
- name: Publish to MavenCentral
run: ./gradlew nvplib:core:publishToMavenCentral nvplib:nfc:publishToMavenCentral --no-configuration-cache
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_CONTENTS }}
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ sonar {
property("sonar.organization", "lcacheux")
}
}

val nvplibVersion: String? by extra {
providers.exec {
commandLine("git", "describe", "--tags", "--match", "nvplib-*")
}.standardOutput.asText.get().trim().removePrefix("nvplib-")
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ kotlin.code.style=official
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
ksp.useKSP2=false
33 changes: 20 additions & 13 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
[versions]
java = "17"
java = "21"
nvplibJava = "8"
android-minSdk = "24"
android-compileSdk = "36"
agp = "8.13.2"
compose-plugin="1.9.0"
hilt = "2.57.1"
kotlin = "2.1.21"
compose-plugin="1.9.3"
hilt = "2.57.2"
kotlin = "2.2.20"
coroutines = "1.10.2"
room = "2.8.2"
sqlite = "2.6.1"
androidx-datastore = "1.1.7"
room = "2.8.4"
sqlite = "2.6.2"
androidx-datastore = "1.2.0"
bytonio = "0.0.3"

[plugins]
ksp = { id = "com.google.devtools.ksp", version = "2.1.21-2.0.1" }
ksp = { id = "com.google.devtools.ksp", version = "2.2.20-2.0.4" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
Expand All @@ -22,20 +24,21 @@ hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
room = { id = "androidx.room", version.ref = "room" }
jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
dokka = { id = "org.jetbrains.dokka", version = "2.0.0" }
dokka = { id = "org.jetbrains.dokka", version = "2.1.0" }
sonarqube = { id = "org.sonarqube", version = "6.3.1.5724" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.35.0" }

[libraries]
colorpicker-compose = { module = "com.github.skydoves:colorpicker-compose", version = "1.1.2" }
colorpicker-compose = { module = "com.github.skydoves:colorpicker-compose", version = "1.1.3" }
filekit-compose = { module = "io.github.vinceglb:filekit-compose", version = "0.8.8" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "coroutines" }
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version = "1.11.0" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version = "1.12.1" }
androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version = "androidx-datastore" }
androidx-datastore-core = { module = "androidx.datastore:datastore-core", version.ref = "androidx-datastore" }
androidx-lifecycle-viewmodel-compose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version = "2.9.3" }
androidx-lifecycle-viewmodel-compose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version = "2.9.6" }

# Room
androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
Expand All @@ -48,11 +51,15 @@ hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt"
hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" }
hilt-android-testing = { module = "com.google.dagger:hilt-android-testing", version.ref = "hilt" }

# Bytonio
bytonio-core = { module = "net.cacheux.bytonio:bytonio-core", version.ref = "bytonio" }
bytonio-processor = { module = "net.cacheux.bytonio:bytonio-processor", version.ref = "bytonio" }

# Testing
junit = { group = "junit", name = "junit", version = "4.13.2" }
androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version = "1.3.0" }
androidx-test-runner = { group = "androidx.test", name = "runner", version="1.7.0" }
mockito-android = { group = "org.mockito", name = "mockito-android", version = "5.20.0" }
mockito-kotlin = { group = "org.mockito.kotlin", name = "mockito-kotlin", version = "6.1.0" }
turbine = { group = "app.cash.turbine", name = "turbine", version = "1.2.1" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version = "1.9.3" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version = "1.10.0" }
152 changes: 83 additions & 69 deletions nvplib/core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,92 +1,106 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

plugins {
id("java-library")
id("maven-publish")
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.dokka)
signing
alias(libs.plugins.ksp)
alias(libs.plugins.mavenPublish)
}

kotlin {
jvmToolchain(libs.versions.java.get().toInt())
}
val nvplibVersion: String? by project
group = "net.cacheux.nvplib"
version = nvplibVersion ?: "unknown"

java {
withSourcesJar()
}
kotlin {
jvmToolchain(libs.versions.nvplibJava.get().toInt())

dependencies {
implementation(kotlin("reflect"))
jvm()

testImplementation(libs.junit)
testImplementation(project(":nvplib:testing"))
testImplementation(project(":utils"))
}
val xcfName = "bytonioKit"

tasks.register<Jar>("dokkaHtmlJar") {
dependsOn(tasks.dokkaHtml)
from(tasks.dokkaHtml.flatMap { it.outputDirectory })
archiveClassifier.set("html-docs")
}
iosX64 {
binaries.framework {
baseName = xcfName
}
}

tasks.register<Jar>("dokkaJavadocJar") {
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}
iosArm64 {
binaries.framework {
baseName = xcfName
}
}

publishing {
repositories {
maven {
url = uri(layout.buildDirectory.dir("release"))
iosSimulatorArm64 {
binaries.framework {
baseName = xcfName
}
}

publications {
create<MavenPublication>("mavenCore") {
groupId = "net.cacheux.nvplib"
artifactId = "nvplib-core"
version = "0.1.2"
afterEvaluate {
from(components["java"])
artifact(tasks["dokkaHtmlJar"])
artifact(tasks["dokkaJavadocJar"])
sourceSets {
commonMain {
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
dependencies {
api(libs.bytonio.core)
}
}

pom {
name = "NVP Lib Core"
description = "Core library to read data from Novopen insulin pens"
url = "https://github.com/lcacheux/nov-open-reader"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
id = "lcacheux"
name = "Leo Cacheux"
email = "leo@cacheux.net"
}
}
scm {
connection = "scm:git:https://github.com/lcacheux/nov-open-reader.git"
developerConnection = "scm:git:ssh://github.com/lcacheux/nov-open-reader.git"
url = "https://github.com/lcacheux/nov-open-reader"
}
jvmTest {
dependencies {
implementation(libs.junit)
implementation(project(":nvplib:testing"))
implementation(project(":utils"))
}
}
}
}

val signingIfAvailable: (Publication) -> Unit by project
signingIfAvailable(publishing.publications.getByName("mavenCore"))
ksp {
arg("bytonio.packageName", "net.cacheux.nvplib.generated")
arg("bytonio.dataSizeFormat", "short")
}

tasks.create<Zip>("bundleZip") {
dependsOn("publish")
from(layout.buildDirectory.dir("release").get()) {
exclude("**/*.asc.*")
dependencies {
add("kspCommonMainMetadata", libs.bytonio.processor)
}

mavenPublishing {
publishToMavenCentral()

signAllPublications()

coordinates(group.toString(), "nvplib-core", version.toString())

pom {
name = "NVP Lib Core"
description = "Core library to read data from Novopen insulin pens"
url = "https://github.com/lcacheux/nov-open-reader"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
id = "lcacheux"
name = "Leo Cacheux"
email = "leo@cacheux.net"
}
}
scm {
connection = "scm:git:https://github.com/lcacheux/nov-open-reader.git"
developerConnection = "scm:git:ssh://github.com/lcacheux/nov-open-reader.git"
url = "https://github.com/lcacheux/nov-open-reader"
}
}
archiveFileName = "nvplib-core.zip"
destinationDirectory = layout.buildDirectory.dir("bundle").get()
}

afterEvaluate {
tasks.withType(KotlinCompilationTask::class).configureEach {
if (name != "kspCommonMainKotlinMetadata") {
dependsOn("kspCommonMainKotlinMetadata")
}
}
tasks.findByName("sourcesJar")?.dependsOn("kspCommonMainKotlinMetadata")
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.cacheux.nvplib

import java.nio.ByteBuffer
import net.cacheux.bytonio.utils.reader
import kotlin.experimental.and

/**
Expand All @@ -27,13 +27,12 @@ fun DataReader.readResult(command: ByteArray): TransceiveResult {
onDataSent(command)
val data = readData(command)
onDataReceived(data)
val buffer = ByteBuffer.wrap(data)
val buffer = data.reader()
val dataSize = buffer.remaining() - 2
val result = ByteArray(dataSize)
buffer.get(result, 0, dataSize)
val result = buffer.readByteArray(dataSize)

return TransceiveResult(
content = ByteBuffer.wrap(result),
success = (buffer.getShort() and 0xffff.toShort()) == NvpController.COMMAND_COMPLETED
content = result.reader(),
success = (buffer.readShort().toShort() and 0xffff.toShort()) == NvpController.COMMAND_COMPLETED
)
}
Loading