Skip to content

Commit 6756872

Browse files
authored
Merge branch 'master' into update/s3-2.20.128
2 parents 2e14960 + f10c1be commit 6756872

File tree

31 files changed

+256
-53
lines changed

31 files changed

+256
-53
lines changed

.git-blame-ignore-revs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Scala Steward: Reformat with scalafmt 3.7.12
2+
ca5770e327fea2fad0a3bf2f79f896e7a507d2d5

.github/workflows/scala-steward.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
on:
2+
schedule:
3+
- cron: '0 0 * * 0'
4+
5+
name: Launch Scala Steward
6+
7+
jobs:
8+
scala-steward:
9+
runs-on: ubuntu-22.04
10+
name: Launch Scala Steward
11+
steps:
12+
- name: Launch Scala Steward
13+
uses: scala-steward-org/scala-steward-action@v2
14+
with:
15+
github-app-id: ${{ secrets.APP_ID }}
16+
github-app-installation-id: ${{ secrets.APP_INSTALLATION_ID }}
17+
github-app-key: ${{ secrets.APP_PRIVATE_KEY }}

.mergify.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pull_request_rules:
2+
- name: Automatic merge on approval
3+
conditions:
4+
- label!=early-semver-major
5+
- label!=semver-spec-major
6+
- "#files=1"
7+
- "#approved-reviews-by>=1"
8+
- check-success=CI - Jenkins
9+
- author=scala-steward
10+
- or:
11+
- label=early-semver-minor
12+
- label=early-semver-patch
13+
actions:
14+
merge:
15+
method: merge

