Skip to content

Commit

Permalink
chore: improve compiler warnings (DEV-1611) (#2784)
Browse files Browse the repository at this point in the history
  • Loading branch information
BalduinLandolt committed Aug 14, 2023
1 parent 35ce421 commit 00379ce
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 32 deletions.
19 changes: 14 additions & 5 deletions build.sbt
Expand Up @@ -183,9 +183,18 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
"-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations",
"-Wunused:imports",
"-Wunused:privates",
"-Wunused:locals",
"-Wunused:explicits",
"-Wunused:implicits",
"-Wunused:params",
"-Wunused:patvars",
"-Wdead-code",
"-Wvalue-discard",
"-Xlint:doc-detached",
// silence twirl templates unused imports warnings
"-Wconf:src=target/.*:s",
"-Wunused:imports"
"-Wconf:src=target/.*:s"
),
logLevel := Level.Info,
javaAgents += Dependencies.aspectjweaver
Expand Down Expand Up @@ -268,12 +277,12 @@ lazy val integration: Project = Project(id = "integration", base = file("integra
scalacOptions ++= Seq(
"-feature",
"-unchecked",
"-deprecation",
// "-deprecation",
"-Yresolve-term-conflict:package",
"-Ymacro-annotations",
"-Wunused:imports",
// silence twirl templates unused imports warnings
"-Wconf:src=target/.*:s",
"-Wunused:imports"
"-Wconf:src=target/.*:s"
),
logLevel := Level.Info,
javaAgents += Dependencies.aspectjweaver,
Expand Down
Expand Up @@ -23,7 +23,7 @@ import org.knora.webapi.messages.store.triplestoremessages.RdfDataObject
*/
class CORSSupportE2ESpec extends E2ESpec {

implicit def default(implicit system: ActorSystem) = RouteTestTimeout(
implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(
FiniteDuration(appConfig.defaultTimeout.toNanos, NANOSECONDS)
)

Expand Down
Expand Up @@ -64,9 +64,9 @@ class OntologyV2R2RSpec extends R2RSpec {
private implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance

private val ontologiesPath =
DSPApiDirectives.handleErrors(system, appConfig)(OntologiesRouteV2().makeRoute)
DSPApiDirectives.handleErrors(appConfig)(OntologiesRouteV2().makeRoute)
private val resourcesPath =
DSPApiDirectives.handleErrors(system, appConfig)(ResourcesRouteV2(appConfig).makeRoute)
DSPApiDirectives.handleErrors(appConfig)(ResourcesRouteV2(appConfig).makeRoute)

implicit val ec: ExecutionContextExecutor = system.dispatcher

Expand Down
Expand Up @@ -2120,7 +2120,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {

"correctly update the ontology cache when adding a resource, so that the resource can afterwards be found by gravsearch" in {
val freetestLastModDate: Instant = Instant.parse("2012-12-12T12:12:12.12Z")
DSPApiDirectives.handleErrors(system, appConfig)(OntologiesRouteV2().makeRoute)
DSPApiDirectives.handleErrors(appConfig)(OntologiesRouteV2().makeRoute)
val auth = BasicHttpCredentials(SharedTestDataADM.anythingAdminUser.email, SharedTestDataADM.testPass)

// create a new resource class and add a property with cardinality to it
Expand Down
Expand Up @@ -50,15 +50,15 @@ class SearchRouteV2R2RSpec extends R2RSpec {
private implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance

private val searchPath =
DSPApiDirectives.handleErrors(system, appConfig)(
DSPApiDirectives.handleErrors(appConfig)(
SearchRouteV2(routeData.appConfig.v2.fulltextSearch.searchValueMinLength).makeRoute
)
private val resourcePath =
DSPApiDirectives.handleErrors(system, appConfig)(ResourcesRouteV2(appConfig).makeRoute)
DSPApiDirectives.handleErrors(appConfig)(ResourcesRouteV2(appConfig).makeRoute)
private val standoffPath =
DSPApiDirectives.handleErrors(system, appConfig)(StandoffRouteV2().makeRoute)
DSPApiDirectives.handleErrors(appConfig)(StandoffRouteV2().makeRoute)
private val valuesPath =
DSPApiDirectives.handleErrors(system, appConfig)(ValuesRouteV2().makeRoute)
DSPApiDirectives.handleErrors(appConfig)(ValuesRouteV2().makeRoute)

implicit val ec: ExecutionContextExecutor = system.dispatcher

Expand Down
6 changes: 3 additions & 3 deletions webapi/src/main/scala/org/knora/webapi/core/HttpServerZ.scala
Expand Up @@ -51,9 +51,9 @@ object HttpServerZ {
@tailrec
def replaceSlugs(seg: List[Path.Segment], acc: Path): Path =
seg match {
case head :: slug :: next if slugs.contains(head.text) => replaceSlugs(next, acc / head.text / s":${head.text}")
case head :: next => replaceSlugs(next, acc / head.text)
case Nil => acc
case head :: _ :: next if slugs.contains(head.text) => replaceSlugs(next, acc / head.text / s":${head.text}")
case head :: next => replaceSlugs(next, acc / head.text)
case Nil => acc
}
Middleware.metrics(
pathLabelMapper = { case request: Request => replaceSlugs(request.path.segments.toList, Path.empty).toString },
Expand Down
Expand Up @@ -5,7 +5,6 @@

package org.knora.webapi.http.directives

import akka.actor.ActorSystem
import akka.http.scaladsl.server
import akka.http.scaladsl.server.Directives.handleExceptions
import akka.http.scaladsl.server.Directives.handleRejections
Expand All @@ -26,9 +25,9 @@ object DSPApiDirectives {
def rejectionHandler: RejectionHandler = CorsDirectives.corsRejectionHandler.withFallback(RejectionHandler.default)

// Our exception handler
def exceptionHandler(system: ActorSystem, appConfig: AppConfig): ExceptionHandler = KnoraExceptionHandler(appConfig)
def exceptionHandler(appConfig: AppConfig): ExceptionHandler = KnoraExceptionHandler(appConfig)

// Combining the two handlers for convenience
def handleErrors(system: ActorSystem, appConfig: AppConfig): server.Directive[Unit] =
handleRejections(rejectionHandler) & handleExceptions(exceptionHandler(system, appConfig))
def handleErrors(appConfig: AppConfig): server.Directive[Unit] =
handleRejections(rejectionHandler) & handleExceptions(exceptionHandler(appConfig))
}
Expand Up @@ -64,14 +64,6 @@ final case class HealthRouteZ() {
.setStatus(statusCode(result.status))
)

/**
* Returns a string representation "healthy" or "unhealthy" from a boolean.
*
* @param s a boolean from which to derive the state
* @return either "healthy" or "unhealthy"
*/
private def status(s: Boolean): String = if (s) "healthy" else "unhealthy"

/**
* Returns the HTTP status according to the input boolean.
*
Expand Down
Expand Up @@ -144,7 +144,6 @@ case class CreateDefaultObjectAccessPermissionAPIRequestADM(
* @param forGroup the new group IRI.
*/
case class ChangePermissionGroupApiRequestADM(forGroup: IRI) extends PermissionsADMJsonProtocol {
private val stringFormatter = StringFormatter.getInstanceForConstantOntologies

if (forGroup.isEmpty) {
throw BadRequestException(s"IRI of new group cannot be empty.")
Expand Down Expand Up @@ -180,7 +179,6 @@ case class ChangePermissionResourceClassApiRequestADM(forResourceClass: IRI) ext
if (forResourceClass.isEmpty) {
throw BadRequestException(s"Resource class IRI cannot be empty.")
}
private val stringFormatter = StringFormatter.getInstanceForConstantOntologies
Iri
.validateAndEscapeIri(forResourceClass)
.getOrElse(
Expand Down
Expand Up @@ -112,9 +112,9 @@ private final case class ApiRoutesImpl(
val routes: Route =
logDuration {
ServerVersion.addServerHeader {
DSPApiDirectives.handleErrors(routeData.system, appConfig) {
DSPApiDirectives.handleErrors(appConfig) {
CorsDirectives.cors(CorsSettings(routeData.system)) {
DSPApiDirectives.handleErrors(routeData.system, appConfig) {
DSPApiDirectives.handleErrors(appConfig) {
HealthRoute().makeRoute ~
VersionRoute().makeRoute ~
RejectingRoute(appConfig, runtime).makeRoute ~
Expand Down

0 comments on commit 00379ce

Please sign in to comment.