From cac34eea85e2fc1c14ee22e02d043a71554f733b Mon Sep 17 00:00:00 2001 From: NovaFox161 Date: Fri, 18 Aug 2023 20:47:31 -0500 Subject: [PATCH] Upgrade to Spring 3.1.2 and JDK 17 --- .github/workflows/gradle.yml | 2 +- build.gradle.kts | 4 ++-- .../kotlin/org/dreamexposure/discal/cam/Cam.kt | 2 +- .../dreamexposure/discal/client/DisCalClient.kt | 11 +++++++++++ .../discal/client/service/ShutdownHook.kt | 17 ----------------- .../discal/core/spring/GlobalErrorHandler.kt | 4 ++-- gradle.properties | 12 ++++++------ .../dreamexposure/discal/server/DisCalServer.kt | 2 +- settings.gradle.kts | 2 +- .../org/dreamexposure/discal/web/DisCalWeb.kt | 2 +- 10 files changed, 26 insertions(+), 32 deletions(-) delete mode 100644 client/src/main/kotlin/org/dreamexposure/discal/client/service/ShutdownHook.kt diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 58e16ff11..fbadf672c 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -14,7 +14,7 @@ jobs: if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'DreamExposure/DisCal-Discord-Bot' }} strategy: matrix: - java: [ 16, 17 ] + java: [ 17 ] steps: - uses: actions/checkout@v2 diff --git a/build.gradle.kts b/build.gradle.kts index ff7976854..5d2029a34 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -37,8 +37,8 @@ allprojects { apply(plugin = "kotlin") //Compiler nonsense - java.sourceCompatibility = JavaVersion.VERSION_16 - java.targetCompatibility = JavaVersion.VERSION_16 + java.sourceCompatibility = JavaVersion.VERSION_17 + java.targetCompatibility = JavaVersion.VERSION_17 // Versions --- found in gradle.properties val kotlinVersion: String by properties diff --git a/cam/src/main/kotlin/org/dreamexposure/discal/cam/Cam.kt b/cam/src/main/kotlin/org/dreamexposure/discal/cam/Cam.kt index 76b51512b..5791e6a3a 100644 --- a/cam/src/main/kotlin/org/dreamexposure/discal/cam/Cam.kt +++ b/cam/src/main/kotlin/org/dreamexposure/discal/cam/Cam.kt @@ -1,5 +1,6 @@ package org.dreamexposure.discal.cam +import jakarta.annotation.PreDestroy import org.dreamexposure.discal.Application import org.dreamexposure.discal.cam.google.GoogleInternalAuthHandler import org.dreamexposure.discal.core.config.Config @@ -8,7 +9,6 @@ import org.dreamexposure.discal.core.logger.LOGGER import org.dreamexposure.discal.core.utils.GlobalVal import org.springframework.boot.builder.SpringApplicationBuilder import org.springframework.stereotype.Component -import javax.annotation.PreDestroy import kotlin.system.exitProcess @Component diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/DisCalClient.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/DisCalClient.kt index 64e9e164c..4df2a9329 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/DisCalClient.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/DisCalClient.kt @@ -1,9 +1,12 @@ package org.dreamexposure.discal.client +import discord4j.core.GatewayDiscordClient +import jakarta.annotation.PreDestroy import org.dreamexposure.discal.Application import org.dreamexposure.discal.client.message.Messages import org.dreamexposure.discal.core.config.Config import org.dreamexposure.discal.core.logger.LOGGER +import org.dreamexposure.discal.core.utils.GlobalVal import org.dreamexposure.discal.core.utils.GlobalVal.DEFAULT import org.springframework.boot.builder.SpringApplicationBuilder import org.springframework.stereotype.Component @@ -11,6 +14,14 @@ import kotlin.system.exitProcess @Component class DisCalClient { + + @PreDestroy + fun onShutdown(gatewayDiscordClient: GatewayDiscordClient) { + LOGGER.info(GlobalVal.STATUS, "Shutting down shard") + + gatewayDiscordClient.logout().subscribe() + } + companion object { @JvmStatic fun main(args: Array) { diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/service/ShutdownHook.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/service/ShutdownHook.kt deleted file mode 100644 index 4cc1ad726..000000000 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/service/ShutdownHook.kt +++ /dev/null @@ -1,17 +0,0 @@ -package org.dreamexposure.discal.client.service - -import discord4j.core.GatewayDiscordClient -import org.dreamexposure.discal.core.logger.LOGGER -import org.dreamexposure.discal.core.utils.GlobalVal.STATUS -import org.springframework.stereotype.Component -import javax.annotation.PreDestroy - -@Component -class ShutdownHook(private val discordClient: GatewayDiscordClient) { - @PreDestroy - fun onShutdown() { - LOGGER.info(STATUS, "Shutting down shard") - - discordClient.logout().subscribe() - } -} diff --git a/core/src/main/kotlin/org/dreamexposure/discal/core/spring/GlobalErrorHandler.kt b/core/src/main/kotlin/org/dreamexposure/discal/core/spring/GlobalErrorHandler.kt index b41f88f57..22de038ee 100644 --- a/core/src/main/kotlin/org/dreamexposure/discal/core/spring/GlobalErrorHandler.kt +++ b/core/src/main/kotlin/org/dreamexposure/discal/core/spring/GlobalErrorHandler.kt @@ -2,12 +2,12 @@ package org.dreamexposure.discal.core.spring import kotlinx.serialization.SerializationException import kotlinx.serialization.encodeToString -import org.dreamexposure.discal.core.`object`.rest.RestError import org.dreamexposure.discal.core.exceptions.AccessRevokedException import org.dreamexposure.discal.core.exceptions.AuthenticationException import org.dreamexposure.discal.core.exceptions.NotFoundException import org.dreamexposure.discal.core.exceptions.TeaPotException import org.dreamexposure.discal.core.logger.LOGGER +import org.dreamexposure.discal.core.`object`.rest.RestError import org.dreamexposure.discal.core.utils.GlobalVal import org.springframework.beans.TypeMismatchException import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler @@ -27,7 +27,7 @@ class GlobalErrorHandler : ErrorWebExceptionHandler { //Handle exceptions we have codes for val restError: RestError = when (throwable) { is ResponseStatusException -> { - when (throwable.status) { + when (throwable.statusCode) { HttpStatus.NOT_FOUND -> { exchange.response.statusCode = HttpStatus.NOT_FOUND LOGGER.trace("404 exchange | Path: ${exchange.request.path}") diff --git a/gradle.properties b/gradle.properties index 97eb414d8..a0ed9ee3a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,24 +4,24 @@ kotlinVersion=1.9.0 # Plugins -springDependencyManagementVersion=1.0.13.RELEASE -jibVersion=3.3.1 +springDependencyManagementVersion=1.1.3 +jibVersion=3.3.2 gitPropertiesVersion=2.4.1 # Buildscript tooling -kotlinPoetVersion=1.12.0 +kotlinPoetVersion=1.14.2 # Tools kotlinxCoroutinesReactorVersion=1.6.4 reactorKotlinExtensions=1.1.7 # Discord -discord4jVersion=3.2.3 +discord4jVersion=3.2.5 discord4jStoresVersion=3.2.2 discordWebhookVersion=0.8.2 # Spring -springVersion=2.7.5 +springVersion=3.1.2 # Thymeleaf thymeleafVersion=3.1.0.M2 @@ -47,4 +47,4 @@ okhttpVersion=4.10.0 copyDownVersion=1.0 # Jib properties -baseImage=eclipse-temurin:16-jdk-alpine +baseImage=eclipse-temurin:17-jdk-alpine diff --git a/server/src/main/kotlin/org/dreamexposure/discal/server/DisCalServer.kt b/server/src/main/kotlin/org/dreamexposure/discal/server/DisCalServer.kt index 0141c8921..1f794f39a 100644 --- a/server/src/main/kotlin/org/dreamexposure/discal/server/DisCalServer.kt +++ b/server/src/main/kotlin/org/dreamexposure/discal/server/DisCalServer.kt @@ -1,5 +1,6 @@ package org.dreamexposure.discal.server +import jakarta.annotation.PreDestroy import org.dreamexposure.discal.Application import org.dreamexposure.discal.core.config.Config import org.dreamexposure.discal.core.database.DatabaseManager @@ -8,7 +9,6 @@ import org.dreamexposure.discal.core.utils.GlobalVal.DEFAULT import org.dreamexposure.discal.core.utils.GlobalVal.STATUS import org.springframework.boot.builder.SpringApplicationBuilder import org.springframework.stereotype.Component -import javax.annotation.PreDestroy import kotlin.system.exitProcess diff --git a/settings.gradle.kts b/settings.gradle.kts index 0d90b06cb..6b5325260 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -17,8 +17,8 @@ pluginManagement { // Spring kotlin("plugin.spring") version kotlinVersion - id("org.springframework.boot") version springVersion apply false id("io.spring.dependency-management") version springDependencyManagementVersion + id("org.springframework.boot") version springVersion apply false // Tooling id("com.gorylenko.gradle-git-properties") version gitPropertiesVersion apply false diff --git a/web/src/main/kotlin/org/dreamexposure/discal/web/DisCalWeb.kt b/web/src/main/kotlin/org/dreamexposure/discal/web/DisCalWeb.kt index 859eb9fff..b290fd2d2 100644 --- a/web/src/main/kotlin/org/dreamexposure/discal/web/DisCalWeb.kt +++ b/web/src/main/kotlin/org/dreamexposure/discal/web/DisCalWeb.kt @@ -1,5 +1,6 @@ package org.dreamexposure.discal.web +import jakarta.annotation.PreDestroy import org.dreamexposure.discal.Application import org.dreamexposure.discal.core.config.Config import org.dreamexposure.discal.core.logger.LOGGER @@ -7,7 +8,6 @@ import org.dreamexposure.discal.core.utils.GlobalVal.DEFAULT import org.dreamexposure.discal.core.utils.GlobalVal.STATUS import org.springframework.boot.builder.SpringApplicationBuilder import org.springframework.stereotype.Component -import javax.annotation.PreDestroy import kotlin.system.exitProcess @Component