Skip to content

Commit

Permalink
#77: Adding support for Scala 2.13 and improving the overall build
Browse files Browse the repository at this point in the history
  • Loading branch information
lsulak committed Sep 22, 2023
1 parent c00f120 commit c1839b5
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 8 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ on:
jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
scala: [2.11.12, 2.12.18, 2.13.11]

name: Scala ${{matrix.scala}}

steps:
- name: Checkout code
Expand All @@ -36,4 +41,4 @@ jobs:
with:
java-version: "[email protected]"
- name: Build and run tests
run: sbt test doc
run: sbt ++${{matrix.scala}} test doc
11 changes: 10 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ lazy val server = (projectMatrix in file("server"))
libraryDependencies ++= Dependencies.serverDependencies,
Compile / packageBin / publishArtifact := false,
(Compile / compile) := ((Compile / compile) dependsOn printSparkScalaVersion).value,
Compile / unmanagedSourceDirectories += {
val sourceDir = (Compile / sourceDirectory).value
if (scalaVersion.value.startsWith("2.13")) {
sourceDir / "scala_2.13+"
}
else {
sourceDir / "scala_2.12-"
}
},
packageBin := (Compile / assembly).value,
artifactPath / (Compile / packageBin) := baseDirectory.value / s"target/${name.value}-${version.value}.war",
webappWebInfClasses := true,
Expand Down Expand Up @@ -102,7 +111,7 @@ lazy val agent = (projectMatrix in file("agent"))
jacocoExcludes := jacocoProjectExcludes()
)
.sparkRow(SparkVersionAxis(Versions.spark2), scalaVersions = Seq(Versions.scala211, Versions.scala212))
.sparkRow(SparkVersionAxis(Versions.spark3), scalaVersions = Seq(Versions.scala212))
.sparkRow(SparkVersionAxis(Versions.spark3), scalaVersions = Seq(Versions.scala212, Versions.scala213))
.jvmPlatform(scalaVersions = Versions.supportedScalaVersions)
.dependsOn(model)

Expand Down
8 changes: 5 additions & 3 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ object Dependencies {
val spark3 = "3.3.2"

val scala211 = "2.11.12"
val scala212 = "2.12.12"
val supportedScalaVersions: Seq[String] = Seq(scala211, scala212)
val scala212 = "2.12.18"
val scala213 = "2.13.11"
val supportedScalaVersions: Seq[String] = Seq(scala211, scala212, scala213)

val scalatest = "3.2.15"
val scalaMockito = "1.17.12"
Expand Down Expand Up @@ -65,7 +66,8 @@ object Dependencies {
scalaVersion match {
case _ if scalaVersion.startsWith("2.11") => Versions.spark2
case _ if scalaVersion.startsWith("2.12") => Versions.spark3
case _ => throw new IllegalArgumentException("Only Scala 2.11 and 2.12 are currently supported.")
case _ if scalaVersion.startsWith("2.13") => Versions.spark3
case _ => throw new IllegalArgumentException("Only Scala 2.11, 2.12, and 2.13 are currently supported.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import za.co.absa.atum.web.model.{BaseApiModel, ControlMeasure, Flow, Partition}

import java.util.UUID
import java.util.concurrent.{ConcurrentHashMap, ConcurrentMap}
import scala.collection.JavaConverters._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

Expand All @@ -40,12 +39,12 @@ object InMemoryApiModelDao {

}

class InMemoryApiModelDao[T <: BaseApiModel] extends ApiModelDao[T] {
class InMemoryApiModelDao[T <: BaseApiModel] extends ApiModelDao[T] with JavaConvertersWrapper {

private val inmemory: ConcurrentMap[UUID, T] = new ConcurrentHashMap[UUID, T]()

def getList(limit: Int, offset: Int, filter: T => Boolean): Future[List[T]] = Future {
inmemory.values.asScala
asScala(inmemory.values)
.filter(filter)
.slice(offset, offset + limit).toList // limiting, todo pagination or similar
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2021 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.atum.web.dao

import scala.collection.JavaConverters.iterableAsScalaIterableConverter

trait JavaConvertersWrapper {
def asScala[T](item: java.lang.Iterable[T]): Iterable[T] = {
item.asScala
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2021 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.atum.web.dao

import scala.jdk.CollectionConverters.IterableHasAsScala

trait JavaConvertersWrapper {
def asScala[T](item: java.lang.Iterable[T]): Iterable[T] = {
item.asScala
}
}

0 comments on commit c1839b5

Please sign in to comment.