Skip to content

Commit 1ae59c2

Browse files
committed
fix(requirements): Correctly categorize manually instantiated classes
Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
1 parent cde9741 commit 1ae59c2

1 file changed

Lines changed: 12 additions & 19 deletions

File tree

plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,19 @@ class RequirementsCommand(
130130
fun Class<out Any>.isBundledPlugin(type: String) =
131131
packageName.startsWith("org.ossreviewtoolkit.plugins.$type.")
132132

133-
val kotlinObject = cliClass.kotlin.objectInstance
134-
135-
val (instance, category) = when {
136-
kotlinObject != null -> {
137-
logger.debug { "$cliClass is a Kotlin object." }
138-
139-
val category = when {
140-
cliClass.isBundledPlugin("packagemanagers") -> "PackageManager"
141-
cliClass.isBundledPlugin("scanners") -> "Scanner"
142-
cliClass.isBundledPlugin("versioncontrolsystems") -> "VersionControlSystem"
143-
else -> "Other tool"
144-
}
145-
146-
kotlinObject to category
147-
}
133+
val instance = cliClass.kotlin.objectInstance?.let {
134+
logger.debug { "$cliClass is a Kotlin object." }
135+
it
136+
} ?: run {
137+
logger.debug { "Trying to instantiate $cliClass without any arguments." }
138+
cliClass.getDeclaredConstructor().newInstance()
139+
}
148140

149-
else -> {
150-
logger.debug { "Trying to instantiate $cliClass without any arguments." }
151-
cliClass.getDeclaredConstructor().newInstance() to "Other tool"
152-
}
141+
val category = when {
142+
cliClass.isBundledPlugin("packagemanagers") -> "PackageManager"
143+
cliClass.isBundledPlugin("scanners") -> "Scanner"
144+
cliClass.isBundledPlugin("versioncontrolsystems") -> "VersionControlSystem"
145+
else -> "Other tool"
153146
}
154147

155148
if (instance.command().isNotEmpty()) {

0 commit comments

Comments
 (0)