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

Several scanner and plugin related refactorings #7572

Merged
merged 13 commits into from
Sep 26, 2023
Merged

Conversation

mnonnenmacher
Copy link
Member

@mnonnenmacher mnonnenmacher commented Sep 26, 2023

Clean-up the scanner API to reduce complexity and adapt the plugin API to prepare for using the API for configurable plugins for more plugins, especially the scanner wrappers. I planned to include this in the same PR, but as this PR has already become very large I will create another PR afterwards. Please see the commit messages for details.

Breaking API change:

The API for ScannerWrapper, PackageCurationProvider, and PackageConfigurationProvider plugins has changed. For details see the PR diff.

@codecov
Copy link

codecov bot commented Sep 26, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (029f1ca) 68.03% compared to head (e626462) 68.03%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #7572   +/-   ##
=========================================
  Coverage     68.03%   68.03%           
  Complexity     2023     2023           
=========================================
  Files           344      344           
  Lines         16727    16727           
  Branches       2371     2371           
=========================================
  Hits          11381    11381           
  Misses         4363     4363           
  Partials        983      983           
Flag Coverage Δ
funTest-docker 69.40% <ø> (ø)
test 35.52% <100.00%> (ø)

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

Files Coverage Δ
...del/src/main/kotlin/config/AdvisorConfiguration.kt 97.61% <ø> (ø)
model/src/main/kotlin/config/OrtConfiguration.kt 97.77% <ø> (ø)
.../main/kotlin/config/PackageManagerConfiguration.kt 91.66% <ø> (ø)
...el/src/main/kotlin/config/ReporterConfiguration.kt 100.00% <ø> (ø)
...del/src/main/kotlin/config/ScannerConfiguration.kt 100.00% <ø> (ø)
.../src/main/kotlin/storages/ClearlyDefinedStorage.kt 82.97% <100.00%> (ø)

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

@@ -25,18 +25,6 @@ import org.ossreviewtoolkit.model.config.Options
import org.semver4j.Semver
import org.semver4j.Semver.VersionDiff

/**
Copy link
Member

Choose a reason for hiding this comment

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

As the feature was not taken into use since its introduction three years ago,

Just FYI, this reminds me of @oheger-bosch's #3372, which unfortunately we never managed to merge. But it's probably right by now to start anew and rethink the scanner configuration matching.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I wanted to close the PR after this is merged. I think in the beginning we expected that we would change the ScanCode options more often but over time it turned out that we barely ever change them and the current approach works well enough. So to me the complexity of the proposed solution is not appropriate to the relevance of the problem.

Remove the unused `downloaderConfig` parameter from the `create`
function of the `ScannerWrapperFactory`.

The `downloaderConfig` was required by the old scanner API which was
removed in c71628d, because there the code to download the source code
was not separated from the scanner plugins.

Signed-off-by: Martin Nonnenmacher <[email protected]>
Use a generic name for the factory function as the previous name will
not match anymore after an upcoming change.

Signed-off-by: Martin Nonnenmacher <[email protected]>
Signed-off-by: Martin Nonnenmacher <[email protected]>
Provide only the scanner specific options to the `ScannerCriteria`
factory function. This improves the separation of concerns as the
function only has to deal with the relevant options.

Provide an empty map as default value for the options to simplify usage
in tests.

Signed-off-by: Martin Nonnenmacher <[email protected]>
The `ScannerConfigMatcher` was intended to support cases where the
`ScannerDetails.configuration` must not be matched exactly. As the
feature was not taken into use since its introduction three years ago,
replace it with a simpler approach to match either the whole
configuration or ignore the configuration to simplify code.

Signed-off-by: Martin Nonnenmacher <[email protected]>
Remove the `ScannerCriteria.forDetails()` function as it was only used
in tests and usage can be replaced by calling the `create()` function
instead.

The functionality to create the `maxVersion` based on a `VersionDiff`
was never made configurable and was always exclusively used by tests.

Signed-off-by: Martin Nonnenmacher <[email protected]>
Add the detected license mapping from the `ScannerConfiguration` to the
`ScanContext` to make it available to `ScannerWrapper`s. This is
currently only required by the `FossId` implementation because FossID
can return arbitrary strings as licenses. These strings can sometimes
not be parsed as SPDX expressions and can therefore not be returned as
part of a `LicenseFinding` in the `ScanSummary`.

A better solution could be to automatically convert all license strings
returned by FossID to a form that can be parsed as SPDX expression, then
the mapping could be applied globally. However, as this would be a
breaking configuration change it is not implemented now and only added
as a TODO comment instead.

Signed-off-by: Martin Nonnenmacher <[email protected]>
Provide only the scanner specific `Options` instead of the
`ScannerConfiguration` to the factory method in `ScannerWrapperFactory`.
This simplifies the implementation of the scanners as they do not have
to find the relevant configuration on their own, and improves separation
of concerns as scanners do not have access to the configuration of other
scanners and the global scanner configuration anymore.

Signed-off-by: Martin Nonnenmacher <[email protected]>
Extract an interface from the duplicated code in
`PackageCurationProviderFactory` and
`PackageConfigurationProviderFactory` to make it reusable by other
plugins.

Signed-off-by: Martin Nonnenmacher <[email protected]>
Merge the `ScannerWrapperFactory` interface and the
`AbstractScannerWrapperFactory` abstract class into a single abstract
class to simplify code. All implementations already inherited from the
abstract class, and the `toString` implementation from the abstract
class should also be supported by all scanner wrapper factories.

Signed-off-by: Martin Nonnenmacher <[email protected]>
Move the `Options` typealias from model to common-utils to make it
available to the plugin API. This allows to increase consistency as many
plugin configurations already use the typealias.

Signed-off-by: Martin Nonnenmacher <[email protected]>
Use the `Options` typealias in the `PluginManager` and rename the
`parseConfig` function of `TypedConfigurablePluginFactory` to
`parseOptions` accordingly.

Signed-off-by: Martin Nonnenmacher <[email protected]>
@mnonnenmacher mnonnenmacher merged commit 6f1976c into main Sep 26, 2023
@mnonnenmacher mnonnenmacher deleted the refactor-scanner branch September 26, 2023 20:07
@mnonnenmacher
Copy link
Member Author

Merged as the failing ClearlyDefinedPackageCurationProviderFunTest is unrelated to this change.

@@ -138,8 +121,9 @@ data class ScannerCriteria(
val minVersion = parseVersion(options[PROP_CRITERIA_MIN_VERSION]) ?: scannerVersion
val maxVersion = parseVersion(options[PROP_CRITERIA_MAX_VERSION]) ?: minVersion.nextMinor()
val name = options[PROP_CRITERIA_NAME] ?: details.name
val configuration = options[PROP_CRITERIA_CONFIGURATION] ?: details.configuration
Copy link
Member

Choose a reason for hiding this comment

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

@mnonnenmacher, I just realized a general problem with this: ScannerCriteria.configuration is nullable to allow matching all configurations, but we can never set it to null via a scanner's Options as this will then fall back to ScannerDetails.configuration which is non-nullable.

@nnobelis
Copy link
Member

@mnonnenmacher: please mark this PR as breaking change, as it changes the plugins interface.

@mnonnenmacher
Copy link
Member Author

@mnonnenmacher: please mark this PR as breaking change, as it changes the plugins interface.

Done, thanks for the reminder.

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.

3 participants