Skip to content

Commit

Permalink
bump Kotlin version to 1.6.10, change JVM Target to 17, bump some lib…
Browse files Browse the repository at this point in the history
…rary version
  • Loading branch information
danurahadi committed Jan 4, 2022
1 parent 0799420 commit ec2296d
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 148 deletions.
18 changes: 9 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ 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
}
}

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
Expand Down Expand Up @@ -142,7 +142,7 @@ artifacts {
}

detekt {
toolVersion = "1.17.1"
toolVersion = "1.19.0"
input = files("src/main/kotlin")
buildUponDefaultConfig = true
parallel = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <reified T : Any> logger(): Logger {
return LoggerFactory.getLogger(T::class.java)
Expand All @@ -36,10 +33,6 @@ fun logger(name: String): Logger {
return LoggerFactory.getLogger(name)
}

fun useLogback() {
System.setProperty(VertxLoggerFactory.LOGGER_DELEGATE_FACTORY_CLASS_NAME, clazz<SLF4JLogDelegateFactory>().name)
}

sealed class LogType

class INFO(val message: String, val throwable: Throwable? = null) : LogType()
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
9 changes: 4 additions & 5 deletions web/src/main/kotlin/id/yoframework/web/extension/Request.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() ?: ""
Expand Down
7 changes: 4 additions & 3 deletions web/src/main/kotlin/id/yoframework/web/extension/Response.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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", "*")
Expand All @@ -38,7 +38,7 @@ fun RoutingContext.text(obj: Any, contentType: String = "text/plain") {
.end(obj.toString())
}

fun RoutingContext.json(headers: Map<String, String> = emptyMap(), message: Any) {
fun RoutingContext.wireJson(headers: Map<String, String> = emptyMap(), message: Any) {
this.response().apply {
headers.entries.fold(this) { response, entries ->
response.putHeader(entries.key, entries.value)
Expand All @@ -58,9 +58,10 @@ fun RoutingContext.ok(message: String = "", headers: Map<String, String> = 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))
}

Expand Down
35 changes: 23 additions & 12 deletions web/src/main/kotlin/id/yoframework/web/extension/Route.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -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())
}

This file was deleted.

Loading

0 comments on commit ec2296d

Please sign in to comment.