Skip to content

Commit

Permalink
Merge pull request #26806 from guardian/scala-2.13-latest
Browse files Browse the repository at this point in the history
Upgrade to Scala `2.13.12`
  • Loading branch information
ioannakok authored Jan 11, 2024
2 parents d894abb + 60a3d88 commit 700a35c
Show file tree
Hide file tree
Showing 105 changed files with 402 additions and 384 deletions.
2 changes: 1 addition & 1 deletion admin/app/model/deploys/ApiResults.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import play.api.mvc._
object ApiResults extends Results {

case class ApiError(message: String, statusCode: Int)
object ApiError { implicit val format = Json.format[ApiError] }
object ApiError { implicit val format: OFormat[ApiError] = Json.format[ApiError] }

case class ApiErrors(errors: List[ApiError]) {
def statusCode: Int = errors.map(_.statusCode).max
Expand Down
6 changes: 3 additions & 3 deletions admin/app/model/deploys/RiffRaff.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package model.deploys

import conf.Configuration
import model.deploys.ApiResults.{ApiError, ApiErrors, ApiResponse}
import play.api.libs.json.{JsError, JsSuccess, Json}
import play.api.libs.json.{JsError, JsSuccess, Json, OFormat}

import scala.concurrent.{ExecutionContext, Future}

case class RiffRaffDeployTags(vcsRevision: Option[String])
object RiffRaffDeployTags { implicit val format = Json.format[RiffRaffDeployTags] }
object RiffRaffDeployTags { implicit val format: OFormat[RiffRaffDeployTags] = Json.format[RiffRaffDeployTags] }

case class RiffRaffDeploy(
uuid: String,
Expand All @@ -19,7 +19,7 @@ case class RiffRaffDeploy(
time: String,
tags: RiffRaffDeployTags,
)
object RiffRaffDeploy { implicit val format = Json.format[RiffRaffDeploy] }
object RiffRaffDeploy { implicit val format: OFormat[RiffRaffDeploy] = Json.format[RiffRaffDeploy] }

class RiffRaffService(httpClient: HttpLike) {

Expand Down
5 changes: 3 additions & 2 deletions admin/app/services/Fastly.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package services
import common.GuLogging
import conf.AdminConfiguration.fastly
import com.amazonaws.services.cloudwatch.model.{Dimension, MetricDatum}

import java.util.Date
import play.api.libs.ws.WSClient
import play.api.libs.json.{JsValue, Json}
import play.api.libs.json.{JsValue, Json, OFormat}

import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration._
Expand Down Expand Up @@ -33,7 +34,7 @@ class FastlyStatisticService(wsClient: WSClient) extends GuLogging {
start_time: Long,
)

private implicit val FastlyApiStatFormat = Json.format[FastlyApiStat]
private implicit val FastlyApiStatFormat: OFormat[FastlyApiStat] = Json.format[FastlyApiStat]

private val regions = List("usa", "europe", "ausnz")

Expand Down
8 changes: 4 additions & 4 deletions admin/app/tools/charts/charts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ object FormattedChart {

case class Cell(v: String)

implicit val cellReads = Json.writes[Cell]
implicit val rowReads = Json.writes[Row]
implicit val columnReads = Json.writes[Column]
implicit val tableReads = Json.writes[DataTable]
implicit val cellReads: OWrites[Cell] = Json.writes[Cell]
implicit val rowReads: OWrites[Row] = Json.writes[Row]
implicit val columnReads: OWrites[Column] = Json.writes[Column]
implicit val tableReads: OWrites[DataTable] = Json.writes[DataTable]
}

// A variation of Chart that can be easily serialised into a Google Visualization DataTable Json object.
Expand Down
2 changes: 1 addition & 1 deletion article/test/AnalyticsFeatureTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.scalatest.matchers.should.Matchers
with GivenWhenThen
with Matchers
with ConfiguredTestSuite {
implicit val config = Configuration
implicit val config: Configuration.type = Configuration

Feature("Analytics") {

Expand Down
7 changes: 3 additions & 4 deletions commercial/app/CommercialLifecycle.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package commercial

import java.util.concurrent.Executors

import commercial.model.merchandise.jobs.Industries
import app.LifecycleComponent
import commercial.model.feeds._
import common.LoggingField._
import common.{PekkoAsync, JobScheduler, GuLogging}
import common.{GuLogging, JobScheduler, PekkoAsync}
import metrics.MetricUploader
import play.api.inject.ApplicationLifecycle

import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.{ExecutionContext, ExecutionContextExecutorService, Future}
import scala.util.control.NonFatal

object CommercialMetrics {
Expand All @@ -28,7 +27,7 @@ class CommercialLifecycle(
with GuLogging {

// This class does work that should be kept separate from the EC used to serve requests
implicit private val ec = ExecutionContext.fromExecutorService(
implicit private val ec: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(
Executors.newFixedThreadPool(10),
)

Expand Down
2 changes: 1 addition & 1 deletion commercial/app/controllers/JobsController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class JobsController(jobsAgent: JobsAgent, val controllerComponents: ControllerC
extends BaseController
with implicits.Requests {

implicit val codec = Codec.utf_8
implicit val codec: Codec = Codec.utf_8

private def jobSample(specificIds: Seq[String], segment: Segment): Seq[Job] =
(jobsAgent.specificJobs(specificIds) ++ jobsAgent.jobsTargetedAt(segment)).distinct.take(2)
Expand Down
2 changes: 1 addition & 1 deletion common/app/common/GuLogging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.util.{Failure, Success, Try}

trait GuLogging {

lazy implicit val log = Logger(getClass)
lazy implicit val log: Logger = Logger(getClass)

protected def logException(e: Exception): Unit = {
log.error(ExceptionUtils.getStackTrace(e))
Expand Down
2 changes: 1 addition & 1 deletion common/app/common/RequestLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ case class RequestLoggerFields(request: RequestHeader, response: Option[Result],

val allowListedHeaders = (for {
headerName <- allowListedHeaderNames
value <- allHeadersFields.get(headerName)
value <- allHeadersFields.map { case (key, value) => (key.toLowerCase, value) }.get(headerName.toLowerCase)
} yield headerName -> value).toMap

val guardianSpecificHeaders = allHeadersFields.view.filterKeys(_.toUpperCase.startsWith("X-GU-")).toMap
Expand Down
4 changes: 2 additions & 2 deletions common/app/common/SNSNotification.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package common

import play.api.libs.json.Json
import play.api.libs.json.{Json, OFormat}

object SNSNotification {
implicit val jsonFormats = Json.format[SNSNotification]
implicit val jsonFormats: OFormat[SNSNotification] = Json.format[SNSNotification]
}

case class SNSNotification(
Expand Down
10 changes: 5 additions & 5 deletions common/app/common/commercial/CommercialProperties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import com.gu.contentapi.client.model.v1.{Content, Section, Tag}
import common.Edition
import common.Edition.defaultEdition
import common.dfp.DfpAgent
import play.api.libs.json.Json
import play.api.libs.json.{Format, Json, OFormat}

case class EditionCommercialProperties(branding: Option[Branding], adTargeting: Set[AdTargetParam])

object EditionCommercialProperties {
implicit val thirdNeedlessFormatter = EditionAdTargeting.adTargetParamFormat
implicit val secondNeedlessFormatter = EditionBranding.brandingFormat
implicit val firstNeedlessFormatter = Json.format[EditionCommercialProperties]
implicit val thirdNeedlessFormatter: Format[AdTargetParam] = EditionAdTargeting.adTargetParamFormat
implicit val secondNeedlessFormatter: Format[Branding] = EditionBranding.brandingFormat
implicit val firstNeedlessFormatter: OFormat[EditionCommercialProperties] = Json.format[EditionCommercialProperties]

}
case class CommercialProperties(
Expand Down Expand Up @@ -54,7 +54,7 @@ case class CommercialProperties(

object CommercialProperties {

implicit val commercialPropertiesFormat = Json.format[CommercialProperties]
implicit val commercialPropertiesFormat: OFormat[CommercialProperties] = Json.format[CommercialProperties]

val empty = CommercialProperties(
editionBrandings = Set.empty,
Expand Down
2 changes: 1 addition & 1 deletion common/app/common/commercial/EditionAdTargeting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ object EditionAdTargeting {
}
}

implicit val editionAdTargetingFormat = Json.format[EditionAdTargeting]
implicit val editionAdTargetingFormat: OFormat[EditionAdTargeting] = Json.format[EditionAdTargeting]

private val adTargeter = new AdTargeter(
platform = "ng",
Expand Down
4 changes: 2 additions & 2 deletions common/app/common/commercial/EditionBranding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ case class EditionBranding(edition: Edition, branding: Option[Branding])

object EditionBranding {

implicit val brandingFormat = {
implicit val brandingFormat: Format[Branding] = {

implicit val dimensionsFormat = Json.format[Dimensions]

Expand Down Expand Up @@ -42,7 +42,7 @@ object EditionBranding {
Format(brandingReads, Json.writes[Branding])
}

implicit val editionBrandingFormat = Json.format[EditionBranding]
implicit val editionBrandingFormat: OFormat[EditionBranding] = Json.format[EditionBranding]

val editions = Edition.allEditions.toSet

Expand Down
4 changes: 2 additions & 2 deletions common/app/common/commercial/PrebidIndexSite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ case class PrebidIndexSite(bp: Breakpoint, id: Int)

object PrebidIndexSite {

implicit val breakpointFormat = new Format[Breakpoint] {
implicit val breakpointFormat: Format[Breakpoint] = new Format[Breakpoint] {
def reads(json: JsValue): JsResult[Breakpoint] =
json match {
case JsString("D") => JsSuccess(Desktop)
Expand All @@ -28,7 +28,7 @@ object PrebidIndexSite {
case _ => JsString("D")
}
}
implicit val format = Json.format[PrebidIndexSite]
implicit val format: OFormat[PrebidIndexSite] = Json.format[PrebidIndexSite]

private val defaultSiteIds = Set(
PrebidIndexSite(Desktop, 208283),
Expand Down
2 changes: 1 addition & 1 deletion common/app/common/commercial/hosted/HostedVideoPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ case class HostedVideoPage(
}

object HostedVideoPage extends GuLogging {
private implicit val ordering = EncodingOrdering
private implicit val ordering: EncodingOrdering.type = EncodingOrdering

def fromContent(content: Content): Option[HostedVideoPage] = {
log.info(s"Building hosted video ${content.id} ...")
Expand Down
12 changes: 5 additions & 7 deletions common/app/common/dfp/AdSize.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ case class AdSize(width: Int, height: Int)

object AdSize {

implicit val writes = new Writes[AdSize] {
def writes(size: AdSize): JsValue = {
Json.obj(
"width" -> size.width,
"height" -> size.height,
)
}
implicit val writes: Writes[AdSize] = (size: AdSize) => {
Json.obj(
"width" -> size.width,
"height" -> size.height,
)
}

implicit val reads: Reads[AdSize] = (
Expand Down
59 changes: 27 additions & 32 deletions common/app/common/dfp/DfpData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.joda.time.DateTime
import org.joda.time.DateTime.now
import org.joda.time.format.ISODateTimeFormat
import play.api.libs.functional.syntax._
import play.api.libs.json
import play.api.libs.json._
import play.api.libs.json.JodaReads._

Expand All @@ -30,13 +31,9 @@ object GuLineItemType {
case otherLineItemType => Other(otherLineItemType)
}

implicit val guLineItemWrites = new Writes[GuLineItemType] {
def writes(lineItemType: GuLineItemType): JsValue = {
lineItemType match {
case Sponsorship => JsString("sponsorship")
case Other(lineItemTypeAsString) => JsString(lineItemTypeAsString)
}
}
implicit val guLineItemWrites: Writes[GuLineItemType] = {
case Sponsorship => JsString("sponsorship")
case Other(lineItemTypeAsString) => JsString(lineItemTypeAsString)
}

implicit val guLineItemTypeReads: Reads[GuLineItemType] =
Expand All @@ -62,11 +59,11 @@ case class GuCustomTargetingValue(
)

object GuCustomTargetingValue {
implicit val format = Json.format[GuCustomTargetingValue]
implicit val format: OFormat[GuCustomTargetingValue] = Json.format[GuCustomTargetingValue]
}

object GuCustomTargeting {
implicit val format = Json.format[GuCustomTargeting]
implicit val format: OFormat[GuCustomTargeting] = Json.format[GuCustomTargeting]
}

case class CustomTarget(name: String, op: String, values: Seq[String]) {
Expand Down Expand Up @@ -168,7 +165,7 @@ case class GuAdUnit(id: String, path: Seq[String], status: String) {

object GuAdUnit {

implicit val adUnitFormats = Json.format[GuAdUnit]
implicit val adUnitFormats: OFormat[GuAdUnit] = Json.format[GuAdUnit]

val ACTIVE = "ACTIVE"
val INACTIVE = "INACTIVE"
Expand Down Expand Up @@ -296,24 +293,22 @@ object GuLineItem {

private val timeFormatter = ISODateTimeFormat.dateTime().withZoneUTC()

implicit val lineItemWrites = new Writes[GuLineItem] {
def writes(lineItem: GuLineItem): JsValue = {
Json.obj(
"id" -> lineItem.id,
"orderId" -> lineItem.orderId,
"name" -> lineItem.name,
"lineItemType" -> lineItem.lineItemType,
"startTime" -> timeFormatter.print(lineItem.startTime),
"endTime" -> lineItem.endTime.map(timeFormatter.print(_)),
"isPageSkin" -> lineItem.isPageSkin,
"sponsor" -> lineItem.sponsor,
"status" -> lineItem.status,
"costType" -> lineItem.costType,
"creativePlaceholders" -> lineItem.creativePlaceholders,
"targeting" -> lineItem.targeting,
"lastModified" -> timeFormatter.print(lineItem.lastModified),
)
}
implicit val lineItemWrites: Writes[GuLineItem] = (lineItem: GuLineItem) => {
Json.obj(
"id" -> lineItem.id,
"orderId" -> lineItem.orderId,
"name" -> lineItem.name,
"lineItemType" -> lineItem.lineItemType,
"startTime" -> timeFormatter.print(lineItem.startTime),
"endTime" -> lineItem.endTime.map(timeFormatter.print(_)),
"isPageSkin" -> lineItem.isPageSkin,
"sponsor" -> lineItem.sponsor,
"status" -> lineItem.status,
"costType" -> lineItem.costType,
"creativePlaceholders" -> lineItem.creativePlaceholders,
"targeting" -> lineItem.targeting,
"lastModified" -> timeFormatter.print(lineItem.lastModified),
)
}

implicit val lineItemReads: Reads[GuLineItem] = (
Expand Down Expand Up @@ -356,16 +351,15 @@ case class GuCreativeTemplateParameter(

object GuCreativeTemplateParameter {

implicit val GuCreativeTemplateParameterWrites = new Writes[GuCreativeTemplateParameter] {
def writes(param: GuCreativeTemplateParameter): JsValue = {
implicit val GuCreativeTemplateParameterWrites: Writes[GuCreativeTemplateParameter] =
(param: GuCreativeTemplateParameter) => {
Json.obj(
"type" -> param.parameterType,
"label" -> param.label,
"isRequired" -> param.isRequired,
"description" -> param.description,
)
}
}

implicit val GuCreativeTemplateParameterReads: Reads[GuCreativeTemplateParameter] = (
(JsPath \ "type").read[String] and
Expand Down Expand Up @@ -397,7 +391,8 @@ object GuCreative {
(mapById(old) ++ mapById(recent)).values.toSeq
}

implicit val dateToTimestampWrites = play.api.libs.json.JodaWrites.JodaDateTimeNumberWrites
implicit val dateToTimestampWrites: json.JodaWrites.JodaDateTimeNumberWrites.type =
play.api.libs.json.JodaWrites.JodaDateTimeNumberWrites
implicit val guCreativeFormats: Format[GuCreative] = Json.format[GuCreative]
}

Expand Down
Loading

0 comments on commit 700a35c

Please sign in to comment.