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
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Check style
run: ./gradlew spotlessCheck
- name: Build
run: ./gradlew build
- name: Test
Expand All @@ -37,6 +39,8 @@ jobs:
tag_name="${{ github.ref_name }}"
python ./tools/version_validator.py "$tag_name"
echo "tag_name=$tag_name" >> $GITHUB_OUTPUT
- name: Check style
run: ./gradlew spotlessCheck
- name: Build
run: ./gradlew -PVERSION=${{ steps.version.outputs.tag_name }} build
- name: Test
Expand Down
217 changes: 110 additions & 107 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import io.gitlab.arturbosch.detekt.Detekt
import java.util.Properties
import java.io.FileInputStream
import java.io.IOException
import java.util.Properties
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.detekt)
alias(libs.plugins.diffplug.spotless)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.jreleaser)
`maven-publish`
Expand All @@ -17,10 +18,12 @@ val keystorePropertiesFile = rootProject.file("keystore.properties")
val keystoreProperties = Properties()

try {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
} catch (ignored: IOException) {
if (project.hasProperty("centralUsername")) keystoreProperties["centralUsername"] = property("centralUsername")
if (project.hasProperty("centralPassword")) keystoreProperties["centralPassword"] = property("centralPassword")
if (project.hasProperty("centralUsername"))
keystoreProperties["centralUsername"] = property("centralUsername")
if (project.hasProperty("centralPassword"))
keystoreProperties["centralPassword"] = property("centralPassword")
}

android {
Expand All @@ -33,8 +36,8 @@ android {

// The version must be of the form "X.Y.Z[-b][-SNAPSHOT]"
version =
if (project.hasProperty("VERSION")) project.property("VERSION").toString()
else "1.0.1-SNAPSHOT"
if (project.hasProperty("VERSION")) project.property("VERSION").toString()
else "1.0.1-SNAPSHOT"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -48,30 +51,34 @@ android {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

testOptions { unitTests { isIncludeAndroidResources = true } }

publishing {
singleVariant("release") {}
}
publishing { singleVariant("release") {} }
}

kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
kotlin { compilerOptions { jvmTarget.set(JvmTarget.JVM_17) } }

detekt {
config.setFrom("$projectDir/config/detekt.yml")
spotless {
kotlin {
target("**/*.kts", "**/*.kt")
// Versions can be monitored: https://github.com/facebook/ktfmt/releases
ktfmt("0.58")
}
json {
target("**/*.json")
gson().indentWithSpaces(4)
}
}

detekt { config.setFrom("$projectDir/config/detekt.yml") }

tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true)
sarif.required.set(true)
md.required.set(true)
}
reports {
html.required.set(true)
sarif.required.set(true)
md.required.set(true)
}
}

