Skip to content

Commit 3ed51b0

Browse files
Merge pull request #314 from ie3-institute/ms/#313-updating-to-scala3
Updated to `scala3`
2 parents 3b400dd + 8edee59 commit 3ed51b0

Some content is hidden

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

51 files changed

+174
-181
lines changed

.scalafmt.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version = 3.8.1
2+
runner.dialect = scala3
3+
4+
rewrite.scala3.convertToNewSyntax = true
5+
rewrite.scala3.removeOptionalBraces = no
6+
7+
rewrite.rules = []

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Fixed Version Check logic for Dependabot PRs [#330](https://github.com/ie3-institute/simBench2psdm/issues/330)
1717
- Removed Jenkins Pipeline. Now using GitHub Actions [#328](https://github.com/ie3-institute/simBench2psdm/issues/328)
1818
- Switch to Java 21 [#343](https://github.com/ie3-institute/simBench2psdm/issues/343)
19+
- Updated to `scala3` [#313](https://github.com/ie3-institute/simBench2psdm/issues/313)
1920

2021
## [1.0.0] - 2021-08-03
2122
### Added

build.gradle

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ ext {
1717
//version (changing these should be considered thoroughly!)
1818
javaVersion = JavaVersion.VERSION_21
1919

20-
scalaVersion = '2.13'
21-
scalaBinaryVersion = '2.13.18'
20+
scalaVersion = '3'
21+
scalaBinaryVersion = '3.7.0'
2222
tscfgVersion = '1.2.5'
2323
slf4jVersion = '2.0.17'
2424

@@ -27,7 +27,7 @@ ext {
2727

2828
group = 'com.github.ie3-institute'
2929
description = 'simbench2psdm'
30-
java {
30+
java{
3131
sourceCompatibility = javaVersion
3232
targetCompatibility = javaVersion
3333
}
@@ -43,10 +43,10 @@ apply from: scriptsLocation + 'mavenCentralPublish.gradle'
4343

4444
repositories {
4545
mavenCentral()
46-
maven { url 'https://www.jitpack.io' } // allows github repos as dependencies
46+
maven { url = 'https://www.jitpack.io' } // allows github repos as dependencies
4747

4848
// sonatype snapshots repo // todo remove
49-
maven { url 'https://oss.sonatype.org/service/local/repositories/snapshots/content' }
49+
maven { url = 'https://oss.sonatype.org/service/local/repositories/snapshots/content' }
5050
}
5151

5252
dependencies {
@@ -59,7 +59,7 @@ dependencies {
5959
}
6060

6161
/* util functions */
62-
implementation('com.github.ie3-institute:PowerSystemUtils:2.2.1') {
62+
implementation('com.github.ie3-institute:PowerSystemUtils:3.1.0') {
6363
exclude group: 'org.apache.logging.log4j'
6464
exclude group: 'org.slf4j'
6565
/* Exclude our own nested dependencies */
@@ -82,8 +82,8 @@ dependencies {
8282

8383
// NEW scala libs //
8484
// CORE Scala //
85-
implementation "org.scala-lang:scala-library:$scalaBinaryVersion"
86-
implementation 'org.scala-lang.modules:scala-parallel-collections_2.13:1.2.0'
85+
implementation "org.scala-lang:scala3-library_3:$scalaBinaryVersion"
86+
implementation "org.scala-lang.modules:scala-parallel-collections_$scalaVersion:1.2.0"
8787

8888
// TEST Scala //
8989
testImplementation "org.scalatest:scalatest_${scalaVersion}:3.2.19"
@@ -93,7 +93,7 @@ dependencies {
9393

9494
// config //
9595
implementation 'com.typesafe:config:+'
96-
implementation "com.github.carueda:tscfg_2.13:${tscfgVersion}"
96+
implementation "com.github.carueda:tscfg_$scalaVersion:${tscfgVersion}"
9797

9898
// cmd args parser //
9999
implementation "com.github.scopt:scopt_${scalaVersion}:+"

gradle/scripts/scoverage.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
scoverage {
66
scoverageVersion = "2.4.2"
7-
scoverageScalaVersion = scalaBinaryVersion
87
coverageOutputHTML = false
98
coverageOutputXML = true
109
coverageOutputCobertura = false

gradle/scripts/spotless.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spotless {
1414

1515
//sets a license header, removes unused imports and formats conforming to the scala fmt formatter
1616
scala {
17-
scalafmt()
17+
scalafmt().configFile('.scalafmt.conf')
1818
}
1919

2020
/* cf. https://github.com/diffplug/spotless/tree/master/plugin-gradle */

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package edu.ie3.simbench.config
33
import java.io.File
44
import java.nio.file.Paths
55

6-
import com.typesafe.config.{ConfigFactory, Config => TypesafeConfig}
7-
import scopt.{OptionParser => scoptOptionParser}
6+
import com.typesafe.config.{ConfigFactory, Config as TypesafeConfig}
7+
import scopt.OptionParser as scoptOptionParser
88

99
object ArgsParser {
1010
// case class for allowed arguments
@@ -24,11 +24,11 @@ object ArgsParser {
2424
)
2525
})
2626
.validate(value =>
27-
if (value.trim.isEmpty) failure("config location cannot be empty")
27+
if value.trim.isEmpty then failure("config location cannot be empty")
2828
else success
2929
)
3030
.validate(value =>
31-
if (value.contains("\\"))
31+
if value.contains("\\") then
3232
failure("wrong config path, expected: /, found: \\")
3333
else success
3434
)
@@ -48,7 +48,7 @@ object ArgsParser {
4848

4949
private def parseTypesafeConfig(fileName: String): TypesafeConfig = {
5050
val file = Paths.get(fileName).toFile
51-
if (!file.exists())
51+
if !file.exists() then
5252
throw new Exception(s"Missing config file on path $fileName")
5353
parseTypesafeConfig(file)
5454
}

src/main/scala/edu/ie3/simbench/config/ConfigValidator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ case object ConfigValidator {
4747
*/
4848
@throws[CodeValidationException]
4949
private def checkSimbenchCodes(codes: List[java.lang.String]): Unit = {
50-
for (code <- codes) {
50+
for code <- codes do {
5151
SimbenchCode.isValid(code) match {
5252
case Success(_) =>
5353
case Failure(exception) => throw exception

src/main/scala/edu/ie3/simbench/config/SimbenchConfig.scala

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ object SimbenchConfig {
2626
"directoryHierarchy"
2727
),
2828
fileEncoding =
29-
if (c.hasPathOrNull("fileEncoding")) c.getString("fileEncoding")
29+
if c.hasPathOrNull("fileEncoding") then c.getString("fileEncoding")
3030
else "UTF-8",
3131
fileEnding =
32-
if (c.hasPathOrNull("fileEnding")) c.getString("fileEnding")
32+
if c.hasPathOrNull("fileEnding") then c.getString("fileEnding")
3333
else ".csv",
3434
separator =
35-
if (c.hasPathOrNull("separator")) c.getString("separator") else ";"
35+
if c.hasPathOrNull("separator") then c.getString("separator") else ";"
3636
)
3737
}
3838
}
@@ -78,14 +78,14 @@ object SimbenchConfig {
7878
): SimbenchConfig.Io.Input.Download = {
7979
SimbenchConfig.Io.Input.Download(
8080
baseUrl =
81-
if (c.hasPathOrNull("baseUrl")) c.getString("baseUrl")
81+
if c.hasPathOrNull("baseUrl") then c.getString("baseUrl")
8282
else "https://daks.uni-kassel.de/bitstreams",
8383
failOnExistingFiles =
8484
c.hasPathOrNull("failOnExistingFiles") && c.getBoolean(
8585
"failOnExistingFiles"
8686
),
8787
directory =
88-
if (c.hasPathOrNull("folder")) c.getString("folder")
88+
if c.hasPathOrNull("folder") then c.getString("folder")
8989
else "inputData/download/"
9090
)
9191
}
@@ -98,13 +98,13 @@ object SimbenchConfig {
9898
): SimbenchConfig.Io.Input = {
9999
SimbenchConfig.Io.Input(
100100
csv = SimbenchConfig.CsvConfig(
101-
if (c.hasPathOrNull("csv")) c.getConfig("csv")
101+
if c.hasPathOrNull("csv") then c.getConfig("csv")
102102
else com.typesafe.config.ConfigFactory.parseString("csv{}"),
103103
parentPath + "csv.",
104104
$tsCfgValidator
105105
),
106106
download = SimbenchConfig.Io.Input.Download(
107-
if (c.hasPathOrNull("download")) c.getConfig("download")
107+
if c.hasPathOrNull("download") then c.getConfig("download")
108108
else com.typesafe.config.ConfigFactory.parseString("download{}"),
109109
parentPath + "download.",
110110
$tsCfgValidator
@@ -127,13 +127,13 @@ object SimbenchConfig {
127127
SimbenchConfig.Io.Output(
128128
compress = !c.hasPathOrNull("compress") || c.getBoolean("compress"),
129129
csv = SimbenchConfig.CsvConfig(
130-
if (c.hasPathOrNull("csv")) c.getConfig("csv")
130+
if c.hasPathOrNull("csv") then c.getConfig("csv")
131131
else com.typesafe.config.ConfigFactory.parseString("csv{}"),
132132
parentPath + "csv.",
133133
$tsCfgValidator
134134
),
135135
targetDir =
136-
if (c.hasPathOrNull("targetFolder")) c.getString("targetFolder")
136+
if c.hasPathOrNull("targetFolder") then c.getString("targetFolder")
137137
else "convertedData"
138138
)
139139
}
@@ -146,13 +146,13 @@ object SimbenchConfig {
146146
): SimbenchConfig.Io = {
147147
SimbenchConfig.Io(
148148
input = SimbenchConfig.Io.Input(
149-
if (c.hasPathOrNull("input")) c.getConfig("input")
149+
if c.hasPathOrNull("input") then c.getConfig("input")
150150
else com.typesafe.config.ConfigFactory.parseString("input{}"),
151151
parentPath + "input.",
152152
$tsCfgValidator
153153
),
154154
output = SimbenchConfig.Io.Output(
155-
if (c.hasPathOrNull("output")) c.getConfig("output")
155+
if c.hasPathOrNull("output") then c.getConfig("output")
156156
else com.typesafe.config.ConfigFactory.parseString("output{}"),
157157
parentPath + "output.",
158158
$tsCfgValidator
@@ -168,13 +168,13 @@ object SimbenchConfig {
168168
val parentPath: java.lang.String = ""
169169
val $result = SimbenchConfig(
170170
conversion = SimbenchConfig.Conversion(
171-
if (c.hasPathOrNull("conversion")) c.getConfig("conversion")
171+
if c.hasPathOrNull("conversion") then c.getConfig("conversion")
172172
else com.typesafe.config.ConfigFactory.parseString("conversion{}"),
173173
parentPath + "conversion.",
174174
$tsCfgValidator
175175
),
176176
io = SimbenchConfig.Io(
177-
if (c.hasPathOrNull("io")) c.getConfig("io")
177+
if c.hasPathOrNull("io") then c.getConfig("io")
178178
else com.typesafe.config.ConfigFactory.parseString("io{}"),
179179
parentPath + "io.",
180180
$tsCfgValidator
@@ -189,7 +189,7 @@ object SimbenchConfig {
189189
parentPath: java.lang.String,
190190
$tsCfgValidator: $TsCfgValidator
191191
): scala.List[java.lang.String] = {
192-
import scala.jdk.CollectionConverters._
192+
import scala.jdk.CollectionConverters.*
193193
cl.asScala.map(cv => $_str(cv)).toList
194194
}
195195
private def $_expE(
@@ -200,15 +200,15 @@ object SimbenchConfig {
200200
new java.lang.RuntimeException(
201201
s"${cv.origin.lineNumber}: " +
202202
"expecting: " + exp + " got: " +
203-
(if (u.isInstanceOf[java.lang.String]) "\"" + u + "\"" else u)
203+
(if u.isInstanceOf[java.lang.String] then "\"" + u + "\"" else u)
204204
)
205205
}
206206

207207
private def $_str(cv: com.typesafe.config.ConfigValue): java.lang.String = {
208208
java.lang.String.valueOf(cv.unwrapped())
209209
}
210210

211-
private final class $TsCfgValidator {
211+
final class $TsCfgValidator {
212212
private val badPaths =
213213
scala.collection.mutable.ArrayBuffer[java.lang.String]()
214214

@@ -228,7 +228,7 @@ object SimbenchConfig {
228228
}
229229

230230
def validate(): Unit = {
231-
if (badPaths.nonEmpty) {
231+
if badPaths.nonEmpty then {
232232
throw new com.typesafe.config.ConfigException(
233233
badPaths.mkString("Invalid configuration:\n ", "\n ", "")
234234
) {}

src/main/scala/edu/ie3/simbench/convert/CoordinateConverter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package edu.ie3.simbench.convert
33
import edu.ie3.datamodel.models.input.NodeInput
44
import edu.ie3.simbench.model.datamodel.Coordinate
55
import edu.ie3.util.geo.GeoUtils
6-
import org.locationtech.jts.geom.{Point, Coordinate => JTSCoordinate}
6+
import org.locationtech.jts.geom.{Point, Coordinate as JTSCoordinate}
77

88
/** Converts a SimBench coordinate to the needed geometry position of
99
* PowerSystemDataModel

src/main/scala/edu/ie3/simbench/convert/GridConverter.scala

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import edu.ie3.datamodel.models.input.graphics.{
2020
LineGraphicInput,
2121
NodeGraphicInput
2222
}
23-
import edu.ie3.datamodel.models.input.system._
23+
import edu.ie3.datamodel.models.input.system.*
2424
import edu.ie3.datamodel.models.result.NodeResult
2525
import edu.ie3.datamodel.models.timeseries.individual.IndividualTimeSeries
2626
import edu.ie3.datamodel.models.value.{PValue, SValue}
@@ -33,11 +33,11 @@ import edu.ie3.simbench.convert.types.{
3333
Transformer2wTypeConverter
3434
}
3535
import edu.ie3.simbench.exception.ConversionException
36-
import edu.ie3.simbench.model.datamodel._
36+
import edu.ie3.simbench.model.datamodel.*
3737

3838
import scala.annotation.tailrec
39-
import scala.collection.parallel.CollectionConverters._
40-
import scala.jdk.CollectionConverters._
39+
import scala.collection.parallel.CollectionConverters.*
40+
import scala.jdk.CollectionConverters.*
4141

4242
case object GridConverter extends LazyLogging {
4343

@@ -61,7 +61,7 @@ case object GridConverter extends LazyLogging {
6161
removeSwitches: Boolean
6262
): (
6363
JointGridContainer,
64-
Set[IndividualTimeSeries[_ <: PValue]],
64+
Set[IndividualTimeSeries[? <: PValue]],
6565
Seq[MappingEntry],
6666
Vector[NodeResult]
6767
) = {
@@ -130,11 +130,10 @@ case object GridConverter extends LazyLogging {
130130
gridInput.lines,
131131
subnetConverter
132132
)
133-
val joinOverrides = if (removeSwitches) {
133+
val joinOverrides = if removeSwitches then {
134134
/* If switches are meant to be removed, join all nodes at closed switches */
135135
determineJoinOverrides(gridInput.switches, slackNodeKeys)
136-
} else
137-
Vector.empty
136+
} else Vector.empty
138137

139138
val nodeConversion =
140139
convertNodes(
@@ -156,10 +155,9 @@ case object GridConverter extends LazyLogging {
156155
"Creation of three winding transformers is not yet implemented."
157156
)
158157
val switches =
159-
if (!removeSwitches)
158+
if !removeSwitches then
160159
SwitchConverter.convert(gridInput.switches, nodeConversion).toSet.asJava
161-
else
162-
Set.empty[SwitchInput].asJava
160+
else Set.empty[SwitchInput].asJava
163161
val measurements = MeasurementConverter
164162
.convert(gridInput.measurements, nodeConversion)
165163
.toSet
@@ -284,8 +282,7 @@ case object GridConverter extends LazyLogging {
284282
): Vector[SubnetOverride] = {
285283
/* If the start node is among the junctions, do not travel further (Attention: Start node should not be among
286284
* junctions when the traversing starts, otherwise nothing will happen at all.) */
287-
if (junctions.contains(startNode))
288-
return overrides
285+
if junctions.contains(startNode) then return overrides
289286

290287
/* Get all switches, that are connected to the current starting point. If the other end of the switch is a junction,
291288
* don't follow this path, as the other side wouldn't be touched anyways. */
@@ -297,7 +294,7 @@ case object GridConverter extends LazyLogging {
297294
case _ => false
298295
}
299296

300-
if (nextSwitches.isEmpty) {
297+
if nextSwitches.isEmpty then {
301298
/* There is no further switch, therefore the end is reached -> return the new mapping. Please note, as the subnet
302299
* of the current node is only altered, if there is a next switch available, dead end nodes are not altered. */
303300
overrides
@@ -585,7 +582,7 @@ case object GridConverter extends LazyLogging {
585582
branchNodes.contains(convertedNode)
586583
} match {
587584
case (connectedNodes, unconnectedNodes) =>
588-
if (unconnectedNodes.nonEmpty)
585+
if unconnectedNodes.nonEmpty then
589586
logger.warn(
590587
"The nodes with following keys are not part of any branch (aka. isolated) and will be neglected in the sequel.\n\t{}",
591588
unconnectedNodes.map(_._1.getKey).mkString("\n\t")
@@ -610,7 +607,7 @@ case object GridConverter extends LazyLogging {
610607
nodeConversion: Map[Node, NodeInput]
611608
): (
612609
SystemParticipants,
613-
Set[IndividualTimeSeries[_ <: PValue]],
610+
Set[IndividualTimeSeries[? <: PValue]],
614611
Seq[MappingEntry]
615612
) = {
616613
/* Convert all participant groups */
@@ -640,7 +637,7 @@ case object GridConverter extends LazyLogging {
640637
timeSeries.getUuid
641638
)
642639
}.toSeq
643-
val timeSeries: Set[IndividualTimeSeries[_ <: PValue]] =
640+
val timeSeries: Set[IndividualTimeSeries[? <: PValue]] =
644641
participantsToTimeSeries.map(_._2).toSet
645642

646643
(

0 commit comments

Comments
 (0)