-
Notifications
You must be signed in to change notification settings - Fork 364
Improve the logic to determine the main license #10349
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
base: main
Are you sure you want to change the base?
Changes from all commits
468dee1
c25bc22
ac6e185
7290fa3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,11 +23,13 @@ | |
| import org.ossreviewtoolkit.model.Identifier | ||
| import org.ossreviewtoolkit.model.LicenseSource | ||
| import org.ossreviewtoolkit.model.Provenance | ||
| import org.ossreviewtoolkit.model.RepositoryProvenance | ||
| import org.ossreviewtoolkit.model.config.CopyrightGarbage | ||
| import org.ossreviewtoolkit.model.config.LicenseFilePatterns | ||
| import org.ossreviewtoolkit.model.config.PathExclude | ||
| import org.ossreviewtoolkit.model.utils.PathLicenseMatcher | ||
| import org.ossreviewtoolkit.model.utils.vcsPath | ||
| import org.ossreviewtoolkit.utils.common.FileMatcher | ||
Check warningCode scanning / detekt Detects unused imports Warning
Unused import
Check warningCode scanning / QDJVMC Unused import directive Warning
Unused import directive
|
||
| import org.ossreviewtoolkit.utils.ort.CopyrightStatementsProcessor | ||
| import org.ossreviewtoolkit.utils.spdx.SpdxExpression | ||
| import org.ossreviewtoolkit.utils.spdx.SpdxLicenseChoice | ||
|
|
@@ -83,31 +85,32 @@ | |
| * in any of the configured [LicenseFilePatterns] matched against the root path of the package (or project). | ||
| */ | ||
| fun mainLicense(): SpdxExpression? { | ||
| val matcher = PathLicenseMatcher(LicenseFilePatterns.getInstance()) | ||
| val licensePaths = flatMap { resolvedLicense -> | ||
| val licenseFilePatterns = LicenseFilePatterns.getInstance() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commit-message: If this fixes this serious performance issue, I believe this should be made more prominent. Furthermore, could you add some details, why exactly previously it was so slow?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For these topics, I'd refer to the original fix in ebc6fe0. |
||
| val licenseMatcher = PathLicenseMatcher(licenseFilePatterns) | ||
|
|
||
| val declaredLicenses = filter(LicenseView.ONLY_DECLARED, filterSources = true) | ||
| val detectedLicenses = filter(LicenseView.ONLY_DETECTED, filterSources = true) | ||
|
|
||
| val licensePaths = detectedLicenses.flatMapTo(mutableSetOf()) { resolvedLicense -> | ||
| resolvedLicense.locations.map { it.location.path } | ||
| } | ||
|
|
||
| val applicablePathsCache = mutableMapOf<String, Map<String, Set<String>>>() | ||
| val detectedLicenses = filterTo(mutableSetOf()) { resolvedLicense -> | ||
| resolvedLicense.locations.any { | ||
| val rootPath = (it.provenance as? RepositoryProvenance)?.vcsInfo?.path.orEmpty() | ||
| val packageRoot = detectedLicenses.firstOrNull()?.locations?.firstOrNull()?.provenance.vcsPath | ||
|
|
||
| val applicableLicensePaths = applicablePathsCache.getOrPut(rootPath) { | ||
| matcher.getApplicableLicenseFilesForDirectories( | ||
| licensePaths, | ||
| listOf(rootPath) | ||
| ) | ||
| } | ||
| val applicableLicensePaths = licenseMatcher.getApplicableLicenseFilesForDirectories( | ||
| licensePaths, | ||
| listOf(packageRoot) | ||
| ) | ||
|
|
||
| val applicableLicenseFiles = applicableLicensePaths[rootPath].orEmpty() | ||
| val applicableLicenseFiles = applicableLicensePaths[packageRoot].orEmpty() | ||
|
|
||
| val relevantDetectedLicenses = detectedLicenses.filterTo(mutableSetOf()) { resolvedLicense -> | ||
| resolvedLicense.locations.any { | ||
| it.location.path in applicableLicenseFiles | ||
| } | ||
| } | ||
|
|
||
| val declaredLicenses = filter(LicenseView.ONLY_DECLARED) | ||
| val mainLicenses = (detectedLicenses + declaredLicenses.licenses) | ||
| val mainLicenses = (declaredLicenses.licenses + relevantDetectedLicenses) | ||
| .flatMap { it.originalExpressions } | ||
| .map { it.expression } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only maybe related: Are we actually missing some kind of
distinct()call onrelativeFilePathsin ...?As I just noticed the comment, that the issue came from large amount of paths.