Skip to content

Commit

Permalink
fix: ReflectionService class initialization failed
Browse files Browse the repository at this point in the history
  • Loading branch information
QuadStingray committed Oct 6, 2023
1 parent ad712a4 commit a445b04
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ trait RestServer extends LazyLogging {

def startServer()(implicit ex: ExecutionContext): Future[Unit]

def registerMongoCampServerDefaultConfigs: Unit
def registerMongoCampServerDefaultConfigs(): Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.mongocamp.server.service
import io.github.classgraph.{ClassGraph, ScanResult}

import scala.jdk.CollectionConverters._
import scala.reflect.runtime.universe.runtimeMirror
import scala.util.Try

// todo https://github.com/classgraph/classgraph/wiki/Code-examples
Expand All @@ -27,11 +28,9 @@ class ReflectionService {
clazzInstance.map(_.asInstanceOf[T])
}
else {
// todo: chekc if this is needed
// lazy val mirror = runtimeMirror(foundClazz.getClassLoader)
// val instance = Try(mirror.reflectModule(mirror.moduleSymbol(foundClazz)).instance).toOption
// instance.map(_.asInstanceOf[T])
List.empty
lazy val mirror = runtimeMirror(foundClazz.getClassLoader)
val instance = Try(mirror.reflectModule(mirror.moduleSymbol(foundClazz)).instance).toOption
instance.map(_.asInstanceOf[T])
}
})
reflected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Server extends App with LazyLogging with RouteConcatenation with RestServ
lazy val interface: String = ConfigurationService.getConfigValue[String](DefaultConfigurations.ConfigKeyServerInterface)
lazy val port: Int = ConfigurationService.getConfigValue[Long](DefaultConfigurations.ConfigKeyServerPort).toInt

private def inizializeRoutesPlugin: List[RoutesPlugin] = {
private def initializeRoutesPlugin: List[RoutesPlugin] = {
val pluginList = ReflectionService
.instancesForType(classOf[RoutesPlugin])
.filterNot(plugin => ConfigurationService.getConfigValue[List[String]](DefaultConfigurations.ConfigKeyPluginsIgnored).contains(plugin.getClass.getName))
Expand All @@ -50,7 +50,7 @@ object Server extends App with LazyLogging with RouteConcatenation with RestServ
def listOfRoutePlugins: List[RoutesPlugin] = routesPluginList

private def serverEndpoints: List[ServerEndpoint[AkkaStreams with WebSockets, Future]] = {
InformationRoutes.routes ++ AuthRoutes.authEndpoints ++ AdminRoutes.endpoints ++ inizializeRoutesPlugin.flatMap(_.endpoints) ++ IndexRoutes.endpoints
InformationRoutes.routes ++ AuthRoutes.authEndpoints ++ AdminRoutes.endpoints ++ initializeRoutesPlugin.flatMap(_.endpoints) ++ IndexRoutes.endpoints
}

private def routes(implicit ex: ExecutionContext): Route = {
Expand Down Expand Up @@ -136,5 +136,5 @@ object Server extends App with LazyLogging with RouteConcatenation with RestServ

startServer()

override def registerMongoCampServerDefaultConfigs: Unit = ConfigurationService.registerMongoCampServerDefaultConfigs()
override def registerMongoCampServerDefaultConfigs(): Unit = ConfigurationService.registerMongoCampServerDefaultConfigs()
}

0 comments on commit a445b04

Please sign in to comment.