Skip to content
This repository was archived by the owner on Nov 13, 2025. It is now read-only.
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
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'
- uses: actions/cache@v4
with:
path: |
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
branches:
- main

permissions:
contents: read

jobs:
gradle-test:
runs-on: ubuntu-latest
Expand All @@ -17,7 +20,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'
- uses: actions/cache@v4
with:
path: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ jte-classes/
logs/

### Files ###
.envrc
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Kraken

![Java Version](https://img.shields.io/badge/Temurin-17-green?style=flat-square&logo=eclipse-adoptium)
![Kotlin Version](https://img.shields.io/badge/Kotlin-2.1.0-green?style=flat-square&logo=kotlin)
![Java Version](https://img.shields.io/badge/Temurin-21-green?style=flat-square&logo=eclipse-adoptium)
![Kotlin Version](https://img.shields.io/badge/Kotlin-2.2.0-green?style=flat-square&logo=kotlin)
![Status](https://img.shields.io/badge/Status-Beta-yellowgreen?style=flat-square)

[![Gradle](https://img.shields.io/badge/Gradle-8.12.0-informational?style=flat-square&logo=gradle)](https://github.com/gradle/gradle)
[![Ktlint](https://img.shields.io/badge/Ktlint-1.5.0-informational?style=flat-square)](https://github.com/pinterest/ktlint)
[![Gradle](https://img.shields.io/badge/Gradle-8.14.3-informational?style=flat-square&logo=gradle)](https://github.com/gradle/gradle)
[![Spotless](https://img.shields.io/badge/Spotless-7.1.0-informational?style=flat-square)](https://github.com/diffplug/spotless)

[![Github - Version](https://img.shields.io/github/v/tag/Buried-In-Code/Kraken?logo=Github&label=Version&style=flat-square)](https://github.com/Buried-In-Code/Kraken/tags)
[![Github - License](https://img.shields.io/github/license/Buried-In-Code/Kraken?logo=Github&label=License&style=flat-square)](https://opensource.org/licenses/MIT)
Expand All @@ -30,7 +30,7 @@ Then, add Kraken as a dependency.

```kts
dependencies {
implementation("com.github.Buried-In-Code:Kraken:0.2.3")
implementation("com.github.Buried-In-Code:Kraken:0.4.0")
}
```

Expand All @@ -40,6 +40,7 @@ dependencies {
import github.buriedincode.kraken.Metron
import github.buriedincode.kraken.SQLiteCache
import github.buriedincode.kraken.AuthenticationException
import github.buriedincode.kraken.RateLimitException
import github.buriedincode.kraken.ServiceException

fun main() {
Expand All @@ -64,6 +65,8 @@ fun main() {

} catch (ae: AuthenticationException) {
println("Invalid Metron Username/Password.")
} catch(re: RatelimitException) {
println("Rate limit exceeded. Please try again later.")
} catch (se: ServiceException) {
println("Unsuccessful request: ${se.message}")
}
Expand Down
240 changes: 126 additions & 114 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,164 +1,176 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import java.net.HttpURLConnection
import java.net.URL
import java.net.URI
import java.nio.file.Files
import java.nio.file.StandardOpenOption
import kotlin.io.path.absolutePathString
import kotlin.io.path.createDirectories
import kotlin.io.path.div

plugins {
`java-library`
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.dokka)
alias(libs.plugins.ktlint)
alias(libs.plugins.versions)
`maven-publish`
`java-library`
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.dokka)
alias(libs.plugins.spotless)
alias(libs.plugins.versions)
`maven-publish`
}

println("Kotlin v${KotlinVersion.CURRENT}")

println("Java v${System.getProperty("java.version")}")

println("Arch: ${System.getProperty("os.arch")}")

group = "github.buriedincode"
version = "0.3.1"

version = "0.4.0"

repositories {
mavenCentral()
mavenLocal()
mavenCentral()
mavenLocal()
}

dependencies {
implementation(libs.bundles.kotlinx.serialization)
implementation(libs.kotlin.logging)
runtimeOnly(libs.sqlite.jdbc)
testImplementation(libs.junit.jupiter)
testRuntimeOnly(libs.junit.platform.launcher)
testRuntimeOnly(libs.kotlin.reflect)
testRuntimeOnly(libs.log4j2.slf4j2.impl)
}
implementation(libs.bundles.kotlinx.serialization)
implementation(libs.kotlin.logging)

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
runtimeOnly(libs.sqlite.jdbc)

testImplementation(libs.junit.jupiter)

kotlin {
jvmToolchain(17)
testRuntimeOnly(libs.junit.platform.launcher)
testRuntimeOnly(libs.log4j2.slf4j2)
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
version = "1.5.0"
java { toolchain { languageVersion = JavaLanguageVersion.of(21) } }

kotlin { jvmToolchain(21) }

spotless {
kotlin {
ktfmt().kotlinlangStyle().configure {
it.setMaxWidth(120)
it.setBlockIndent(2)
it.setContinuationIndent(2)
it.setRemoveUnusedImports(true)
it.setManageTrailingCommas(true)
}
}
kotlinGradle {
ktfmt().kotlinlangStyle().configure {
it.setMaxWidth(120)
it.setBlockIndent(2)
it.setContinuationIndent(2)
it.setRemoveUnusedImports(true)
it.setManageTrailingCommas(true)
}
}
}

tasks.test {
environment("METRON__USERNAME", System.getenv("METRON__USERNAME"))
environment("METRON__PASSWORD", System.getenv("METRON__PASSWORD"))
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
environment("METRON__USERNAME", System.getenv("METRON__USERNAME"))
environment("METRON__PASSWORD", System.getenv("METRON__PASSWORD"))
useJUnitPlatform()
testLogging { events("passed", "skipped", "failed") }
}

fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}

tasks.withType<DependencyUpdatesTask> {
gradleReleaseChannel = "current"
resolutionStrategy {
componentSelection {
all {
if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
reject("Release candidate")
}
}
gradleReleaseChannel = "current"
checkForGradleUpdate = true
checkConstraints = false
checkBuildEnvironmentConstraints = false
resolutionStrategy {
componentSelection {
all {
if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
reject("Release candidate")
}
}
}
}
}

publishing {
publications {
create<MavenPublication>("kraken") {
from(components["java"])
}
}
}
publishing { publications { create<MavenPublication>("kraken") { from(components["java"]) } } }

tasks.register("processReadme") {
group = "documentation"
description = "Processes the README.md file to inline SVG badges."
group = "documentation"
description = "Processes the README.md file to inline SVG badges."

doLast {
val linkedBadgePattern = """\[\!\[(.*?)\]\((.*?)\)\]\((.*?)\)""".toRegex() // [![alt](url)](link)
val badgePattern = """\!\[(.*?)\]\((.*?)\)""".toRegex() // ![alt](url)
doLast {
val linkedBadgePattern = """\[\!\[(.*?)\]\((.*?)\)\]\((.*?)\)""".toRegex() // [![alt](url)](link)
val badgePattern = """\!\[(.*?)\]\((.*?)\)""".toRegex() // ![alt](url)

val inputPath = project.rootDir.toPath().resolve("README.md")
val outputPath = project.buildDir.toPath().resolve("Processed-README.md")
val inputPath = project.rootDir.toPath() / "README.md"
val outputPath = project.layout.buildDirectory.get().asFile.toPath() / "Processed-README.md"

if (!Files.exists(inputPath)) {
throw IllegalStateException("${inputPath.toAbsolutePath()} not found.")
}
if (!Files.exists(inputPath)) {
throw IllegalStateException("${inputPath.absolutePathString()} not found.")
}

var content = Files.readAllLines(inputPath).joinToString("\n")
content = content.replaceFirst("# Kraken", "# Module Kraken")

fun fetchSvg(url: String): String? {
return try {
val connection = URL(url).openConnection() as HttpURLConnection
connection.requestMethod = "GET"
connection.connect()

if (connection.responseCode == 200 && connection.contentType.contains("image/svg+xml")) {
connection.inputStream.bufferedReader().use { it.readText() }
} else {
println("Warning: $url is not an SVG badge")
null
}
} catch (e: Exception) {
println("Error fetching $url: ${e.message}")
null
}
}
var content = Files.readAllLines(inputPath).joinToString("\n")
content = content.replaceFirst("# Kraken", "# Module Kraken")

fun processContent(pattern: Regex, replaceFunction: (MatchResult) -> String): String {
return pattern.replace(content) { match ->
replaceFunction(match)
}
}
fun fetchSvg(url: String): String? {
return try {
val connection = URI.create(url).toURL().openConnection() as HttpURLConnection
connection.requestMethod = "GET"
connection.connect()

content = processContent(linkedBadgePattern) { match ->
val altText = match.groupValues[1]
val badgeUrl = match.groupValues[2]
val linkUrl = match.groupValues[3]
val svgContent = fetchSvg(badgeUrl)
if (svgContent != null) {
"""<a href="$linkUrl" target="_blank">$svgContent</a>"""
} else {
"""<a href="$linkUrl" target="_blank"><img alt="$altText" src="$badgeUrl" /></a>"""
}
}

content = processContent(badgePattern) { match ->
val altText = match.groupValues[1]
val badgeUrl = match.groupValues[2]
val svgContent = fetchSvg(badgeUrl)
svgContent ?: """<img alt="$altText" src="$badgeUrl" />"""
if (connection.responseCode == 200 && connection.contentType.contains("image/svg+xml")) {
connection.inputStream.bufferedReader().use { it.readText() }
} else {
println("Warning: $url is not an SVG badge")
null
}
} catch (e: Exception) {
println("Error fetching $url: ${e.message}")
null
}
}

Files.createDirectories(outputPath.parent)
Files.writeString(outputPath, content, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
println("Processing complete. Output written to ${outputPath.toAbsolutePath()}")
fun processContent(pattern: Regex, replaceFunction: (MatchResult) -> String): String {
return pattern.replace(content) { match -> replaceFunction(match) }
}

content =
processContent(linkedBadgePattern) { match ->
val altText = match.groupValues[1]
val badgeUrl = match.groupValues[2]
val linkUrl = match.groupValues[3]
val svgContent = fetchSvg(badgeUrl)
if (svgContent != null) {
"""<a href="$linkUrl" target="_blank">$svgContent</a>"""
} else {
"""<a href="$linkUrl" target="_blank"><img alt="$altText" src="$badgeUrl" /></a>"""
}
}

content =
processContent(badgePattern) { match ->
val altText = match.groupValues[1]
val badgeUrl = match.groupValues[2]
val svgContent = fetchSvg(badgeUrl)
svgContent ?: """<img alt="$altText" src="$badgeUrl" />"""
}

outputPath.parent.createDirectories()
Files.writeString(outputPath, content, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
println("Processing complete. Output written to ${outputPath.absolutePathString()}")
}
}

tasks.dokkaHtml {
dependsOn("processReadme")
dokkaSourceSets {
configureEach {
includes.from(project.buildDir.toPath().resolve("Processed-README.md"))
}
}
dependsOn("processReadme")
dokkaSourceSets {
configureEach { includes.from(project.layout.buildDirectory.get().asFile.toPath() / "Processed-README.md") }
}
}
Binary file modified cache.sqlite
Binary file not shown.
17 changes: 8 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ kotlin = "2.2.0"
dokka = { id = "org.jetbrains.dokka", version = "2.0.0" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "13.0.0" }
spotless = { id = "com.diffplug.spotless", version = "7.1.0" }
versions = { id = "com.github.ben-manes.versions", version = "0.52.0" }

[libraries]
junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version = "5.13.3" }
junit-platform-launcher = { group = "org.junit.platform", name = "junit-platform-launcher" }
kotlin-logging = { group = "io.github.oshai", name = "kotlin-logging-jvm", version = "7.0.7" }
kotlin-reflect = { group = "org.jetbrains.kotlin", name = "kotlin-reflect", version.ref = "kotlin" }
kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version = "0.7.1-0.6.x-compat" }
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version = "1.9.0" }
log4j2-slf4j2-impl = { group = "org.apache.logging.log4j", name = "log4j-slf4j2-impl", version = "2.25.1" }
sqlite-jdbc = { group = "org.xerial", name = "sqlite-jdbc", version = "3.50.2.0" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version = "5.13.3" }
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher", version = "1.13.3" }
kotlin-logging = { module = "io.github.oshai:kotlin-logging-jvm", version = "7.0.7" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version = "0.7.1" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.9.0" }
log4j2-slf4j2 = { module = "org.apache.logging.log4j:log4j-slf4j2-impl", version = "2.25.1" }
sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version = "3.50.2.0" }

[bundles]
kotlinx-serialization = ["kotlinx-serialization-json", "kotlinx-datetime"]
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Loading
Loading