Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Prepare Scala 3 compatibility by adding -Xsource:3 compiler flag #2924

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version = "3.7.15"
runner.dialect = scala213
runner.dialect = Scala213Source3
maxColumn = 120
align.preset = most
align.multiline = false
Expand Down
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import com.typesafe.sbt.SbtNativePackager.autoImport.NativePackagerHelper.*
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.{Docker, dockerRepository}
import com.typesafe.sbt.packager.docker.{Cmd, ExecCmd}
import org.knora.Dependencies
import sbt.Keys.version
import sbt.*
import sys.process.*
import sbt.Keys.version

import scala.language.postfixOps
import scala.sys.process.*

//////////////////////////////////////
// GLOBAL SETTINGS
Expand Down Expand Up @@ -177,6 +177,8 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
)
.settings(
scalacOptions ++= Seq(
"-Xsource:3",
"-Wconf:msg=constructor modifiers are assumed:s",
"-feature",
"-unchecked",
"-deprecation",
Expand Down
4 changes: 3 additions & 1 deletion integration/src/test/scala/org/knora/sipi/SipiIT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ object MockDspApiServer {
}

def resetAndGetWireMockServer: URIO[WireMockServer, WireMockServer] =
ZIO.serviceWith[WireMockServer] { it => it.resetAll(); it }
ZIO.serviceWith[WireMockServer] { it =>
it.resetAll(); it
}

def resetAndStubGetResponse(url: String, status: Int): URIO[WireMockServer, WireMockServer] =
resetAndGetWireMockServer.tap(server => ZIO.succeed(stubGetJsonResponse(server, url, status)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class CardinalitiesSpec extends CoreSpec {
_.isPropertyUsedInResources(internalClassIri, internalPropertyIri)
)
)
resF map { res => println(res); assert(res, "property is used in resource (instance of that resource class)") }
resF map { res =>
println(res); assert(res, "property is used in resource (instance of that resource class)")
}
}

"detect that property is not in use, when not used in a resource" in {
Expand Down Expand Up @@ -81,7 +83,9 @@ class CardinalitiesSpec extends CoreSpec {
_.isPropertyUsedInResources(internalClassIri, internalPropertyIri)
)
)
resF map { res => println(res); assert(res, "property is used in resource (instance of resource class)") }
resF map { res =>
println(res); assert(res, "property is used in resource (instance of resource class)")
}
}

"detect that property is in use, when used in a resource of a subclass" in {
Expand All @@ -93,7 +97,9 @@ class CardinalitiesSpec extends CoreSpec {
UnsafeZioRun.runToFuture(
ZIO.serviceWithZIO[CardinalityHandler](_.isPropertyUsedInResources(internalClassIri, internalPropertyIri))
)
resF map { res => println(res); assert(res, "property is used in a resource of subclass") }
resF map { res =>
println(res); assert(res, "property is used in a resource of subclass")
}
}
}
}
2 changes: 1 addition & 1 deletion webapi/src/main/scala/dsp/constants/SalsahGui.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package dsp.constants

import dsp.errors._
import dsp.errors.*

/**
* Contains string constants for IRIs from ontologies used by the application.
Expand Down
6 changes: 2 additions & 4 deletions webapi/src/main/scala/dsp/valueobjects/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ package dsp.valueobjects
import com.google.gwt.safehtml.shared.UriUtils.encodeAllowEscapes
import zio.prelude.ZValidation.Failure
import zio.prelude.ZValidation.Success
import zio.prelude._

import scala.collection.immutable.List
import zio.prelude.*

import dsp.constants.SalsahGui
import dsp.errors.ValidationException
Expand Down Expand Up @@ -278,7 +276,7 @@ object Schema {
case Some(valueType) if valueType.toString() == "iri" => {
val iriWithoutBrackets: Option[String] =
if (value.startsWith("<") && value.endsWith(">")) Some(value.substring(1, value.length - 1)) else None
iriWithoutBrackets.map { valueWithoutBrackets: String =>
iriWithoutBrackets.map { valueWithoutBrackets =>
if (Iri.urlValidator.isValid(encodeAllowEscapes(valueWithoutBrackets))) value else None
}
}
Expand Down
4 changes: 2 additions & 2 deletions webapi/src/main/scala/dsp/valueobjects/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package dsp.valueobjects

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder
import zio._
import zio.*
import zio.config.magnolia.Descriptor
import zio.json.JsonCodec
import zio.json.JsonDecoder
import zio.json.JsonEncoder
import zio.prelude.Assertion._
import zio.prelude.Assertion.*
import zio.prelude.Subtype
import zio.prelude.Validation

Expand Down
2 changes: 1 addition & 1 deletion webapi/src/main/scala/dsp/valueobjects/V2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package dsp.valueobjects

import zio.json._
import zio.json.*

object V2 {

Expand Down
6 changes: 3 additions & 3 deletions webapi/src/main/scala/org/knora/webapi/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

package org.knora.webapi

import zio._
import zio.*

import org.knora.webapi.core._
import org.knora.webapi.core.*
import org.knora.webapi.slice.infrastructure.MetricsServer
import org.knora.webapi.util.Logger

Expand All @@ -30,6 +30,6 @@
/**
* Entrypoint of our Application
*/
override def run: ZIO[Environment with ZIOAppArgs with Scope, Any, Any] =
override def run: ZIO[Environment & ZIOAppArgs & Scope, Any, Any] =
AppServer.make *> MetricsServer.make

