Skip to content

Commit

Permalink
refactor(plugins-api)!: Rename PluginDescriptor.className to id
Browse files Browse the repository at this point in the history
The new name makes it clearer that the property is a unique identifier
for the plugin. While it currently always matches the class name, this
will change in an upcoming commit.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Sep 2, 2024
1 parent 4da006b commit d15eaa1
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 14 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 @@ -76,7 +76,7 @@ class Advisor(
logger.info { "There are no packages to give advice for." }
} else {
val providers = providerFactories.map {
val providerConfig = config.config?.get(it.descriptor.className)
val providerConfig = config.config?.get(it.descriptor.id)
it.create(PluginConfig(providerConfig?.options.orEmpty(), providerConfig?.secrets.orEmpty()))
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/advisors/nexus-iq/src/main/kotlin/NexusIq.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private val READ_TIMEOUT = Duration.ofSeconds(60)
factory = AdviceProviderFactory::class
)
class NexusIq(override val descriptor: PluginDescriptor, private val config: NexusIqConfiguration) : AdviceProvider {
override val details = AdvisorDetails(descriptor.className, enumSetOf(AdvisorCapability.VULNERABILITIES))
override val details = AdvisorDetails(descriptor.id, enumSetOf(AdvisorCapability.VULNERABILITIES))

private val service by lazy {
NexusIqService.create(
Expand Down
2 changes: 1 addition & 1 deletion plugins/advisors/oss-index/src/main/kotlin/OssIndex.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private const val BULK_REQUEST_SIZE = 128
factory = AdviceProviderFactory::class
)
class OssIndex(override val descriptor: PluginDescriptor, config: OssIndexConfiguration) : AdviceProvider {
override val details = AdvisorDetails(descriptor.className, enumSetOf(AdvisorCapability.VULNERABILITIES))
override val details = AdvisorDetails(descriptor.id, enumSetOf(AdvisorCapability.VULNERABILITIES))

private val service by lazy {
OssIndexService.create(
Expand Down
2 changes: 1 addition & 1 deletion plugins/advisors/osv/src/main/kotlin/Osv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import us.springett.cvss.Cvss
factory = AdviceProviderFactory::class
)
class Osv(override val descriptor: PluginDescriptor, config: OsvConfiguration) : AdviceProvider {
override val details = AdvisorDetails(descriptor.className, enumSetOf(AdvisorCapability.VULNERABILITIES))
override val details = AdvisorDetails(descriptor.id, enumSetOf(AdvisorCapability.VULNERABILITIES))

private val service = OsvServiceWrapper(
serverUrl = config.serverUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class VulnerableCode(override val descriptor: PluginDescriptor, config: Vulnerab
* The details returned with each [AdvisorResult] produced by this instance. As this is constant, it can be
* created once beforehand.
*/
override val details = AdvisorDetails(descriptor.className, enumSetOf(AdvisorCapability.VULNERABILITIES))
override val details = AdvisorDetails(descriptor.id, enumSetOf(AdvisorCapability.VULNERABILITIES))

private val service by lazy {
val client = OkHttpClientHelper.buildClient {
Expand Down
2 changes: 1 addition & 1 deletion plugins/api/src/main/kotlin/PluginDescriptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data class PluginDescriptor(
/**
* The name of the plugin class. Must be unique among all plugins for the same factory class.
*/
val className: String,
val id: String,

/**
* The description of the plugin.
Expand Down
2 changes: 1 addition & 1 deletion plugins/api/src/main/kotlin/PluginFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface PluginFactory<out PLUGIN : Plugin> {
.iterator()
.asSequence()
.associateByTo(sortedMapOf(String.CASE_INSENSITIVE_ORDER)) {
it.descriptor.className
it.descriptor.id
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/compiler/src/main/kotlin/JsonSpecGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class JsonSpecGenerator(private val codeGenerator: CodeGenerator) {
val jsonObject = buildJsonObject {
putJsonObject("descriptor") {
put("displayName", pluginSpec.descriptor.displayName)
put("className", pluginSpec.descriptor.className)
put("id", pluginSpec.descriptor.id)
put("description", pluginSpec.descriptor.description)

putJsonArray("options") {
Expand All @@ -63,7 +63,7 @@ class JsonSpecGenerator(private val codeGenerator: CodeGenerator) {

codeGenerator.createNewFileByPath(
dependencies = Dependencies(aggregating = true, *listOfNotNull(pluginSpec.containingFile).toTypedArray()),
path = "META-INF/plugin/${pluginSpec.packageName}.${pluginSpec.descriptor.className}",
path = "META-INF/plugin/${pluginSpec.packageName}.${pluginSpec.descriptor.id}",
extensionName = "json"
).use { output ->
json.encodeToStream(jsonObject, output)
Expand Down
8 changes: 4 additions & 4 deletions plugins/compiler/src/main/kotlin/PluginFactoryGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ class PluginFactoryGenerator(private val codeGenerator: CodeGenerator) {
}.build()

// Create the factory class.
val className = "${pluginSpec.descriptor.className}Factory"
val className = "${pluginSpec.descriptor.id}Factory"
val classSpec = TypeSpec.classBuilder(className)
.addSuperinterface(pluginSpec.factory.typeName)
.addProperty(descriptorProperty)
.addFunction(createFunction)
.build()

// Write the factory class to a file.
FileSpec.builder(ClassName(pluginSpec.packageName, "${pluginSpec.descriptor.className}Factory"))
FileSpec.builder(ClassName(pluginSpec.packageName, "${pluginSpec.descriptor.id}Factory"))
.addType(classSpec)
.build()
.writeTo(codeGenerator, aggregating = true, originatingKSFiles = listOfNotNull(pluginSpec.containingFile))
Expand Down Expand Up @@ -149,13 +149,13 @@ class PluginFactoryGenerator(private val codeGenerator: CodeGenerator) {
"""
PluginDescriptor(
displayName = %S,
className = %S,
id = %S,
description = %S,
options = listOf(
""".trimIndent(),
descriptor.displayName,
descriptor.className,
descriptor.id,
descriptor.description
)

Expand Down
2 changes: 1 addition & 1 deletion plugins/compiler/src/main/kotlin/PluginSpecFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class PluginSpecFactory {
containingFile = pluginClass.containingFile,
descriptor = PluginDescriptor(
displayName = ortPlugin.name,
className = pluginClass.simpleName.asString(),
id = pluginClass.simpleName.asString(),
description = ortPlugin.description,
options = pluginOptions
),
Expand Down

0 comments on commit d15eaa1

Please sign in to comment.