Skip to content

Commit

Permalink
advisor: Rename AdvisorFactory to VulnerabilityProviderFactory
Browse files Browse the repository at this point in the history
In the following commit, vulnerability providers, such as NexusIq, are going
to implement the VulnerabilitProvider class instead of the Advisor class. Thus,
rename the factory to match the name.

Signed-off-by: Korbinian Singhammer <[email protected]>
  • Loading branch information
Korbinian Singhammer authored and sschuberth committed Mar 17, 2021
1 parent 5155332 commit 5578f81
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion advisor/src/main/kotlin/Advisor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import org.ossreviewtoolkit.utils.showStackTrace
*/
abstract class Advisor(val advisorName: String, protected val config: AdvisorConfiguration) {
companion object {
private val LOADER = ServiceLoader.load(AdvisorFactory::class.java)!!
private val LOADER = ServiceLoader.load(VulnerabilityProviderFactory::class.java)!!

/**
* The list of all available advisors in the classpath.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ package org.ossreviewtoolkit.advisor
import java.util.ServiceLoader

import org.ossreviewtoolkit.model.config.AdvisorConfiguration
import org.ossreviewtoolkit.utils.ORT_CONFIG_FILENAME
import org.ossreviewtoolkit.utils.ortConfigDirectory

/**
* A common interface for use with [ServiceLoader] that all [AbstractAdvisorFactory] classes need to implement.
* A common interface for use with [ServiceLoader] that all [AbstractVulnerabilityProviderFactory]
* classes need to implement.
*/
interface AdvisorFactory {
interface VulnerabilityProviderFactory {
/**
* The name to use to refer to the advisor.
*/
Expand All @@ -41,11 +44,16 @@ interface AdvisorFactory {
/**
* A generic factory class for an [Advisor].
*/
abstract class AbstractAdvisorFactory<out T : Advisor>(
abstract class AbstractVulnerabilityProviderFactory<out T : Advisor>(
override val advisorName: String
) : AdvisorFactory {
) : VulnerabilityProviderFactory {
abstract override fun create(config: AdvisorConfiguration): T

protected fun <T> getProviderConfiguration(config: AdvisorConfiguration, select: (AdvisorConfiguration) -> T?): T =
select(config) ?: throw IllegalArgumentException(
"No $advisorName advisor configuration found in ${ortConfigDirectory.resolve(ORT_CONFIG_FILENAME)}"
)

/**
* Return the advisor's name here to allow Clikt to display something meaningful when listing the scanners
* which are enabled by default via their factories.
Expand Down
4 changes: 2 additions & 2 deletions advisor/src/main/kotlin/advisors/NexusIq.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.io.IOException
import java.net.URI
import java.time.Instant

import org.ossreviewtoolkit.advisor.AbstractAdvisorFactory
import org.ossreviewtoolkit.advisor.AbstractVulnerabilityProviderFactory
import org.ossreviewtoolkit.advisor.Advisor
import org.ossreviewtoolkit.clients.nexusiq.NexusIqService
import org.ossreviewtoolkit.model.AdvisorDetails
Expand Down Expand Up @@ -54,7 +54,7 @@ class NexusIq(
name: String,
config: AdvisorConfiguration
) : Advisor(name, config) {
class Factory : AbstractAdvisorFactory<NexusIq>("NexusIQ") {
class Factory : AbstractVulnerabilityProviderFactory<NexusIq>("NexusIQ") {
override fun create(config: AdvisorConfiguration) = NexusIq(advisorName, config)
}

Expand Down
4 changes: 2 additions & 2 deletions advisor/src/main/kotlin/advisors/VulnerableCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope

import org.ossreviewtoolkit.advisor.AbstractAdvisorFactory
import org.ossreviewtoolkit.advisor.AbstractVulnerabilityProviderFactory
import org.ossreviewtoolkit.advisor.Advisor
import org.ossreviewtoolkit.clients.vulnerablecode.VulnerableCodeService
import org.ossreviewtoolkit.model.AdvisorDetails
Expand All @@ -46,7 +46,7 @@ import org.ossreviewtoolkit.utils.ortConfigDirectory
* [VulnerableCode][https://github.com/nexB/vulnerablecode] instance.
*/
class VulnerableCode(name: String, config: AdvisorConfiguration) : Advisor(name, config) {
class Factory : AbstractAdvisorFactory<VulnerableCode>("VulnerableCode") {
class Factory : AbstractVulnerabilityProviderFactory<VulnerableCode>("VulnerableCode") {
override fun create(config: AdvisorConfiguration) = VulnerableCode(advisorName, config)
}

Expand Down

0 comments on commit 5578f81

Please sign in to comment.