Upgraded to Kotlin 1.5.0

This commit is contained in:
Erik C. Thauvin 2021-04-26 15:23:21 -07:00
parent c950d7349a
commit aaf44db38a
16 changed files with 77 additions and 75 deletions

View file

@ -8,8 +8,8 @@ plugins {
id 'jacoco' id 'jacoco'
id 'java' id 'java'
id 'net.thauvin.erik.gradle.semver' version '1.0.4' id 'net.thauvin.erik.gradle.semver' version '1.0.4'
id 'org.jetbrains.kotlin.jvm' version '1.4.31' id 'org.jetbrains.kotlin.jvm' version '1.5.0'
id 'org.jetbrains.kotlin.kapt' version '1.4.31' id 'org.jetbrains.kotlin.kapt' version '1.5.0'
id 'org.sonarqube' version '3.1.1' id 'org.sonarqube' version '3.1.1'
id 'pmd' id 'pmd'
} }
@ -23,8 +23,8 @@ final def semverProcessor = "net.thauvin.erik:semver:1.2.0"
ext.versions = [ ext.versions = [
jacoco : '0.8.6', jacoco : '0.8.6',
log4j : '2.14.1', log4j : '2.14.1',
pmd : '6.32.0', pmd : '6.34.0',
spotbugs: '4.2.2' spotbugs: '4.2.3'
] ]
repositories { repositories {
@ -44,12 +44,12 @@ dependencies {
implementation 'com.rometools:rome:1.15.0' implementation 'com.rometools:rome:1.15.0'
implementation 'commons-cli:commons-cli:1.4' implementation 'commons-cli:commons-cli:1.4'
implementation 'commons-net:commons-net:3.7.2' implementation 'commons-net:commons-net:3.8.0'
implementation 'net.aksingh:owm-japis:2.5.3.0' implementation 'net.aksingh:owm-japis:2.5.3.0'
implementation 'net.objecthunter:exp4j:0.4.8' implementation 'net.objecthunter:exp4j:0.4.8'
implementation 'net.thauvin.erik:pinboard-poster:1.0.1' implementation 'net.thauvin.erik:pinboard-poster:1.0.3'
implementation 'org.apache.commons:commons-lang3:3.12.0' implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-RC'
implementation 'org.json:json:20210307' implementation 'org.json:json:20210307'
implementation 'org.jsoup:jsoup:1.13.1' implementation 'org.jsoup:jsoup:1.13.1'
implementation 'org.twitter4j:twitter4j-core:4.0.7' implementation 'org.twitter4j:twitter4j-core:4.0.7'

View file

@ -30,7 +30,6 @@
<rule ref="category/java/bestpractices.xml/SystemPrintln"/> <rule ref="category/java/bestpractices.xml/SystemPrintln"/>
<rule ref="category/java/bestpractices.xml/UnusedAssignment"/> <rule ref="category/java/bestpractices.xml/UnusedAssignment"/>
<rule ref="category/java/bestpractices.xml/UnusedFormalParameter"/> <rule ref="category/java/bestpractices.xml/UnusedFormalParameter"/>
<rule ref="category/java/bestpractices.xml/UnusedImports"/>
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable"/> <rule ref="category/java/bestpractices.xml/UnusedLocalVariable"/>
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/> <rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/> <rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
@ -59,8 +58,6 @@
<rule ref="category/java/codestyle.xml/BooleanGetMethodName"/> <rule ref="category/java/codestyle.xml/BooleanGetMethodName"/>
<rule ref="category/java/codestyle.xml/CallSuperInConstructor"/> <rule ref="category/java/codestyle.xml/CallSuperInConstructor"/>
<rule ref="category/java/codestyle.xml/ControlStatementBraces"/> <rule ref="category/java/codestyle.xml/ControlStatementBraces"/>
<rule ref="category/java/codestyle.xml/DontImportJavaLang"/>
<rule ref="category/java/codestyle.xml/DuplicateImports"/>
<rule ref="category/java/codestyle.xml/EmptyMethodInAbstractClassShouldBeAbstract"/> <rule ref="category/java/codestyle.xml/EmptyMethodInAbstractClassShouldBeAbstract"/>
<rule ref="category/java/codestyle.xml/ExtendsObject"/> <rule ref="category/java/codestyle.xml/ExtendsObject"/>
<rule ref="category/java/codestyle.xml/FieldDeclarationsShouldBeAtStartOfClass"/> <rule ref="category/java/codestyle.xml/FieldDeclarationsShouldBeAtStartOfClass"/>
@ -163,7 +160,6 @@
<rule ref="category/java/errorprone.xml/FinalizeOverloaded"/> <rule ref="category/java/errorprone.xml/FinalizeOverloaded"/>
<rule ref="category/java/errorprone.xml/FinalizeShouldBeProtected"/> <rule ref="category/java/errorprone.xml/FinalizeShouldBeProtected"/>
<rule ref="category/java/errorprone.xml/IdempotentOperations"/> <rule ref="category/java/errorprone.xml/IdempotentOperations"/>
<rule ref="category/java/errorprone.xml/ImportFromSamePackage"/>
<rule ref="category/java/errorprone.xml/InstantiationToGetClass"/> <rule ref="category/java/errorprone.xml/InstantiationToGetClass"/>
<rule ref="category/java/errorprone.xml/InvalidLogMessageFormat"/> <rule ref="category/java/errorprone.xml/InvalidLogMessageFormat"/>
<rule ref="category/java/errorprone.xml/JumbledIncrementer"/> <rule ref="category/java/errorprone.xml/JumbledIncrementer"/>

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View file

@ -259,7 +259,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
*/ */
private fun helpResponse(sender: String, topic: String, isPrivate: Boolean) { private fun helpResponse(sender: String, topic: String, isPrivate: Boolean) {
val isOp = isOp(sender) val isOp = isOp(sender)
if (topic.isBlank() || !addons.help(sender, topic.toLowerCase().trim(), isOp, isPrivate)) { if (topic.isBlank() || !addons.help(sender, topic.lowercase().trim(), isOp, isPrivate)) {
helpDefault(sender, isOp, isPrivate) helpDefault(sender, isOp, isPrivate)
} }
} }
@ -317,7 +317,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
tell.send(sender, true) tell.send(sender, true)
if (message.matches("(?i)${Pattern.quote(nick)}:.*".toRegex())) { // mobibot: <command> if (message.matches("(?i)${Pattern.quote(nick)}:.*".toRegex())) { // mobibot: <command>
val cmds = message.substring(message.indexOf(':') + 1).trim().split(" ".toRegex(), 2) val cmds = message.substring(message.indexOf(':') + 1).trim().split(" ".toRegex(), 2)
val cmd = cmds[0].toLowerCase() val cmd = cmds[0].lowercase()
val args = if (cmds.size > 1) { val args = if (cmds.size > 1) {
cmds[1].trim() cmds[1].trim()
} else "" } else ""
@ -342,7 +342,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
) { ) {
if (logger.isDebugEnabled) logger.debug(">>> $sender : $message") if (logger.isDebugEnabled) logger.debug(">>> $sender : $message")
val cmds = message.split(" ".toRegex(), 2) val cmds = message.split(" ".toRegex(), 2)
val cmd = cmds[0].toLowerCase() val cmd = cmds[0].lowercase()
val args = if (cmds.size > 1) { val args = if (cmds.size > 1) {
cmds[1].trim() cmds[1].trim()
} else "" } else ""
@ -559,7 +559,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
e.printStackTrace(System.err) e.printStackTrace(System.err)
exitProcess(1) exitProcess(1)
} }
val nickname = p.getProperty("nick", Mobibot::class.java.name.toLowerCase()) val nickname = p.getProperty("nick", Mobibot::class.java.name.lowercase())
val channel = p.getProperty("channel") val channel = p.getProperty("channel")
val logsDir = ensureDir(p.getProperty("logs", "."), false) val logsDir = ensureDir(p.getProperty("logs", "."), false)

View file

@ -51,7 +51,7 @@ object PinboardUtils {
*/ */
@JvmStatic @JvmStatic
fun addPin(poster: PinboardPoster, ircServer: String, entry: EntryLink) = runBlocking { fun addPin(poster: PinboardPoster, ircServer: String, entry: EntryLink) = runBlocking {
val add = GlobalScope.async { val add = async {
poster.addPin( poster.addPin(
entry.link, entry.link,
entry.title, entry.title,
@ -68,7 +68,7 @@ object PinboardUtils {
*/ */
@JvmStatic @JvmStatic
fun deletePin(poster: PinboardPoster, entry: EntryLink) = runBlocking { fun deletePin(poster: PinboardPoster, entry: EntryLink) = runBlocking {
val delete = GlobalScope.async { val delete = async {
poster.deletePin(entry.link) poster.deletePin(entry.link)
} }
delete.await() delete.await()
@ -79,7 +79,7 @@ object PinboardUtils {
*/ */
@JvmStatic @JvmStatic
fun updatePin(poster: PinboardPoster, ircServer: String, oldUrl: String, entry: EntryLink) = runBlocking { fun updatePin(poster: PinboardPoster, ircServer: String, oldUrl: String, entry: EntryLink) = runBlocking {
val update = GlobalScope.async { val update = async {
with(entry) { with(entry) {
if (oldUrl != link) { if (oldUrl != link) {
poster.deletePin(oldUrl) poster.deletePin(oldUrl)

View file

@ -70,7 +70,7 @@ class Ignore(bot: Mobibot) : AbstractCommand(bot) {
@JvmStatic @JvmStatic
fun isNotIgnored(nick: String): Boolean { fun isNotIgnored(nick: String): Boolean {
return !ignored.contains(nick.toLowerCase()) return !ignored.contains(nick.lowercase())
} }
} }
@ -82,8 +82,8 @@ class Ignore(bot: Mobibot) : AbstractCommand(bot) {
isPrivate: Boolean isPrivate: Boolean
) { ) {
if (!isOp) { if (!isOp) {
val nick = sender.toLowerCase() val nick = sender.lowercase()
val isMe = args.toLowerCase().startsWith(me) val isMe = args.lowercase().startsWith(me)
ignoreNick(bot, nick, isMe, isPrivate) ignoreNick(bot, nick, isMe, isPrivate)
} else { } else {
ignoreOp(bot, sender, args, isPrivate) ignoreOp(bot, sender, args, isPrivate)
@ -125,10 +125,10 @@ class Ignore(bot: Mobibot) : AbstractCommand(bot) {
private fun ignoreOp(bot: Mobibot, sender: String, args: String, isPrivate: Boolean) { private fun ignoreOp(bot: Mobibot, sender: String, args: String, isPrivate: Boolean) {
if (args.isNotEmpty()) { if (args.isNotEmpty()) {
val nicks = args.toLowerCase().split(" ") val nicks = args.lowercase().split(" ")
for (nick in nicks) { for (nick in nicks) {
val ignore = if (me == nick) { val ignore = if (me == nick) {
nick.toLowerCase() nick.lowercase()
} else { } else {
nick nick
} }

View file

@ -70,7 +70,7 @@ class View(bot: Mobibot) : AbstractCommand(bot) {
private fun showPosts(bot: Mobibot, args: String, sender: String) { private fun showPosts(bot: Mobibot, args: String, sender: String) {
val max = entries.size val max = entries.size
var lcArgs = args.toLowerCase() var lcArgs = args.lowercase()
var i = 0 var i = 0
if (lcArgs.isEmpty() && max > maxEntries) { if (lcArgs.isEmpty() && max > maxEntries) {
i = max - maxEntries i = max - maxEntries

View file

@ -172,7 +172,7 @@ class EntryLink : Serializable {
var category: SyndCategoryImpl var category: SyndCategoryImpl
for (tag in tags) { for (tag in tags) {
if (!tag.isNullOrBlank()) { if (!tag.isNullOrBlank()) {
val t = tag.toLowerCase() val t = tag.lowercase()
val mod = t[0] val mod = t[0]
if (mod == '-') { if (mod == '-') {
// Don't remove the channel tag // Don't remove the channel tag

View file

@ -157,8 +157,8 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
if (cmds[3] == cmds[1] || "0" == cmds[0]) { if (cmds[3] == cmds[1] || "0" == cmds[0]) {
PublicMessage("You're kidding, right?") PublicMessage("You're kidding, right?")
} else { } else {
val to = cmds[1].toUpperCase() val to = cmds[1].uppercase()
val from = cmds[3].toUpperCase() val from = cmds[3].uppercase()
if (EXCHANGE_RATES.containsKey(to) && EXCHANGE_RATES.containsKey(from)) { if (EXCHANGE_RATES.containsKey(to) && EXCHANGE_RATES.containsKey(from)) {
try { try {
val amt = cmds[0].replace(",", "").toDouble() val amt = cmds[0].replace(",", "").toDouble()
@ -166,10 +166,10 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
val doubleTo = EXCHANGE_RATES[from]!!.toDouble() val doubleTo = EXCHANGE_RATES[from]!!.toDouble()
PublicMessage( PublicMessage(
NumberFormat.getCurrencyInstance(Constants.LOCALE).format(amt).substring(1) NumberFormat.getCurrencyInstance(Constants.LOCALE).format(amt).substring(1)
+ " ${cmds[1].toUpperCase()} = " + " ${cmds[1].uppercase()} = "
+ NumberFormat.getCurrencyInstance(Constants.LOCALE) + NumberFormat.getCurrencyInstance(Constants.LOCALE)
.format(amt * doubleTo / doubleFrom).substring(1) .format(amt * doubleTo / doubleFrom).substring(1)
+ " ${cmds[3].toUpperCase()}" + " ${cmds[3].uppercase()}"
) )
} catch (e: NumberFormatException) { } catch (e: NumberFormatException) {
ErrorMessage("Let's try with some real numbers next time, okay?") ErrorMessage("Let's try with some real numbers next time, okay?")

View file

@ -43,17 +43,17 @@ import kotlin.random.Random
class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) { class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) {
init { init {
with(commands) { with(commands) {
add(Hands.ROCK.name.toLowerCase()) add(Hands.ROCK.name.lowercase())
add(Hands.PAPER.name.toLowerCase()) add(Hands.PAPER.name.lowercase())
add(Hands.SCISSORS.name.toLowerCase()) add(Hands.SCISSORS.name.lowercase())
} }
with(help) { with(help) {
add("To play Rock Paper Scissors:") add("To play Rock Paper Scissors:")
add( add(
Utils.helpFormat( Utils.helpFormat(
"%c ${Hands.ROCK.name.toLowerCase()} | ${Hands.PAPER.name.toLowerCase()}" "%c ${Hands.ROCK.name.lowercase()} | ${Hands.PAPER.name.lowercase()}"
+ " | ${Hands.SCISSORS.name.toLowerCase()}" + " | ${Hands.SCISSORS.name.lowercase()}"
) )
) )
} }
@ -82,8 +82,8 @@ class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) {
companion object { companion object {
// For testing. // For testing.
fun winLoseOrDraw(player: String, bot: String): String { fun winLoseOrDraw(player: String, bot: String): String {
val hand = Hands.valueOf(player.toUpperCase()) val hand = Hands.valueOf(player.uppercase())
val botHand = Hands.valueOf(bot.toUpperCase()) val botHand = Hands.valueOf(bot.uppercase())
return when { return when {
hand == botHand -> "draw" hand == botHand -> "draw"
@ -94,7 +94,7 @@ class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) {
} }
override fun commandResponse(sender: String, cmd: String, args: String, isPrivate: Boolean) { override fun commandResponse(sender: String, cmd: String, args: String, isPrivate: Boolean) {
val hand = Hands.valueOf(cmd.toUpperCase()) val hand = Hands.valueOf(cmd.uppercase())
val botHand = Hands.values()[Random.nextInt(0, Hands.values().size)] val botHand = Hands.values()[Random.nextInt(0, Hands.values().size)]
with(bot) { with(bot) {
when { when {

View file

@ -121,7 +121,8 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
@Throws(ModuleException::class) @Throws(ModuleException::class)
fun getQuote(symbol: String, apiKey: String?): List<Message> { fun getQuote(symbol: String, apiKey: String?): List<Message> {
if (apiKey.isNullOrBlank()) { if (apiKey.isNullOrBlank()) {
throw ModuleException("${STOCK_CMD.capitalize()} is disabled. The API key is missing.") throw ModuleException(
"${STOCK_CMD.replaceFirstChar { it.uppercase() }} is disabled. The API key is missing.")
} }
return if (symbol.isNotBlank()) { return if (symbol.isNotBlank()) {
val debugMessage = "getQuote($symbol)" val debugMessage = "getQuote($symbol)"
@ -132,8 +133,8 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
// Search for symbol/keywords // Search for symbol/keywords
response = Utils.urlReader( response = Utils.urlReader(
URL( URL(
"${ALAPHAVANTAGE_URL}SYMBOL_SEARCH&keywords=" + Utils.encodeUrl(symbol) + "&apikey=" "${ALAPHAVANTAGE_URL}SYMBOL_SEARCH&keywords=" + Utils.encodeUrl(symbol)
+ Utils.encodeUrl(apiKey) + "&apikey=" + Utils.encodeUrl(apiKey)
) )
) )
var json = getJsonResponse(response, debugMessage) var json = getJsonResponse(response, debugMessage)
@ -185,8 +186,8 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
) )
add( add(
NoticeMessage( NoticeMessage(
" Change: " + Utils.unescapeXml(quote.getString("09. change")) " Change: " + Utils.unescapeXml(quote.getString("09. change")) + " ["
+ " [" + Utils.unescapeXml(quote.getString("10. change percent")) + ']' + Utils.unescapeXml(quote.getString("10. change percent")) + ']'
) )
) )
} }

View file

@ -32,6 +32,7 @@
package net.thauvin.erik.mobibot.modules; package net.thauvin.erik.mobibot.modules;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.thauvin.erik.mobibot.Mobibot; import net.thauvin.erik.mobibot.Mobibot;
import net.thauvin.erik.mobibot.Utils; import net.thauvin.erik.mobibot.Utils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -71,6 +72,7 @@ public final class War extends AbstractModule {
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@SuppressFBWarnings("DMI_RANDOM_USED_ONLY_ONCE")
@Override @Override
public void commandResponse(@NotNull final String sender, public void commandResponse(@NotNull final String sender,
@NotNull final String cmd, @NotNull final String cmd,

View file

@ -100,7 +100,8 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
@Throws(ModuleException::class) @Throws(ModuleException::class)
fun getWeather(query: String, apiKey: String?): List<Message> { fun getWeather(query: String, apiKey: String?): List<Message> {
if (apiKey.isNullOrBlank()) { if (apiKey.isNullOrBlank()) {
throw ModuleException("${WEATHER_CMD.capitalize()} is disabled. The API key is missing.") throw ModuleException(
"${WEATHER_CMD.replaceFirstChar { it.uppercase() }} is disabled. The API key is missing.")
} }
val owm = OWM(apiKey) val owm = OWM(apiKey)
val messages = mutableListOf<Message>() val messages = mutableListOf<Message>()
@ -122,7 +123,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
} }
if (cwd.hasCityName()) { if (cwd.hasCityName()) {
messages.add( messages.add(
PublicMessage("City: ${cwd.cityName} [${country.toUpperCase()}]") PublicMessage("City: ${cwd.cityName} [${country.uppercase()}]")
) )
with(cwd.mainData) { with(cwd.mainData) {
if (this != null) { if (this != null) {
@ -147,7 +148,9 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
if (list != null) { if (list != null) {
for (w in list) { for (w in list) {
if (w != null) { if (w != null) {
condition.append(' ').append(w.getDescription().capitalize()).append('.') condition.append(' ')
.append(w.getDescription().replaceFirstChar { it.uppercase() })
.append('.')
} }
} }
messages.add(NoticeMessage(condition.toString())) messages.add(NoticeMessage(condition.toString()))
@ -162,7 +165,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
messages.add( messages.add(
NoticeMessage( NoticeMessage(
"https://openweathermap.org/find?q=" "https://openweathermap.org/find?q="
+ Utils.encodeUrl("$city,${country.toUpperCase()}"), + Utils.encodeUrl("$city,${country.uppercase()}"),
Colors.GREEN Colors.GREEN
) )
) )

View file

@ -72,7 +72,7 @@ class WorldTime(bot: Mobibot) : AbstractModule(bot) {
*/ */
@JvmStatic @JvmStatic
fun worldTime(query: String): Message { fun worldTime(query: String): Message {
val tz = COUNTRIES_MAP[(query.substring(query.indexOf(' ') + 1).trim()).toUpperCase()] val tz = COUNTRIES_MAP[(query.substring(query.indexOf(' ') + 1).trim()).uppercase()]
val response: String = if (tz != null) { val response: String = if (tz != null) {
if (BEATS_KEYWORD == tz) { if (BEATS_KEYWORD == tz) {
"The current Internet Time is: " + Utils.bold(internetTime() + ' ' + BEATS_KEYWORD) "The current Internet Time is: " + Utils.bold(internetTime() + ' ' + BEATS_KEYWORD)

View file

@ -69,7 +69,7 @@ open class LocalProperties {
} }
private fun keyToEnv(key: String): String { private fun keyToEnv(key: String): String {
return key.replace('-', '_').toUpperCase() return key.replace('-', '_').uppercase()
} }
} }
} }

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle #Generated by the Semver Plugin for Gradle
#Fri Mar 12 21:10:57 PST 2021 #Mon Apr 26 15:10:03 PDT 2021
version.buildmeta=434 version.buildmeta=452
version.major=0 version.major=0
version.minor=8 version.minor=8
version.patch=0 version.patch=0
version.prerelease=beta version.prerelease=beta
version.project=mobibot version.project=mobibot
version.semver=0.8.0-beta+434 version.semver=0.8.0-beta+452