Added detekt extension

This commit is contained in:
Erik C. Thauvin 2023-11-25 18:08:13 -08:00
parent 44c1e8db3e
commit e34ea334d6
27 changed files with 68 additions and 130 deletions

View file

@ -35,9 +35,10 @@ import rife.bld.BuildCommand;
import rife.bld.Project;
import rife.bld.dependencies.Repository;
import rife.bld.extension.CompileKotlinOperation;
import rife.bld.extension.CompileKotlinOptions;
import rife.bld.extension.DetektOperation;
import rife.bld.extension.GeneratedVersionOperation;
import rife.bld.extension.JacocoReportOperation;
import rife.bld.operations.exceptions.ExitStatusException;
import rife.tools.FileUtils;
import rife.tools.exceptions.FileUtilsErrorException;
@ -68,12 +69,13 @@ public class MobibotBuild extends Project {
autoDownloadPurge = true;
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, new Repository("https://jitpack.io"));
var log4j = version(2, 21, 1);
var log4j = version(2, 22, 0);
var kotlin = version(1, 9, 21);
scope(compile)
// PircBotX
.include(dependency("com.github.pircbotx", "pircbotx", "2.3.1"))
// Commons (mostly for PircBotX)
.include(dependency("org.apache.commons", "commons-lang3", "3.13.0"))
.include(dependency("org.apache.commons", "commons-lang3", "3.14.0"))
.include(dependency("org.apache.commons", "commons-text", "1.11.0"))
.include(dependency("commons-codec", "commons-codec", "1.16.0"))
.include(dependency("commons-net", "commons-net", "3.10.0"))
@ -81,7 +83,10 @@ public class MobibotBuild extends Project {
.include(dependency("com.google.code.gson", "gson", "2.10.1"))
.include(dependency("com.google.guava", "guava", "32.1.3-jre"))
// Kotlin
.include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", version(1, 9, 20)))
.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.jetbrains.kotlinx", "kotlinx-coroutines-core", "1.7.3"))
.include(dependency("org.jetbrains.kotlinx", "kotlinx-cli-jvm", "0.3.6"))
// Logging
@ -97,13 +102,13 @@ public class MobibotBuild extends Project {
.include(dependency("org.json", "json", "20231013"))
.include(dependency("org.jsoup", "jsoup", "1.16.2"))
// Thauvin
.include(dependency("net.thauvin.erik", "cryptoprice", "1.0.1"))
.include(dependency("net.thauvin.erik", "jokeapi", "0.9.0"))
.include(dependency("net.thauvin.erik", "pinboard-poster", "1.1.0"))
.include(dependency("net.thauvin.erik", "cryptoprice", "1.0.2-SNAPSHOT"))
.include(dependency("net.thauvin.erik", "jokeapi", "0.9.1-SNAPSHOT"))
.include(dependency("net.thauvin.erik", "pinboard-poster", "1.1.1-SNAPSHOT"))
.include(dependency("net.thauvin.erik.urlencoder", "urlencoder-lib-jvm", "1.4.0"));
scope(test)
.include(dependency("com.willowtreeapps.assertk", "assertk-jvm", version(0, 27, 0)))
.include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", version(1, 9, 20)))
.include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", version(1, 9, 21)))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1)));
@ -132,11 +137,6 @@ public class MobibotBuild extends Project {
releaseInfo();
new CompileKotlinOperation()
.fromProject(this)
.compileOptions(
new CompileKotlinOptions()
.jdkRelease(javaRelease)
.verbose(true)
)
.execute();
}
@ -150,6 +150,23 @@ public class MobibotBuild extends Project {
FileUtils.copy(new File(buildDistDirectory(), jarFileName()), new File(deploy, "mobibot.jar"));
}
@BuildCommand(summary = "Checks source with Detekt")
public void detekt() throws ExitStatusException, IOException, InterruptedException {
new DetektOperation()
.fromProject(this)
.baseline("config/detekt/baseline.xml")
.execute();
}
@BuildCommand(value = "detekt-baseline", summary = "Creates the Detekt baseline")
public void detektBaseline() throws ExitStatusException, IOException, InterruptedException {
new DetektOperation()
.fromProject(this)
.baseline("config/detekt/baseline.xml")
.createBaseline(true)
.execute();
}
@BuildCommand(summary = "Generates JaCoCo Reports")
public void jacoco() throws IOException {
new JacocoReportOperation()

View file

@ -63,7 +63,7 @@ object Constants {
* User-Agent
*/
const val USER_AGENT =
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
/**
* The help command.

View file

@ -1,34 +1,3 @@
/*
* ReleaseInfo.kt
*
* Copyright 2004-2023 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.
*/
/*
* This file is automatically generated
* Do not modify! -- ALL CHANGES WILL BE ERASED!
@ -45,11 +14,12 @@ import java.time.ZoneId
*/
object ReleaseInfo {
const val PROJECT = "mobibot"
const val VERSION = "0.8.0-rc+20231111131825"
const val VERSION = "0.8.0-rc+20231125180722"
@JvmField
@Suppress("MagicNumber")
val BUILD_DATE: LocalDateTime = LocalDateTime.ofInstant(
Instant.ofEpochMilli(1699737505341L), ZoneId.systemDefault()
Instant.ofEpochMilli(1700964443060L), ZoneId.systemDefault()
)
const val WEBSITE = "https://www.mobitopia.org/mobibot/"

View file

@ -143,5 +143,4 @@ class Ignore : AbstractCommand() {
ignored.addAll(value.split(LinksManager.TAG_MATCH))
}
}
}

View file

@ -41,4 +41,4 @@ import org.junit.jupiter.api.extension.ExtendWith
@Target(AnnotationTarget.TYPE, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
@ExtendWith(DisableOnCiCondition::class)
annotation class DisabledOnCi
annotation class DisableOnCi

View file

@ -42,9 +42,6 @@ import java.net.MalformedURLException
import java.net.UnknownHostException
import kotlin.test.Test
/**
* The `FeedReader Test` class.
*/
class FeedReaderTest {
@Test
fun readFeedTest() {

View file

@ -68,9 +68,6 @@ import java.time.LocalDateTime
import java.util.*
import kotlin.test.Test
/**
* The `Utils Test` class.
*/
class UtilsTest {
private val ascii =
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

View file

@ -48,18 +48,18 @@ class SeenTest {
seen.clear()
assertThat(seen::seenNicks).isEmpty()
seen.load()
assertThat(seen::seenNicks).key(nick).isNotNull()
assertThat(seen::seenNicks).key(NICK).isNotNull()
}
@Test
@Order(2)
fun addTest() {
val last = seen.seenNicks[nick]?.lastSeen
seen.add(nick.lowercase())
val last = seen.seenNicks[NICK]?.lastSeen
seen.add(NICK.lowercase())
assertThat(seen).all {
prop(Seen::seenNicks).size().isEqualTo(1)
prop(Seen::seenNicks).key(nick).isNotNull().prop(SeenNick::lastSeen).isNotEqualTo(last)
prop(Seen::seenNicks).key(nick).isNotNull().prop(SeenNick::nick).isNotNull().isEqualTo(nick.lowercase())
prop(Seen::seenNicks).key(NICK).isNotNull().prop(SeenNick::lastSeen).isNotEqualTo(last)
prop(Seen::seenNicks).key(NICK).isNotNull().prop(SeenNick::nick).isNotNull().isEqualTo(NICK.lowercase())
}
}
@ -75,12 +75,12 @@ class SeenTest {
companion object {
private val tmpFile = kotlin.io.path.createTempFile(suffix = ".ser")
private val seen = Seen(tmpFile.toAbsolutePath().toString())
private const val nick = "ErikT"
private const val NICK = "ErikT"
@JvmStatic
@BeforeClass
fun beforeClass() {
seen.add(nick)
seen.add(NICK)
assertThat(tmpFile.fileSize(), "tmpFile.size").isGreaterThan(0)
}

View file

@ -41,9 +41,6 @@ import java.time.LocalDateTime
import java.time.temporal.Temporal
import kotlin.test.Test
/**
* The `TellMessageTest` class.
*/
class TellMessageTest {
private fun isValidDate(date: Temporal): Boolean {
return Duration.between(date, LocalDateTime.now()).toMinutes() < 1

View file

@ -39,13 +39,6 @@ import java.security.SecureRandom
import java.util.*
import kotlin.test.Test
/**
* The `EntryUtilsTest` class.
*
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
* @created 2019-04-19
* @since 1.0
*/
class EntryLinkTest {
private val entryLink = EntryLink(
"https://www.mobitopia.org/", "Mobitopia", "Skynx", "JimH", "#mobitopia",

View file

@ -39,9 +39,6 @@ import net.thauvin.erik.mobibot.Utils.bold
import net.thauvin.erik.mobibot.modules.Calc.Companion.calculate
import kotlin.test.Test
/**
* The `CalcTest` class.
*/
class CalcTest {
@Test
fun testCalculate() {

View file

@ -35,7 +35,7 @@ import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.hasNoCause
import assertk.assertions.isInstanceOf
import net.thauvin.erik.mobibot.DisabledOnCi
import net.thauvin.erik.mobibot.DisableOnCi
import net.thauvin.erik.mobibot.LocalProperties
import kotlin.test.Test
@ -48,7 +48,7 @@ class ChatGptTest : LocalProperties() {
}
@Test
@DisabledOnCi
@DisableOnCi
fun testChat() {
val apiKey = getProperty(ChatGpt.API_KEY_PROP)
assertThat(

View file

@ -41,9 +41,6 @@ import net.thauvin.erik.mobibot.modules.CryptoPrices.Companion.getCurrencyName
import net.thauvin.erik.mobibot.modules.CryptoPrices.Companion.loadCurrencies
import kotlin.test.Test
/**
* The `CryptoPricesTest` class.
*/
class CryptoPricesTest {
init {
loadCurrencies()

View file

@ -44,10 +44,6 @@ import net.thauvin.erik.mobibot.msg.Message
import net.thauvin.erik.mobibot.msg.PublicMessage
import kotlin.test.Test
/**
* The `CurrencyConvertTest` class.
*/
class CurrencyConverterTest : LocalProperties() {
init {
val apiKey = getProperty(CurrencyConverter.API_KEY_PROP)

View file

@ -34,7 +34,7 @@ import assertk.all
import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.*
import net.thauvin.erik.mobibot.DisabledOnCi
import net.thauvin.erik.mobibot.DisableOnCi
import net.thauvin.erik.mobibot.ExceptionSanitizer.sanitize
import net.thauvin.erik.mobibot.LocalProperties
import net.thauvin.erik.mobibot.modules.GoogleSearch.Companion.searchGoogle
@ -42,9 +42,6 @@ import net.thauvin.erik.mobibot.msg.ErrorMessage
import net.thauvin.erik.mobibot.msg.Message
import kotlin.test.Test
/**
* The `GoogleSearchTest` class.
*/
class GoogleSearchTest : LocalProperties() {
@Test
fun testAPIKeys() {
@ -65,7 +62,7 @@ class GoogleSearchTest : LocalProperties() {
}
@Test
@DisabledOnCi
@DisableOnCi
@Throws(ModuleException::class)
fun testSearchGoogle() {
val apiKey = getProperty(GoogleSearch.API_KEY_PROP)

View file

@ -38,9 +38,6 @@ import net.thauvin.erik.mobibot.msg.Message
import net.thauvin.erik.mobibot.msg.PublicMessage
import kotlin.test.Test
/**
* The `JokeTest` class.
*/
class JokeTest {
@Test
@Throws(ModuleException::class)

View file

@ -37,9 +37,6 @@ import net.thauvin.erik.mobibot.modules.Lookup.Companion.nslookup
import net.thauvin.erik.mobibot.modules.Lookup.Companion.whois
import kotlin.test.Test
/**
* The `Lookup Test` class.
*/
class LookupTest {
@Test
@Throws(Exception::class)

View file

@ -39,9 +39,6 @@ import org.junit.jupiter.params.provider.MethodSource
import java.io.IOException
import kotlin.test.Test
/**
* The `ModuleExceptionTest` class.
*/
class ModuleExceptionTest {
companion object {
const val DEBUG_MESSAGE = "debugMessage"

View file

@ -36,9 +36,6 @@ import assertk.assertions.isNotEmpty
import net.thauvin.erik.mobibot.modules.Ping.Companion.randomPing
import kotlin.test.Test
/**
* The `PingTest` class.
*/
class PingTest {
@Test
fun testPingsArray() {

View file

@ -41,9 +41,6 @@ import net.thauvin.erik.mobibot.msg.ErrorMessage
import net.thauvin.erik.mobibot.msg.Message
import kotlin.test.Test
/**
* The `StockQuoteTest` class.
*/
class StockQuoteTest : LocalProperties() {
private fun buildMatch(label: String): String {
return "${label}:[ ]+[0-9.]+".prependIndent()

View file

@ -45,9 +45,6 @@ import net.thauvin.erik.mobibot.modules.Weather2.Companion.mphToKmh
import net.thauvin.erik.mobibot.msg.Message
import kotlin.test.Test
/**
* The `Weather2Test` class.
*/
class Weather2Test : LocalProperties() {
@Test
fun testFtoC() {

View file

@ -36,7 +36,7 @@ import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.hasMessage
import assertk.assertions.isInstanceOf
import net.thauvin.erik.mobibot.DisabledOnCi
import net.thauvin.erik.mobibot.DisableOnCi
import net.thauvin.erik.mobibot.ExceptionSanitizer.sanitize
import net.thauvin.erik.mobibot.LocalProperties
import net.thauvin.erik.mobibot.modules.WolframAlpha.Companion.queryWolfram
@ -54,7 +54,7 @@ class WolframAlphaTest : LocalProperties() {
}
@Test
@DisabledOnCi
@DisableOnCi
@Throws(ModuleException::class)
fun queryWolframTest() {
val apiKey = getProperty(WolframAlpha.APPID_KEY_PROP)

View file

@ -42,9 +42,6 @@ import org.pircbotx.Colors
import java.time.ZoneId
import kotlin.test.Test
/**
* The `WordTimeTest` class.
*/
class WordTimeTest {
@Test
fun testTime() {