Skip to content

Commit

Permalink
Update to Kotlin 1.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pambrose committed Jul 27, 2023
1 parent f7bab93 commit 1d50d8e
Show file tree
Hide file tree
Showing 30 changed files with 171 additions and 176 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ depends:
./gradlew dependencies

upgrade-wrapper:
./gradlew wrapper --gradle-version=8.1.1 --distribution-type=bin
./gradlew wrapper --gradle-version=8.2.1 --distribution-type=bin
24 changes: 11 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ buildscript {
plugins {
id 'java'
id 'application'
id 'org.jetbrains.kotlin.jvm' version '1.8.21' apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.21' apply false
id 'org.jetbrains.kotlin.jvm' version '1.9.0' apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.0' apply false
id 'org.jmailen.kotlinter' version "3.13.0" apply false
id 'com.github.gmazzo.buildconfig' version '4.0.4' apply false
id "com.github.ben-manes.versions" version '0.46.0' apply false
id "org.flywaydb.flyway" version "9.18.0"
id 'com.github.gmazzo.buildconfig' version '4.1.2' apply false
id "com.github.ben-manes.versions" version '0.47.0' apply false
id "org.flywaydb.flyway" version "9.21.1"
}

ext {
Expand Down Expand Up @@ -87,11 +87,11 @@ ext {
allprojects {
description = 'ReadingBat Core'
group 'com.github.readingbat'
version '1.33.6'
version '1.34.0'

apply plugin: 'application'
apply plugin: 'java-library' // gradle 7
apply plugin: 'maven-publish' // required for jitpack.io install // gradle 7
apply plugin: 'java-library'
apply plugin: 'maven-publish' // required for jitpack.io install
apply plugin: 'org.jmailen.kotlinter'
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
Expand All @@ -108,7 +108,6 @@ allprojects {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

// gradle 7
publishing {
publications {
mavenJava(MavenPublication) {
Expand Down Expand Up @@ -163,12 +162,11 @@ subprojects {
withSourcesJar()
}

// kotlin {
// jvmToolchain(17)
// }
kotlin {
jvmToolchain(17)
}

tasks.withType(KotlinCompile).configureEach {
kotlinOptions.jvmTarget = JavaVersion.VERSION_17
kotlinOptions.freeCompilerArgs += ['-Xbackend-threads=8',
'-opt-in=kotlin.time.ExperimentalTime',
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ org.gradle.configureondemand=true
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.jvmargs=-Xmx8g -Dkotlin.daemon.jvm.options=-Xmx6g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
cloud_version=1.11.2
cloud_version=1.13.1
commons_version=1.10.0
css_version=1.0.0-pre.560
css_version=1.0.0-pre.601
exposed_version=0.41.1
flexmark_version=0.64.8
github_api_version=1.315
Expand All @@ -17,15 +17,15 @@ java_script_version=2.0.0
khealth_version=2.1.1
kotest_version=5.6.2
kotest_ktor_version=4.4.3
kotlin_version=1.8.21
ktor_version=2.3.1
logback_version=1.4.7
kotlin_version=1.9.0
ktor_version=2.3.2
logback_version=1.4.8
logging_version=4.0.0-beta-2
pgjdbc_version=0.8.9
postgres_version=42.6.0
prometheus_version=0.16.0
proxy_version=1.17.0
redis_version=4.4.0-rc1
proxy_version=1.18.0
redis_version=5.0.0-beta2
serialization_version=1.5.1
sendgrid_version=4.9.3
utils_version=1.38.0
utils_version=1.39.9
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jdk:
- openjdk11
- openjdk17
install:
- ./gradlew build -xtest
- ./gradlew publishToMavenLocal
Expand Down
2 changes: 1 addition & 1 deletion readingbat-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ buildConfig {

buildConfigField('String', 'CORE_NAME', "\"${project.name}\"")
buildConfigField('String', 'CORE_VERSION', "\"${project.version}\"")
buildConfigField('String', 'CORE_RELEASE_DATE', "\"05/25/23\"")
buildConfigField('String', 'CORE_RELEASE_DATE', "\"07/27/23\"")
}

// Include build uberjars in heroku deploy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.github.readingbat.utils.ExposedUtils.readonlyTx
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.sessions.*
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import mu.two.KLogging
import org.jetbrains.exposed.sql.and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ import kotlinx.css.BorderCollapse.separate
import kotlinx.css.Display.block
import kotlinx.css.FontWeight.Companion.bold
import kotlinx.css.LinearDimension.Companion.auto
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.properties.boxShadow

internal object CssNames {
const val CHECK_ANSWERS = "checkAnswers"
Expand Down Expand Up @@ -188,7 +189,7 @@ internal val cssContent by lazy {
fontSize = 155.pct
}
rule("th, td") {
padding = "1px"
padding = Padding(1.px)
textAlign = TextAlign.left
}
rule("th") {
Expand All @@ -197,9 +198,9 @@ internal val cssContent by lazy {
rule("div.$GROUP_ITEM_SRC") {
maxWidth = 300.px
minWidth = 300.px
margin = "15px"
padding = "10px"
border = "1px solid gray"
margin = Margin(15.px)
padding = Padding(10.px)
border = Border(1.px, BorderStyle.solid, Color.gray)
borderRadius = LinearDimension("1em")
}
rule("td.$FUNC_COL") {
Expand All @@ -216,14 +217,14 @@ internal val cssContent by lazy {
}
rule("td.$FEEDBACK") {
width = 10.em
border = "7px solid white"
border = Border(7.px, BorderStyle.solid, Color.white)
}
rule("td.$HINT") {
//width = 10.em
//border = "7px solid white"
}
rule(".$DASHBOARD") {
border = "1px solid #DDDDDD"
border = Border(1.px, BorderStyle.solid, Color("#DDDDDD"))
borderCollapse = BorderCollapse.collapse
}
rule(".$CHECK_ANSWERS") {
Expand Down Expand Up @@ -280,7 +281,7 @@ internal val cssContent by lazy {
}
rule(".$INVOC_TD") {
borderCollapse = separate
border = "1px solid black"
border = Border(1.px, BorderStyle.solid, Color.black)
width = 7.px
height = 15.px
backgroundColor = Color(INCOMPLETE_COLOR)
Expand All @@ -296,17 +297,17 @@ internal val cssContent by lazy {
}
rule("nav ul") {
listStyleType = ListStyleType.none
padding = "0"
margin = "0"
padding = Padding(0.px)
margin = Margin(0.px)
}
rule("nav li") {
display = Display.inline
border = "solid"
border = Border(1.px, BorderStyle.solid)
borderWidth = LinearDimension("1px 1px 0 1px")
margin = "0 25px 0 6px"
margin = Margin(0.px, 25.px, 0.px, 6.px)
}
rule("nav li a") {
padding = "0 40px"
padding = Padding(0.px, 40.px)
}
rule(".$EXPERIMENT") {
marginTop = 1.em
Expand Down Expand Up @@ -334,9 +335,13 @@ internal val cssContent by lazy {
// This takes care of the blue vertical stripe to the left of the code
rule("pre[class*=\"language-\"] > code") {
val color = "#0600EE"
borderLeft = "10px solid $color"
boxShadow(Color(color), (-1).px, 0.px, 0.px, 0.px)
boxShadow(Color("#dfdfdf"), 0.px, 0.px, 0.px, 1.px)
borderLeft = Border(10.px, BorderStyle.solid, Color(color))
boxShadow = BoxShadows().apply {
BoxShadow(Color(color), (-1).px, 0.px, 0.px, 0.px)
}
boxShadow = BoxShadows().apply {
BoxShadow(Color("#dfdfdf"), 0.px, 0.px, 0.px, 1.px)
}
}
rule(".language-java") {
//width = 950.px // !important
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class FunctionInfo(
else -> this.toInt() == that.toInt()
}
result to (if (result) "" else deriveHint())
}.getOrElse { e ->
}.getOrElse { _ ->
false to deriveHint()
}
}
Expand Down Expand Up @@ -293,7 +293,7 @@ class FunctionInfo(
else -> toInt() == correctAnswer.toInt()
}
result to (if (result) "" else deriveHint())
}.getOrElse { e ->
}.getOrElse { _ ->
false to deriveHint()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ import com.github.readingbat.server.FullName.Companion.UNKNOWN_FULLNAME
import com.github.readingbat.server.ReadingBatServer.adminUsers
import com.github.readingbat.server.ResetId.Companion.EMPTY_RESET_ID
import com.github.readingbat.server.ws.ChallengeWs.classTargetName
import com.github.readingbat.server.ws.ChallengeWs.multiServerWsWriteChannel
import com.github.readingbat.server.ws.ChallengeWs.singleServerWsChannel
import com.github.readingbat.server.ws.ChallengeWs.multiServerWsWriteFlow
import com.github.readingbat.server.ws.ChallengeWs.singleServerWsFlow
import com.github.readingbat.server.ws.PubSubCommandsWs.ChallengeAnswerData
import com.github.readingbat.server.ws.PubSubCommandsWs.PubSubTopic.LIKE_DISLIKE
import com.github.readingbat.server.ws.PubSubCommandsWs.PubSubTopic.USER_ANSWERS
import com.github.readingbat.utils.ExposedUtils.readonlyTx
import com.pambrose.common.exposed.get
import com.pambrose.common.exposed.upsert
import kotlinx.html.Entities.nbsp
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import mu.two.KLogging
Expand Down Expand Up @@ -475,17 +474,17 @@ class User {
)
val targetName = classTargetName(enrolledClassCode, challengeMd5)
val dashboardInfo = DashboardInfo(userId, complete, numCorrect, dashboardHistory)
(if (isMultiServerEnabled()) multiServerWsWriteChannel else singleServerWsChannel)
.send(ChallengeAnswerData(USER_ANSWERS, targetName, dashboardInfo.toJson()))
(if (isMultiServerEnabled()) multiServerWsWriteFlow else singleServerWsFlow)
.emit(ChallengeAnswerData(USER_ANSWERS, targetName, dashboardInfo.toJson()))
}

suspend fun publishLikeDislike(challengeMd5: String, likeDislike: Int) {
logger.debug { "Publishing user likeDislike to $enrolledClassCode on $challengeMd5 for $this" }
val targetName = classTargetName(enrolledClassCode, challengeMd5)
val emoji = likeDislikeEmoji(likeDislike)
val likeDislikeInfo = LikeDislikeInfo(userId, emoji)
(if (isMultiServerEnabled()) multiServerWsWriteChannel else singleServerWsChannel)
.send(ChallengeAnswerData(LIKE_DISLIKE, targetName, likeDislikeInfo.toJson()))
(if (isMultiServerEnabled()) multiServerWsWriteFlow else singleServerWsFlow)
.emit(ChallengeAnswerData(LIKE_DISLIKE, targetName, likeDislikeInfo.toJson()))
}

suspend fun resetHistory(funcInfo: FunctionInfo, challenge: Challenge, maxHistoryLength: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@ internal fun isDbmsEnabled() = Property.DBMS_ENABLED.getProperty(false)
internal fun isRedisEnabled() = Property.REDIS_ENABLED.getProperty(false)

internal fun isSaveRequestsEnabled() =
Property.SAVE_REQUESTS_ENABLED.getProperty(true, false) && isDbmsEnabled() && EnvVar.IPGEOLOCATION_KEY.isDefined()
Property.SAVE_REQUESTS_ENABLED.getProperty(
default = true,
errorOnNonInit = false
) && isDbmsEnabled() && EnvVar.IPGEOLOCATION_KEY.isDefined()

internal fun isContentCachingEnabled() =
Property.CONTENT_CACHING_ENABLED.getProperty(false, false) && isDbmsEnabled() && isRedisEnabled()
Property.CONTENT_CACHING_ENABLED.getProperty(
default = false,
errorOnNonInit = false
) && isDbmsEnabled() && isRedisEnabled()

internal fun isMultiServerEnabled() = Property.MULTI_SERVER_ENABLED.getProperty(false)

Expand Down Expand Up @@ -164,7 +170,7 @@ private val <T> KFunction<T>.fqMethodName get() = "${javaClass.packageName}.$nam
private suspend fun evalDsl(code: String, sourceName: String) =
runCatching {
kotlinScriptPool.eval { eval(code) as ReadingBatContent }.apply { validate() }
}.onFailure { e ->
}.onFailure { _ ->
logger.info { "Error in ${sourceName.removePrefix(GH_PREFIX)}:\n$code" }
}.getOrThrow()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ enum class LanguageType(val useDoubleQuotes: Boolean, val suffix: String, val sr
}
}

fun String.toLanguageType() = values().firstOrNull { it.name.equals(this, ignoreCase = true) }
fun String.toLanguageType() = entries.firstOrNull { it.name.equals(this, ignoreCase = true) }

internal fun Parameters.getLanguageType(parameterName: String) =
this[parameterName]?.let { it.toLanguageType() ?: Java } ?: Java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ enum class ReturnType(val typeStr: String) {
StringListType("List<String>");

companion object {
val String.asReturnType get() = values().firstOrNull { this == it.typeStr }
val String.asReturnType get() = entries.firstOrNull { this == it.typeStr }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import com.github.readingbat.dsl.ChallengeGroup
import com.github.readingbat.dsl.ReadingBatContent
import com.github.readingbat.dsl.challenge.Challenge
import com.github.readingbat.dsl.isDbmsEnabled
import com.github.readingbat.pages.ChallengePage.headerColor
import com.github.readingbat.pages.ChallengePage.HEADER_COLOR
import com.github.readingbat.pages.PageUtils.backLink
import com.github.readingbat.pages.PageUtils.bodyHeader
import com.github.readingbat.pages.PageUtils.encodeUriElems
Expand Down Expand Up @@ -159,7 +159,7 @@ internal object ChallengeGroupPage : KLogging() {
enrollees: List<User>
) {
h3 {
style = "margin-left: 5px; color: $headerColor"
style = "margin-left: 5px; color: $HEADER_COLOR"
a(classes = UNDERLINE) {
href =
if (groupName.isNotValid())
Expand Down
Loading

0 comments on commit 1d50d8e

Please sign in to comment.