Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala 2.13 upgrade #195

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/conf/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import play.api.{Configuration => PlayConfiguration}
import story_packages.services.Logging

import scala.language.reflectiveCalls
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

class BadConfigurationException(msg: String) extends RuntimeException(msg)

Expand Down
2 changes: 1 addition & 1 deletion app/story_packages/metrics/CloudWatch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.amazonaws.services.cloudwatch.model._
import conf.ApplicationConfiguration
import story_packages.services.Logging

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

class CloudWatch(config: ApplicationConfiguration) extends Logging {

Expand Down
2 changes: 1 addition & 1 deletion app/story_packages/metrics/FrontendMetrics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ case class FrontendStatisticSet(metric: FrontendMetric, datapoints: List[DataPoi
lazy val sampleCount: Double = datapoints.size
lazy val maximum: Double = Try(datapoints.maxBy(_.value).value).getOrElse(0L).toDouble
lazy val minimum: Double = Try(datapoints.minBy(_.value).value).getOrElse(0L).toDouble
lazy val sum: Double = datapoints.map(_.value).sum
lazy val sum: Double = datapoints.map(_.value).sum.toDouble
lazy val average: Double =
Try(sum / sampleCount).toOption.getOrElse(0L)

Expand Down
7 changes: 4 additions & 3 deletions app/story_packages/metrics/metrics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import story_packages.services.Logging
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.jdk.CollectionConverters._
import scala.collection.mutable.Buffer

object SystemMetrics {

Expand All @@ -22,17 +23,17 @@ object SystemMetrics {

def gcCount: Double = {
val totalGcCount = bean.getCollectionCount
totalGcCount - lastGcCount.getAndSet(totalGcCount)
(totalGcCount - lastGcCount.getAndSet(totalGcCount)).toDouble
}

def gcTime: Double = {
val totalGcTime = bean.getCollectionTime
totalGcTime - lastGcTime.getAndSet(totalGcTime)
(totalGcTime - lastGcTime.getAndSet(totalGcTime)).toDouble
}
}


lazy val garbageCollectors: Seq[GcRateMetric] = ManagementFactory.getGarbageCollectorMXBeans.asScala.map(new GcRateMetric(_))
lazy val garbageCollectors: Seq[GcRateMetric] = ManagementFactory.getGarbageCollectorMXBeans.asScala.map(new GcRateMetric(_)).toSeq


// divide by 1048576 to convert bytes to MB
Expand Down
2 changes: 1 addition & 1 deletion app/story_packages/services/Database.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import conf.ApplicationConfiguration
import story_packages.updates.ReindexPage
import story_packages.util.Identity._

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import scala.concurrent.Future
import scala.util.{Failure, Success, Try}

Expand Down
2 changes: 1 addition & 1 deletion app/story_packages/services/DynamoReindexJobs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import story_packages.metrics.ReindexMetrics
import conf.ApplicationConfiguration
import story_packages.updates._

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

class DynamoReindexJobs(config: ApplicationConfiguration) extends Logging {
private lazy val client =
Expand Down
2 changes: 1 addition & 1 deletion app/story_packages/updates/AuditingUpdates.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import play.api.libs.json.Json
import conf.ApplicationConfiguration
import story_packages.services.Logging

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

class AuditingUpdates(config: ApplicationConfiguration) extends Logging {

Expand Down
4 changes: 2 additions & 2 deletions app/story_packages/util/ContentUpgrade.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ object ContentUpgrade {
def upgradeItem(json: JValue): JValue = {
Try({
val jsonString = JsonMethods.compact(JsonMethods.render(json))
val maybeParsedJson: Option[Json] = parser.parse(jsonString).right.toOption
val maybeCapiContent: Option[Content] = maybeParsedJson.flatMap(json => json.as[Content].right.toOption)
val maybeParsedJson: Option[Json] = parser.parse(jsonString).toOption
val maybeCapiContent: Option[Content] = maybeParsedJson.flatMap(json => json.as[Content].toOption)

(json, maybeCapiContent) match {
case (jsObject: JObject, Some(content)) =>
Expand Down
14 changes: 0 additions & 14 deletions app/story_packages/util/Enumerators.scala

This file was deleted.

2 changes: 1 addition & 1 deletion app/story_packages/util/SanitizeInput.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object SanitizeInput {
def fromString(s: String) = sanitizeRegex.replaceAllIn(s, "")

def fromConfigSeo(config: ConfigJson): ConfigJson = {
config.copy(fronts = config.fronts.mapValues(sanitizeSeoInputFromFront))
config.copy(fronts = config.fronts.view.mapValues(sanitizeSeoInputFromFront).toMap)
}

private def sanitizeSeoInputFromFront(front: FrontJson): FrontJson = front.copy(
Expand Down
7 changes: 3 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ packageSummary := "Story packages"

packageDescription := "Guardian story packages editor"

scalaVersion := "2.12.16"
scalaVersion := "2.13.14"

import sbt.Resolver

Expand All @@ -28,7 +28,7 @@ Universal / javaOptions ++= Seq(
s"-J-Xloggc:/var/log/${packageName.value}/gc.log"
)

scalacOptions := Seq("-unchecked", "-deprecation", "-target:jvm-1.8",
scalacOptions := Seq("-unchecked", "-deprecation", "-release:8",
"-Xcheckinit", "-encoding", "utf8", "-feature", "-Xfatal-warnings")

Compile / doc / sources := Seq.empty
Expand Down Expand Up @@ -75,12 +75,11 @@ libraryDependencies ++= jacksonOverrides ++ Seq(
"com.gu" %% "fapi-client-play28" % "4.0.4",
"com.gu" %% "pan-domain-auth-play_2-8" % "4.0.0",
"com.gu" %% "story-packages-model" % "2.2.0",
"com.gu" %% "thrift-serializer" % "4.0.0",
"com.gu" %% "thrift-serializer" % "4.0.2",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the first version of thrift-serializer to support Scala 2.13, so this is the most minimal change I could make to get the project to compile. There have been many newer versions since then, the current is 5.0.7:

https://index.scala-lang.org/guardian/thrift-serializer/artifacts/thrift-serializer

"org.json4s" %% "json4s-native" % json4sVersion,
"org.json4s" %% "json4s-jackson" % json4sVersion,
"net.logstash.logback" % "logstash-logback-encoder" % "7.2",
"com.typesafe.play" %% "play-json" % "2.9.4",
"com.typesafe.play" %% "play-iteratees" % "2.6.1",
"org.julienrf" %% "play-json-derived-codecs" % "10.1.0",
"org.scalatest" %% "scalatest" % "3.2.15" % "test"
)
Expand Down
2 changes: 1 addition & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ GET /editorial controllers.ViewsController
GET /training controllers.ViewsController.collectionEditor()

GET /collection/*collectionId controllers.FaciaToolController.getCollection(collectionId)
POST /edits controllers.FaciaToolController.collectionEdits
POST /edits controllers.FaciaToolController.collectionEdits()
GET /defaults controllers.DefaultsController.configuration()

GET /story-package/*id controllers.StoryPackagesController.getPackage(id)
Expand Down
1 change: 0 additions & 1 deletion test/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import org.scalatest.Suites

class FaciaToolTestSuite extends Suites (
new story_packages.metrics.DurationMetricTest,
new story_packages.util.EnumeratorsTest,
new story_packages.util.RichFutureTest,
new story_packages.util.SanitizeInputTest) {}
26 changes: 0 additions & 26 deletions test/story_packages/util/EnumeratorsTest.scala

This file was deleted.

Loading