Skip to content

Commit 27fa1d7

Browse files
committed
Merge remote-tracking branch 'origin/ms/#53-upgrate-to-scala3' into ms/ReCoDe
# Conflicts: # src/main/scala/edu/ie3/simona/config/RuntimeConfig.scala # src/main/scala/edu/ie3/simona/config/SimonaConfig.scala # src/main/scala/edu/ie3/simona/sim/setup/ExtSimSetupData.scala
2 parents b0ecf1c + 4884d2b commit 27fa1d7

File tree

77 files changed

+451
-393
lines changed

Some content is hidden

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

77 files changed

+451
-393
lines changed

.scalafmt.conf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
version = 3.8.1
2-
runner.dialect = scala213
2+
runner.dialect = scala3
3+
4+
rewrite.scala3.convertToNewSyntax = false
5+
rewrite.scala3.removeOptionalBraces = no
36

47
rewrite.trailingCommas.style = multiple
8+
9+
rewrite.rules = []

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## Updated
10+
- Upgraded `scala2` to `scala3` [#53](https://github.com/ie3-institute/simona/issues/53)
11+
12+
## [4.0.0] - 2025-05-09
13+
914
### Added
1015
- Add safety factor sRated calculation [#629](https://github.com/ie3-institute/simona/issues/629)
1116
- Re-implemented ResultEventListener in akka typed [#343](https://github.com/ie3-institute/simona/issues/343)

build.gradle

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,29 @@ ext {
2121
// version (changing these should be considered thoroughly!)
2222
javaVersion = JavaVersion.VERSION_17
2323

24-
scalaVersion = '2.13'
25-
scalaBinaryVersion = '2.13.16'
24+
scalaVersion = '3'
25+
scalaBinaryVersion = '3.7.0'
2626
pekkoVersion = '1.1.3'
2727
jtsVersion = '1.20.0'
2828
confluentKafkaVersion = '7.9.0'
29-
scapegoatVersion = '3.1.8'
29+
scapegoatVersion = '3.1.9'
3030

3131
junitVersion = '1.12.2'
3232
testContainerVersion = '0.43.0'
3333

3434
scriptsLocation = 'gradle' + File.separator + 'scripts' + File.separator // location of script plugins
35+
36+
scala3compilerOptions = [
37+
"-source:3.7-migration",
38+
"-print-tasty",
39+
"-feature",
40+
"-language:implicitConversions",
41+
"-language:existentials",
42+
"-Wunused:all",
43+
"-Xmax-inlines:128"
44+
//"-explain",
45+
//"-explain-types"
46+
]
3547
}
3648

3749
group = 'com.github.ie3-institute'
@@ -66,26 +78,26 @@ repositories {
6678
dependencies {
6779

6880
// ie³ internal repository
69-
implementation('com.github.ie3-institute:PowerSystemUtils:2.2.1') {
81+
implementation('com.github.ie3-institute:PowerSystemUtils:3.1.0') {
7082
exclude group: 'org.apache.logging.log4j'
7183
exclude group: 'org.slf4j'
7284
/* Exclude our own nested dependencies */
7385
exclude group: 'com.github.ie3-institute'
7486
}
75-
implementation('com.github.ie3-institute:PowerSystemDataModel:6.0.0') {
87+
implementation('com.github.ie3-institute:PowerSystemDataModel:7.0.0') {
7688
exclude group: 'org.apache.logging.log4j'
7789
exclude group: 'org.slf4j'
7890
/* Exclude our own nested dependencies */
7991
exclude group: 'com.github.ie3-institute'
8092
}
81-
implementation('com.github.ie3-institute:powerflow:0.2') {
93+
implementation('com.github.ie3-institute:powerflow:0.3.0') {
8294
exclude group: 'org.apache.logging.log4j'
8395
exclude group: 'org.slf4j'
8496
/* Exclude our own nested dependencies */
8597
exclude group: 'edu.ie3'
8698
}
8799

88-
implementation('com.github.ie3-institute:simonaAPI:0.8.0') {
100+
implementation('com.github.ie3-institute:simonaAPI:0.9.0') {
89101
exclude group: 'org.apache.logging.log4j'
90102
exclude group: 'org.slf4j'
91103
/* Exclude our own nested dependencies */
@@ -118,17 +130,18 @@ dependencies {
118130

119131
/* --- Scala libs --- */
120132
/* CORE Scala */
121-
implementation "org.scala-lang:scala-library:${scalaBinaryVersion}"
133+
implementation "org.scala-lang:scala3-library_3:${scalaBinaryVersion}"
122134

123135
/* CORE Pekko */
124-
implementation "org.apache.pekko:pekko-actor_${scalaVersion}:${pekkoVersion}"
125-
implementation "org.apache.pekko:pekko-actor-typed_${scalaVersion}:${pekkoVersion}"
126-
implementation "org.apache.pekko:pekko-slf4j_${scalaVersion}:${pekkoVersion}"
136+
implementation "org.apache.pekko:pekko-actor_3:${pekkoVersion}"
137+
implementation "org.apache.pekko:pekko-actor-typed_3:${pekkoVersion}"
138+
implementation "org.apache.pekko:pekko-slf4j_3:${pekkoVersion}"
127139

128140
/* config */
129141
implementation 'com.typesafe:config:1.4.3'
130142
implementation "com.github.scopt:scopt_${scalaVersion}:4.1.0" // cmd args parser
131-
implementation "com.github.pureconfig:pureconfig_${scalaVersion}:0.17.9"
143+
implementation "com.github.pureconfig:pureconfig-core_${scalaVersion}:0.17.9"
144+
implementation "com.github.pureconfig:pureconfig-generic-scala3_${scalaVersion}:0.17.9"
132145

133146
// JTS
134147
implementation ("org.locationtech.jts:jts-core:${jtsVersion}") {
@@ -143,7 +156,7 @@ dependencies {
143156
/* Kafka */
144157
implementation "org.apache.kafka:kafka-clients:${confluentKafkaVersion}-ccs"
145158
implementation "io.confluent:kafka-streams-avro-serde:${confluentKafkaVersion}"
146-
implementation "com.sksamuel.avro4s:avro4s-core_${scalaVersion}:4.1.2"
159+
implementation "com.sksamuel.avro4s:avro4s-core_${scalaVersion}:5.0.14"
147160

148161
implementation 'org.apache.commons:commons-math3:3.6.1' // apache commons math3
149162
implementation 'org.apache.poi:poi-ooxml:5.4.1' // used for FilenameUtils
@@ -153,6 +166,9 @@ dependencies {
153166
implementation 'org.apache.commons:commons-csv:1.14.0'
154167
implementation "org.scalanlp:breeze_${scalaVersion}:2.1.0" // scientific calculations (http://www.scalanlp.org/)
155168
implementation 'org.jgrapht:jgrapht-core:1.5.2'
169+
170+
// needed, because scala won't compile otherwise
171+
implementation 'org.influxdb:influxdb-java:2.24'
156172
}
157173

158174
tasks.withType(JavaCompile).configureEach {
@@ -190,7 +206,7 @@ shadowJar {
190206
// using compileScala instead of tasks.withType(ScalaCompile) prevents applying scapegoat to scala test classes
191207
// see https://docs.gradle.org/current/userguide/scala_plugin.html#sec:configure_scala_classpath for details
192208
tasks.withType(ScalaCompile).configureEach {
193-
scalaCompileOptions.additionalParameters = [
209+
scalaCompileOptions.additionalParameters = scala3compilerOptions + [
194210
"-Xplugin:" + configurations.scalaCompilerPlugin.asPath,
195211
"-P:scapegoat:dataDir:" + project.layout.buildDirectory.get().asFile.absolutePath + "/reports/scapegoat/src/",
196212
"-P:scapegoat:disabledInspections:TryGet"
@@ -203,7 +219,7 @@ tasks.withType(ScalaCompile).configureEach {
203219

204220
// separate scapegoat report for test classes
205221
compileTestScala {
206-
scalaCompileOptions.additionalParameters = [
222+
scalaCompileOptions.additionalParameters = scala3compilerOptions + [
207223
"-Xplugin:" + configurations.scalaCompilerPlugin.asPath,
208224
"-P:scapegoat:dataDir:" + project.layout.buildDirectory.get().asFile.absolutePath + "/reports/scapegoat/testsrc/",
209225
"-P:scapegoat:disabledInspections:TryGet"

gradle/scripts/scoverage.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
scoverage {
66
scoverageVersion = "2.3.0"
7-
scoverageScalaVersion = scalaBinaryVersion
7+
scoverageScalaVersion //= scalaBinaryVersion
88
coverageOutputHTML = false
99
coverageOutputXML = true
1010
coverageOutputCobertura = false

src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import edu.ie3.simona.ontology.messages.{Activation, SchedulerMessage}
2828
import edu.ie3.simona.service.Data.PrimaryData.ComplexPower
2929
import edu.ie3.simona.service.em.ExtEmDataService
3030
import edu.ie3.simona.util.TickUtil.TickLong
31-
import edu.ie3.util.quantities.QuantityUtils.RichQuantityDouble
31+
import edu.ie3.util.quantities.QuantityUtils._
3232
import edu.ie3.util.scala.quantities.DefaultQuantities._
3333
import org.apache.pekko.actor.typed.scaladsl.Behaviors
3434
import org.apache.pekko.actor.typed.{ActorRef, Behavior}

src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ object EmDataCore {
5555
* @param lastActiveTick
5656
* The last active tick, if applicable
5757
*/
58-
final case class Inactive private (
58+
final case class Inactive(
5959
private val modelToActor: Map[UUID, Actor],
6060
private val activationQueue: PriorityMultiBiSet[Long, UUID],
6161
private val flexWithNext: Set[UUID],

src/main/scala/edu/ie3/simona/agent/grid/GridAgentData.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object GridAgentData {
4343
* @param activationAdapter
4444
* adapter for [[Activation]]
4545
*/
46-
final case class GridAgentConstantData private (
46+
final case class GridAgentConstantData(
4747
environmentRefs: EnvironmentRefs,
4848
simonaConfig: SimonaConfig,
4949
listener: Iterable[ActorRef[ResultEvent]],
@@ -97,7 +97,7 @@ object GridAgentData {
9797
* Set of subgrid numbers of [[GridAgent]]s that don't have their request
9898
* answered, yet
9999
*/
100-
final case class PowerFlowDoneData private (
100+
final case class PowerFlowDoneData(
101101
gridAgentBaseData: GridAgentBaseData,
102102
powerFlowResult: PowerFlowResult,
103103
pendingRequestAnswers: Set[Int],
@@ -210,7 +210,7 @@ object GridAgentData {
210210
* @param sweepValueStores
211211
* a value store for sweep results
212212
*/
213-
final case class GridAgentBaseData private (
213+
final case class GridAgentBaseData(
214214
gridEnv: GridEnvironment,
215215
powerFlowParams: PowerFlowParams,
216216
currentSweepNo: Int,

src/main/scala/edu/ie3/simona/agent/grid/GridAgentMessages.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import edu.ie3.simona.agent.grid.GridAgentMessages.Responses.{
1111
ExchangePower,
1212
ExchangeVoltage,
1313
}
14+
import edu.ie3.simona.agent.participant.ParticipantAgent
1415
import edu.ie3.simona.ontology.messages.Activation
1516
import edu.ie3.simona.scheduler.ScheduleLock.ScheduleKey
1617
import edu.ie3.util.scala.quantities.ReactivePower
@@ -95,7 +96,7 @@ object GridAgentMessages {
9596
(ActorRef[GridAgent.Request], SlackVoltageResponse)
9697

9798
sealed trait ReceivedPowerValues extends ReceivedValues {
98-
def values: Vector[PowerRequestResponse[_]]
99+
def values: Vector[(ActorRef[_], PowerResponse)]
99100
}
100101

101102
/** Wrapper for received asset power values (p, q)
@@ -104,7 +105,7 @@ object GridAgentMessages {
104105
* the asset power values and their senders
105106
*/
106107
final case class ReceivedAssetPowerValues(
107-
values: Vector[PowerRequestResponse[_]]
108+
values: Vector[PowerRequestResponse[ParticipantAgent.Request]]
108109
) extends ReceivedPowerValues
109110

110111
/** Wrapper for received grid power values (p, q)
@@ -169,7 +170,7 @@ object GridAgentMessages {
169170
/** Indicate that the power flow calculation failed, as a reply to a
170171
* [[RequestGridPower]].
171172
*/
172-
final case object FailedPowerFlow extends PowerResponse
173+
case object FailedPowerFlow extends PowerResponse
173174

174175
/** Provide power values as a reply to a
175176
* [[edu.ie3.simona.agent.participant.ParticipantAgent.RequestAssetPowerMessage]]

src/main/scala/edu/ie3/simona/agent/grid/ReceivedValuesStore.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import java.util.UUID
4040
* mapping of node uuids to received slack voltages from superior
4141
* [[GridAgent]] s if any
4242
*/
43-
final case class ReceivedValuesStore private (
43+
final case class ReceivedValuesStore(
4444
nodeToReceivedPower: NodeToReceivedPower,
4545
nodeToReceivedSlackVoltage: NodeToReceivedSlackVoltage,
4646
)
@@ -105,7 +105,9 @@ object ReceivedValuesStore {
105105
/* Collect everything, that I expect from my asset agents */
106106
val assetsToReceivedPower: NodeToReceivedPower = nodeToAssetAgents.collect {
107107
case (uuid: UUID, actorRefs: Set[ActorRef[ParticipantAgent.Request]]) =>
108-
(uuid, actorRefs.map(actorRef => actorRef -> None).toMap)
108+
val map: Map[ActorRef[?], Option[PowerResponse]] =
109+
actorRefs.map(actorRef => actorRef -> None).toMap
110+
(uuid, map)
109111
}
110112

111113
/* Add everything, that I expect from my subordinate grid agents. */

src/main/scala/edu/ie3/simona/agent/grid/SweepValueStore.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ case object SweepValueStore {
3434
* @param nodeUuid
3535
* node uuid of the sweep data
3636
*/
37-
final case class SweepValueStoreData private (
37+
final case class SweepValueStoreData(
3838
nodeUuid: UUID,
3939
stateData: StateData,
4040
)

src/main/scala/edu/ie3/simona/agent/participant/ParticipantAgent.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import org.apache.pekko.actor.typed.scaladsl.Behaviors
2626
import org.apache.pekko.actor.typed.{ActorRef, Behavior}
2727
import squants.{Dimensionless, Each}
2828

29-
import scala.reflect.ClassTag
30-
3129
/** Agent that represents and acts on behalf of any system participant model,
3230
* which is defined as a subclass of
3331
* [[edu.ie3.simona.model.participant.ParticipantModel]].
@@ -87,9 +85,7 @@ object ParticipantAgent {
8785
* @tparam P
8886
* The type of primary data to be received.
8987
*/
90-
final case class PrimaryRegistrationSuccessfulMessage[
91-
P <: PrimaryData: ClassTag
92-
](
88+
final case class PrimaryRegistrationSuccessfulMessage[P <: PrimaryData](
9389
override val serviceRef: ActorRef[_ >: ServiceMessage],
9490
firstDataTick: Long,
9591
primaryDataExtra: PrimaryDataExtra[P],

src/main/scala/edu/ie3/simona/agent/participant/ParticipantGridAdapter.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ final case class ParticipantGridAdapter(
5252
private val expectedRequestTick: Long,
5353
private val tickToPower: SortedMap[Long, ComplexPower],
5454
avgPowerResult: Option[AvgPowerResult],
55-
private implicit val requestVoltageDeviationTolerance: Dimensionless,
56-
) {
55+
)(private implicit val requestVoltageDeviationTolerance: Dimensionless) {
5756

5857
/** Whether a power request is expected and has not yet arrived, thus is
5958
* awaited, for the given tick.
@@ -206,7 +205,8 @@ object ParticipantGridAdapter {
206205
expectedRequestTick = expectedRequestTick,
207206
tickToPower = SortedMap.empty,
208207
avgPowerResult = None,
209-
requestVoltageDeviationTolerance = requestVoltageDeviationTolerance,
208+
)(
209+
requestVoltageDeviationTolerance = requestVoltageDeviationTolerance
210210
)
211211

212212
private def reduceTickToPowerMap(

src/main/scala/edu/ie3/simona/config/ArgsParser.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ object ArgsParser extends LazyLogging {
107107

108108
val argsConfig =
109109
ConfigFactory.parseString(
110-
s"""config = "${parsedArgs.configLocation.get.replace("\\", "\\\\")}""""
110+
s"""config = "${parsedArgs.configLocation
111+
.getOrElse("")
112+
.replace("\\", "\\\\")}""""
111113
)
112114

113115
// note: this overrides the default config values provided in the config file!

src/main/scala/edu/ie3/simona/config/ConfigFailFast.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,10 @@ object ConfigFailFast extends LazyLogging {
625625
checkCouchbaseParams(params)
626626
case Some(BaseInfluxDb1xParams(database, _, url)) =>
627627
checkInfluxDb1xParams("WeatherSource", url, database)
628-
case Some(params: SqlParams) =>
629-
checkSqlParams(params)
628+
case Some(
629+
BaseSqlParams(jdbcUrl, password, schemaName, tableName, userName)
630+
) =>
631+
checkSqlParams(jdbcUrl, password, schemaName, tableName, userName)
630632
case Some(_: SampleParams) =>
631633
// sample weather, no check required
632634
// coordinate source must be sample coordinate source
@@ -685,8 +687,16 @@ object ConfigFailFast extends LazyLogging {
685687
}
686688

687689
"csv"
688-
case Some(sqlParams: SqlParams) =>
689-
checkSqlParams(sqlParams)
690+
case Some(
691+
BaseSqlParams(
692+
jdbcUrl,
693+
password,
694+
schemaName,
695+
tableName,
696+
userName,
697+
)
698+
) =>
699+
checkSqlParams(jdbcUrl, password, schemaName, tableName, userName)
690700
"sql"
691701
case Some(_: SampleParams) =>
692702
"sample"

0 commit comments

Comments
 (0)