Skip to content

Commit 4ff69bb

Browse files
authored
chore: Replace classpath scanner implementation (#60)
* chore - Replace classpath scanner implementation * chore - Add replacement info for deprecated channel ref
1 parent 5563c60 commit 4ff69bb

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

kotlin-asyncapi-core/src/main/kotlin/org/openfolder/kotlinasyncapi/model/channel/Channel.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ class Channel {
2222
var parameters: ReferencableParametersMap? = null
2323
var bindings: Any? = null
2424

25-
@Deprecated("Usage of the \$ref property has been deprecated")
25+
@Deprecated(
26+
message = "Usage of the \$ref property has been deprecated",
27+
replaceWith = ReplaceWith("Reference().ref()")
28+
)
2629
fun ref(value: String): String =
2730
value.also { `$ref` = it }
2831

kotlin-asyncapi-spring-web/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
<groupId>io.swagger.core.v3</groupId>
4040
<artifactId>swagger-core</artifactId>
4141
</dependency>
42+
<dependency>
43+
<groupId>io.github.classgraph</groupId>
44+
<artifactId>classgraph</artifactId>
45+
</dependency>
4246
<dependency>
4347
<groupId>org.springframework</groupId>
4448
<artifactId>spring-web</artifactId>

kotlin-asyncapi-spring-web/src/main/kotlin/org/openfolder/kotlinasyncapi/springweb/AsyncApiAutoConfiguration.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ internal open class AsyncApiAnnotationAutoConfiguration {
101101
ChannelProcessor()
102102

103103
@Bean
104-
open fun annotationScanner(context: ApplicationContext) =
105-
DefaultAnnotationScanner(context)
104+
open fun annotationScanner() =
105+
DefaultAnnotationScanner()
106106

107107
@Bean
108108
open fun annotationProvider(
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package org.openfolder.kotlinasyncapi.springweb.context.annotation
22

3-
import org.openfolder.kotlinasyncapi.annotation.AsyncApiAnnotation
4-
import org.springframework.context.ApplicationContext
5-
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
6-
import org.springframework.core.type.filter.AnnotationTypeFilter
3+
import io.github.classgraph.ClassGraph
74
import org.springframework.stereotype.Component
85
import kotlin.reflect.KClass
96

@@ -12,16 +9,15 @@ internal interface AnnotationScanner {
129
}
1310

1411
@Component
15-
internal class DefaultAnnotationScanner(
16-
private val context: ApplicationContext
17-
) : AnnotationScanner {
12+
internal class DefaultAnnotationScanner : AnnotationScanner {
1813
override fun scan(scanPackage: String, annotation: KClass<out Annotation>): List<KClass<*>> {
19-
val classPathScanner = ClassPathScanningCandidateComponentProvider(false).also {
20-
it.addIncludeFilter(AnnotationTypeFilter(AsyncApiAnnotation::class.java))
21-
}
14+
val packageClasses = ClassGraph()
15+
.enableAllInfo()
16+
.acceptPackages(scanPackage)
17+
.scan()
2218

23-
return classPathScanner.findCandidateComponents(scanPackage).map {
24-
Class.forName(it.beanClassName).kotlin
25-
}.toList()
19+
return packageClasses.getClassesWithAnnotation(annotation.java).standardClasses.map {
20+
it.loadClass().kotlin
21+
}
2622
}
2723
}

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@
255255
<artifactId>swagger-core</artifactId>
256256
<version>2.2.8</version>
257257
</dependency>
258+
<dependency>
259+
<groupId>io.github.classgraph</groupId>
260+
<artifactId>classgraph</artifactId>
261+
<version>4.8.157</version>
262+
</dependency>
258263
<dependency>
259264
<groupId>org.jetbrains.kotlin</groupId>
260265
<artifactId>kotlin-scripting-jvm-host</artifactId>

0 commit comments

Comments
 (0)