tasks.withType<Test> {
Expand Down Expand Up @@ -99,98 +106,94 @@ dependencies {
androidTestImplementation(libs.androidx.espresso.core)
}

if (keystoreProperties.containsKey("centralUsername") && keystoreProperties.containsKey("centralPassword")) {
afterEvaluate {
publishing {
publications {
create<MavenPublication>("release") {
from(components["release"])

pom {
name = "Khronicle"
packaging = "aar"
description = "An SLF4J backend for Android."
url = "https://github.com/esri/khronicle"

scm {
connection = "scm:git:https://github.com/esri/khronicle"
developerConnection = "scm:git:https://github.com/esri/khronicle"
url = "https://github.com/esri/khronicle"
}

licenses {
license {
name = "Apache License 2.0"
url = "https://spdx.org/licenses/Apache-2.0.html"
}
}

developers {
developer {
id = "award"
name = "Adam Ward"
email = "[email protected]"
}
developer {
id = "jonasvautherin"
name = "Jonas Vautherin"
email = "[email protected]"
}
}
}
}
if (
keystoreProperties.containsKey("centralUsername") &&
keystoreProperties.containsKey("centralPassword")
) {
afterEvaluate {
publishing {
publications {
create<MavenPublication>("release") {
from(components["release"])

pom {
name = "Khronicle"
packaging = "aar"
description = "An SLF4J backend for Android."
url = "https://github.com/esri/khronicle"

scm {
connection = "scm:git:https://github.com/esri/khronicle"
developerConnection = "scm:git:https://github.com/esri/khronicle"
url = "https://github.com/esri/khronicle"
}
repositories {
maven {
url = uri(layout.buildDirectory.dir("target/staging-deploy"))
}

licenses {
license {
name = "Apache License 2.0"
url = "https://spdx.org/licenses/Apache-2.0.html"
}
}

developers {
developer {
id = "award"
name = "Adam Ward"
email = "[email protected]"
}
developer {
id = "jonasvautherin"
name = "Jonas Vautherin"
email = "[email protected]"
}
}
}
}
}
repositories { maven { url = uri(layout.buildDirectory.dir("target/staging-deploy")) } }
}
}

jreleaser {
signing {
setActive("ALWAYS")
armored.set(true)
setMode("COMMAND")
jreleaser {
signing {
setActive("ALWAYS")
armored.set(true)
setMode("COMMAND")

command {
keyName.set("C8B1511EF991537875A649517D5F7A7C9542C299")
}
command { keyName.set("C8B1511EF991537875A649517D5F7A7C9542C299") }
}
deploy {
release {
github {
skipRelease = true
skipTag = true
}
deploy {
release {
github {
skipRelease = true
skipTag = true
}
}
maven {
mavenCentral {
create("sonatype") {
verifyPom = false
setActive("RELEASE")
username = keystoreProperties["centralUsername"] as String
password = keystoreProperties["centralPassword"] as String
url = "https://central.sonatype.com/api/v1/publisher"
stagingRepository("build/target/staging-deploy")
}
}
nexus2 {
create("snapshot-deploy") {
verifyPom = false
setActive("SNAPSHOT")
snapshotUrl.set("https://central.sonatype.com/repository/maven-snapshots")
url = "https://central.sonatype.com/repository/maven-snapshots"
applyMavenCentralRules = true
snapshotSupported = true
username = keystoreProperties["centralUsername"] as String
password = keystoreProperties["centralPassword"] as String
stagingRepository("build/target/staging-deploy")
}
}
}
}
maven {
mavenCentral {
create("sonatype") {
verifyPom = false
setActive("RELEASE")
username = keystoreProperties["centralUsername"] as String
password = keystoreProperties["centralPassword"] as String
url = "https://central.sonatype.com/api/v1/publisher"
stagingRepository("build/target/staging-deploy")
}
}
nexus2 {
create("snapshot-deploy") {
verifyPom = false
setActive("SNAPSHOT")
snapshotUrl.set("https://central.sonatype.com/repository/maven-snapshots")
url = "https://central.sonatype.com/repository/maven-snapshots"
applyMavenCentralRules = true
snapshotSupported = true
username = keystoreProperties["centralUsername"] as String
password = keystoreProperties["centralPassword"] as String
stagingRepository("build/target/staging-deploy")
}
}
}
}
}
}

2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ material = "1.12.0"
mockkVersion = "1.14.5"
robolectric = "4.15.1"
slf4jApi = "2.0.17"
spotlessPlugin = "7.2.1"

[libraries]
android-gradle-plugin = { group = "com.android.tools.build", name = "gradle", version.ref = "agp" }
Expand All @@ -30,6 +31,7 @@ slf4j-api = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4jApi"}
[plugins]
android-library = { id = "com.android.library", version.ref = "agp" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
diffplug-spotless = { id = "com.diffplug.spotless", version.ref = "spotlessPlugin" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
jreleaser = { id = "org.jreleaser", version.ref = "jreleaser-plugin" }

28 changes: 13 additions & 15 deletions src/main/java/com/esri/logger/khronicle/ConfigurationParser.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2025 Esri
//
//
// Licensed under the Apache License Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -102,9 +102,10 @@ class ConfigurationParser {
when (parser.name) {
TAG_ENCODER -> handleEncoder(appender)
else -> {
val property = kClass.memberProperties
.filterIsInstance<KMutableProperty1<Any, Any?>>()
.find { it.name == parser.name }
val property =
kClass.memberProperties.filterIsInstance<KMutableProperty1<Any, Any?>>().find {
it.name == parser.name
}

if (property != null) {
val contents = readText()
Expand Down Expand Up @@ -139,9 +140,7 @@ class ConfigurationParser {

private fun handleRoot() =
handleTag(parser, TAG_ROOT) {
val root = checkNotNull(loggers["root"]) {
"Root config should be pre-initialized"
}
val root = checkNotNull(loggers["root"]) { "Root config should be pre-initialized" }

parser.getAttributeValue(null, ATTR_LEVEL)?.let { level -> root.setLevel(level) }

Expand All @@ -164,9 +163,10 @@ class ConfigurationParser {

private fun handleLogger() =
handleTag(parser, TAG_LOGGER) {
val name = requireNotNull(parser.getAttributeValue(null, ATTR_NAME)) {
"Logger configuration requires name attribute"
}
val name =
requireNotNull(parser.getAttributeValue(null, ATTR_NAME)) {
"Logger configuration requires name attribute"
}
val logger = LoggerConfig()
loggers[name] = logger

Expand Down Expand Up @@ -209,9 +209,7 @@ class ConfigurationParser {
}

private fun skip() {
check(parser.eventType == XmlPullParser.START_TAG) {
"The element must start with a START_TAG"
}
check(parser.eventType == XmlPullParser.START_TAG) { "The element must start with a START_TAG" }

var depth = 1
while (depth != 0) {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/esri/logger/khronicle/FileExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2025 Esri
//
//
// Licensed under the Apache License Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -37,7 +37,8 @@ internal fun File.incrementNumberedFileName(namePrefix: String, extension: Strin
indexString.isDigitsOnly() -> indexString.toInt() + 1
else ->
throw IllegalArgumentException(
"Input file did not follow required prefix#extension pattern")
"Input file did not follow required prefix#extension pattern"
)
}

val newFile = File(path.removeSuffix(name), "$namePrefix$newIndex$extension")
Expand Down
Loading