From ec2296db28b5f1b3a68376ff9ad04b86b8427c5c Mon Sep 17 00:00:00 2001 From: Argi Danu Rahadi Date: Tue, 4 Jan 2022 15:49:56 +0700 Subject: [PATCH] bump Kotlin version to 1.6.10, change JVM Target to 17, bump some library version --- build.gradle | 18 +++---- buildSrc/build.gradle | 4 +- ...framework.kotlin-common-conventions.gradle | 22 ++++---- .../core/extension/filesystem/FileSystem.kt | 4 +- .../core/extension/logger/Logger.kt | 7 --- gradle.properties | 6 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../morphia/module/MorphiaModule.kt | 2 + settings.gradle | 4 +- .../id/yoframework/web/extension/Request.kt | 9 ++-- .../id/yoframework/web/extension/Response.kt | 7 +-- .../id/yoframework/web/extension/Route.kt | 35 ++++++++----- .../web/security/SecurityProvider.kt | 41 --------------- .../yoframework/web/security/SecurityUser.kt | 50 ------------------- 14 files changed, 63 insertions(+), 148 deletions(-) delete mode 100644 web/src/main/kotlin/id/yoframework/web/security/SecurityProvider.kt delete mode 100644 web/src/main/kotlin/id/yoframework/web/security/SecurityUser.kt diff --git a/build.gradle b/build.gradle index b210de7..66d6437 100644 --- a/build.gradle +++ b/build.gradle @@ -1,27 +1,27 @@ ext { version = project.property('version') - kotlinVersion = "1.5.30" - vertxVersion = '3.9.5' + kotlinVersion = "1.6.10" + vertxVersion = '4.2.3' pebbleVersion = '3.1.5' - coroutineVersion = "1.5.1" + coroutineVersion = "1.6.0" arrowVersion = "0.7.2" - logbackVersion = '1.2.3' - logstashLogbackEncoderVersion = '6.6' + logbackVersion = '1.2.10' + logstashLogbackEncoderVersion = '7.0.1' commonsLangVersion = '3.12.0' commonsIOVersion = '2.11.0' commonsCodecVersion = '1.15' - daggerVersion = '2.38.1' - jacksonVersion = '2.12.5' + daggerVersion = '2.40.5' + jacksonVersion = '2.13.1' morphiaVersion = '1.3.2' quartzVersion = "2.3.2" jakartaElVersion = '4.0.1' - hibernateValidatorVersion = '7.0.1.Final' + hibernateValidatorVersion = '7.0.2.Final' elImplVersion = "2.2" jBCryptVersion = '0.4.1' @@ -31,7 +31,7 @@ ext { ebeanVersion = "12.11.2" jdbiVersion = "3.0.1" hikariCPVersion = "5.0.0" - flywayVersion = "7.14.1" + flywayVersion = "8.3.0" restAssuredVersion = '3.0.3' embeddedMongoVersion = '2.0.0' diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index b7991f0..d7cabbd 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -5,8 +5,8 @@ plugins { id 'groovy-gradle-plugin' } -def kotlinVersion = '1.5.30' -def detektVersion = '1.18.1' +def kotlinVersion = '1.6.10' +def detektVersion = '1.19.0' repositories { // Use the plugin portal to apply community plugins in convention plugins. diff --git a/buildSrc/src/main/groovy/yoframework.kotlin-common-conventions.gradle b/buildSrc/src/main/groovy/yoframework.kotlin-common-conventions.gradle index 0a9e752..43dcfeb 100644 --- a/buildSrc/src/main/groovy/yoframework.kotlin-common-conventions.gradle +++ b/buildSrc/src/main/groovy/yoframework.kotlin-common-conventions.gradle @@ -58,13 +58,13 @@ dependencies { tasks { compileKotlin { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 kotlinOptions { - jvmTarget = "11" - apiVersion = "1.5" - languageVersion = "1.5" + jvmTarget = "17" + apiVersion = "1.6" + languageVersion = "1.6" allWarningsAsErrors = true incremental = true useIR = true @@ -72,13 +72,13 @@ tasks { } compileTestKotlin { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 kotlinOptions { - jvmTarget = "11" - apiVersion = "1.5" - languageVersion = "1.5" + jvmTarget = "17" + apiVersion = "1.6" + languageVersion = "1.6" allWarningsAsErrors = true incremental = true useIR = true @@ -142,7 +142,7 @@ artifacts { } detekt { - toolVersion = "1.17.1" + toolVersion = "1.19.0" input = files("src/main/kotlin") buildUponDefaultConfig = true parallel = true diff --git a/core/src/main/kotlin/id/yoframework/core/extension/filesystem/FileSystem.kt b/core/src/main/kotlin/id/yoframework/core/extension/filesystem/FileSystem.kt index 386790e..697acbb 100644 --- a/core/src/main/kotlin/id/yoframework/core/extension/filesystem/FileSystem.kt +++ b/core/src/main/kotlin/id/yoframework/core/extension/filesystem/FileSystem.kt @@ -20,10 +20,10 @@ import io.vertx.core.buffer.Buffer import io.vertx.core.file.FileSystem import io.vertx.kotlin.coroutines.awaitResult -suspend fun FileSystem.readFile(path: String): Buffer { +suspend fun FileSystem.readFileAsync(path: String): Buffer { return awaitResult { this.readFile(path, it) } } -suspend fun FileSystem.writeFile(path: String, data: Buffer): Void { +suspend fun FileSystem.writeFileAsync(path: String, data: Buffer): Void { return awaitResult { this.writeFile(path, data, it) } } diff --git a/core/src/main/kotlin/id/yoframework/core/extension/logger/Logger.kt b/core/src/main/kotlin/id/yoframework/core/extension/logger/Logger.kt index 291ff8c..7c1ebd1 100644 --- a/core/src/main/kotlin/id/yoframework/core/extension/logger/Logger.kt +++ b/core/src/main/kotlin/id/yoframework/core/extension/logger/Logger.kt @@ -16,13 +16,10 @@ package id.yoframework.core.extension.logger -import id.yoframework.core.extension.system.clazz -import io.vertx.core.logging.SLF4JLogDelegateFactory import net.logstash.logback.marker.Markers import org.slf4j.Logger import org.slf4j.LoggerFactory import kotlin.reflect.KClass -import io.vertx.core.logging.LoggerFactory as VertxLoggerFactory inline fun logger(): Logger { return LoggerFactory.getLogger(T::class.java) @@ -36,10 +33,6 @@ fun logger(name: String): Logger { return LoggerFactory.getLogger(name) } -fun useLogback() { - System.setProperty(VertxLoggerFactory.LOGGER_DELEGATE_FACTORY_CLASS_NAME, clazz().name) -} - sealed class LogType class INFO(val message: String, val throwable: Throwable? = null) : LogType() diff --git a/gradle.properties b/gradle.properties index 7e6c7b3..a12df3d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Set the project version -version=0.4.5 +version=0.4.6 # Set the JVM heap size org.gradle.jvmargs=-Xms1g -Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options=-Xmx1G @@ -8,10 +8,10 @@ org.gradle.jvmargs=-Xms1g -Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfM org.gradle.daemon=false # Enable the build cache -org.gradle.caching=false +org.gradle.caching=true # Enable parallelize build -org.gradle.parallel=false +org.gradle.parallel=true # Enable configure on demand org.gradle.configureondemand=false diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a2..2e6e589 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/morphia/src/main/kotlin/id/yoframework/morphia/module/MorphiaModule.kt b/morphia/src/main/kotlin/id/yoframework/morphia/module/MorphiaModule.kt index 2b43312..ecf5a8a 100644 --- a/morphia/src/main/kotlin/id/yoframework/morphia/module/MorphiaModule.kt +++ b/morphia/src/main/kotlin/id/yoframework/morphia/module/MorphiaModule.kt @@ -28,6 +28,7 @@ import id.yoframework.core.json.getExcept import id.yoframework.core.json.getTry import id.yoframework.core.module.CoreModule import io.vertx.core.json.JsonObject +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.ObsoleteCoroutinesApi import kotlinx.coroutines.newFixedThreadPoolContext import javax.inject.Named @@ -92,6 +93,7 @@ class MorphiaModule { @Singleton @Named("morphiaThreadPool") @ObsoleteCoroutinesApi + @DelicateCoroutinesApi fun morphiaThreadPool(config: JsonObject): CoroutineContext { val mongoThreadPoolSize = config.getInteger("MORPHIA_THREAD_POOL_SIZE", DEFAULT_THREAD_POOL) log.info("Initialize Mongo Database with thread pool size $mongoThreadPoolSize") diff --git a/settings.gradle b/settings.gradle index bc7e3b2..40c4208 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,5 @@ -if (JavaVersion.current() < JavaVersion.VERSION_1_8) { - throw new GradleException("This build must be run at least with java 8") +if (JavaVersion.current() < JavaVersion.VERSION_11) { + throw new GradleException("This build must be run at least with java 11") } rootProject.name = 'yoframework' diff --git a/web/src/main/kotlin/id/yoframework/web/extension/Request.kt b/web/src/main/kotlin/id/yoframework/web/extension/Request.kt index 3741ca5..3d48b50 100644 --- a/web/src/main/kotlin/id/yoframework/web/extension/Request.kt +++ b/web/src/main/kotlin/id/yoframework/web/extension/Request.kt @@ -18,7 +18,6 @@ package id.yoframework.web.extension import arrow.core.Try import arrow.core.getOrElse -import id.yoframework.web.security.SecurityUser import io.vertx.core.json.JsonArray import io.vertx.core.json.JsonObject import io.vertx.ext.web.RoutingContext @@ -43,10 +42,10 @@ fun RoutingContext.principal(): JsonObject? { return this.user()?.principal() } -@Suppress("deprecation") -fun RoutingContext.securityUser(): SecurityUser? { - return this.user() as? SecurityUser -} +//@Suppress("deprecation") +//fun RoutingContext.securityUser(): SecurityUser? { +// return this.user() as? SecurityUser +//} fun RoutingContext.getRemoteIpAddress(): String { return this.request()?.remoteAddress()?.host() ?: "" diff --git a/web/src/main/kotlin/id/yoframework/web/extension/Response.kt b/web/src/main/kotlin/id/yoframework/web/extension/Response.kt index 33c436f..fae1979 100644 --- a/web/src/main/kotlin/id/yoframework/web/extension/Response.kt +++ b/web/src/main/kotlin/id/yoframework/web/extension/Response.kt @@ -25,7 +25,7 @@ import io.vertx.ext.web.common.template.TemplateEngine import io.vertx.kotlin.core.json.Json import io.vertx.kotlin.coroutines.awaitResult -fun RoutingContext.json(obj: Any) { +fun RoutingContext.wireJson(obj: Any) { val response = this.response() response.putHeader("Content-Type", "application/json; charset=utf-8") .putHeader("Access-Control-Allow-Origin", "*") @@ -38,7 +38,7 @@ fun RoutingContext.text(obj: Any, contentType: String = "text/plain") { .end(obj.toString()) } -fun RoutingContext.json(headers: Map = emptyMap(), message: Any) { +fun RoutingContext.wireJson(headers: Map = emptyMap(), message: Any) { this.response().apply { headers.entries.fold(this) { response, entries -> response.putHeader(entries.key, entries.value) @@ -58,9 +58,10 @@ fun RoutingContext.ok(message: String = "", headers: Map = empty } } -fun RoutingContext.prettyJson(obj: Any) { +fun RoutingContext.wirePrettyJson(obj: Any) { val response = this.response() response.putHeader("Content-Type", "application/json; charset=utf-8") + .putHeader("Access-Control-Allow-Origin", "*") .end(Json.encodePrettily(obj)) } diff --git a/web/src/main/kotlin/id/yoframework/web/extension/Route.kt b/web/src/main/kotlin/id/yoframework/web/extension/Route.kt index cc5f4a8..1eefdf3 100644 --- a/web/src/main/kotlin/id/yoframework/web/extension/Route.kt +++ b/web/src/main/kotlin/id/yoframework/web/extension/Route.kt @@ -26,8 +26,7 @@ import io.vertx.ext.web.RoutingContext import io.vertx.ext.web.common.template.TemplateEngine import io.vertx.ext.web.handler.StaticHandler import io.vertx.kotlin.coroutines.dispatcher -import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import kotlin.coroutines.CoroutineContext @@ -57,11 +56,13 @@ fun Route.serveStatic(webRoot: String): Route { }) } -@DelicateCoroutinesApi -fun Route.asyncHandler(coroutineContext: CoroutineContext? = null, handler: suspend RoutingContext.() -> Unit): Route { +fun Route.asyncHandler( + coroutineContext: CoroutineContext? = null, + handler: suspend RoutingContext.() -> Unit +): Route { return this.handler { routingContext -> val context = coroutineContext ?: routingContext.vertx().dispatcher() - GlobalScope.launch(context) { + CoroutineScope(context).launch { Try { handler(routingContext) }.getOrElse { @@ -71,22 +72,32 @@ fun Route.asyncHandler(coroutineContext: CoroutineContext? = null, handler: susp } } -@DelicateCoroutinesApi -fun Route.jsonHandler(coroutineContext: CoroutineContext? = null, handler: suspend RoutingContext.() -> Any): Route { - return this.asyncHandler(coroutineContext) { this.json(handler(this)) } +fun Route.jsonAsyncHandler( + coroutineContext: CoroutineContext? = null, + handler: suspend RoutingContext.() -> Any +): Route { + return this.asyncHandler(coroutineContext) { this.wireJson(handler(this)) } +} + +fun Route.syncHandler(handler: RoutingContext.() -> Unit): Route { + return this.handler { routingContext -> + handler(routingContext) + } +} + +fun Route.jsonHandler(handler: RoutingContext.() -> Any): Route { + return this.syncHandler { this.wireJson(handler(this)) } } -@DelicateCoroutinesApi fun Route.templateHandler( - coroutineContext: CoroutineContext? = null, engine: TemplateEngine, templateName: String ): Route { - return this.asyncHandler(coroutineContext) { + return this.asyncHandler { this.text(render(engine, templateName)) } } -fun Router.subRoute(path: String, subController: Controller): Router { +fun Router.subRoute(path: String, subController: Controller): Route { return this.mountSubRouter(path, subController.create()) } diff --git a/web/src/main/kotlin/id/yoframework/web/security/SecurityProvider.kt b/web/src/main/kotlin/id/yoframework/web/security/SecurityProvider.kt deleted file mode 100644 index 373985a..0000000 --- a/web/src/main/kotlin/id/yoframework/web/security/SecurityProvider.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C)2018 - Deny Prasetyo - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package id.yoframework.web.security - -import arrow.core.Try -import arrow.core.getOrElse -import io.vertx.core.AsyncResult -import io.vertx.core.Future -import io.vertx.core.Handler -import io.vertx.core.json.JsonObject -import io.vertx.ext.auth.AuthProvider -import io.vertx.ext.auth.User -import kotlinx.coroutines.runBlocking - -interface SecurityProvider : AuthProvider { - override fun authenticate(authInfo: JsonObject, resultHandler: Handler>) = runBlocking { - Try { - val user = authenticate(authInfo) - resultHandler.handle(Future.succeededFuture(user)) - }.getOrElse { - val exception = SecurityException(it) - resultHandler.handle(Future.failedFuture(exception)) - } - } - - suspend fun authenticate(authInfo: JsonObject): SecurityUser -} diff --git a/web/src/main/kotlin/id/yoframework/web/security/SecurityUser.kt b/web/src/main/kotlin/id/yoframework/web/security/SecurityUser.kt deleted file mode 100644 index 29aec32..0000000 --- a/web/src/main/kotlin/id/yoframework/web/security/SecurityUser.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C)2018 - Deny Prasetyo - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package id.yoframework.web.security - -import io.vertx.core.AsyncResult -import io.vertx.core.Future -import io.vertx.core.Handler -import io.vertx.core.json.JsonObject -import io.vertx.ext.auth.* -import io.vertx.ext.auth.AuthProvider -import java.io.Serializable - -@Suppress("deprecation", "WildcardImport") -class SecurityUser(private val model: SecurityModel, private val accesses: List) : AbstractUser(), - Serializable { - - override fun doIsPermitted(permission: String, resultHandler: Handler>) { - resultHandler.handle(Future.succeededFuture(doIsPermitted(permission))) - } - - fun doIsPermitted(permission: String): Boolean { - return accesses.contains(permission) - } - - override fun setAuthProvider(authProvider: AuthProvider?) { - // no-op comment in auth provider function - } - - override fun principal(): JsonObject { - return model.toJsonObject() - } - - companion object { - const val serialVersionUID = 1L - } -}