Skip to content

Commit

Permalink
feat(plugins-api): Allow to manually set the plugin ID
Browse files Browse the repository at this point in the history
By default, the plugin ID is derived from the class name. In some cases
this is not desired, for example, when the ID should be an abbreviation
of the class name, or when the spelling is different because the class
name follows Kotlin naming conventions. Allow manually setting the ID in
such situations.

Note that annotation parameters cannot be nullable, therefore an empty
string is set as default value for the new property.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Sep 9, 2024
1 parent 785514e commit 723e003
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions plugins/api/src/main/kotlin/OrtPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ import kotlin.reflect.KClass
*/
@Target(AnnotationTarget.CLASS)
annotation class OrtPlugin(
/**
* The id of the plugin. Must be unique among all plugins for the same extension point. If empty, the id is derived
* from the class name.
*/
val id: String = "",

/** The display name of the plugin. */
val displayName: String,

Expand Down
6 changes: 5 additions & 1 deletion plugins/compiler/src/main/kotlin/PluginSpecFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ class PluginSpecFactory {

val pluginOptions = configClass?.getPluginOptions().orEmpty()

val pluginId = ortPlugin.id.ifEmpty {
pluginClass.simpleName.asString().removeSuffix(pluginParentClass.simpleName.asString())
}

return PluginSpec(
containingFile = pluginClass.containingFile,
descriptor = PluginDescriptor(
id = pluginClass.simpleName.asString().removeSuffix(pluginParentClass.simpleName.asString()),
id = pluginId,
displayName = ortPlugin.displayName,
description = ortPlugin.description,
options = pluginOptions
Expand Down

0 comments on commit 723e003

Please sign in to comment.