Skip to content

Commit

Permalink
fix: ReflectionService class search fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
QuadStingray committed Oct 6, 2023
1 parent a445b04 commit 795511f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ final class ReflectionServiceSubstitutions {

@Substitute
def inizializeClassGraph(): ClassGraph = {
// val classGraph = new ClassGraph()
// .enableAllInfo()
// .addClassLoader(ClassLoader.getSystemClassLoader)
// .disableNestedJarScanning()
// .disableModuleScanning()
// .disableDirScanning()
// .disableRuntimeInvisibleAnnotations()
// .initializeLoadedClasses()
// classGraph
null
val classGraph = new ClassGraph()
.enableAllInfo()
.addClassLoader(ClassLoader.getSystemClassLoader)
.disableNestedJarScanning()
.disableModuleScanning()
.disableDirScanning()
.disableRuntimeInvisibleAnnotations()
.initializeLoadedClasses()
classGraph
}

@Substitute
Expand All @@ -31,7 +30,6 @@ final class ReflectionServiceSubstitutions {
println("Register Class Loader is not supported at native image")
}


@Substitute
def scan(): ScanResult = {
ScanResult.fromJSON("{}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ class ReflectionService {
}
}

def getClassListByName(className: String): List[Class[_]] = {
def getClassListByInterfaceName(className: String): List[Class[_]] = {
scanResult.getClassesImplementing(className).asScala.toList.map(_.loadClass())
}

def getClassByName(className: String): Class[_] = {
val classList = getClassListByName(className)
classList.headOption.getOrElse(throw new ClassNotFoundException())
Try(scanResult.getClassInfo(className).loadClass()).toOption.getOrElse(throw new ClassNotFoundException())
}

}
Expand All @@ -78,8 +77,8 @@ object ReflectionService {
def registerClassLoaders(classLoader: ClassLoader): Unit = {
reflectionService.registerClassLoaders(classLoader)
}
def getClassListByName(className: String): List[Class[_]] = {
reflectionService.getClassListByName(className)
def getClassListByInterfaceName(className: String): List[Class[_]] = {
reflectionService.getClassListByInterfaceName(className)
}
def getClassByName(className: String): Class[_] = {
reflectionService.getClassByName(className)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ object JobRoutes extends BaseRoute with RoutesPlugin {

def jobClassesList(): Future[Either[(StatusCode, ErrorDescription, ErrorDescription), List[String]]] = {
Future.successful(Right({
ReflectionService.getSubClassesList(classOf[Job]).map(_.getName).filterNot(_.startsWith("org.quartz"))
ReflectionService.getSubClassesList(classOf[Job]).map(_.getName).filterNot(_.startsWith("org.quartz")).sorted
}))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class JobSuite extends BaseServerSuite {
test("check possible jobs as admin") {
val jobsList = executeRequestToResponse(jobsApi.possibleJobsList("", "", adminBearerToken, "")())
assertEquals(jobsList.size, 2)
assertEquals(jobsList.head, "dev.mongocamp.server.test.CountingTestJob")
assertEquals(jobsList.last, "dev.mongocamp.server.jobs.CleanUpTokenJob")
assertEquals(jobsList.last, "dev.mongocamp.server.test.CountingTestJob")
assertEquals(jobsList.head, "dev.mongocamp.server.jobs.CleanUpTokenJob")
}

test("check possible jobs as user") {
Expand Down

0 comments on commit 795511f

Please sign in to comment.