From dc0fefcb5352a9ff3c4942b1c4241a38fcd1f851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Siatkowski?= Date: Wed, 10 Aug 2022 16:15:53 +0200 Subject: [PATCH] use scala 2.13 and java 11 (#38) --- .drone.yml | 4 ++-- api/build.gradle | 3 +-- .../api/http/ExtendedHttpRequestSpec.scala | 8 +++++--- build.gradle | 5 +++-- common/build.gradle | 5 ++--- .../com/lbs/common/ModelConverters.scala | 12 +++++------ docker/Dockerfile | 2 +- docker/Dockerfile.arm64 | 2 +- gradle.properties | 4 ++-- server/build.gradle | 6 +++--- .../main/scala/com/lbs/server/lang/Lang.scala | 4 ++-- .../server/repository/DataRepository.scala | 20 +++++++++---------- .../lbs/server/conversation/AkkaTestKit.scala | 5 +++-- .../lbs/server/conversation/AuthSpec.scala | 8 ++++---- .../base/ConversationTestProbe.scala | 2 +- 15 files changed, 45 insertions(+), 45 deletions(-) diff --git a/.drone.yml b/.drone.yml index 451710a..f064dcb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -8,7 +8,7 @@ platform: steps: - name: build - image: java:openjdk-8 + image: amd64/openjdk:11-jdk-slim environment: GRADLE_USER_HOME: ~/.gradle commands: @@ -59,7 +59,7 @@ platform: steps: - name: build - image: arm64v8/openjdk:8-slim + image: arm64v8/openjdk:11-jdk-slim environment: GRADLE_USER_HOME: ~/.gradle commands: diff --git a/api/build.gradle b/api/build.gradle index 3329f79..fdff827 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -2,6 +2,5 @@ dependencies { implementation project(':common') api "org.scalaj:scalaj-http_$scala:2.4.2" - api "org.json4s:json4s-jackson_$scala:3.6.0-M3" - api "com.softwaremill.quicklens:quicklens_$scala:1.4.12" + api "org.json4s:json4s-jackson_$scala:3.6.12" } diff --git a/api/src/test/scala/com/lbs/api/http/ExtendedHttpRequestSpec.scala b/api/src/test/scala/com/lbs/api/http/ExtendedHttpRequestSpec.scala index 8b8ab04..43d2655 100644 --- a/api/src/test/scala/com/lbs/api/http/ExtendedHttpRequestSpec.scala +++ b/api/src/test/scala/com/lbs/api/http/ExtendedHttpRequestSpec.scala @@ -3,11 +3,13 @@ package com.lbs.api.http import cats.instances.either._ import com.lbs.api.exception.GenericException import org.mockito.Mockito._ -import org.scalatest.mockito.MockitoSugar -import org.scalatest.{BeforeAndAfterEach, FunSuiteLike, Matchers} +import org.scalatest.BeforeAndAfterEach +import org.scalatest.funsuite.AnyFunSuite +import org.scalatest.matchers.should.Matchers +import org.scalatestplus.mockito.MockitoSugar import scalaj.http.{HttpRequest, HttpResponse} -class ExtendedHttpRequestSpec extends FunSuiteLike with Matchers with MockitoSugar with BeforeAndAfterEach { +class ExtendedHttpRequestSpec extends AnyFunSuite with Matchers with MockitoSugar with BeforeAndAfterEach { private val request = mock[HttpRequest] private type ThrowableOr[T] = Either[Throwable, T] diff --git a/build.gradle b/build.gradle index a1d1dc9..2ba043a 100644 --- a/build.gradle +++ b/build.gradle @@ -16,9 +16,10 @@ allprojects { dependencies { compileOnly "org.scala-lang:scala-library:$scala.$scala_minor" - testImplementation "org.scalatest:scalatest_$scala:3.0.4" + testImplementation "org.scalatest:scalatest_$scala:3.2.11" + testRuntimeOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' // version depends on scalatest dependency - testImplementation "org.mockito:mockito-core:2.13.0" + testImplementation "org.scalatestplus:mockito-4-2_$scala:3.2.11.0" testImplementation "org.pegdown:pegdown:1.6.0" } } diff --git a/common/build.gradle b/common/build.gradle index c8b27d5..66d8a81 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,5 +1,4 @@ dependencies { - api "org.slf4j:slf4j-api:1.7.25" - api "ch.qos.logback:logback-classic:1.2.3" - api "org.typelevel:cats-core_$scala:2.0.0-M1" + api "ch.qos.logback:logback-classic:1.2.11" + api "org.typelevel:cats-core_$scala:2.8.0" } diff --git a/common/src/main/scala/com/lbs/common/ModelConverters.scala b/common/src/main/scala/com/lbs/common/ModelConverters.scala index d4d8de1..a9ad3c7 100644 --- a/common/src/main/scala/com/lbs/common/ModelConverters.scala +++ b/common/src/main/scala/com/lbs/common/ModelConverters.scala @@ -1,9 +1,8 @@ package com.lbs.common -import scala.collection.TraversableLike -import scala.collection.generic.CanBuildFrom -import scala.language.{higherKinds, implicitConversions} +import scala.collection.{BuildFrom, IterableOps} +import scala.language.implicitConversions trait ModelConverters { @@ -15,9 +14,8 @@ trait ModelConverters { def mapTo[To](implicit converter: ObjectConverter[From, To]): To = converter.convert(anyRef) } - implicit def sequenceConverters[From, To, Col[+X] <: TraversableLike[X, Col[X]]] - (implicit objectConverter: ObjectConverter[From, To], bf: CanBuildFrom[Col[From], To, Col[To]]): ObjectConverter[Col[From], Col[To]] = { - col: Col[From] => col.map(objectConverter.convert) - } + implicit def sequenceConverters[From, To, Col[+X] <: IterableOps[X, Col, Col[X]]] + (implicit objectConverter: ObjectConverter[From, To]): ObjectConverter[Col[From], Col[To]] = + (col: Col[From]) => col.map(objectConverter.convert) } diff --git a/docker/Dockerfile b/docker/Dockerfile index 2256750..038c677 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM azul/zulu-openjdk-alpine:8u282-jre +FROM amd64/openjdk:11-jre-slim RUN apk update && apk upgrade && apk add netcat-openbsd tzdata && apk add --no-cache nss RUN mkdir -p /app diff --git a/docker/Dockerfile.arm64 b/docker/Dockerfile.arm64 index a347d8a..8254beb 100644 --- a/docker/Dockerfile.arm64 +++ b/docker/Dockerfile.arm64 @@ -1,4 +1,4 @@ -FROM arm64v8/openjdk:8-alpine +FROM arm64v8/openjdk:11-jre-slim RUN apk update && apk upgrade && apk add netcat-openbsd tzdata && apk add --no-cache nss RUN mkdir -p /app diff --git a/gradle.properties b/gradle.properties index 68e7962..8ad262c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,5 +3,5 @@ org.gradle.parallel=true org.gradle.configureondemand=true org.gradle.jvmargs=-Dfile.encoding=UTF-8 -scala=2.12 -scala_minor=16 \ No newline at end of file +scala=2.13 +scala_minor=8 \ No newline at end of file diff --git a/server/build.gradle b/server/build.gradle index 3ba7fd5..c58d1d6 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -6,14 +6,14 @@ dependencies { implementation project(":bot") implementation project(":common") - implementation "com.lihaoyi:sourcecode_$scala:0.1.4" + implementation "com.lihaoyi:sourcecode_$scala:0.3.0" implementation "org.springframework.boot:spring-boot-starter" implementation "org.springframework.boot:spring-boot-starter-data-jpa" implementation "org.liquibase:liquibase-core" - implementation "org.jasypt:jasypt:1.9.2" - implementation "org.postgresql:postgresql:42.2.26" + implementation 'org.jasypt:jasypt:1.9.3' + implementation 'org.postgresql:postgresql:42.3.6' testImplementation "com.typesafe.akka:akka-testkit_$scala:2.6.19" testImplementation "org.springframework.boot:spring-boot-starter-test" diff --git a/server/src/main/scala/com/lbs/server/lang/Lang.scala b/server/src/main/scala/com/lbs/server/lang/Lang.scala index 078d1ea..135602e 100644 --- a/server/src/main/scala/com/lbs/server/lang/Lang.scala +++ b/server/src/main/scala/com/lbs/server/lang/Lang.scala @@ -21,7 +21,7 @@ object Lang { LangsMap.getOrElse(id, sys.error(s"Unknown language id $id")) } - val version: String = Try(Source.fromFile("version").getLines.mkString).getOrElse("Unknown") + val version: String = Try(Source.fromFile("version").getLines().mkString).getOrElse("Unknown") } trait Lang { @@ -35,7 +35,7 @@ trait Lang { protected def capitalizeFirstLetter(str: String): String = { if (str != null && str != "") { val fistCapitalLetter = str.head.toTitleCase - fistCapitalLetter + str.tail.toLowerCase + s"$fistCapitalLetter${str.tail.toLowerCase}" } else "" } diff --git a/server/src/main/scala/com/lbs/server/repository/DataRepository.scala b/server/src/main/scala/com/lbs/server/repository/DataRepository.scala index df43b90..983a6b0 100644 --- a/server/src/main/scala/com/lbs/server/repository/DataRepository.scala +++ b/server/src/main/scala/com/lbs/server/repository/DataRepository.scala @@ -7,7 +7,7 @@ import org.springframework.stereotype.Repository import java.time.ZonedDateTime import javax.persistence.EntityManager -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ @Repository class DataRepository(@Autowired em: EntityManager) { @@ -21,7 +21,7 @@ class DataRepository(@Autowired em: EntityManager) { | order by city.time desc""".stripMargin, classOf[CityHistory]) .setParameter("accountId", accountId) .setMaxResults(maxHistory) - .getResultList.asScala + .getResultList.asScala.toSeq } def getClinicHistory(accountId: Long, cityId: Long): Seq[ClinicHistory] = { @@ -32,7 +32,7 @@ class DataRepository(@Autowired em: EntityManager) { .setParameter("accountId", accountId) .setParameter("cityId", cityId) .setMaxResults(maxHistory) - .getResultList.asScala + .getResultList.asScala.toSeq } def getServiceHistory(accountId: Long, cityId: Long, clinicId: Option[Long]): Seq[ServiceHistory] = { @@ -45,7 +45,7 @@ class DataRepository(@Autowired em: EntityManager) { .setParameter("cityId", cityId) .setMaxResults(maxHistory) - clinicId.map(id => query.setParameter("clinicId", id)).getOrElse(query).getResultList.asScala + clinicId.map(id => query.setParameter("clinicId", id)).getOrElse(query).getResultList.asScala.toSeq } def getDoctorHistory(accountId: Long, cityId: Long, clinicId: Option[Long], serviceId: Long): Seq[DoctorHistory] = { @@ -60,7 +60,7 @@ class DataRepository(@Autowired em: EntityManager) { .setParameter("serviceId", serviceId) .setMaxResults(maxHistory) - clinicId.map(id => query.setParameter("clinicId", id)).getOrElse(query).getResultList.asScala + clinicId.map(id => query.setParameter("clinicId", id)).getOrElse(query).getResultList.asScala.toSeq } def findCredentials(accountId: Long): Option[Credentials] = { @@ -73,7 +73,7 @@ class DataRepository(@Autowired em: EntityManager) { def getActiveMonitorings: Seq[Monitoring] = { em.createQuery( """select monitoring from Monitoring monitoring where monitoring.active = true""".stripMargin, classOf[Monitoring]) - .getResultList.asScala + .getResultList.asScala.toSeq } def getActiveMonitoringsCount(accountId: Long): JLong = { @@ -89,7 +89,7 @@ class DataRepository(@Autowired em: EntityManager) { """select monitoring from Monitoring monitoring where monitoring.active = true | and monitoring.accountId = :accountId order by monitoring.dateTo asc""".stripMargin, classOf[Monitoring]) .setParameter("accountId", accountId) - .getResultList.asScala + .getResultList.asScala.toSeq } def getAllMonitoringsCount(accountId: Long): JLong = { @@ -107,7 +107,7 @@ class DataRepository(@Autowired em: EntityManager) { .setParameter("accountId", accountId) .setFirstResult(start) .setMaxResults(count) - .getResultList.asScala + .getResultList.asScala.toSeq } @@ -131,7 +131,7 @@ class DataRepository(@Autowired em: EntityManager) { """select monitoring from Monitoring monitoring where monitoring.active = true | and monitoring.created > :since""".stripMargin, classOf[Monitoring]) .setParameter("since", since) - .getResultList.asScala + .getResultList.asScala.toSeq } def findMonitoring(accountId: Long, monitoringId: Long): Option[Monitoring] = { @@ -206,7 +206,7 @@ class DataRepository(@Autowired em: EntityManager) { em.createQuery( "select credentials from Credentials credentials where credentials.userId = :userId", classOf[Credentials]) .setParameter("userId", userId) - .getResultList.asScala + .getResultList.asScala.toSeq } def findUserCredentialsByUserIdAndAccountId(userId: Long, accountId: Long): Option[Credentials] = { diff --git a/server/src/test/scala/com/lbs/server/conversation/AkkaTestKit.scala b/server/src/test/scala/com/lbs/server/conversation/AkkaTestKit.scala index f97be58..5fd7523 100644 --- a/server/src/test/scala/com/lbs/server/conversation/AkkaTestKit.scala +++ b/server/src/test/scala/com/lbs/server/conversation/AkkaTestKit.scala @@ -2,9 +2,10 @@ package com.lbs.server.conversation import akka.actor.ActorSystem import akka.testkit.{ImplicitSender, TestKit} -import org.scalatest.{BeforeAndAfterAll, WordSpecLike} +import org.scalatest.BeforeAndAfterAll +import org.scalatest.wordspec.AnyWordSpecLike -abstract class AkkaTestKit extends TestKit(ActorSystem()) with ImplicitSender with WordSpecLike with BeforeAndAfterAll { +abstract class AkkaTestKit extends TestKit(ActorSystem()) with ImplicitSender with AnyWordSpecLike with BeforeAndAfterAll { override def afterAll(): Unit = { TestKit.shutdownActorSystem(system) } diff --git a/server/src/test/scala/com/lbs/server/conversation/AuthSpec.scala b/server/src/test/scala/com/lbs/server/conversation/AuthSpec.scala index 6cfa25b..117f38e 100644 --- a/server/src/test/scala/com/lbs/server/conversation/AuthSpec.scala +++ b/server/src/test/scala/com/lbs/server/conversation/AuthSpec.scala @@ -63,8 +63,8 @@ class AuthSpec extends AkkaTestKit { val cmd = Command(source, Message("1", Some("any"))) auth ! cmd chatActor.expectMsg(cmd) - unauthorizedHelpActor.expectNoMsg() - loginActor.expectNoMsg() + unauthorizedHelpActor.expectNoMessage() + loginActor.expectNoMessage() } } @@ -85,8 +85,8 @@ class AuthSpec extends AkkaTestKit { val cmd = Command(source, Message("1", Some("any"))) auth ! cmd chatActor.expectMsg(cmd) - unauthorizedHelpActor.expectNoMsg() - loginActor.expectNoMsg() + unauthorizedHelpActor.expectNoMessage() + loginActor.expectNoMessage() } "initialize dialogue with login actor on /login command" in { diff --git a/server/src/test/scala/com/lbs/server/conversation/base/ConversationTestProbe.scala b/server/src/test/scala/com/lbs/server/conversation/base/ConversationTestProbe.scala index cb99276..35cc5cb 100644 --- a/server/src/test/scala/com/lbs/server/conversation/base/ConversationTestProbe.scala +++ b/server/src/test/scala/com/lbs/server/conversation/base/ConversationTestProbe.scala @@ -4,7 +4,7 @@ import akka.actor.ActorSystem import akka.testkit.TestProbe import org.mockito.ArgumentMatchers._ import org.mockito.Mockito._ -import org.scalatest.mockito.MockitoSugar +import org.scalatestplus.mockito.MockitoSugar import scala.reflect.ClassTag