2020package org.ossreviewtoolkit.plugins.commands.requirements
2121
2222import com.github.ajalt.clikt.core.ProgramResult
23- import com.github.ajalt.clikt.parameters.options.default
24- import com.github.ajalt.clikt.parameters.options.option
25- import com.github.ajalt.clikt.parameters.options.split
26- import com.github.ajalt.clikt.parameters.types.enum
2723import com.github.ajalt.mordant.rendering.Theme
2824
2925import java.io.File
3026import java.lang.reflect.Modifier
3127import java.util.EnumSet
3228
33- import kotlin.reflect.full.companionObjectInstance
34-
3529import org.apache.logging.log4j.kotlin.logger
3630
3731import org.ossreviewtoolkit.analyzer.PackageManager
@@ -42,7 +36,6 @@ import org.ossreviewtoolkit.plugins.api.PluginDescriptor
4236import org.ossreviewtoolkit.plugins.commands.api.OrtCommand
4337import org.ossreviewtoolkit.plugins.commands.api.OrtCommandFactory
4438import org.ossreviewtoolkit.utils.common.CommandLineTool
45- import org.ossreviewtoolkit.utils.common.Plugin
4639import org.ossreviewtoolkit.utils.common.enumSetOf
4740import org.ossreviewtoolkit.utils.spdx.scanCodeLicenseTextDir
4841
@@ -64,8 +57,6 @@ private val SUCCESS_PREFIX = "\t${Theme.Default.success("*")} "
6457class RequirementsCommand (
6558 descriptor : PluginDescriptor = RequirementsCommandFactory .descriptor
6659) : OrtCommand(descriptor) {
67- private enum class RequirementsType { PLUGINS , COMMANDS }
68-
6960 private enum class VersionStatus {
7061 /* * The determined version satisfies ORT's requirements. */
7162 SATISFIED ,
@@ -80,17 +71,10 @@ class RequirementsCommand(
8071 UNAVAILABLE
8172 }
8273
83- private val list by option(
84- " --list" , " -l" ,
85- help = " A comma-separated list of requirements to list."
86- ).enum<RequirementsType >().split(" ," ).default(RequirementsType .entries)
87-
8874 private val reflections by lazy { Reflections (" org.ossreviewtoolkit" , Scanners .SubTypes ) }
8975
9076 override fun run () {
91- if (RequirementsType .PLUGINS in list) listPlugins()
92-
93- val status = if (RequirementsType .COMMANDS in list) checkToolVersions() else enumSetOf(VersionStatus .SATISFIED )
77+ val status = checkToolVersions()
9478
9579 echo(" Prefix legend:" )
9680 echo(" ${DANGER_PREFIX } The tool was not found in the PATH environment." )
@@ -127,30 +111,6 @@ class RequirementsCommand(
127111 }
128112 }
129113
130- private fun listPlugins () {
131- getPluginsByType().toSortedMap().forEach { (name, all) ->
132- echo(Theme .Default .info(" $name plugins:" ))
133- echo(all.joinToString(" \n " , postfix = " \n " ) { " ${SUCCESS_PREFIX }$it " })
134- }
135- }
136-
137- internal fun getPluginsByType (): Map <String , Set <String >> {
138- val pluginClasses = reflections.getSubTypesOf(Plugin ::class .java)
139-
140- val pluginTypes = pluginClasses.mapNotNull { clazz ->
141- val companion = clazz.declaredClasses.find { it.name.endsWith(" \$ Companion" ) }
142- val all = runCatching { companion ?.getDeclaredMethod(" getALL" ) }.getOrNull()
143-
144- all?.let {
145- @Suppress(" UNCHECKED_CAST" )
146- val plugins = all.invoke(clazz.kotlin.companionObjectInstance) as Map <String , * >
147- clazz.simpleName to plugins.keys
148- }
149- }
150-
151- return pluginTypes.toMap()
152- }
153-
154114 private fun checkToolVersions (): EnumSet <VersionStatus > {
155115 // Toggle bits in here to denote the kind of error. Skip the first bit as status code 1 is already used above.
156116 val overallStatus = enumSetOf<VersionStatus >()
0 commit comments