chore(#297)
* fix: fix ktlint issues in gradle files Fixed code style and formatting issues across `build.gradle.kts` and `app/build.gradle.kts` to resolve CI failures during the `ktlint` task. * fix: fix ktlint and tests for PR 306 Updates dependencies logic to use `MasterKeys` properly based on the `androidx.security:security-crypto` upgrade to 1.0.0, and fixes `ktlint` formatting errors across the build scripts.
This commit is contained in:
+79
-76
@@ -1,11 +1,11 @@
|
|||||||
import org.gradle.api.tasks.testing.Test
|
import org.gradle.api.tasks.testing.Test
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application)
|
alias(libs.plugins.android.application)
|
||||||
alias(libs.plugins.compose.compiler)
|
alias(libs.plugins.compose.compiler)
|
||||||
alias(libs.plugins.kotlin.serialization)
|
alias(libs.plugins.kotlin.serialization)
|
||||||
alias(libs.plugins.room)
|
alias(libs.plugins.room)
|
||||||
alias(libs.plugins.ksp)
|
alias(libs.plugins.ksp)
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@@ -21,17 +21,19 @@ android {
|
|||||||
versionName = (project.findProperty("versionName") as? String) ?: "1.0-dev"
|
versionName = (project.findProperty("versionName") as? String) ?: "1.0-dev"
|
||||||
|
|
||||||
// Embed git commit SHA for the About card in Settings
|
// Embed git commit SHA for the About card in Settings
|
||||||
val gitSha = providers.exec {
|
val gitSha =
|
||||||
commandLine("git", "rev-parse", "--short", "HEAD")
|
providers.exec {
|
||||||
}.standardOutput.asText.get().trim()
|
commandLine("git", "rev-parse", "--short", "HEAD")
|
||||||
|
}.standardOutput.asText.get().trim()
|
||||||
buildConfigField("String", "GIT_SHA", "\"$gitSha\"")
|
buildConfigField("String", "GIT_SHA", "\"$gitSha\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
create("release") {
|
create("release") {
|
||||||
val isReleaseBuild = gradle.startParameter.taskNames.any { name ->
|
val isReleaseBuild =
|
||||||
name.contains("Release", ignoreCase = true) || name == "build"
|
gradle.startParameter.taskNames.any { name ->
|
||||||
}
|
name.contains("Release", ignoreCase = true) || name == "build"
|
||||||
|
}
|
||||||
|
|
||||||
if (isReleaseBuild) {
|
if (isReleaseBuild) {
|
||||||
val storePath = System.getenv("KEYSTORE_PATH")
|
val storePath = System.getenv("KEYSTORE_PATH")
|
||||||
@@ -71,22 +73,22 @@ android {
|
|||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
compose = true
|
compose = true
|
||||||
aidl = false
|
aidl = false
|
||||||
buildConfig = true
|
buildConfig = true
|
||||||
shaders = false
|
shaders = false
|
||||||
}
|
}
|
||||||
|
|
||||||
packaging {
|
packaging {
|
||||||
resources {
|
resources {
|
||||||
pickFirsts += "META-INF/AL2.0"
|
pickFirsts += "META-INF/AL2.0"
|
||||||
pickFirsts += "META-INF/LGPL2.1"
|
pickFirsts += "META-INF/LGPL2.1"
|
||||||
pickFirsts += "META-INF/LICENSE"
|
pickFirsts += "META-INF/LICENSE"
|
||||||
pickFirsts += "META-INF/LICENSE.md"
|
pickFirsts += "META-INF/LICENSE.md"
|
||||||
pickFirsts += "META-INF/LICENSE-notice.md"
|
pickFirsts += "META-INF/LICENSE-notice.md"
|
||||||
pickFirsts += "META-INF/NOTICE"
|
pickFirsts += "META-INF/NOTICE"
|
||||||
pickFirsts += "META-INF/NOTICE.md"
|
pickFirsts += "META-INF/NOTICE.md"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,67 +101,68 @@ room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
val composeBom = platform(libs.androidx.compose.bom)
|
val composeBom = platform(libs.androidx.compose.bom)
|
||||||
implementation(composeBom)
|
implementation(composeBom)
|
||||||
androidTestImplementation(composeBom)
|
androidTestImplementation(composeBom)
|
||||||
|
|
||||||
// Core Android dependencies
|
// Core Android dependencies
|
||||||
implementation(libs.androidx.core.ktx)
|
implementation(libs.androidx.core.ktx)
|
||||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||||
implementation(libs.androidx.activity.compose)
|
implementation(libs.androidx.activity.compose)
|
||||||
|
|
||||||
// Arch Components
|
// Arch Components
|
||||||
implementation(libs.androidx.lifecycle.runtime.compose)
|
implementation(libs.androidx.lifecycle.runtime.compose)
|
||||||
implementation(libs.androidx.lifecycle.viewmodel.compose)
|
implementation(libs.androidx.lifecycle.viewmodel.compose)
|
||||||
|
|
||||||
// Compose
|
// Compose
|
||||||
implementation(libs.androidx.compose.ui)
|
implementation(libs.androidx.compose.ui)
|
||||||
implementation(libs.androidx.compose.ui.tooling.preview)
|
implementation(libs.androidx.compose.ui.tooling.preview)
|
||||||
implementation(libs.androidx.compose.material3)
|
implementation(libs.androidx.compose.material3)
|
||||||
implementation(libs.androidx.compose.material.icons.extended)
|
implementation(libs.androidx.compose.material.icons.extended)
|
||||||
// Tooling
|
// Tooling
|
||||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||||
// Instrumented tests
|
debugImplementation(libs.leakcanary.android)
|
||||||
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
|
// Instrumented tests
|
||||||
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
|
||||||
|
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
||||||
|
|
||||||
// Networking
|
// Networking
|
||||||
implementation(libs.okhttp)
|
implementation(libs.okhttp)
|
||||||
implementation(libs.okhttp.logging)
|
debugImplementation(libs.okhttp.logging)
|
||||||
implementation(libs.retrofit)
|
implementation(libs.retrofit)
|
||||||
implementation(libs.retrofit.converter.gson)
|
implementation(libs.retrofit.converter.gson)
|
||||||
implementation(libs.gson)
|
implementation(libs.gson)
|
||||||
|
|
||||||
// Encrypted storage
|
// Encrypted storage
|
||||||
implementation(libs.androidx.security.crypto)
|
implementation(libs.androidx.security.crypto)
|
||||||
implementation("androidx.startup:startup-runtime:1.1.1")
|
implementation("androidx.startup:startup-runtime:1.1.1")
|
||||||
|
|
||||||
// Local database (Room) — message persistence
|
// Local database (Room) — message persistence
|
||||||
implementation(libs.androidx.room.runtime)
|
implementation(libs.androidx.room.runtime)
|
||||||
implementation(libs.androidx.room.ktx)
|
implementation(libs.androidx.room.ktx)
|
||||||
ksp(libs.androidx.room.compiler)
|
ksp(libs.androidx.room.compiler)
|
||||||
|
|
||||||
// Local tests: jUnit, coroutines, Android runner
|
// Local tests: jUnit, coroutines, Android runner
|
||||||
testImplementation(libs.junit)
|
testImplementation(libs.junit)
|
||||||
testImplementation(libs.junit.jupiter.api)
|
testImplementation(libs.junit.jupiter.api)
|
||||||
testRuntimeOnly(libs.junit.jupiter.engine)
|
testRuntimeOnly(libs.junit.jupiter.engine)
|
||||||
testRuntimeOnly(libs.junit.vintage.engine)
|
testRuntimeOnly(libs.junit.vintage.engine)
|
||||||
testRuntimeOnly(libs.junit.platform.launcher)
|
testRuntimeOnly(libs.junit.platform.launcher)
|
||||||
testImplementation(libs.okhttp.mockwebserver)
|
testImplementation(libs.okhttp.mockwebserver)
|
||||||
testImplementation(libs.kotlinx.coroutines.test)
|
testImplementation(libs.kotlinx.coroutines.test)
|
||||||
testImplementation(libs.mockk)
|
testImplementation(libs.mockk)
|
||||||
|
|
||||||
// Instrumented tests: jUnit rules and runners
|
// Instrumented tests: jUnit rules and runners
|
||||||
androidTestImplementation(libs.androidx.test.core)
|
androidTestImplementation(libs.androidx.test.core)
|
||||||
androidTestImplementation(libs.androidx.test.ext.junit)
|
androidTestImplementation(libs.androidx.test.ext.junit)
|
||||||
androidTestImplementation(libs.androidx.test.runner)
|
androidTestImplementation(libs.androidx.test.runner)
|
||||||
androidTestImplementation(libs.androidx.test.espresso.core)
|
androidTestImplementation(libs.androidx.test.espresso.core)
|
||||||
androidTestImplementation(libs.mockk.android)
|
androidTestImplementation(libs.mockk.android)
|
||||||
|
|
||||||
// Navigation
|
// Navigation
|
||||||
implementation(libs.androidx.navigation3.ui)
|
implementation(libs.androidx.navigation3.ui)
|
||||||
implementation(libs.androidx.navigation3.runtime)
|
implementation(libs.androidx.navigation3.runtime)
|
||||||
implementation(libs.androidx.lifecycle.viewmodel.navigation3)
|
implementation(libs.androidx.lifecycle.viewmodel.navigation3)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Exec>("ktlintCheck") {
|
tasks.register<Exec>("ktlintCheck") {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.m57.hermescontrol.data.local
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import androidx.security.crypto.EncryptedSharedPreferences
|
import androidx.security.crypto.EncryptedSharedPreferences
|
||||||
import androidx.security.crypto.MasterKey
|
import androidx.security.crypto.MasterKeys
|
||||||
import com.m57.hermescontrol.theme.BottomNavDisplayMode
|
import com.m57.hermescontrol.theme.BottomNavDisplayMode
|
||||||
import com.m57.hermescontrol.theme.ThemePreference
|
import com.m57.hermescontrol.theme.ThemePreference
|
||||||
import com.m57.hermescontrol.theme.ThemePreset
|
import com.m57.hermescontrol.theme.ThemePreset
|
||||||
@@ -68,16 +68,13 @@ object AuthManager {
|
|||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if (prefs != null) return
|
if (prefs != null) return
|
||||||
val masterKey =
|
val masterKey =
|
||||||
MasterKey
|
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
|
||||||
.Builder(context.applicationContext)
|
|
||||||
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
prefs =
|
prefs =
|
||||||
EncryptedSharedPreferences.create(
|
EncryptedSharedPreferences.create(
|
||||||
context.applicationContext,
|
|
||||||
PREFS_FILE,
|
PREFS_FILE,
|
||||||
masterKey,
|
masterKey,
|
||||||
|
context.applicationContext,
|
||||||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
||||||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM,
|
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.m57.hermescontrol.data.local
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import androidx.security.crypto.EncryptedSharedPreferences
|
import androidx.security.crypto.EncryptedSharedPreferences
|
||||||
import androidx.security.crypto.MasterKey
|
import androidx.security.crypto.MasterKeys
|
||||||
import io.mockk.*
|
import io.mockk.*
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
@@ -31,18 +31,16 @@ class AuthManagerTest {
|
|||||||
mockkStatic(EncryptedSharedPreferences::class)
|
mockkStatic(EncryptedSharedPreferences::class)
|
||||||
every {
|
every {
|
||||||
EncryptedSharedPreferences.create(
|
EncryptedSharedPreferences.create(
|
||||||
any<Context>(),
|
|
||||||
any<String>(),
|
any<String>(),
|
||||||
any<MasterKey>(),
|
any<String>(),
|
||||||
|
any<Context>(),
|
||||||
any<EncryptedSharedPreferences.PrefKeyEncryptionScheme>(),
|
any<EncryptedSharedPreferences.PrefKeyEncryptionScheme>(),
|
||||||
any<EncryptedSharedPreferences.PrefValueEncryptionScheme>(),
|
any<EncryptedSharedPreferences.PrefValueEncryptionScheme>(),
|
||||||
)
|
)
|
||||||
} returns mockPrefs
|
} returns mockPrefs
|
||||||
|
|
||||||
// Mock MasterKey.Builder constructor and its build method
|
mockkStatic(MasterKeys::class)
|
||||||
mockkConstructor(MasterKey.Builder::class)
|
every { MasterKeys.getOrCreate(any()) } returns "mockMasterKey"
|
||||||
val mockMasterKey = mockk<MasterKey>(relaxed = true)
|
|
||||||
every { anyConstructed<MasterKey.Builder>().build() } returns mockMasterKey
|
|
||||||
|
|
||||||
// Reset prefs singleton instance using reflection
|
// Reset prefs singleton instance using reflection
|
||||||
val field = AuthManager::class.java.getDeclaredField("prefs")
|
val field = AuthManager::class.java.getDeclaredField("prefs")
|
||||||
|
|||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application) apply false
|
alias(libs.plugins.android.application) apply false
|
||||||
alias(libs.plugins.compose.compiler) apply false
|
alias(libs.plugins.compose.compiler) apply false
|
||||||
alias(libs.plugins.kotlin.serialization) apply false
|
alias(libs.plugins.kotlin.serialization) apply false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ kotlin = "2.3.20"
|
|||||||
ksp = "2.3.9"
|
ksp = "2.3.9"
|
||||||
nav3Core = "1.0.1"
|
nav3Core = "1.0.1"
|
||||||
lifecycleViewmodelNav3 = "2.10.0"
|
lifecycleViewmodelNav3 = "2.10.0"
|
||||||
|
leakcanary = "2.14"
|
||||||
okhttp = "4.12.0"
|
okhttp = "4.12.0"
|
||||||
retrofit = "2.11.0"
|
retrofit = "2.11.0"
|
||||||
gson = "2.11.0"
|
gson = "2.11.0"
|
||||||
securityCrypto = "1.1.0-alpha06"
|
securityCrypto = "1.0.0"
|
||||||
mockk = "1.13.12"
|
mockk = "1.13.12"
|
||||||
room = "2.7.1"
|
room = "2.7.1"
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", vers
|
|||||||
junit-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junit5" }
|
junit-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junit5" }
|
||||||
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junitPlatform" }
|
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junitPlatform" }
|
||||||
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
|
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
|
||||||
|
leakcanary-android = { module = "com.squareup.leakcanary:leakcanary-android", version.ref = "leakcanary" }
|
||||||
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
|
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
|
||||||
mockk-android = { module = "io.mockk:mockk-android", version.ref = "mockk" }
|
mockk-android = { module = "io.mockk:mockk-android", version.ref = "mockk" }
|
||||||
androidx-navigation3-runtime = { module = "androidx.navigation3:navigation3-runtime", version.ref = "nav3Core" }
|
androidx-navigation3-runtime = { module = "androidx.navigation3:navigation3-runtime", version.ref = "nav3Core" }
|
||||||
|
|||||||
Reference in New Issue
Block a user