Skip to content

Commit

Permalink
Upgrade to Kotlin 2.1.0 and ktor 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pambrose committed Dec 3, 2024
1 parent 47f6559 commit 6827020
Show file tree
Hide file tree
Showing 63 changed files with 837 additions and 379 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trim_trailing_whitespace = true
[build.gradle]
indent_size = 4

[{Makefile, makefile}]
[{Makefile,makefile}]
indent_style = tab
indent_size = 4

Expand Down
31 changes: 14 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ buildscript {
plugins {
id 'java'
id 'application'
id 'org.jetbrains.kotlin.jvm' version '2.0.21' apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '2.0.21' apply false
id 'org.jmailen.kotlinter' version "4.5.0" apply false
id 'org.jetbrains.kotlin.jvm' version '2.1.0' apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '2.1.0' apply false
// id 'org.jmailen.kotlinter' version "4.5.0" apply false
id 'com.github.gmazzo.buildconfig' version '5.5.1' apply false
id "com.github.ben-manes.versions" version '0.51.0' apply false
id "org.flywaydb.flyway" version "11.0.0"
Expand Down Expand Up @@ -46,9 +46,10 @@ ext {

ktor_server_core : "io.ktor:ktor-server:$ktor_version",
ktor_server_cio : "io.ktor:ktor-server-cio:$ktor_version",
ktor_server_auth : "io.ktor:ktor-server-auth-jvm:$ktor_version",
ktor_sessions : "io.ktor:ktor-server-sessions:$ktor_version",
ktor_html : "io.ktor:ktor-server-html-builder:$ktor_version",
ktor_locations : "io.ktor:ktor-server-locations:$ktor_version",
ktor_resources : "io.ktor:ktor-server-resources:$ktor_version",
ktor_metrics : "io.ktor:ktor-server-metrics:$ktor_version",
ktor_websockets : "io.ktor:ktor-server-websockets:$ktor_version",
ktor_compression : "io.ktor:ktor-server-compression:$ktor_version",
Expand All @@ -75,7 +76,7 @@ ext {

github : "org.kohsuke:github-api:$github_api_version",

ktor_server_tests : "io.ktor:ktor-server-tests:$ktor_version",
ktor_server_tests: "org.jetbrains.kotlin:kotlin-test:$kotlin_version",
ktor_server_test_host : "io.ktor:ktor-server-test-host:$ktor_version",

kotest_runner_junit5 : "io.kotest:kotest-runner-junit5:$kotest_version",
Expand All @@ -87,12 +88,12 @@ ext {
allprojects {
description = 'ReadingBat Core'
group 'com.github.readingbat'
version '1.40.5'
version '1.40.7'

apply plugin: 'application'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'org.jmailen.kotlinter'
// apply plugin: 'org.jmailen.kotlinter'
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
apply plugin: 'com.github.gmazzo.buildconfig'
Expand All @@ -104,8 +105,8 @@ allprojects {
maven { url = 'https://jitpack.io' }
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
// sourceCompatibility = JavaVersion.VERSION_17
// targetCompatibility = JavaVersion.VERSION_17

// publishing {
// publications {
Expand All @@ -130,9 +131,6 @@ subprojects {
//implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
//implementation "org.jetbrains.kotlinx:kotlinx-serialization-core:$serialization_version"

implementation "io.ktor:ktor-server-locations:$ktor_version"

//implementation "dev.hayden:khealth:$khealth_version"

implementation "io.github.oshai:kotlin-logging-jvm:$logging_version"
implementation "ch.qos.logback:logback-classic:$logback_version"
Expand Down Expand Up @@ -174,7 +172,6 @@ subprojects {
'-opt-in=kotlin.contracts.ExperimentalContracts',
'-opt-in=kotlinx.coroutines.ObsoleteCoroutinesApi',
'-opt-in=kotlin.ExperimentalStdlibApi',
'-opt-in=io.ktor.server.locations.KtorExperimentalLocationsAPI',
'-opt-in=kotlinx.coroutines.InternalCoroutinesApi',
'-opt-in=kotlinx.coroutines.DelicateCoroutinesApi',
]
Expand All @@ -191,10 +188,10 @@ subprojects {
}
}

kotlinter {
ignoreFailures = false
reporters = ['checkstyle', 'plain']
}
// kotlinter {
// ignoreFailures = false
// reporters = ['checkstyle', 'plain']
// }
}

flyway {
Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ org.gradle.jvmargs=-Xmx8g -Dkotlin.daemon.jvm.options=-Xmx6g -XX:+HeapDumpOnOutO
# Jars
cloud_version=1.21.0
commons_version=1.12.0
css_version=1.0.0-pre.838
css_version=1.0.0-pre.841
exposed_version=0.56.0
flexmark_version=0.64.8
github_api_version=1.324
gson_version=2.11.0
hikari_version=6.2.1
java_script_version=2.0.0
khealth_version=2.1.1
khealth_version=3.0.1
kotest_ktor_version=4.4.3
kotest_version=5.9.1
kotlin_version=2.0.21
ktor_version=2.3.12
kotlin_version=2.1.0
ktor_version=3.0.1
logback_version=1.5.12
logging_version=7.0.0
logging_version=7.0.3
pgjdbc_version=0.8.9
postgres_version=42.7.4
prometheus_version=0.16.0
proxy_version=1.22.0
redis_version=5.1.5
proxy_version=1.23.0
redis_version=5.2.0
sendgrid_version=4.10.2
serialization_version=1.7.3
utils_version=2.1.2
utils_version=2.3.2
7 changes: 4 additions & 3 deletions readingbat-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ dependencies {

implementation libraries.ktor_server_core
implementation libraries.ktor_server_cio
implementation libraries.ktor_server_auth
implementation libraries.ktor_client_core
implementation libraries.ktor_client_cio

implementation libraries.ktor_sessions
implementation libraries.ktor_html
implementation libraries.ktor_locations
implementation libraries.ktor_metrics
implementation libraries.ktor_websockets
implementation libraries.ktor_compression
implementation libraries.ktor_calllogging
implementation libraries.ktor_resources

implementation libraries.khealth
// implementation libraries.khealth

implementation libraries.jedis

Expand Down Expand Up @@ -116,7 +117,7 @@ buildConfig {

buildConfigField('String', 'CORE_NAME', "\"${project.name}\"")
buildConfigField('String', 'CORE_VERSION', "\"${project.version}\"")
buildConfigField('String', 'CORE_RELEASE_DATE', "\"11/08/24\"")
buildConfigField('String', 'CORE_RELEASE_DATE', "\"12/2/24\"")
}

// Include build uberjars in heroku deploy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.github.readingbat.server.UsersTable
import com.pambrose.common.exposed.get
import com.pambrose.common.exposed.readonlyTx
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.http.*
import io.ktor.http.Parameters
import org.jetbrains.exposed.sql.Count
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ import com.github.readingbat.server.SessionAnswerHistoryTable
import com.github.readingbat.server.SessionChallengeInfoTable
import com.pambrose.common.exposed.readonlyTx
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.sessions.*
import io.ktor.server.application.ApplicationCall
import io.ktor.server.sessions.get
import io.ktor.server.sessions.sessions
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json.Default.decodeFromString
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.insertAndGetId
import org.jetbrains.exposed.sql.transactions.transaction
import java.time.Instant

internal data class UserPrincipal(val userId: String, val created: Long = Instant.now().toEpochMilli()) : Principal
@Serializable
internal data class UserPrincipal(val userId: String, val created: Long = Instant.now().toEpochMilli())

@Serializable
data class BrowserSession(val id: String, val created: Long = Instant.now().toEpochMilli()) {
fun queryOrCreateSessionDbmsId() =
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,68 @@ import com.github.readingbat.common.CssNames.SUCCESS
import com.github.readingbat.common.CssNames.TD_PADDING
import com.github.readingbat.common.CssNames.UNDERLINE
import com.github.readingbat.common.CssNames.USER_RESP
import kotlinx.css.*
import kotlinx.css.Border
import kotlinx.css.BorderCollapse
import kotlinx.css.BorderCollapse.separate
import kotlinx.css.BorderStyle
import kotlinx.css.Color
import kotlinx.css.CssBuilder
import kotlinx.css.Display
import kotlinx.css.Display.block
import kotlinx.css.FontWeight.Companion.bold
import kotlinx.css.LinearDimension
import kotlinx.css.LinearDimension.Companion.auto
import kotlinx.css.ListStyleType
import kotlinx.css.Margin
import kotlinx.css.Padding
import kotlinx.css.Position
import kotlinx.css.TextAlign
import kotlinx.css.VerticalAlign
import kotlinx.css.a
import kotlinx.css.background
import kotlinx.css.backgroundColor
import kotlinx.css.body
import kotlinx.css.border
import kotlinx.css.borderCollapse
import kotlinx.css.borderLeft
import kotlinx.css.borderRadius
import kotlinx.css.borderSpacing
import kotlinx.css.borderWidth
import kotlinx.css.boxShadow
import kotlinx.css.color
import kotlinx.css.display
import kotlinx.css.em
import kotlinx.css.fontFamily
import kotlinx.css.fontSize
import kotlinx.css.fontWeight
import kotlinx.css.h2
import kotlinx.css.height
import kotlinx.css.lineHeight
import kotlinx.css.listStyleType
import kotlinx.css.margin
import kotlinx.css.marginBottom
import kotlinx.css.marginLeft
import kotlinx.css.marginRight
import kotlinx.css.marginTop
import kotlinx.css.maxWidth
import kotlinx.css.minWidth
import kotlinx.css.p
import kotlinx.css.padding
import kotlinx.css.paddingLeft
import kotlinx.css.paddingRight
import kotlinx.css.pct
import kotlinx.css.position
import kotlinx.css.properties.BoxShadow
import kotlinx.css.properties.BoxShadows
import kotlinx.css.properties.LineHeight
import kotlinx.css.properties.TextDecoration
import kotlinx.css.properties.TextDecorationLine.underline
import kotlinx.css.px
import kotlinx.css.textAlign
import kotlinx.css.textDecoration
import kotlinx.css.top
import kotlinx.css.verticalAlign
import kotlinx.css.width

internal object CssNames {
const val CHECK_ANSWERS = "checkAnswers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,34 @@

package com.github.readingbat.common

import com.github.pambrose.common.util.*
import com.github.pambrose.common.util.asBracketed
import com.github.pambrose.common.util.isBracketed
import com.github.pambrose.common.util.isDoubleQuoted
import com.github.pambrose.common.util.isNotBracketed
import com.github.pambrose.common.util.isNotDoubleQuoted
import com.github.pambrose.common.util.isNotFloat
import com.github.pambrose.common.util.isNotInt
import com.github.pambrose.common.util.isNotQuoted
import com.github.pambrose.common.util.isSingleQuoted
import com.github.pambrose.common.util.singleToDoubleQuoted
import com.github.pambrose.common.util.toDoubleQuoted
import com.github.readingbat.dsl.LanguageType.Java
import com.github.readingbat.dsl.LanguageType.Kotlin
import com.github.readingbat.dsl.LanguageType.Python
import com.github.readingbat.dsl.ReturnType
import com.github.readingbat.dsl.ReturnType.*
import com.github.readingbat.dsl.ReturnType.BooleanArrayType
import com.github.readingbat.dsl.ReturnType.BooleanListType
import com.github.readingbat.dsl.ReturnType.BooleanType
import com.github.readingbat.dsl.ReturnType.FloatArrayType
import com.github.readingbat.dsl.ReturnType.FloatListType
import com.github.readingbat.dsl.ReturnType.FloatType
import com.github.readingbat.dsl.ReturnType.IntArrayType
import com.github.readingbat.dsl.ReturnType.IntListType
import com.github.readingbat.dsl.ReturnType.IntType
import com.github.readingbat.dsl.ReturnType.Runtime
import com.github.readingbat.dsl.ReturnType.StringArrayType
import com.github.readingbat.dsl.ReturnType.StringListType
import com.github.readingbat.dsl.ReturnType.StringType
import com.github.readingbat.dsl.challenge.Challenge
import com.github.readingbat.posts.ChallengeResults
import com.github.readingbat.server.ChallengeMd5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import com.github.readingbat.common.PropertyNames.DBMS
import com.github.readingbat.common.PropertyNames.READINGBAT
import com.github.readingbat.common.PropertyNames.SITE
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.server.application.*
import io.ktor.server.config.*
import io.ktor.server.application.Application
import io.ktor.server.config.ApplicationConfigurationException
import java.util.concurrent.atomic.AtomicBoolean

open class KtorProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,31 @@ import com.github.readingbat.posts.ChallengeResults
import com.github.readingbat.posts.DashboardHistory
import com.github.readingbat.posts.DashboardInfo
import com.github.readingbat.posts.LikeDislikeInfo
import com.github.readingbat.server.*
import com.github.readingbat.server.BrowserSessionsTable
import com.github.readingbat.server.ChallengeName
import com.github.readingbat.server.ClassesTable
import com.github.readingbat.server.Email
import com.github.readingbat.server.Email.Companion.EMPTY_EMAIL
import com.github.readingbat.server.Email.Companion.UNKNOWN_EMAIL
import com.github.readingbat.server.EnrolleesTable
import com.github.readingbat.server.FullName
import com.github.readingbat.server.FullName.Companion.EMPTY_FULLNAME
import com.github.readingbat.server.FullName.Companion.UNKNOWN_FULLNAME
import com.github.readingbat.server.GroupName
import com.github.readingbat.server.Invocation
import com.github.readingbat.server.LanguageName
import com.github.readingbat.server.Password
import com.github.readingbat.server.PasswordResetsTable
import com.github.readingbat.server.ReadingBatServer.adminUsers
import com.github.readingbat.server.ResetId
import com.github.readingbat.server.ResetId.Companion.EMPTY_RESET_ID
import com.github.readingbat.server.UserAnswerHistoryTable
import com.github.readingbat.server.UserChallengeInfoTable
import com.github.readingbat.server.UserSessionsTable
import com.github.readingbat.server.UsersTable
import com.github.readingbat.server.passwordResetsIndex
import com.github.readingbat.server.userAnswerHistoryIndex
import com.github.readingbat.server.userSessionIndex
import com.github.readingbat.server.ws.ChallengeWs.classTargetName
import com.github.readingbat.server.ws.ChallengeWs.multiServerWsWriteFlow
import com.github.readingbat.server.ws.ChallengeWs.singleServerWsFlow
Expand Down Expand Up @@ -530,7 +548,8 @@ class User {
classCode.isEnabled -> {
// Check to see if the teacher that owns class has it set as their active class in one of the sessions
val teacherId = classCode.fetchClassTeacherId()
teacherId.isNotEmpty() && teacherId.toUser().interestedInActiveClassCode(classCode)
teacherId.isNotEmpty() &&
teacherId.toUser().interestedInActiveClassCode(classCode)
.also { logger.debug { "Publishing teacherId: $teacherId for $classCode" } }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ import com.github.pambrose.common.util.isNull
import com.github.pambrose.common.util.pathOf
import com.github.readingbat.common.Endpoints.CHALLENGE_ROOT
import com.github.readingbat.server.LanguageName
import io.ktor.http.*
import java.util.*
import io.ktor.http.Parameters

enum class LanguageType(val useDoubleQuotes: Boolean, val suffix: String, val srcPrefix: String) {
Java(true, "java", "src/main/java"),
Python(false, "py", "python"),
Kotlin(true, "kt", "src/main/kotlin"),
;

internal val languageName = LanguageName(name.lowercase(Locale.getDefault()))
internal val languageName = LanguageName(name.lowercase())
internal val contentRoot = pathOf(CHALLENGE_ROOT, languageName)

val isJava by lazy { this == Java }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import com.github.readingbat.server.GroupName
import com.github.readingbat.server.Language
import com.github.readingbat.server.LanguageName
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO
import io.ktor.client.request.header
import io.ktor.client.statement.bodyAsText
import kotlinx.coroutines.runBlocking
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
Expand Down
Loading

0 comments on commit 6827020

Please sign in to comment.