Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate reporter to new plugin API #9182

Merged
merged 18 commits into from
Nov 9, 2024
Merged

Conversation

mnonnenmacher
Copy link
Member

@mnonnenmacher mnonnenmacher commented Sep 22, 2024

Migrate the reporter to the new plugin API, see the commit messages for details.

@mnonnenmacher mnonnenmacher force-pushed the reporter-refactorings branch 2 times, most recently from c658c37 to aa85547 Compare September 22, 2024 18:18
Copy link

codecov bot commented Sep 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.09%. Comparing base (a5adf08) to head (d902e04).
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #9182   +/-   ##
=========================================
  Coverage     68.09%   68.09%           
- Complexity     1291     1293    +2     
=========================================
  Files           250      250           
  Lines          8814     8814           
  Branches        916      916           
=========================================
  Hits           6002     6002           
  Misses         2427     2427           
  Partials        385      385           
Flag Coverage Δ
funTest-docker 65.06% <ø> (ø)
funTest-non-docker 33.74% <ø> (+0.17%) ⬆️
test 35.87% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mnonnenmacher mnonnenmacher force-pushed the reporter-refactorings branch 2 times, most recently from ef79cd6 to 63d352f Compare November 7, 2024 10:36
PluginConfiguration(options)
)
fun generateReport(result: OrtResult, options: Options): List<Result<File>> =
CycloneDxReporterFactory().create(PluginConfig(options)).generateReport(ReporterInput(result), outputDir)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using the factory now in several tests because it is the easiest way to create a reporter with the default configuration (the config class must not have default arguments). This is not nice and I will make a follow-up PR to simplify this.

@mnonnenmacher mnonnenmacher marked this pull request as ready for review November 7, 2024 20:30
@mnonnenmacher mnonnenmacher requested a review from a team as a code owner November 7, 2024 20:30
plugins/compiler/src/main/kotlin/PluginSpecFactory.kt Outdated Show resolved Hide resolved
* A list of alternative names for the option. This can be used to make renaming options backward-compatible.
* Aliases are tried in the order they are defined until a value is found.
*/
val aliases: Array<String> = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says it's a list although it's an array... which we barely use so far in the code base. Just curious, what's the reason to use an array here?

Copy link
Member Author

@mnonnenmacher mnonnenmacher Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists are not allowed in annotation classes, it's a language limitation. Updated the comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually arrays could be more efficient if you can cope with their limitations. I wonder whether we should make more use of them anyway.

cli/src/funTest/kotlin/ExamplesFunTest.kt Show resolved Hide resolved
class DocBookTemplateReporter : AsciiDocTemplateReporter() {
@OrtPlugin(
displayName = "DocBook Template Reporter",
description = "Generates DocBook files from Apache Freemarker templates.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I somehow feel that mentioning AsciiDoc is at least equally important to mentioning Freemarker. So should we say "Generates DocBook from AsciiDoc files with Freemarker templates."

Similar below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the double "from" in "from AsciiDoc files from Apache Freemarker" does not read so nice now (I found my proposal from above better 😁), but we could improve that later.

Comment on lines +48 to +50
internal val DEFAULT = PlainTextTemplateReporterConfig(
templateIds = listOf("NOTICE_DEFAULT"),
templatePaths = null
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this to the top level instead of wrapping it in a companion object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like scoping such constants, to me PlainTextTemplateReporterConfig.DEFAULT also reads much better than DEFAULT_PLAIN_TEXT_TEMPLATE_REPORTER_CONFIG.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The discussion we once had in the core team came to the conclusion that such scoping is only useful for public properties. Or maybe it was non-private properties? Then you would be right for the internal case. Let's keep it as-is then.

Copy link
Member

@sschuberth sschuberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, comments are optional to address.

Make the `defaultValue` property of the `OrtPluginOption` annotation
optional. As annotation properties cannot be nullable, define a constant
to mark if the default value should be ignored.

This is a preparation for adding more properties to the annotation.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Add the property `OrtPluginOption.aliases` to define optional aliases
for configuration options. This can be used to rename options in a
backward-compatible way.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Convert `AsciiDocTemplateReporter` to an abstract class. This allows to
simplify the constructor by making `backend` an abstract property.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Migrate the reporters to the new plugin API. Reporter implementations
get their configuration options via the `generateReport` function. With
the new plugin API the configuration options are provided as a
constructor parameter. With this change both ways are supported to allow
for a step-by-step migration in the following commits.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Add a config class for the reporter and use it instead of the options
passed to the `generateReport` function.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Add a config class for the reporter and use it instead of the options
passed to the `generateReport` function.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Add a config class for the reporter and use it instead of the options
passed to the `generateReport` function.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Add a config class for the reporter and use it instead of the options
passed to the `generateReport` function.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Add a config class for the reporter and use it instead of the options
passed to the `generateReport` function.

While add it, also add missing configuration options to the tests.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Add a config class for the reporter and use it instead of the options
passed to the `generateReport` function.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Use dedicated function arguments for the template IDs and paths in
`FreemarkerTemplateProcessor` to make the API typesafe and prepare for
introducing configuration classes for the related reporters.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Add a config class for the `PlainTextTemplateReporter` and use it
instead of the options passed to the `generateReport` function.

While at it, improve the configuration option names to be plural but
keep supporting the old names for compatibility.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Add config classes for the reporters and use them instead of the options
passed to the `generateReport` function.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
Add config classes for the reporters and use them instead of the options
passed to the `generateReport` function.

Several tests that unsure the presence of configuration options can be
removed, because this is now done by the generated plugin factory.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
All reporters have been migrated to receive their configuration options
via the constructor, so remove the now unused `config` argument from the
`generateReport` function.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
@mnonnenmacher mnonnenmacher merged commit 4596888 into main Nov 9, 2024
23 checks passed
@mnonnenmacher mnonnenmacher deleted the reporter-refactorings branch November 9, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants