From cd4d86969f2cbf6df6e3cec02061c926b2e3c8ba Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 25 Nov 2023 21:14:02 -0800 Subject: [PATCH] Added detekt extension --- .idea/kotlinc.xml | 2 +- .idea/misc.xml | 2 ++ baseline.xml | 8 ------- examples/gradle/.idea/.name | 2 +- examples/gradle/.idea/kotlinc.xml | 2 +- examples/gradle/.idea/misc.xml | 10 ++++++++ examples/gradle/README.md | 4 ++-- lib/bld/bld-wrapper.properties | 1 + pom.xml | 18 +++++++++++++++ .../thauvin/erik/crypto/CryptoPriceBuild.java | 23 ++++++++++++++++++- .../net/thauvin/erik/crypto/CryptoPrice.kt | 10 +++++--- 11 files changed, 65 insertions(+), 17 deletions(-) delete mode 100644 baseline.xml diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index f8467b4..ae3f30a 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 2fcd8af..32c94e0 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,6 +3,8 @@ + + diff --git a/baseline.xml b/baseline.xml deleted file mode 100644 index c4d9ac8..0000000 --- a/baseline.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - ThrowsCount:CryptoPrice.kt$CryptoPrice.Companion$ @JvmStatic @JvmOverloads @Throws(CryptoException::class, IOException::class) fun apiCall(paths: List<String>, params: Map<String, String> = emptyMap()): String - ThrowsCount:CryptoPrice.kt$CryptoPrice.Companion$@JvmStatic @Throws(CryptoException::class) fun String.toPrice(): CryptoPrice - - diff --git a/examples/gradle/.idea/.name b/examples/gradle/.idea/.name index 12e49ff..925a65b 100644 --- a/examples/gradle/.idea/.name +++ b/examples/gradle/.idea/.name @@ -1 +1 @@ -cryptoprice-examples-gradle +cryptoprice-examples-gradle \ No newline at end of file diff --git a/examples/gradle/.idea/kotlinc.xml b/examples/gradle/.idea/kotlinc.xml index e805548..ae3f30a 100644 --- a/examples/gradle/.idea/kotlinc.xml +++ b/examples/gradle/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/examples/gradle/.idea/misc.xml b/examples/gradle/.idea/misc.xml index 65c5674..55cdab6 100644 --- a/examples/gradle/.idea/misc.xml +++ b/examples/gradle/.idea/misc.xml @@ -2,6 +2,16 @@ + diff --git a/examples/gradle/README.md b/examples/gradle/README.md index f0d4aeb..fd8a622 100644 --- a/examples/gradle/README.md +++ b/examples/gradle/README.md @@ -1,5 +1,5 @@ ## Kotlin Example -To compile & run the Kotlin example: +To run the Kotlin example: ```console ./gradlew run @@ -9,7 +9,7 @@ To compile & run the Kotlin example: ## Java Example -To compile & run the Java example: +To run the Java example: ```console ./gradlew runJava diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index ff9973f..ac34063 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -2,6 +2,7 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true bld.extension.jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.1 bld.extensions=com.uwyn.rife2:bld-kotlin:0.9.0-SNAPSHOT +bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.0-SNAPSHOT bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.downloadLocation= bld.sourceDirectories= diff --git a/pom.xml b/pom.xml index 831e7a5..47da6a8 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,24 @@ 1.9.21 compile + + org.jetbrains.kotlin + kotlin-stdlib-common + 1.9.21 + compile + + + org.jetbrains.kotlin + kotlin-stdlib-jdk7 + 1.9.21 + compile + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + 1.9.21 + compile + org.json json diff --git a/src/bld/java/net/thauvin/erik/crypto/CryptoPriceBuild.java b/src/bld/java/net/thauvin/erik/crypto/CryptoPriceBuild.java index c58bf24..c33e9eb 100644 --- a/src/bld/java/net/thauvin/erik/crypto/CryptoPriceBuild.java +++ b/src/bld/java/net/thauvin/erik/crypto/CryptoPriceBuild.java @@ -3,6 +3,7 @@ package net.thauvin.erik.crypto; import rife.bld.BuildCommand; import rife.bld.Project; import rife.bld.extension.CompileKotlinOperation; +import rife.bld.extension.DetektOperation; import rife.bld.extension.JacocoReportOperation; import rife.bld.extension.dokka.DokkaOperation; import rife.bld.extension.dokka.LoggingLevel; @@ -35,8 +36,12 @@ public class CryptoPriceBuild extends Project { autoDownloadPurge = true; repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL); + final var kotlin = version(1, 9, 21); scope(compile) - .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", version(1, 9, 21))) + .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin)) + .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib-common", kotlin)) + .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib-jdk7", kotlin)) + .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib-jdk8", kotlin)) .include(dependency("org.json", "json", "20231013")) .include(dependency("com.squareup.okhttp3", "okhttp", version(4, 12, 0))); scope(test) @@ -91,6 +96,22 @@ public class CryptoPriceBuild extends Project { .execute(); } + @BuildCommand(summary = "Checks source with Detekt") + public void detekt() throws ExitStatusException, IOException, InterruptedException { + new DetektOperation() + .fromProject(this) + .execute(); + } + + @BuildCommand(value = "detekt-baseline", summary = "Creates the Detekt baseline") + public void detektBaseline() throws ExitStatusException, IOException, InterruptedException { + new DetektOperation() + .fromProject(this) + .baseline("detekt-baseline.xml") + .createBaseline(true) + .execute(); + } + @BuildCommand(summary = "Generates JaCoCo Reports") public void jacoco() throws IOException { new JacocoReportOperation() diff --git a/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt b/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt index 609b971..0940aac 100644 --- a/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt +++ b/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt @@ -113,12 +113,16 @@ open class CryptoPrice(val base: String, val currency: String, val amount: BigDe if (json.has("errors")) { val data = json.getJSONArray("errors") throw CryptoException( - response.code, data.getJSONObject(0).getString("id"), + response.code, + data.getJSONObject(0).getString("id"), data.getJSONObject(0).getString("message") ) } else { - throw CryptoException(response.code, json.getString("error"), - json.getString("message")) + throw CryptoException( + response.code, + json.getString("error"), + json.getString("message") + ) } } } catch (e: JSONException) {