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

migration to scala 3 #175

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ jobs:
apps: sbt
- name: Scalafix Lint
run: sbt scalafixLint
- name: Scapegoat Lint
run: sbt scapegoatLint
# - name: Scapegoat Lint
# run: sbt scapegoatLint
unit_test:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: Print DependencyCheck Result
uses: albuch/[email protected]
with:
jsonReportPath: "app1/target/scala-2.13/dependency-check-report.json"
jsonReportPath: "app1/target/scala-3.4.0/dependency-check-report.json"
22 changes: 16 additions & 6 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
// .scalafix.conf
rules = [
DisableSyntax,
OrganizeImports,
RemoveUnused
]
DisableSyntax.noFinalize = true

// `rules` on compilation
triggered.rules = [
DisableSyntax
]
OrganizeImports {
groupedImports = Explode
expandRelative = true
removeUnused = true
groups = [
"re:javax?\\."
"scala."
"scala.meta."
"*"
]
}

RemoveUnused {
imports = false
}
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version=3.8.3
runner.dialect = scala213source3
runner.dialect = scala3
maxColumn = 80
4 changes: 2 additions & 2 deletions app1/app/TraceApplicationLoader.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.softwaremill.macwire.*
import com.softwaremill.macwire._
import kamon.Kamon
import play.api.*
import play.api.ApplicationLoader.Context
import play.api._
import play.api.libs.ws.WSClient
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.routing.Router
Expand Down
6 changes: 3 additions & 3 deletions app1/app/TraceModule.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import scala.concurrent.ExecutionContext

import controllers.AppController
import play.api.Configuration
import play.api.libs.ws.WSClient
import play.api.mvc.ControllerComponents
import services.TraceService

import scala.concurrent.ExecutionContext