.scalafmt.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = 3.7.10
1+
version = 3.7.12
22
runner.dialect = scala3
33
fileOverride {
44
"glob:**/scala-2-modules/**" {

README.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1+
[![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org)
2+
13
# scala-tutorials
4+
This is the main repo for all the sample code used in the scala tutorials.
5+
6+
# Compiling and Running Tests
7+
This repo uses a multi-module build with many sub modules.
8+
To compile the entire module, you may use the command `sbt compile`. However, this loads all the modules and compiles all of them, which might take some time.
9+
If you are interested in only a particular module, you can compile it by starting sbt shell and using the command `<sub-module-name>/compile`.
10+
Similarly, you can run the tests per module as `<module-name>/test`.
11+
12+
Here are some of the useful commands that can be used within tbe sbt shell
13+
14+
| SBT Command | Description |
15+
|---------------------------|-------------------------------------------------------------------------------------------------------|
16+
| project <sub-module-name> | Switch to a particular module. After this, the command `compile`, `test` etc runs only on that module |
17+
| <sub-module>/compile | Compile only the provided module |
18+
| projects | Lists all the sub modules |
19+
| <sub-module>/run | Run the main class within the sub-module |
220

21+
# Test Naming Standards
322
In this repository, we have classified the tests in 4 categories.
423

524
| Category | Description |
@@ -21,6 +40,6 @@ Note that these commands are defined at the root level of the project and hence
2140
| Live Test | `sbt liveTests` | `src/it/scala` or `src/it/scala-2` | Test class name must end with `LiveTest` |
2241
| Manual Test | `sbt manualTests` | `src/it/scala` or `src/it/scala-2` | Test class name must end with `ManualTest` |
2342

24-
# Code fomatting
43+
# Code formatting
2544

26-
Before creating a PR, make sure the code is correctly formatted running `sbt scalafmt`.
45+
Before creating a PR, run `sbt scalafmtAll` to automatically format the entire codebase. To check if there are any formatting issues(without fixing them), you may run `sbt scalafmtCheckAll`

build.sbt

+18-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ val jUnitInterface = "com.github.sbt" % "junit-interface" % "0.13.3" % "test"
99
val catsEffect = "org.typelevel" %% "cats-effect" % "3.5.1"
1010
val catEffectTest = "org.typelevel" %% "cats-effect-testkit" % "3.5.1" % Test
1111
val scalaReflection = "org.scala-lang" % "scala-reflect" % scalaV
12-
val logback = "ch.qos.logback" % "logback-classic" % "1.3.8"
12+
val logback = "ch.qos.logback" % "logback-classic" % "1.3.11"
1313
val embedMongoVersion = "4.7.1"
1414

1515
val scalaTestDeps = Seq(
@@ -81,7 +81,7 @@ lazy val scala_core_7 = (project in file("scala-core-7"))
8181
libraryDependencies ++= scalaTestDeps,
8282
libraryDependencies += jUnitInterface,
8383
libraryDependencies += "com.github.scopt" %% "scopt" % "4.1.0",
84-
libraryDependencies += "org.rogach" %% "scallop" % "4.1.0",
84+
libraryDependencies += "org.rogach" %% "scallop" % "5.0.0",
8585
libraryDependencies += "org.backuity.clist" %% "clist-core" % "3.5.1",
8686
libraryDependencies += "org.backuity.clist" %% "clist-macros" % "3.5.1" % "provided",
8787
libraryDependencies += "args4j" % "args4j" % "2.33"
@@ -219,14 +219,15 @@ lazy val scala_akka_2 = (project in file("scala-akka-2"))
219219
"com.lightbend.akka" %% "akka-stream-alpakka-sse" % "5.0.0",
220220
"com.typesafe.akka" %% "akka-persistence-typed" % AkkaVersion,
221221
"com.typesafe.akka" %% "akka-actor-testkit-typed" % AkkaVersion % "it,test",
222-
"com.typesafe.akka" %% "akka-http-testkit" % AkkaHttpVersion % "it,test"
222+
"com.typesafe.akka" %% "akka-http-testkit" % AkkaHttpVersion % "it,test",
223+
"com.typesafe.akka" %% "akka-stream-testkit" % AkkaVersion % Test
223224
) ++ scalaTestDeps.map(_.withConfigurations(Some("it,test")))
224225
)
225226
val monocleVersion = "2.1.0"
226227
val slickVersion = "3.4.1"
227228
val shapelessVersion = "2.3.10"
228229
val scalazVersion = "7.3.7"
229-
val fs2Version = "3.7.0"
230+
val fs2Version = "3.8.0"
230231
val AkkaVersion = "2.8.0"
231232
val AkkaHttpVersion = "10.5.0"
232233
val reactiveMongo = "1.0.10"
@@ -259,7 +260,7 @@ lazy val scala_libraries = (project in file("scala-libraries"))
259260

260261
val circeVersion = "0.14.5"
261262
val monixVersion = "3.4.1"
262-
val elastic4sVersion = "8.8.1"
263+
val elastic4sVersion = "8.8.3"
263264
val sparkVersion = "3.4.1"
264265

265266
val sparkCoreDep = "org.apache.spark" %% "spark-core" % sparkVersion
@@ -364,7 +365,7 @@ lazy val scala_libraries_4 = (project in file("scala-libraries-4"))
364365
sparkCoreDep,
365366
logback,
366367
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.5",
367-
"org.typelevel" %% "cats-core" % "2.9.0"
368+
"org.typelevel" %% "cats-core" % "2.10.0"
368369
),
369370
libraryDependencies ++= Seq(
370371
"com.clever-cloud.pulsar4s" %% "pulsar4s-core" % "2.9.0",
@@ -373,7 +374,7 @@ lazy val scala_libraries_4 = (project in file("scala-libraries-4"))
373374
),
374375
libraryDependencies ++= Seq(
375376
"software.amazon.awssdk" % "s3" % "2.20.128",
376-
"com.amazonaws" % "aws-java-sdk-s3" % "1.12.514" % IntegrationTest,
377+
"com.amazonaws" % "aws-java-sdk-s3" % "1.12.532" % IntegrationTest,
377378
"com.dimafeng" %% "testcontainers-scala-scalatest" % "0.40.17" % IntegrationTest,
378379
"com.dimafeng" %% "testcontainers-scala-localstack-v2" % "0.40.17" % IntegrationTest
379380
),
@@ -386,13 +387,13 @@ lazy val scala_libraries_4 = (project in file("scala-libraries-4"))
386387
)
387388

