Skip to content

Commit 9a8f63d

Browse files
committed
Sanitize with -Xsource:3
1 parent d54c3c9 commit 9a8f63d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+222
-292
lines changed

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ val workaround = {
161161

162162
scalacOptions += "-deprecation"
163163
scalacOptions += "-feature"
164+
//https://docs.scala-lang.org/scala3/guides/migration/tooling-scala2-xsource3.html
165+
scalacOptions += "-Xsource:3"
164166

165167
run / fork := true
166168

src/main/java/util/ConnectionStatusChecker.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ private long testSockets(String hostAddress, int port) {
102102
*/
103103
private boolean testPing(String hostAddress) throws IOException, InterruptedException {
104104
String os = System.getProperty("os.name");
105-
String pingOption = (os.equals("Windows 10")) ? "n" : "c"; // 'c' for non-windows os
105+
String pingOption = (os.equals("Windows 10")) ? "n" : "c";
106106

107-
Process p1 = java.lang.Runtime.getRuntime().exec("ping -" + pingOption + " 1 " + hostAddress);
107+
String[] cmd = {"ping", "-" + pingOption, "1", hostAddress};
108+
Process p1 = java.lang.Runtime.getRuntime().exec(cmd);
108109
int returnVal = p1.waitFor();
109110
return returnVal == 0;
110111
}

src/main/scala/actor/Buncher.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.apache.pekko.actor.typed.scaladsl.Behaviors
44
import org.apache.pekko.actor.typed.{ActorRef, ActorSystem, Behavior}
55

66
import scala.collection.immutable
7-
import scala.concurrent.duration._
7+
import scala.concurrent.duration.*
88

99
/**
1010
* This akka typed actor FSM example demonstrates how to:
@@ -57,7 +57,7 @@ object Buncher extends App {
5757

5858
// states of the FSM represented as behaviors
5959

60-
private def idle(data: Data): Behavior[Event] = Behaviors.receiveMessage[Event] { message: Event =>
60+
private def idle(data: Data): Behavior[Event] = Behaviors.receiveMessage[Event] { message =>
6161
(message, data) match {
6262
case (SetTarget(ref), Uninitialized) =>
6363
// action: add obj to queue

src/main/scala/akkahttp/HTTPResponseStream.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import org.apache.pekko.actor.ActorSystem
55
import org.apache.pekko.http.scaladsl.Http
66
import org.apache.pekko.http.scaladsl.common.{EntityStreamingSupport, JsonEntityStreamingSupport}
77
import org.apache.pekko.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
8-
import org.apache.pekko.http.scaladsl.model._
9-
import org.apache.pekko.http.scaladsl.server.Directives.{complete, get, logRequestResult, path, _}
8+
import org.apache.pekko.http.scaladsl.model.*
9+
import org.apache.pekko.http.scaladsl.server.Directives.{complete, get, logRequestResult, path, *}
1010
import org.apache.pekko.http.scaladsl.server.Route
1111
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
1212
import org.apache.pekko.stream.scaladsl.{Flow, Sink, Source}
1313
import org.slf4j.{Logger, LoggerFactory}
1414
import sample.graphstage.StreamEventInspector
15-
import spray.json.DefaultJsonProtocol
15+
import spray.json.{DefaultJsonProtocol, RootJsonFormat}
1616

1717
import scala.concurrent.Future
18-
import scala.concurrent.duration._
18+
import scala.concurrent.duration.*
1919
import scala.util.{Failure, Success}
2020

2121
/**
@@ -41,7 +41,7 @@ object HTTPResponseStream extends App with DefaultJsonProtocol with SprayJsonSup
4141

4242
final case class Person(name: String)
4343

44-
implicit def personFormat = jsonFormat1(Person)
44+
implicit def personFormat: RootJsonFormat[Person] = jsonFormat1(Person)
4545

4646
implicit val jsonStreamingSupport: JsonEntityStreamingSupport = EntityStreamingSupport.json()
4747

@@ -75,10 +75,10 @@ object HTTPResponseStream extends App with DefaultJsonProtocol with SprayJsonSup
7575
}
7676

7777

78-
val printSink = Sink.foreach[Person] { each: Person => logger.info(s"Client processed element: $each") }
78+
val printSink = Sink.foreach[Person] { each => logger.info(s"Client processed element: $each") }
7979

8080
val processorFlow: Flow[Person, Person, NotUsed] = Flow[Person].map {
81-
each: Person => {
81+
each => {
8282
//logger.info(s"Process: $each")
8383
each
8484
}
@@ -88,19 +88,19 @@ object HTTPResponseStream extends App with DefaultJsonProtocol with SprayJsonSup
8888
def server(address: String, port: Int): Unit = {
8989

9090
def routes: Route = logRequestResult("httpecho") {
91-
path("download" / Segment) { clientId: String =>
91+
path("download" / Segment) { clientId =>
9292
get {
9393
logger.info(s"Server received request with id: $clientId, start streaming response...")
94-
extractRequest { r: HttpRequest =>
95-
val finishedWriting = r.discardEntityBytes().future
94+
extractRequest { httpRequest =>
95+
val finishedWriting = httpRequest.discardEntityBytes().future
9696
onComplete(finishedWriting) { _ =>
9797

9898
val numberOfMessages = 100
9999
val response = Source
100100
.tick(1.second, 100.millis, ())
101101
.zipWith(Source(1 to numberOfMessages))((_, nbr) => Person(s"$clientId-$nbr"))
102102
// Optional, eg for debugging
103-
.via(StreamEventInspector(r.uri.path.toString(), Person => Person.toString))
103+
.via(StreamEventInspector(httpRequest.uri.path.toString(), Person => Person.toString))
104104
complete(response)
105105
}
106106
}

src/main/scala/akkahttp/HttpFileEcho.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import org.apache.pekko.actor.ActorSystem
44
import org.apache.pekko.http.scaladsl.Http
55
import org.apache.pekko.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
66
import org.apache.pekko.http.scaladsl.marshalling.Marshal
7-
import org.apache.pekko.http.scaladsl.model._
8-
import org.apache.pekko.http.scaladsl.server.Directives.{complete, logRequestResult, path, _}
7+
import org.apache.pekko.http.scaladsl.model.*
8+
import org.apache.pekko.http.scaladsl.server.Directives.{complete, logRequestResult, path, *}
99
import org.apache.pekko.http.scaladsl.server.Route
1010
import org.apache.pekko.http.scaladsl.server.directives.FileInfo
1111
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
1212
import org.apache.pekko.stream.RestartSettings
1313
import org.apache.pekko.stream.scaladsl.{Compression, FileIO, RestartSource, Sink, Source}
14-
import spray.json.DefaultJsonProtocol
14+
import spray.json.{DefaultJsonProtocol, RootJsonFormat}
1515

1616
import java.io.File
1717
import java.nio.file.Paths
1818
import java.time.LocalTime
19-
import scala.collection.parallel.CollectionConverters._
20-
import scala.concurrent.duration._
19+
import scala.collection.parallel.CollectionConverters.*
20+
import scala.concurrent.duration.*
2121
import scala.concurrent.{Await, Future}
2222
import scala.sys.process.{Process, stringSeqToProcess}
2323
import scala.util.{Failure, Success}
@@ -26,7 +26,7 @@ trait JsonProtocol extends DefaultJsonProtocol with SprayJsonSupport {
2626

2727
case class FileHandle(fileName: String, absolutePath: String, length: Long)
2828

29-
implicit def fileInfoFormat = jsonFormat3(FileHandle)
29+
implicit def fileInfoFormat: RootJsonFormat[FileHandle] = jsonFormat3(FileHandle)
3030
}
3131

3232
/**
@@ -94,7 +94,7 @@ object HttpFileEcho extends App with JsonProtocol {
9494
} ~
9595
path("download") {
9696
get {
97-
entity(as[FileHandle]) { fileHandle: FileHandle =>
97+
entity(as[FileHandle]) { fileHandle =>
9898
println(s"Server received download request for: ${fileHandle.fileName}")
9999

100100
// Activate to simulate rnd server ex during download and thus provoke retry on client

src/main/scala/akkahttp/HttpFileEchoStream.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import org.apache.pekko.actor.ActorSystem
55
import org.apache.pekko.http.scaladsl.Http
66
import org.apache.pekko.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
77
import org.apache.pekko.http.scaladsl.marshalling.Marshal
8-
import org.apache.pekko.http.scaladsl.model._
9-
import org.apache.pekko.http.scaladsl.server.Directives.{complete, logRequestResult, path, _}
8+
import org.apache.pekko.http.scaladsl.model.*
9+
import org.apache.pekko.http.scaladsl.server.Directives.{complete, logRequestResult, path, *}
1010
import org.apache.pekko.http.scaladsl.server.Route
1111
import org.apache.pekko.http.scaladsl.server.directives.FileInfo
1212
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
1313
import org.apache.pekko.stream.scaladsl.{FileIO, Keep, Sink, Source}
1414
import org.apache.pekko.stream.{OverflowStrategy, QueueOfferResult, ThrottleMode}
15-
import spray.json.DefaultJsonProtocol
15+
import spray.json.{DefaultJsonProtocol, RootJsonFormat}
1616

1717
import java.io.File
1818
import java.nio.file.Paths
1919
import java.time.LocalTime
20-
import scala.concurrent.duration._
20+
import scala.concurrent.duration.*
2121
import scala.concurrent.{Await, Future, Promise}
2222
import scala.util.{Failure, Success}
2323

@@ -43,7 +43,7 @@ object HttpFileEchoStream extends App with DefaultJsonProtocol with SprayJsonSup
4343

4444
final case class FileHandle(fileName: String, absolutePath: String, length: Long = 0)
4545

46-
implicit def fileInfoFormat = jsonFormat3(FileHandle)
46+
implicit def fileInfoFormat: RootJsonFormat[FileHandle] = jsonFormat3(FileHandle)
4747

4848
val resourceFileName = "testfile.jpg"
4949
val (address, port) = ("127.0.0.1", 6000)
@@ -78,7 +78,7 @@ object HttpFileEchoStream extends App with DefaultJsonProtocol with SprayJsonSup
7878
} ~
7979
path("download") {
8080
get {
81-
entity(as[FileHandle]) { fileHandle: FileHandle =>
81+
entity(as[FileHandle]) { fileHandle =>
8282
println(s"Server: Received download request for: ${fileHandle.fileName}")
8383

8484
// Activate to simulate rnd server ex during download
@@ -139,7 +139,7 @@ object HttpFileEchoStream extends App with DefaultJsonProtocol with SprayJsonSup
139139

140140

141141
def createDownloadRequest(fileToDownload: FileHandle): Future[HttpRequest] = {
142-
Marshal(fileToDownload).to[RequestEntity].map { entity: MessageEntity =>
142+
Marshal(fileToDownload).to[RequestEntity].map { entity =>
143143
val target = Uri(s"http://$address:$port").withPath(org.apache.pekko.http.scaladsl.model.Uri.Path("/download"))
144144
HttpRequest(HttpMethods.GET, uri = target, entity = entity)
145145
}

src/main/scala/akkahttp/ReverseProxy.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package akkahttp
22

33
import akkahttp.ReverseProxy.Mode.Mode
44
import com.typesafe.config.{ConfigFactory, ConfigValueFactory}
5-
import io.circe._
5+
import io.circe.*
66
import org.apache.pekko.actor.ActorSystem
7-
import org.apache.pekko.http.scaladsl.Http
7+
import org.apache.pekko.http.scaladsl.model.*
88
import org.apache.pekko.http.scaladsl.model.Uri.Authority
9-
import org.apache.pekko.http.scaladsl.model._
109
import org.apache.pekko.http.scaladsl.model.headers.{Host, RawHeader}
11-
import org.apache.pekko.http.scaladsl.server.Directives._
10+
import org.apache.pekko.http.scaladsl.server.Directives.*
1211
import org.apache.pekko.http.scaladsl.server.Route
1312
import org.apache.pekko.http.scaladsl.settings.ServerSettings
13+
import org.apache.pekko.http.scaladsl.{Http, HttpExt}
1414
import org.apache.pekko.pattern.CircuitBreaker
1515
import org.apache.pekko.stream.ThrottleMode
1616
import org.apache.pekko.stream.scaladsl.{Sink, Source}
@@ -20,7 +20,7 @@ import java.util.concurrent.ConcurrentHashMap
2020
import java.util.concurrent.atomic.AtomicInteger
2121
import scala.collection.parallel.CollectionConverters.ImmutableIterableIsParallelizable
2222
import scala.concurrent.duration.DurationInt
23-
import scala.concurrent.{ExecutionContext, Future, Promise, TimeoutException}
23+
import scala.concurrent.*
2424
import scala.util.{Failure, Success}
2525

2626
/**
@@ -60,9 +60,9 @@ object ReverseProxy extends App {
6060
val logger: Logger = LoggerFactory.getLogger(this.getClass)
6161
implicit val system: ActorSystem = ActorSystem()
6262

63-
implicit val executionContext = system.dispatcher
63+
implicit val executionContext: ExecutionContextExecutor = system.dispatcher
6464

65-
implicit val http = Http(system)
65+
implicit val http: HttpExt = Http(system)
6666

6767
val circuitBreakers = new ConcurrentHashMap[String, CircuitBreaker]()
6868
val requestCounter = new AtomicInteger(0)

src/main/scala/akkahttp/SampleRoutes.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import org.apache.pekko.http.scaladsl.Http
77
import org.apache.pekko.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
88
import org.apache.pekko.http.scaladsl.model.StatusCodes.InternalServerError
99
import org.apache.pekko.http.scaladsl.model.{ContentTypes, HttpResponse, StatusCodes}
10-
import org.apache.pekko.http.scaladsl.server.Directives._
11-
import org.apache.pekko.http.scaladsl.server._
10+
import org.apache.pekko.http.scaladsl.server.*
11+
import org.apache.pekko.http.scaladsl.server.Directives.*
1212
import org.apache.pekko.util.Timeout
1313
import org.slf4j.{Logger, LoggerFactory}
1414
import spray.json.DefaultJsonProtocol
1515

1616
import java.nio.file.Paths
1717
import scala.concurrent.Await
18-
import scala.concurrent.duration._
18+
import scala.concurrent.duration.*
1919
import scala.sys.process.{Process, stringSeqToProcess}
2020
import scala.util.{Failure, Success}
2121

@@ -33,7 +33,7 @@ object SampleRoutes extends App with DefaultJsonProtocol with SprayJsonSupport {
3333
val logger: Logger = LoggerFactory.getLogger(this.getClass)
3434
implicit val system: ActorSystem = ActorSystem()
3535

36-
import spray.json._
36+
import spray.json.*
3737
import system.dispatcher
3838

3939
val faultyActor = system.actorOf(Props[FaultyActor](), "FaultyActor")
@@ -112,7 +112,7 @@ object SampleRoutes extends App with DefaultJsonProtocol with SprayJsonSupport {
112112
// curl -X GET localhost:6002/acceptAll -H "Accept: text/plain"
113113
// curl -X GET localhost:6002/acceptAll -H "Accept: text/xxx"
114114
val acceptAll: Route = get {
115-
path("acceptAll") { ctx: RequestContext =>
115+
path("acceptAll") { ctx =>
116116
// withAcceptAll: Remove/Ignore accept headers and always return application/json
117117
ctx.withAcceptAll.complete("""{ "foo": "bar" }""".parseJson)
118118
}

src/main/scala/akkahttp/WebsocketChatEcho.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package akkahttp
22

33
import org.apache.pekko.http.scaladsl.Http
44
import org.apache.pekko.http.scaladsl.model.StatusCodes
5-
import org.apache.pekko.http.scaladsl.model.ws._
6-
import org.apache.pekko.http.scaladsl.server.Directives._
5+
import org.apache.pekko.http.scaladsl.model.ws.*
6+
import org.apache.pekko.http.scaladsl.server.Directives.*
77
import org.apache.pekko.http.scaladsl.server.Route
88
import org.apache.pekko.stream.scaladsl.{BroadcastHub, Flow, Keep, MergeHub, Sink, Source}
99
import org.apache.pekko.{Done, NotUsed}
1010

11-
import scala.collection.parallel.CollectionConverters._
11+
import scala.collection.parallel.CollectionConverters.*
1212
import scala.concurrent.Future
13-
import scala.concurrent.duration._
13+
import scala.concurrent.duration.*
1414
/**
1515
* A simple WebSocket chat system using only akka streams with the help of MergeHub Source and BroadcastHub Sink
1616
* See also: [[WebsocketEcho]]
@@ -66,7 +66,7 @@ object WebsocketChatEcho extends App with ClientCommon {
6666
logger.info(s"Server received: $text")
6767
Future.successful(text)
6868
case TextMessage.Streamed(textStream) =>
69-
textStream.runFold("")(_ + _)
69+
textStream.runReduce(_ + _)
7070
.flatMap(Future.successful)
7171
}
7272
.via(Flow.fromSinkAndSourceCoupled(inSink, outSource))

src/main/scala/akkahttp/WebsocketEcho.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import org.apache.pekko.Done
44
import org.apache.pekko.actor.{ActorRef, ActorSystem}
55
import org.apache.pekko.http.scaladsl.Http
66
import org.apache.pekko.http.scaladsl.model.StatusCodes
7-
import org.apache.pekko.http.scaladsl.model.ws._
8-
import org.apache.pekko.http.scaladsl.server.Directives._
7+
import org.apache.pekko.http.scaladsl.model.ws.*
8+
import org.apache.pekko.http.scaladsl.server.Directives.*
99
import org.apache.pekko.http.scaladsl.server.Route
1010
import org.apache.pekko.http.scaladsl.server.directives.WebSocketDirectives
1111
import org.apache.pekko.pattern.ask
@@ -18,17 +18,17 @@ import sttp.client3.{UriContext, asWebSocket, basicRequest}
1818
import sttp.ws.WebSocket
1919

2020
import java.time.LocalDateTime
21-
import scala.collection.parallel.CollectionConverters._
21+
import scala.collection.parallel.CollectionConverters.*
2222
import scala.concurrent.duration.DurationInt
23-
import scala.concurrent.{Await, Future, Promise}
23+
import scala.concurrent.{Await, ExecutionContextExecutor, Future, Promise}
2424
import scala.language.postfixOps
2525
import scala.sys.process.{Process, stringSeqToProcess}
2626
import scala.util.{Failure, Success}
2727

2828
trait ClientCommon {
2929
val logger: Logger = LoggerFactory.getLogger(this.getClass)
3030
implicit val system: ActorSystem = ActorSystem()
31-
implicit val executionContext = system.dispatcher
31+
implicit val executionContext: ExecutionContextExecutor = system.dispatcher
3232

3333
val printSink: Sink[Message, Future[Done]] =
3434
Sink.foreach {

src/main/scala/akkahttp/WebsocketEchoActors.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.apache.pekko.Done
55
import org.apache.pekko.actor.{Actor, ActorRef, Props}
66
import org.apache.pekko.http.scaladsl.Http
77
import org.apache.pekko.http.scaladsl.model.ws.{BinaryMessage, Message, TextMessage}
8-
import org.apache.pekko.http.scaladsl.server.Directives._
8+
import org.apache.pekko.http.scaladsl.server.Directives.*
99
import org.apache.pekko.http.scaladsl.server.Route
1010
import org.apache.pekko.stream.scaladsl.{Flow, Sink, Source}
1111
import org.apache.pekko.stream.{CompletionStrategy, OverflowStrategy}
@@ -96,7 +96,7 @@ object WebsocketEchoActors extends App with ClientCommon {
9696
bufferSize = 100,
9797
overflowStrategy = OverflowStrategy.dropHead)
9898
.mapMaterializedValue {
99-
outSourceActorRef: ActorRef => {
99+
outSourceActorRef => {
100100
chatRef ! Protocol.OpenConnection(outSourceActorRef, connectionId)
101101
}
102102
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
package akkahttp.oidc
22

33
import org.apache.pekko.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
4-
import spray.json.DefaultJsonProtocol._
4+
import spray.json.DefaultJsonProtocol.*
5+
import spray.json.RootJsonFormat
56

67
trait JsonSupport extends SprayJsonSupport {
78

89
case class Keys(keys: Seq[KeyData])
910
case class KeyData(kid: String, n: String, e: String)
1011

11-
implicit val keyDataFormat = jsonFormat3(KeyData)
12-
implicit val keysFormat = jsonFormat1(Keys)
12+
implicit val keyDataFormat: RootJsonFormat[KeyData] = jsonFormat3(KeyData)
13+
implicit val keysFormat: RootJsonFormat[Keys] = jsonFormat1(Keys)
1314

1415
case class UserKeycloak(firstName: Option[String], lastName: Option[String], email: Option[String])
1516
case class UsersKeycloak(users: Seq[UserKeycloak])
1617

17-
implicit val userJsonFormat = jsonFormat3(UserKeycloak)
18-
implicit val usersJsonFormat = jsonFormat1(UsersKeycloak)
18+
implicit val userJsonFormat: RootJsonFormat[UserKeycloak] = jsonFormat3(UserKeycloak)
19+
implicit val usersJsonFormat: RootJsonFormat[UsersKeycloak] = jsonFormat1(UsersKeycloak)
1920
}

0 commit comments

Comments
 (0)