Check warning on line 34 in webapi/src/main/scala/org/knora/webapi/Main.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/Main.scala#L34

Added line #L34 was not covered by tests
}
10 changes: 5 additions & 5 deletions webapi/src/main/scala/org/knora/webapi/config/AppConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
package org.knora.webapi.config

import com.typesafe.config.ConfigFactory
import zio._
import zio.config._
import zio.config.magnolia._
import zio.config.typesafe._
import zio.*
import zio.config.*
import zio.config.magnolia.*
import zio.config.typesafe.*

import java.time.Duration

Expand Down Expand Up @@ -203,7 +203,7 @@ final case class InstrumentationServerConfig(
)

object AppConfig {
type AppConfigurations = AppConfig with JwtConfig with DspIngestConfig with Triplestore
type AppConfigurations = AppConfig & JwtConfig & DspIngestConfig & Triplestore

val layer: ULayer[AppConfigurations] = {
val appConfigLayer = ZLayer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package org.knora.webapi.core

import org.apache.pekko
import zio._
import zio.*
import zio.macros.accessible

import scala.concurrent.ExecutionContext
Expand Down
26 changes: 5 additions & 21 deletions webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package org.knora.webapi.core

import org.apache.pekko
import zio._
import zio.*
import zio.macros.accessible

import org.knora.webapi.core
Expand All @@ -32,17 +32,8 @@ trait AppRouter {

object AppRouter {
val layer: ZLayer[
core.ActorSystem
with CardinalityHandler
with CardinalityService
with ConstructResponseUtilV2
with MessageRelay
with OntologyCache
with OntologyHelpers
with OntologyRepo
with PermissionUtilADM
with ResourceUtilV2
with StandoffTagUtilV2,
core.ActorSystem & CardinalityHandler & CardinalityService & ConstructResponseUtilV2 & MessageRelay &
OntologyCache & OntologyHelpers & OntologyRepo & PermissionUtilADM & ResourceUtilV2 & StandoffTagUtilV2,
Nothing,
AppRouter
] =
Expand All @@ -52,15 +43,8 @@ object AppRouter {
messageRelay <- ZIO.service[MessageRelay]
runtime <-
ZIO.runtime[
CardinalityHandler
with CardinalityService
with ConstructResponseUtilV2
with OntologyCache
with OntologyHelpers
with OntologyRepo
with PermissionUtilADM
with ResourceUtilV2
with StandoffTagUtilV2
CardinalityHandler & CardinalityService & ConstructResponseUtilV2 & OntologyCache & OntologyHelpers &
OntologyRepo & PermissionUtilADM & ResourceUtilV2 & StandoffTagUtilV2
]
} yield new AppRouter {
implicit val system: org.apache.pekko.actor.ActorSystem = as.system
Expand Down
13 changes: 3 additions & 10 deletions webapi/src/main/scala/org/knora/webapi/core/AppServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package org.knora.webapi.core

import zio._
import zio.*

import org.knora.webapi.config.AppConfig
import org.knora.webapi.core.domain.AppState
Expand Down Expand Up @@ -156,15 +156,8 @@ final case class AppServer(
object AppServer {

private type AppServerEnvironment =
State
with TriplestoreService
with RepositoryUpdater
with ActorSystem
with OntologyCache
with IIIFService
with CacheService
with HttpServer
with AppConfig
State & TriplestoreService & RepositoryUpdater & ActorSystem & OntologyCache & IIIFService & CacheService &
HttpServer & AppConfig

/**
* Initializes the AppServer instance with the required services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package org.knora.webapi.core

import org.apache.pekko
import zio._
import zio.*

import org.knora.webapi.config.AppConfig
import org.knora.webapi.core
Expand All @@ -22,7 +22,7 @@ trait HttpServer {
}

object HttpServer {
val layer: ZLayer[ActorSystem with AppConfig with ApiRoutes, Nothing, HttpServer] =
val layer: ZLayer[ActorSystem & AppConfig & ApiRoutes, Nothing, HttpServer] =
ZLayer.scoped {
for {
as <- ZIO.service[core.ActorSystem]
Expand Down
81 changes: 18 additions & 63 deletions webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import zio.ZLayer
import org.knora.webapi.config.AppConfig
import org.knora.webapi.config.AppConfig.AppConfigurations
import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.messages.util._
import org.knora.webapi.messages.util.*
import org.knora.webapi.messages.util.search.QueryTraverser
import org.knora.webapi.messages.util.search.gravsearch.prequery.InferenceOptimizationService
import org.knora.webapi.messages.util.search.gravsearch.transformers.ConstructTransformer
Expand All @@ -20,20 +20,20 @@ import org.knora.webapi.messages.util.search.gravsearch.types.GravsearchTypeInsp
import org.knora.webapi.messages.util.standoff.StandoffTagUtilV2
import org.knora.webapi.messages.util.standoff.StandoffTagUtilV2Live
import org.knora.webapi.responders.IriService
import org.knora.webapi.responders.admin._
import org.knora.webapi.responders.v2._
import org.knora.webapi.responders.admin.*
import org.knora.webapi.responders.v2.*
import org.knora.webapi.responders.v2.ontology.CardinalityHandler
import org.knora.webapi.responders.v2.ontology.CardinalityHandlerLive
import org.knora.webapi.responders.v2.ontology.OntologyHelpers
import org.knora.webapi.responders.v2.ontology.OntologyHelpersLive
import org.knora.webapi.routing._
import org.knora.webapi.slice.admin.api._
import org.knora.webapi.routing.*
import org.knora.webapi.slice.admin.api.*
import org.knora.webapi.slice.admin.api.service.MaintenanceRestService
import org.knora.webapi.slice.admin.api.service.ProjectADMRestService
import org.knora.webapi.slice.admin.api.service.ProjectsADMRestServiceLive
import org.knora.webapi.slice.admin.domain.service._
import org.knora.webapi.slice.admin.domain.service.*
import org.knora.webapi.slice.admin.repo.service.KnoraProjectRepoLive
import org.knora.webapi.slice.common.api._
import org.knora.webapi.slice.common.api.*
import org.knora.webapi.slice.common.repo.service.PredicateObjectMapper
import org.knora.webapi.slice.ontology.api.service.RestCardinalityService
import org.knora.webapi.slice.ontology.api.service.RestCardinalityServiceLive
Expand Down Expand Up @@ -65,62 +65,17 @@ object LayersLive {
* The `Environment` that we require to exist at startup.
*/
type DspEnvironmentLive =
ActorSystem
with ApiRoutes
with AppConfigurations
with AppRouter
with Authenticator
with CacheService
with CacheServiceRequestMessageHandler
with CardinalityHandler
with CardinalityService
with ConstructResponseUtilV2
with ConstructTransformer
with GravsearchTypeInspectionRunner
with GroupsResponderADM
with HttpServer
with IIIFRequestMessageHandler
with IIIFService
with InferenceOptimizationService
with IriService
with IriConverter
with JwtService
with KnoraProjectRepo
with ListsResponderADM
with ListsResponderV2
with MessageRelay
with OntologyCache
with OntologyHelpers
with OntologyRepo
with OntologyResponderV2
with PermissionUtilADM
with PermissionsResponderADM
with PredicateObjectMapper
with ProjectADMRestService
with ProjectADMService
with ProjectExportService
with ProjectExportStorageService
with ProjectImportService
with ProjectsResponderADM
with QueryTraverser
with RepositoryUpdater
with ResourceUtilV2
with ResourceUtilV2
with ResourcesResponderV2
with RestCardinalityService
with RestPermissionService
with RestResourceInfoService
with SearchResponderV2
with SipiResponderADM
with OntologyInferencer
with StandoffResponderV2
with StandoffTagUtilV2
with State
with StoresResponderADM
with StringFormatter
with TriplestoreService
with UsersResponderADM
with ValuesResponderV2
ActorSystem & ApiRoutes & AppConfigurations & AppRouter & Authenticator & CacheService &
CacheServiceRequestMessageHandler & CardinalityHandler & CardinalityService & ConstructResponseUtilV2 &
ConstructTransformer & GravsearchTypeInspectionRunner & GroupsResponderADM & HttpServer &
IIIFRequestMessageHandler & IIIFService & InferenceOptimizationService & IriService & IriConverter & JwtService &
KnoraProjectRepo & ListsResponderADM & ListsResponderV2 & MessageRelay & OntologyCache & OntologyHelpers &
OntologyRepo & OntologyResponderV2 & PermissionUtilADM & PermissionsResponderADM & PredicateObjectMapper &
ProjectADMRestService & ProjectADMService & ProjectExportService & ProjectExportStorageService &
ProjectImportService & ProjectsResponderADM & QueryTraverser & RepositoryUpdater & ResourceUtilV2 &
ResourceUtilV2 & ResourcesResponderV2 & RestCardinalityService & RestPermissionService & RestResourceInfoService &
SearchResponderV2 & SipiResponderADM & OntologyInferencer & StandoffResponderV2 & StandoffTagUtilV2 & State &
StoresResponderADM & StringFormatter & TriplestoreService & UsersResponderADM & ValuesResponderV2

/**
* All effect layers needed to provide the `Environment`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package org.knora.webapi.core

import zio._
import zio.*
import zio.macros.accessible

import org.knora.webapi.messages.ResponderRequest
Expand Down
2 changes: 1 addition & 1 deletion webapi/src/main/scala/org/knora/webapi/core/State.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package org.knora.webapi.core

import zio._
import zio.*
import zio.macros.accessible

import org.knora.webapi.core.domain.AppState
Expand Down