388389
val spireVersion = "0.18.0"
389-
val kafkaVersion = "3.5.0"
390+
val kafkaVersion = "3.5.1"
390391
val pureconfigVersion = "0.17.4"
391-
val jackSonVersion = "2.15.1"
392+
val jackSonVersion = "2.15.2"
392393
val log4jApiScalaVersion = "12.0"
393394
val log4jVersion = "2.20.0"
394395
val avro4sVersion = "3.1.1"
395-
val kafkaAvroSerializer = "6.0.0"
396+
val kafkaAvroSerializer = "6.0.14"
396397

397398
lazy val scala_libraries_5 = (project in file("scala-libraries-5"))
398399
.settings(
@@ -508,7 +509,7 @@ lazy val scala212 = (project in file("scala-2-modules/scala212"))
508509

509510
addCommandAlias(
510511
"ci",
511-
";clean;compile;test:compile;it:compile;scalafmtCheckAll;test"
512+
";compile;test:compile;it:compile;scalafmtCheckAll;test"
512513
)
513514

514515
addCommandAlias(
@@ -518,7 +519,7 @@ addCommandAlias(
518519

519520
addCommandAlias(
520521
"ciFull",
521-
""";ci; set ThisBuild/IntegrationTest/testOptions += Tests.Filter(t => !t.endsWith("ManualTest") && !t.endsWith("LiveTest") ); it:test""".stripMargin
522+
""";clean; ci; set ThisBuild/IntegrationTest/testOptions += Tests.Filter(t => !t.endsWith("ManualTest") && !t.endsWith("LiveTest") ); it:test""".stripMargin
522523
)
523524

524525
addCommandAlias(
@@ -532,3 +533,8 @@ addCommandAlias(
532533
)
533534

534535
lazy val playGroup = (project in file("play-scala"))
536+
537+
//Uncomment this to enable scala-js module. It needs nodejs module as well in local machine
538+
//lazy val scalajs = project in file("scala-js")
539+
lazy val scalatra = project in file("scalatra")
540+
lazy val benchmark = project in file("specialized-benchmark")

play-scala/application-tests/build.sbt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ enablePlugins(PlayScala)
88
scalaVersion := ScalaVersions.scala2Version
99

1010
libraryDependencies += "com.google.inject" % "guice" % "6.0.0"
11-
libraryDependencies += "com.h2database" % "h2" % "1.4.192"
12-
libraryDependencies += "org.postgresql" % "postgresql" % "42.2.14"
11+
libraryDependencies += "com.h2database" % "h2" % "1.4.200"
12+
libraryDependencies += "org.postgresql" % "postgresql" % "42.2.27"
1313
libraryDependencies += "com.typesafe.play" %% "play-slick" % "5.1.0"
1414
libraryDependencies += "com.typesafe.play" %% "play-slick-evolutions" % "5.1.0"
1515
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % Test

play-scala/caching-in-play/build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ libraryDependencies += guice
1111
libraryDependencies += caffeine
1212
libraryDependencies += ws
1313
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test
14-
libraryDependencies += "org.mockito" % "mockito-core" % "3.5.13" % Test
14+
libraryDependencies += "org.mockito" % "mockito-core" % "3.5.15" % Test
1515

1616
PlayKeys.devSettings += "play.server.http.port" -> "9000"

play-scala/configuration-access/build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ scalaVersion := ScalaVersions.scala2Version
99

1010
libraryDependencies += guice
1111
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test
12-
libraryDependencies += "org.mockito" % "mockito-scala_2.13" % "1.15.0" % Test
12+
libraryDependencies += "org.mockito" % "mockito-scala_2.13" % "1.15.1" % Test
1313

1414
// Adds additional packages into Twirl
1515
//TwirlKeys.templateImports += "com.baeldung.controllers._"

play-scala/dependency-injection/build.sbt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ scalaVersion := ScalaVersions.scala2Version
88

99
libraryDependencies += guice
1010
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test
11-
libraryDependencies += "com.softwaremill.macwire" %% "macros" % "2.4.0" % Provided
12-
libraryDependencies += "com.softwaremill.macwire" %% "util" % "2.4.0"
11+
libraryDependencies += "com.softwaremill.macwire" %% "macros" % "2.4.2" % Provided
12+
libraryDependencies += "com.softwaremill.macwire" %% "util" % "2.4.2"

project/plugins.sbt

+10
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "2.2.1")
77
libraryDependencies += "ai.kien" %% "python-native-libs" % "0.2.4"
88
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.19")
99
ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always
10+
11+
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.4.2")
12+
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.2.1")
13+
14+
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
15+
libraryDependencies += "org.scala-js" %% "scalajs-env-jsdom-nodejs" % "1.0.0"
16+
17+
resolvers += Resolver.jcenterRepo
18+
19+
addSbtPlugin("net.aichler" % "sbt-jupiter-interface" % "0.8.3")

scala-akka-2/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
- [Reading Query Parameters in Akka HTTP](https://www.baeldung.com/scala/akka-http-reading-query-parameters)
99
- [Difference Between tell and forward in Akka Actor](https://www.baeldung.com/scala/akka-actor-tell-vs-forward)
1010
- [Testing an Akka HTTP Application](https://www.baeldung.com/scala/akka-http-testing)
11+
- [Introduction to Akka-Streams in Scala](https://www.baeldung.com/scala/akka-streams)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.scala.akka.stream
2+
3+
import akka.actor.ActorSystem
4+
5+
import scala.util.{Failure, Success}
6+
7+
object Main extends App {
8+
implicit val system: ActorSystem = ActorSystem("baeldung")
9+
10+
source
11+
.via(parse)
12+
.via(compare)
13+
.runWith(sink)
14+
.andThen {
15+
case Failure(exception) => println(exception)
16+
case Success((correct, total)) =>
17+
println(s"$correct/$total correct answers")
18+
}(system.dispatcher)
19+
.onComplete(_ => system.terminate())(system.dispatcher)
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.baeldung.scala.akka
2+
3+
import akka.NotUsed
4+
import akka.stream.scaladsl.{Flow, Sink, Source}
5+
6+
import scala.concurrent.Future
7+
8+
package object stream {
9+
val source: Source[String, NotUsed] = Source(
10+
Seq("5,10", "15,15", "78,79", "12,12", "0,0", "456,456")
11+
)
12+
13+
val parse: Flow[String, (Int, Int), NotUsed] =
14+
Flow[String]
15+
.map { pair =>
16+
val parts = pair.split(",")
17+
(parts(0).toInt, parts(1).toInt)
18+
}
19+
20+
val compare: Flow[(Int, Int), Boolean, NotUsed] =
21+
Flow[(Int, Int)]
22+
.map { case (userAnswer, correctAnswer) => userAnswer == correctAnswer }
23+
24+
val sink: Sink[Boolean, Future[(Int, Int)]] = Sink.fold((0, 0)) {
25+
case ((correctCount, total), wasCorrect) =>
26+
if (wasCorrect) (correctCount + 1, total + 1)
27+
else (correctCount, total + 1)
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.baeldung.scala.akka.stream
2+
3+
import akka.actor.ActorSystem
4+
import akka.stream.scaladsl.Keep
5+
import akka.stream.testkit.scaladsl.{TestSink, TestSource}
6+
import org.scalatest.concurrent.ScalaFutures.convertScalaFuture
7+
import org.scalatest.flatspec.AnyFlatSpec
8+
import org.scalatest.matchers.should.Matchers
9+
10+
class StreamTest extends AnyFlatSpec with Matchers {
11+
implicit val system: ActorSystem = ActorSystem("baeldung")
12+
13+
"The parse flow" should "parse pairs of integers" in {
14+
val (pub, sub) = TestSource[String]()
15+
.via(parse)
16+
.toMat(TestSink[(Int, Int)]())(Keep.both)
17+
.run()
18+
19+
pub.sendNext("1,1")
20+
pub.sendNext("145,146")
21+
pub.sendComplete()
22+
23+
sub.requestNext((1, 1))
24+
sub.requestNext((145, 146))
25+
sub.expectComplete()
26+
}
27+
28+
"The compare flow" should "compare pairs of integers" in {
29+
val (pub, sub) = TestSource[(Int, Int)]()
30+
.via(compare)
31+
.toMat(TestSink[Boolean]())(Keep.both)
32+
.run()
33+
34+
pub.sendNext((1, 1))
35+
pub.sendNext((145, 146))
36+
pub.sendComplete()
37+
38+
sub.requestNext(true)
39+
sub.requestNext(false)
40+
sub.expectComplete()
41+
}
42+
43+
"The sink sink" should "count the number of trues" in {
44+
val (probe, result) = TestSource[Boolean]().toMat(sink)(Keep.both).run()
45+
46+
probe.sendNext(true)
47+
probe.sendNext(false)
48+
probe.sendNext(false)
49+
probe.sendComplete()
50+
51+
result.futureValue shouldBe (1, 3)
52+
}
53+
}

scala-core-8/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
- [Get Difference Between Two Dates](https://www.baeldung.com/scala/difference-between-two-dates)
88
- [The Either Type in Scala](https://www.baeldung.com/scala/either-type)
99
- [Understanding the Differences: reduceLeft, reduceRight, foldLeft, foldRight, scanLeft, and scanRight in Scala](https://www.baeldung.com/scala/reduce-fold-scan-left-right)
10+
- [Different Ways to Reverse a Sequence in Scala](https://www.baeldung.com/scala/reverse-sequence)

scala-core-collections-2/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
- [Get a Subarray in Scala](https://www.baeldung.com/scala/extract-subarray)
77
- [Finding the First Element Matching a Condition in a Collection](https://www.baeldung.com/scala/find-first-match-in-collection)
88
- [Append an Element to an Array in Scala](https://www.baeldung.com/scala/array-append-element)
9+
- [Create a Random Sample of Fixed Size From a Scala List](https://www.baeldung.com/scala/list-uniform-sample)

scala-core/build.sbt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Scala 3 configuration
22
lazy val Scala3Test = config("scala3Test").extend(Test)
33
// Source directories
4-
scalaSource in Scala3Test := baseDirectory.value / "src" / "main" / "scala-3"
4+
Scala3Test / scalaSource := baseDirectory.value / "src" / "main" / "scala-3"
55
// Test directories
6-
scalaSource in Scala3Test := baseDirectory.value / "src" / "test" / "scala-3"
6+
Scala3Test / scalaSource := baseDirectory.value / "src" / "test" / "scala-3"

scala-js/build.sbt

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ organization := "com.baeldung"
33

44
version := "1.0-SNAPSHOT"
55

6-
lazy val root = (project in file("."))
7-
.enablePlugins(ScalaJSPlugin)
8-
.settings(
9-
jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv()
10-
)
6+
enablePlugins(ScalaJSPlugin)
117

128
scalaVersion := "2.13.10"
139

1410
scalaJSUseMainModuleInitializer := true
1511
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.2.0"
1612
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.1.2" % Test
13+
14+
//enable the below setting after installing npm package jsdom.
15+
jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv()

scala-sbt/sbt-info/build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ ThisBuild / coverageEnabled := true
4343

4444
ThisBuild / coverageExcludedFiles := """.*SlickTables;.*/scalaz/.*"""
4545

46-
ThisBuild / coverageExcludedPackages := "<empty>;.*CollectionMonoid.*;.*reactivemongo.*"
46+
ThisBuild / coverageExcludedPackages := "<empty>;.*CollectionMonoid.*;.*reactivemongo.*"

scala-test-junit5/project/build.properties

-1
This file was deleted.

scala-test-junit5/project/plugins.sbt

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
resolvers += Resolver.jcenterRepo
21

3-
addSbtPlugin("net.aichler" % "sbt-jupiter-interface" % "0.8.3")

0 commit comments

Comments
 (0)