Skip to content

Commit

Permalink
Scala 2.13 fixes
Browse files Browse the repository at this point in the history
Switched from `JavaConverters` to 2.13's `CollectionConverters`.

Widening conversion from `Long` to `Double` is deprecated, so used `toDouble` instead.

Previously `Buffer` could be assigned to `Seq`, because `Seq` was mutable. Now `Seq` is immutable by default, so `toSeq` is needed to create a `Seq` from a `Buffer`.

`Either` is now right-biased, so `.right` is no longer needed.

`.mapValues` is deprecated, need `.view.mapValues` instead. `.toMap` is also needed to get back to a `Map` from a `MapView`.

Auto-application is deprecated, so `()` must be added in some cases.

Deleted `Enumerators` because it wasn't used, and it was using features unsupported in Scala 2.13.
  • Loading branch information
JamieB-gu committed Jul 23, 2024
1 parent b5d0c67 commit a5bd3f6
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 54 deletions.
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
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.

0 comments on commit a5bd3f6

Please sign in to comment.