trait TraceModule {

import com.softwaremill.macwire.*

lazy val traceService = wire[TraceService]
lazy val traceController = wire[AppController]

implicit val ec: ExecutionContext = scala.concurrent.ExecutionContext.global
given ec: ExecutionContext = scala.concurrent.ExecutionContext.global
def ws: WSClient
def controllerComponents: ControllerComponents
def configuration: Configuration
Expand Down
21 changes: 9 additions & 12 deletions app1/app/controllers/AppController.scala
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
package controllers

import scala.concurrent.ExecutionContext

import play.api.MarkerContext
import play.api.libs.json.Json
import play.api.mvc.{
AbstractController,
Action,
AnyContent,
ControllerComponents
}
import play.api.mvc.AbstractController
import play.api.mvc.Action
import play.api.mvc.AnyContent
import play.api.mvc.ControllerComponents
import play.twirl.api.Html
import services.TraceService
import utils.ContextId
import utils.RequestMarkerContext.requestHeaderToMarkerContext

import scala.concurrent.ExecutionContext

class AppController(
traceService: TraceService,
cc: ControllerComponents
)(implicit ec: ExecutionContext)
)(using ec: ExecutionContext)
extends AbstractController(cc)
with ContextId {

def trace(): Action[AnyContent] =
Action.async { implicit request =>
implicit val mc: MarkerContext =
requestHeaderToMarkerContext(request.headers)
Action.async { request =>
given mc: MarkerContext = requestHeaderToMarkerContext(request.headers)
traceService
.getTrace(getCtxId(request.headers))
.map(response => {
Expand Down
5 changes: 3 additions & 2 deletions app1/app/models/package.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import play.api.libs.json.{Json, OFormat}
import play.api.libs.json.Json
import play.api.libs.json.OFormat

package object models {

case class TraceResponse(id: String)

object TraceResponse {
implicit val TraceResponseFormat: OFormat[TraceResponse] =
given TraceResponseFormat: OFormat[TraceResponse] =
Json.format[TraceResponse]
}

Expand Down
14 changes: 9 additions & 5 deletions app1/app/services/TraceService.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package services

import javax.inject.Inject

import scala.concurrent.ExecutionContext
import scala.concurrent.Future

import models.TraceResponse
import play.api.Configuration
import play.api.Logging
import play.api.MarkerContext
import play.api.libs.ws.WSClient
import play.api.{Configuration, Logging, MarkerContext}
import utils.ContextId

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}

class TraceService @Inject() (ws: WSClient, config: Configuration)
extends Logging {

private lazy val app2URL = config.get[String]("app2.url")

def getTrace(ctxId: String)(implicit
def getTrace(ctxId: String)(using
mc: MarkerContext,
ex: ExecutionContext
): Future[TraceResponse] = {
Expand Down
4 changes: 2 additions & 2 deletions app1/app/utils/ContextId.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package utils

import java.util.UUID

import play.api.Logging
import play.api.mvc.Headers
import utils.ContextId.cId

import java.util.UUID

object ContextId {
lazy val cId = "context-id"
}
Expand Down
2 changes: 1 addition & 1 deletion app1/app/utils/RequestMarkerContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package utils

import kamon.Kamon
import net.logstash.logback.marker.LogstashMarker
import net.logstash.logback.marker.Markers.*
import net.logstash.logback.marker.Markers._
import play.api.MarkerContext
import play.api.mvc.Headers
import utils.ContextId.cId
Expand Down
2 changes: 1 addition & 1 deletion app1/conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,4 @@ kanela.modules {
"org.apache.pekko.stream.scaladsl.FlowOps"
]
}
}
}
3 changes: 1 addition & 2 deletions app1/conf/routes
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

GET / controllers.AppController.index
GET /api/v1/trace controllers.AppController.trace
GET /api/v1/trace controllers.AppController.trace()
7 changes: 4 additions & 3 deletions app1/test/ApplicationSpec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import org.scalatestplus.play.{BaseOneAppPerTest, PlaySpec}
import play.api.test.*
import play.api.test.Helpers.*
import org.scalatestplus.play.BaseOneAppPerTest
import org.scalatestplus.play.PlaySpec
import play.api.test.Helpers._
import play.api.test._

/** */
class ApplicationSpec
Expand Down
2 changes: 1 addition & 1 deletion app1/test/SeleniumSpec.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import org.scalatestplus.play.*
import org.scalatestplus.play._

class SeleniumSpec
extends PlaySpec
Expand Down
7 changes: 4 additions & 3 deletions app1/test/ServerSpec.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatestplus.play.*
import org.scalatest.concurrent.IntegrationPatience
import org.scalatest.concurrent.ScalaFutures
import org.scalatestplus.play._
import play.api.mvc.Results
import play.api.test.Helpers.*
import play.api.test.Helpers._
import play.api.test.WsTestClient

class ServerSpec
Expand Down
4 changes: 3 additions & 1 deletion app1/test/TraceApplicationFactory.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import org.scalatestplus.play.FakeApplicationFactory
import play.api.{Application, ApplicationLoader, Environment}
import play.api.Application
import play.api.ApplicationLoader
import play.api.Environment

trait TraceApplicationFactory extends FakeApplicationFactory {

Expand Down
4 changes: 2 additions & 2 deletions app2/app/TraceApplicationLoader.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.softwaremill.macwire.*
import com.softwaremill.macwire._
import kamon.Kamon
import play.api.*
import play.api.ApplicationLoader.Context
import play.api._
import play.api.routing.Router
import router.Routes

Expand Down
6 changes: 3 additions & 3 deletions app2/app/TraceModule.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import scala.concurrent.ExecutionContext

import controllers.AppController
import play.api.mvc.ControllerComponents

import scala.concurrent.ExecutionContext

trait TraceModule {

import com.softwaremill.macwire.*

lazy val traceController = wire[AppController]

implicit val ec: ExecutionContext = scala.concurrent.ExecutionContext.global
given ec: ExecutionContext = scala.concurrent.ExecutionContext.global
def controllerComponents: ControllerComponents
}
26 changes: 13 additions & 13 deletions app2/app/controllers/AppController.scala
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package controllers

import scala.concurrent.ExecutionContext
import scala.concurrent.Future

import kamon.Kamon
import models.TraceResponse
import play.api.Logging
import play.api.MarkerContext
import play.api.libs.json.Json
import play.api.mvc.{
AbstractController,
Action,
AnyContent,
ControllerComponents
}
import play.api.{Logging, MarkerContext}
import play.api.mvc.AbstractController
import play.api.mvc.Action
import play.api.mvc.AnyContent
import play.api.mvc.ControllerComponents
import play.twirl.api.Html
import utils.RequestMarkerContext.requestHeaderToMarkerContext

import scala.concurrent.{ExecutionContext, Future}

class AppController(
cc: ControllerComponents
)(implicit ec: ExecutionContext)
)(using ec: ExecutionContext)
extends AbstractController(cc)
with Logging {

def trace(): Action[AnyContent] =
Action.async { implicit request =>
implicit val mc: MarkerContext =
Action.async { request =>
given mc: MarkerContext =
requestHeaderToMarkerContext(request.headers)
logger.info("trace request")
logger.info(s"trace request with headers: ${request.headers}")
Future(
Ok(Json.toJson(TraceResponse(Kamon.currentSpan().trace.id.string)))
)
Expand Down
5 changes: 3 additions & 2 deletions app2/app/models/package.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import play.api.libs.json.{Json, OFormat}
import play.api.libs.json.Json
import play.api.libs.json.OFormat

package object models {

case class TraceResponse(id: String)

object TraceResponse {
implicit val TraceResponseFormat: OFormat[TraceResponse] =
given TraceResponseFormat: OFormat[TraceResponse] =
Json.format[TraceResponse]
}

Expand Down
4 changes: 2 additions & 2 deletions app2/app/utils/ContextId.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package utils

import java.util.UUID

import play.api.Logging
import play.api.mvc.Headers
import utils.ContextId.cId

import java.util.UUID

object ContextId {
lazy val cId = "context-id"
}
Expand Down
2 changes: 1 addition & 1 deletion app2/app/utils/RequestMarkerContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package utils

import kamon.Kamon
import net.logstash.logback.marker.LogstashMarker
import net.logstash.logback.marker.Markers.*
import net.logstash.logback.marker.Markers._
import play.api.MarkerContext
import play.api.mvc.Headers
import utils.ContextId.cId
Expand Down
2 changes: 1 addition & 1 deletion app2/conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,4 @@ kanela.modules {
"org.apache.pekko.stream.scaladsl.FlowOps"
]
}
}
}
2 changes: 1 addition & 1 deletion app2/conf/routes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

GET / controllers.AppController.index
GET /api/v1/trace controllers.AppController.trace
GET /api/v1/trace controllers.AppController.trace()

7 changes: 4 additions & 3 deletions app2/test/ApplicationSpec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import org.scalatestplus.play.{BaseOneAppPerTest, PlaySpec}
import play.api.test.*
import play.api.test.Helpers.*
import org.scalatestplus.play.BaseOneAppPerTest
import org.scalatestplus.play.PlaySpec
import play.api.test.Helpers._
import play.api.test._

/** */
class ApplicationSpec
Expand Down
2 changes: 1 addition & 1 deletion app2/test/SeleniumSpec.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import org.scalatestplus.play.*
import org.scalatestplus.play._

class SeleniumSpec
extends PlaySpec
Expand Down
7 changes: 4 additions & 3 deletions app2/test/ServerSpec.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatestplus.play.*
import org.scalatest.concurrent.IntegrationPatience
import org.scalatest.concurrent.ScalaFutures
import org.scalatestplus.play._
import play.api.mvc.Results
import play.api.test.Helpers.*
import play.api.test.Helpers._
import play.api.test.WsTestClient

class ServerSpec
Expand Down
Loading
Loading