Skip to content

Commit

Permalink
Switching to scala 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
staudtMarius committed Dec 4, 2023
1 parent 8463747 commit ddda1db
Show file tree
Hide file tree
Showing 240 changed files with 2,426 additions and 2,746 deletions.
6 changes: 0 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,6 @@ def publishReports(String relativeProjectDir) {
// publish scalatest reports for main project only (currently the only one with scala sources!)
publishHTML([allowMissing: false, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: relativeProjectDir + '/build/reports/tests/scalatest', reportFiles: 'index.html', reportName: "${relativeProjectDir}_scala_tests_report", reportTitles: ''])

// publish scapegoat src report for main project only
publishHTML([allowMissing: false, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: relativeProjectDir + '/build/reports/scapegoat/src', reportFiles: 'scapegoat.html', reportName: "${relativeProjectDir}_scapegoat_src_report", reportTitles: ''])

// publish scapegoat testsrc report for main project only
publishHTML([allowMissing: false, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: relativeProjectDir + '/build/reports/scapegoat/testsrc', reportFiles: 'scapegoat.html', reportName: "${relativeProjectDir}_scapegoat_testsrc_report", reportTitles: ''])

// scoverage report dir
publishHTML([allowMissing: false, alwaysLinkToLastBuild: true, escapeUnderscores: false, keepAll: true, reportDir: relativeProjectDir + '/build/reports/scoverageTest', reportFiles: 'scoverage.xml', reportName: "${relativeProjectDir}_scoverage_report", reportTitles: ''])
}
Expand Down
47 changes: 9 additions & 38 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ ext {
//version (changing these should be considered thoroughly!)
javaVersion = JavaVersion.VERSION_17

scalaVersion = '2.13'
scalaBinaryVersion = '2.13.12'
scalaVersion = '3'
scalaBinaryVersion = '3.3.1'
pekkoVersion = '1.0.1'
jtsVersion = '1.19.0'
confluentKafkaVersion = '7.4.0'
tscfgVersion = '1.0.2'
scapegoatVersion = '2.1.3'

testContainerVersion = '0.41.0'

Expand Down Expand Up @@ -121,33 +120,29 @@ dependencies {

/* --- Scala libs --- */
/* CORE Scala */
implementation "org.scala-lang:scala-library:${scalaBinaryVersion}"
implementation "org.scala-lang:scala3-library_3:${scalaBinaryVersion}"

/* CORE Pekko */
implementation "org.apache.pekko:pekko-actor_${scalaVersion}:${pekkoVersion}"
implementation "org.apache.pekko:pekko-actor-typed_${scalaVersion}:${pekkoVersion}"
implementation "org.apache.pekko:pekko-slf4j_${scalaVersion}:${pekkoVersion}"
implementation "org.apache.pekko:pekko-connectors-csv_${scalaVersion}:${pekkoVersion}"
implementation "org.apache.pekko:pekko-actor_3:${pekkoVersion}"
implementation "org.apache.pekko:pekko-actor-typed_3:${pekkoVersion}"
implementation "org.apache.pekko:pekko-slf4j_3:${pekkoVersion}"
implementation "org.apache.pekko:pekko-connectors-csv_3:${pekkoVersion}"

/* config */
implementation 'com.typesafe:config:1.4.3'
implementation "com.github.carueda:tscfg_2.13:$tscfgVersion"
implementation "com.github.scopt:scopt_${scalaVersion}:4.1.0" // cmd args parser
implementation "com.github.scopt:scopt_3:4.1.0" // cmd args parser

// JTS
implementation ("org.locationtech.jts:jts-core:${jtsVersion}"){
exclude group: 'junit', module: 'junit'
}
implementation "org.locationtech.jts.io:jts-io-common:${jtsVersion}"

/* Scala compiler plugin for static code analysis */
implementation "com.sksamuel.scapegoat:scalac-scapegoat-plugin_${scalaBinaryVersion}:${scapegoatVersion}"
scalaCompilerPlugin "com.sksamuel.scapegoat:scalac-scapegoat-plugin_${scalaBinaryVersion}:${scapegoatVersion}"

/* Kafka */
implementation "org.apache.kafka:kafka-clients:${confluentKafkaVersion}-ccs"
implementation "io.confluent:kafka-streams-avro-serde:${confluentKafkaVersion}"
implementation "com.sksamuel.avro4s:avro4s-core_${scalaVersion}:4.1.1"
implementation "com.sksamuel.avro4s:avro4s-core_${scalaVersion}:5.0.6"

implementation 'org.apache.commons:commons-math3:3.6.1' // apache commons math3
implementation 'org.apache.poi:poi-ooxml:5.2.5' // used for FilenameUtils
Expand Down Expand Up @@ -185,30 +180,6 @@ shadowJar {
archiveBaseName.set('simona')
}



// scapegoat hook configuration
// https://github.com/sksamuel/scapegoat
// using compileScala instead of tasks.withType(ScalaCompile) prevents applying scapegoat to scala test classes
// see https://docs.gradle.org/current/userguide/scala_plugin.html#sec:configure_scala_classpath for details
tasks.withType(ScalaCompile) {
scalaCompileOptions.additionalParameters = [
"-Xplugin:" + configurations.scalaCompilerPlugin.asPath,
"-P:scapegoat:dataDir:" + buildDir + "/reports/scapegoat/src/",
"-P:scapegoat:disabledInspections:VariableShadowing",
"-P:scapegoat:ignoredFiles:.*/SimonaConfig.scala" // see scapegoat-sbt page for this param
]
}

// separate scapegoat report for test classes
compileTestScala {
scalaCompileOptions.additionalParameters = [
"-Xplugin:" + configurations.scalaCompilerPlugin.asPath,
"-P:scapegoat:dataDir:" + buildDir + "/reports/scapegoat/testsrc/",
"-P:scapegoat:disabledInspections:VariableShadowing"
]
}

task printVersion {
doLast {
println project.version
Expand Down
2 changes: 1 addition & 1 deletion gradle/scripts/scoverage.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

scoverage {
scoverageVersion = "2.0.11"
scoverageScalaVersion = scalaBinaryVersion
scoverageScalaVersion // defaults to the detected scala version
coverageOutputHTML = false
coverageOutputXML = true
coverageOutputCobertura = false
Expand Down
4 changes: 0 additions & 4 deletions gradle/scripts/sonarqube.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ sonarqube {
property 'sonar.junit.reportPaths', [
'build/test-results/test'] // Comma-delimited list of paths to Surefire XML-format reports.
// unit tests reports dirs
// scapegoat report dir
property "sonar.scala.scapegoat.reportPaths", [
"build/reports/scapegoat/src/scapegoat-scalastyle.xml",
"build/reports/scapegoat/testsrc/scapegoat-scalastyle.xml"] // Comma-delimited list of paths to Scapegoat reports in the Scalastyle format
// scala specific stuff
property 'sonar.scala.coverage.reportPaths', 'build/reports/scoverageTest/scoverage.xml'

Expand Down
2 changes: 1 addition & 1 deletion gradle/scripts/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spotless {

//sets a license header, removes unused imports and formats conforming to the scala fmt formatter
scala {
scalafmt()
scalafmt().configFile('scalafmt.conf')
licenseHeader ie3LicHead, "package.*\\n"
}

Expand Down
15 changes: 15 additions & 0 deletions scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version = 3.7.3
runner.dialect = scala3

rewrite.scala3.convertToNewSyntax = true
rewrite.scala3.removeOptionalBraces = false


rewrite.rules = [
AvoidInfix,
RedundantBraces,
RedundantParens,
SortModifiers,
PreferCurlyFors,
Imports
]
16 changes: 5 additions & 11 deletions src/main/scala/edu/ie3/simona/actor/SimonaActorNaming.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@ import org.apache.pekko.actor.{ActorRef, ActorRefFactory, Props}
import java.util.UUID

object SimonaActorNaming {

implicit class RichActorRefFactory(private val refFactory: ActorRefFactory)
extends AnyVal {

extension (refFactory: ActorRefFactory)
def simonaActorOf(props: Props, actorId: String): ActorRef =
refFactory.actorOf(props, actorName(props, actorId))

def simonaActorOf(props: Props): ActorRef =
refFactory.actorOf(props, actorName(props, simonaActorUuid))
}

/** Constructs a uuid and cuts it down to 6 digits for convenience. Although
* this is dangerous as duplicates might be possible, it should be sufficient
Expand Down Expand Up @@ -49,7 +44,7 @@ object SimonaActorNaming {
* @return
* the actor name based on simona conventions as string
*/
def actorName(clz: Class[_], actorId: String): String =
def actorName(clz: Class[?], actorId: String): String =
actorName(typeName(clz), actorId)

/** Constructs an actor name based on the simona convention for actor names.
Expand Down Expand Up @@ -82,10 +77,10 @@ object SimonaActorNaming {
* @return
* the type name
*/
def typeName(props: Props): String = {
def typeName(props: Props): String =
props.args.headOption
.flatMap {
case clz: Class[_] => Some(clz)
case clz: Class[?] => Some(clz)
case _ => None
}
.map(clz => typeName(clz))
Expand All @@ -94,14 +89,13 @@ object SimonaActorNaming {
s"Cannot derive actor class from props: $props"
)
)
}

/** Constructs the type name from given class.
*
* @return
* the type name
*/
def typeName(clz: Class[_]): String =
def typeName(clz: Class[?]): String =
clz.getSimpleName.replace("$", "")

/** Pekko prevents the usage of specific special characters as names. This
Expand Down
7 changes: 3 additions & 4 deletions src/main/scala/edu/ie3/simona/agent/SimonaAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ trait SimonaAgent[D]
stay()

case Event(CurrentState, _) =>
goto(stateName) replying stateName
goto(stateName).replying(stateName)

case event =>
log.error(s"Unhandled event '$event' from '${sender()}''")
stay()
}

def holdTick(tick: Long): Unit = {
if (_currentTick.isDefined)
if _currentTick.isDefined then
throw new IllegalStateException(
s"Expected both _currentTick to be 'None' but found ${_currentTick} instead, respectively."
)
Expand All @@ -68,13 +68,12 @@ trait SimonaAgent[D]
currentTick
}

def currentTick: Long = {
def currentTick: Long =
_currentTick.getOrElse(
throw new RuntimeException(
s"$actorName: CurrentTick has been requested, but is not set!"
)
)
}

def currentTickDefined: Boolean = _currentTick.isDefined

Expand Down
Loading

0 comments on commit ddda1db

Please sign in to comment.