From fae8600b4ab144b0a40050ffa279145d92270cd0 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 28 Nov 2023 08:49:04 +0100 Subject: [PATCH 1/2] refactor(requirements): Factor out getting plugins by type Further separate getting information from printing it to improve testability. Signed-off-by: Sebastian Schuberth --- .../src/main/kotlin/RequirementsCommand.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt b/plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt index 08d57b38ce4fb..32115848467f2 100644 --- a/plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt +++ b/plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt @@ -106,6 +106,13 @@ class RequirementsCommand : OrtCommand( } private fun listPlugins() { + getPluginsByType().toSortedMap().forEach { (name, all) -> + echo(Theme.Default.info("$name plugins:")) + echo(all.joinToString("\n", postfix = "\n") { "${SUCCESS_PREFIX}$it" }) + } + } + + private fun getPluginsByType(): Map> { val pluginClasses = reflections.getSubTypesOf(Plugin::class.java) val pluginTypes = pluginClasses.mapNotNull { clazz -> @@ -119,10 +126,7 @@ class RequirementsCommand : OrtCommand( } } - pluginTypes.sortedBy { it.first }.forEach { (name, all) -> - echo(Theme.Default.info("$name plugins:")) - echo(all.joinToString("\n", postfix = "\n") { "${SUCCESS_PREFIX}$it" }) - } + return pluginTypes.toMap() } private fun checkToolVersions(): EnumSet { From 8668fb7162575b881d36401d3d6e9247505581f4 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 28 Nov 2023 08:52:51 +0100 Subject: [PATCH 2/2] test(requirements): Add a test for core plugins to be found Signed-off-by: Sebastian Schuberth --- .../src/funTest/kotlin/RequirementsCommandFunTest.kt | 9 +++++++++ .../requirements/src/main/kotlin/RequirementsCommand.kt | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/commands/requirements/src/funTest/kotlin/RequirementsCommandFunTest.kt b/plugins/commands/requirements/src/funTest/kotlin/RequirementsCommandFunTest.kt index b20e9d5cd718b..3d3ded18a3e36 100644 --- a/plugins/commands/requirements/src/funTest/kotlin/RequirementsCommandFunTest.kt +++ b/plugins/commands/requirements/src/funTest/kotlin/RequirementsCommandFunTest.kt @@ -22,6 +22,8 @@ package org.ossreviewtoolkit.plugins.commands.requirements import com.github.ajalt.clikt.testing.test import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.collections.beEmpty +import io.kotest.matchers.shouldNot import io.kotest.matchers.shouldNotBe class RequirementsCommandFunTest : StringSpec({ @@ -29,4 +31,11 @@ class RequirementsCommandFunTest : StringSpec({ // Status code 1 is only returned if there was an error while instantiating a class via reflection. RequirementsCommand().test().statusCode shouldNotBe 1 } + + "Core plugins are found" { + val plugins = RequirementsCommand().getPluginsByType() + + plugins.keys shouldNot beEmpty() + plugins.values.flatten() shouldNot beEmpty() + } }) diff --git a/plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt b/plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt index 32115848467f2..d59316077444d 100644 --- a/plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt +++ b/plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt @@ -112,7 +112,7 @@ class RequirementsCommand : OrtCommand( } } - private fun getPluginsByType(): Map> { + internal fun getPluginsByType(): Map> { val pluginClasses = reflections.getSubTypesOf(Plugin::class.java) val pluginTypes = pluginClasses.mapNotNull { clazz ->