diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index 751133d..d1179fb 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -3,6 +3,7 @@ bld.downloadExtensionSources=true bld.downloadLocation= bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.10-SNAPSHOT bld.extension-dokka=com.uwyn.rife2:bld-dokka:1.0.4-SNAPSHOT +bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.5 bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.10 bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.1.0-SNAPSHOT bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES diff --git a/src/bld/java/net/thauvin/erik/bitly/BitlyShortenBuild.java b/src/bld/java/net/thauvin/erik/bitly/BitlyShortenBuild.java index 4465ac4..ea44e28 100644 --- a/src/bld/java/net/thauvin/erik/bitly/BitlyShortenBuild.java +++ b/src/bld/java/net/thauvin/erik/bitly/BitlyShortenBuild.java @@ -33,14 +33,10 @@ package net.thauvin.erik.bitly; import rife.bld.BuildCommand; import rife.bld.Project; -import rife.bld.extension.CompileKotlinOperation; -import rife.bld.extension.DetektOperation; -import rife.bld.extension.DokkaOperation; -import rife.bld.extension.JacocoReportOperation; +import rife.bld.extension.*; import rife.bld.extension.dokka.LoggingLevel; import rife.bld.extension.dokka.OutputFormat; import rife.bld.extension.dokka.SourceSet; -import rife.bld.extension.kotlin.CompileOptions; import rife.bld.operations.exceptions.ExitStatusException; import rife.bld.publish.PomBuilder; import rife.bld.publish.PublishDeveloper; @@ -50,6 +46,8 @@ import rife.tools.exceptions.FileUtilsErrorException; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; import java.util.logging.ConsoleHandler; import java.util.logging.Level; @@ -68,12 +66,14 @@ public class BitlyShortenBuild extends Project { version = version(2, 0, 1, "SNAPSHOT"); javaRelease = 11; + downloadSources = true; autoDownloadPurge = true; + repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL); var okHttp = version(4, 12, 0); - final var kotlin = version(2, 1, 20); + final var kotlin = version(2, 1, 21); scope(compile) // Kotlin .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin)) @@ -140,10 +140,9 @@ public class BitlyShortenBuild extends Project { @BuildCommand(summary = "Compiles the Kotlin project") @Override public void compile() throws Exception { - new CompileKotlinOperation() - .fromProject(this) - .compileOptions(new CompileOptions().verbose(true)) - .execute(); + var op = new CompileKotlinOperation().fromProject(this); + op.compileOptions().languageVersion("1.9").verbose(true); + op.execute(); } @BuildCommand(summary = "Checks source with Detekt") @@ -220,4 +219,25 @@ public class BitlyShortenBuild extends Project { PomBuilder.generateInto(publishOperation().fromProject(this).info(), dependencies(), new File(workDirectory, "pom.xml")); } + + @Override + public void test() throws Exception { + var testResultsDir = "build/test-results/test/"; + + var op = testOperation().fromProject(this); + op.testToolOptions().reportsDir(new File(testResultsDir)); + op.execute(); + + var xunitViewer = new File("/usr/bin/xunit-viewer"); + if (xunitViewer.exists() && xunitViewer.canExecute()) { + var reportsDir = "build/reports/tests/test/"; + + Files.createDirectories(Path.of(reportsDir)); + + new ExecOperation() + .fromProject(this) + .command(xunitViewer.getPath(), "-r", testResultsDir, "-o", reportsDir + "index.html") + .execute(); + } + } } diff --git a/src/test/kotlin/net/thauvin/erik/bitly/BeforeAll.kt b/src/test/kotlin/net/thauvin/erik/bitly/BeforeAll.kt new file mode 100644 index 0000000..56f12d8 --- /dev/null +++ b/src/test/kotlin/net/thauvin/erik/bitly/BeforeAll.kt @@ -0,0 +1,52 @@ +/* + * BeforeAll.kt + * + * Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of this project nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.thauvin.erik.bitly + +import org.junit.jupiter.api.extension.BeforeAllCallback +import org.junit.jupiter.api.extension.ExtensionContext +import java.util.concurrent.atomic.AtomicBoolean +import java.util.logging.ConsoleHandler +import java.util.logging.Level + +class BeforeAll : BeforeAllCallback { + private val isFirstTime: AtomicBoolean = AtomicBoolean(true) + + override fun beforeAll(context: ExtensionContext?) { + if (isFirstTime.getAndSet(false)) { + with(Utils.logger) { + addHandler(ConsoleHandler().apply { level = Level.FINE }) + level = Level.FINE + } + } + } +} + diff --git a/src/test/kotlin/net/thauvin/erik/bitly/BitlinksTest.kt b/src/test/kotlin/net/thauvin/erik/bitly/BitlinksTests.kt similarity index 96% rename from src/test/kotlin/net/thauvin/erik/bitly/BitlinksTest.kt rename to src/test/kotlin/net/thauvin/erik/bitly/BitlinksTests.kt index 66de791..19d7467 100644 --- a/src/test/kotlin/net/thauvin/erik/bitly/BitlinksTest.kt +++ b/src/test/kotlin/net/thauvin/erik/bitly/BitlinksTests.kt @@ -1,5 +1,5 @@ /* - * BitlinksTest.kt + * BitlinksTests.kt * * Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net) * @@ -41,18 +41,18 @@ import net.thauvin.erik.bitly.config.deeplinks.CreateDeeplinks import net.thauvin.erik.bitly.config.deeplinks.UpdateDeeplinks import net.thauvin.erik.bitly.config.deeplinks.enums.InstallType import net.thauvin.erik.bitly.config.deeplinks.enums.Os -import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable +import org.junit.jupiter.api.extension.ExtendWith import java.io.File -import java.util.logging.Level import kotlin.test.assertEquals import kotlin.test.assertFailsWith import kotlin.test.assertTrue -class BitlinksTest { +@ExtendWith(BeforeAll::class) +class BitlinksTests { private val bitly = with(File("local.properties")) { if (exists()) { Bitly(toPath()) @@ -63,16 +63,6 @@ class BitlinksTest { private val longUrl = "https://erik.thauvin.net/blog" private val shortUrl = "https://bit.ly/380ojFd" - companion object { - @JvmStatic - @BeforeAll - fun before() { - with(Utils.logger) { - level = Level.FINE - } - } - } - @Nested @DisplayName("Bitlinks Tests") inner class BitlinksTests { @@ -319,7 +309,7 @@ class BitlinksTest { @Test @EnabledIfEnvironmentVariable(named = "CI", matches = "true") fun `Token not specified on CI`() { - val test = Bitly(Constants.EMPTY) // to void picking up the environment variable + val test = Bitly(Constants.EMPTY) // to avoid picking up the environment variable assertFailsWith(IllegalArgumentException::class) { test.bitlinks().shorten(longUrl) diff --git a/src/test/kotlin/net/thauvin/erik/bitly/BitlyTest.kt b/src/test/kotlin/net/thauvin/erik/bitly/BitlyTests.kt similarity index 92% rename from src/test/kotlin/net/thauvin/erik/bitly/BitlyTest.kt rename to src/test/kotlin/net/thauvin/erik/bitly/BitlyTests.kt index 3ad00cf..aa33b48 100644 --- a/src/test/kotlin/net/thauvin/erik/bitly/BitlyTest.kt +++ b/src/test/kotlin/net/thauvin/erik/bitly/BitlyTests.kt @@ -1,5 +1,5 @@ /* - * BitlyTest.kt + * BitlyTests.kt * * Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net) * @@ -39,16 +39,16 @@ import assertk.assertions.prop import net.thauvin.erik.bitly.Utils.removeHttp import net.thauvin.erik.bitly.Utils.toEndPoint import org.json.JSONObject -import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Nested +import org.junit.jupiter.api.extension.ExtendWith import java.io.File -import java.util.logging.Level import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -class BitlyTest { +@ExtendWith(BeforeAll::class) +class BitlyTests { private val bitly = with(File("local.properties")) { if (exists()) { Bitly(toPath()) @@ -58,17 +58,6 @@ class BitlyTest { } private val shortUrl = "https://bit.ly/380ojFd" - companion object { - @JvmStatic - @BeforeAll - fun before() { - with(Utils.logger) { - level = Level.FINE - } - } - } - - @Nested @DisplayName("API Call Tests") inner class ApiCallTests { diff --git a/src/test/kotlin/net/thauvin/erik/bitly/config/ConfigTest.kt b/src/test/kotlin/net/thauvin/erik/bitly/config/ConfigTests.kt similarity index 99% rename from src/test/kotlin/net/thauvin/erik/bitly/config/ConfigTest.kt rename to src/test/kotlin/net/thauvin/erik/bitly/config/ConfigTests.kt index 53debb4..09c45ed 100644 --- a/src/test/kotlin/net/thauvin/erik/bitly/config/ConfigTest.kt +++ b/src/test/kotlin/net/thauvin/erik/bitly/config/ConfigTests.kt @@ -1,5 +1,5 @@ /* - * ConfigTest.kt + * ConfigTests.kt * * Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net) * @@ -46,7 +46,7 @@ import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Nested import kotlin.test.Test -class ConfigTest { +class ConfigTests { @Nested @DisplayName("Build Configuration Tests") inner class BuildConfigurationTests { diff --git a/src/test/kotlin/net/thauvin/erik/bitly/config/deeplinks/DeeplinksTest.kt b/src/test/kotlin/net/thauvin/erik/bitly/config/deeplinks/DeeplinksTests.kt similarity index 99% rename from src/test/kotlin/net/thauvin/erik/bitly/config/deeplinks/DeeplinksTest.kt rename to src/test/kotlin/net/thauvin/erik/bitly/config/deeplinks/DeeplinksTests.kt index 9a0fcb4..cf3ecbb 100644 --- a/src/test/kotlin/net/thauvin/erik/bitly/config/deeplinks/DeeplinksTest.kt +++ b/src/test/kotlin/net/thauvin/erik/bitly/config/deeplinks/DeeplinksTests.kt @@ -1,5 +1,5 @@ /* - * DeeplinksTest.kt + * DeeplinksTests.kt * * Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net) * @@ -43,7 +43,7 @@ import org.junit.Test import java.time.ZoneId import java.time.ZonedDateTime -class DeeplinksTest { +class DeeplinksTests { @Test fun `Create deeplink`() { val deeplinks = CreateDeeplinks().apply {