Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions common/src/main/kotlin/com/lambda/command/CommandRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ object CommandRegistry : Configurable(LambdaConfig), Loadable {
override val name = "command"
val prefix by setting("prefix", ';')

val commands = getInstances<LambdaCommand> {
forPackages("com.lambda.command.commands"); filterInputsBy { it.contains("com.lambda") }
}.toMutableList()
val commands = getInstances<LambdaCommand> { forPackages("com.lambda.command.commands") }.toMutableList()

override fun load(): String {
return "Registered ${commands.size} commands"
Expand Down
4 changes: 1 addition & 3 deletions common/src/main/kotlin/com/lambda/module/ModuleRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import org.reflections.util.ConfigurationBuilder
* The [ModuleRegistry] object is responsible for managing all [Module] instances in the system.
*/
object ModuleRegistry : Loadable {
val modules = getInstances<Module> {
forPackages("com.lambda.module.modules"); filterInputsBy { it.contains("com.lambda") }
}.toMutableList()
val modules = getInstances<Module> { forPackages("com.lambda.module.modules") }.toMutableList()

val moduleNames: Set<String>
get() = modules.map { it.name }.toSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,102 +12,70 @@ annotation class ReflectionsDsl
* A DSL class to configure the Reflections library for runtime scanning.
* This class allows you to specify packages, scanners, URLs, filters, class loaders, and other options
* to build a Reflections configuration.
*
* Important!!
* Be aware that using Reflections can lead to unpredictable and hard-to-debug issues.
* Furthermore, the library we're relying on is outdated and no longer maintained.
* For more reliable methods, refer to Reflections.kt.
*/
@ReflectionsDsl
class ReflectionConfigDsl {
private val packages = mutableListOf<String>()
private val scanners = mutableListOf<Scanners>()
private val urls = mutableListOf<URL>()
private var inputsFilter: (String) -> Boolean = { true }
private val classLoaders = mutableListOf<ClassLoader>()
private var parallel = false

private var shouldExpandSuperTypes = true

/**
* Specifies the packages to be scanned.
*
* @param packages A vararg of package names to be included in the scanning process.
* @return The current instance of [ReflectionConfigDsl] for method chaining.
*/
fun forPackages(vararg packages: String): ReflectionConfigDsl {
fun forPackages(vararg packages: String) {
this.packages += packages
return this
}

/**
* Adds scanners to the configuration.
*
* @param scanners A vararg of [Scanners] to be used for scanning classes, methods, etc.
* @return The current instance of [ReflectionConfigDsl] for method chaining.
*/
fun addScanners(vararg scanners: Scanners): ReflectionConfigDsl {
fun addScanners(vararg scanners: Scanners) {
this.scanners += scanners
return this
}

/**
* Adds URLs to the configuration.
*
* @param urls A vararg of [URL] to be included in the scanning process.
* @return The current instance of [ReflectionConfigDsl] for method chaining.
*/
fun addUrls(vararg urls: URL): ReflectionConfigDsl {
fun addUrls(vararg urls: URL) {
this.urls += urls
return this
}

/**
* Sets a filter for input names.
*
* @param filter A lambda function that takes a [String] and returns a [Boolean], indicating whether the input should be included.
* @return The current instance of [ReflectionConfigDsl] for method chaining.
*/
fun filterInputsBy(filter: (String) -> Boolean): ReflectionConfigDsl {
inputsFilter = filter
return this
}

/**
* Adds class loaders to the configuration.
*
* @param classLoaders A vararg of [ClassLoader] to be used in the scanning process.
* @return The current instance of [ReflectionConfigDsl] for method chaining.
*/
fun addClassLoaders(vararg classLoaders: ClassLoader): ReflectionConfigDsl {
fun addClassLoaders(vararg classLoaders: ClassLoader) {
this.classLoaders += classLoaders
return this
}

/**
* Enables parallel scanning.
*
* @return The current instance of [ReflectionConfigDsl] for method chaining.
* Expand super types during the scan
*/
fun parallel(): ReflectionConfigDsl {
parallel = true
return this
}

/**
* Sets whether to expand super types during scanning.
*
* @param value A [Boolean] indicating whether to expand super types.
* @return The current instance of [ReflectionConfigDsl] for method chaining.
*/
fun expandSuperTypes(value: Boolean): ReflectionConfigDsl {
shouldExpandSuperTypes = value
return this
fun expandSuperTypes(shouldExpand: Boolean) {
shouldExpandSuperTypes = shouldExpand
}

/**
* Builds a [ConfigurationBuilder] based on the current configuration.
*
* @return A [ConfigurationBuilder] configured with the specified packages, scanners, URLs, filters, and class loaders.
*/
fun build(): ConfigurationBuilder = ConfigurationBuilder()
.forPackages(*packages.toTypedArray())
.addUrls(*urls.toTypedArray())
.filterInputsBy(inputsFilter)
.addClassLoaders(*classLoaders.toTypedArray())
.setExpandSuperTypes(shouldExpandSuperTypes)
}
Expand Down