Skip to content

Commit

Permalink
feat(compiler): Remove the parent class name suffix from the plugin id
Browse files Browse the repository at this point in the history
If the name of the plugin class ends with the name of the plugin parent
class, remove this suffix from the id. For example, if the parent class
is called `PackageCurationProvider` and the plugin class is called
`FilePackageCurationProvider`, the id will be just `File`.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Sep 2, 2024
1 parent 35d18a6 commit e15091c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions plugins/compiler/src/main/kotlin/PluginFactoryGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ class PluginFactoryGenerator(private val codeGenerator: CodeGenerator) {
}.build()

// Create the factory class.
val className = "${pluginSpec.descriptor.id}Factory"
val className = "${pluginSpec.typeName.toString().substringAfterLast('.')}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.id}Factory"))
FileSpec.builder(ClassName(pluginSpec.packageName, className))
.addType(classSpec)
.build()
.writeTo(codeGenerator, aggregating = true, originatingKSFiles = listOfNotNull(pluginSpec.containingFile))
Expand Down
2 changes: 1 addition & 1 deletion plugins/compiler/src/main/kotlin/PluginProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PluginProcessor(codeGenerator: CodeGenerator) : SymbolProcessor {
val pluginParentClass = getPluginParentClass(pluginFactoryClass)
checkExtendsPluginClass(pluginClass, pluginParentClass)

val pluginSpec = specFactory.create(pluginAnnotation, pluginClass, pluginFactoryClass)
val pluginSpec = specFactory.create(pluginAnnotation, pluginClass, pluginParentClass, pluginFactoryClass)
serviceLoaderSpecs += factoryGenerator.generate(pluginSpec)
jsonGenerator.generate(pluginSpec)
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/compiler/src/main/kotlin/PluginSpecFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class PluginSpecFactory {
fun create(
ortPlugin: OrtPlugin,
pluginClass: KSClassDeclaration,
pluginParentClass: KSClassDeclaration,
pluginFactoryClass: KSClassDeclaration
): PluginSpec {
val pluginType = pluginClass.asType(emptyList()).toTypeName()
Expand All @@ -63,7 +64,7 @@ class PluginSpecFactory {
return PluginSpec(
containingFile = pluginClass.containingFile,
descriptor = PluginDescriptor(
id = pluginClass.simpleName.asString(),
id = pluginClass.simpleName.asString().removeSuffix(pluginParentClass.simpleName.asString()),
displayName = ortPlugin.name,
description = ortPlugin.description,
options = pluginOptions
Expand Down

0 comments on commit e15091c

Please sign in to comment.