From 2cd7beb572c16692a6c4c01b39614a815a27f9f0 Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Sun, 2 Feb 2025 13:35:29 +0100 Subject: [PATCH 1/3] docs(utils): Remove a broken KDoc reference Constructor arguments cannot be referenced from class docs if they are not also properties. Signed-off-by: Martin Nonnenmacher --- utils/common/src/main/kotlin/FileMatcher.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/common/src/main/kotlin/FileMatcher.kt b/utils/common/src/main/kotlin/FileMatcher.kt index 644cc40490c9e..51f6412feafe8 100644 --- a/utils/common/src/main/kotlin/FileMatcher.kt +++ b/utils/common/src/main/kotlin/FileMatcher.kt @@ -24,7 +24,7 @@ import org.springframework.util.AntPathMatcher /** * A class to determine whether paths are matched by globs. It can either be used via its static [match] functions, or * (in case different paths have to be matched against the same patterns in the same way over and over again) by - * instantiating it with fixed [patterns], optionally [ignoring case][ignoreCase]. + * instantiating it with fixed [patterns], optionally ignoring case. */ class FileMatcher( /** From e6387fb9bada38312de137b3156bdb001820a392 Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Sun, 2 Feb 2025 13:59:11 +0100 Subject: [PATCH 2/3] docs(utils): Fix a reference to a static function Signed-off-by: Martin Nonnenmacher --- utils/common/src/main/kotlin/FileMatcher.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/common/src/main/kotlin/FileMatcher.kt b/utils/common/src/main/kotlin/FileMatcher.kt index 51f6412feafe8..def6c2804000f 100644 --- a/utils/common/src/main/kotlin/FileMatcher.kt +++ b/utils/common/src/main/kotlin/FileMatcher.kt @@ -22,9 +22,9 @@ package org.ossreviewtoolkit.utils.common import org.springframework.util.AntPathMatcher /** - * A class to determine whether paths are matched by globs. It can either be used via its static [match] functions, or - * (in case different paths have to be matched against the same patterns in the same way over and over again) by - * instantiating it with fixed [patterns], optionally ignoring case. + * A class to determine whether paths are matched by globs. It can either be used via its static + * [match][FileMatcher.Companion.match] functions, or (in case different paths have to be matched against the same + * patterns in the same way over and over again) by instantiating it with fixed [patterns], optionally ignoring case. */ class FileMatcher( /** From 3506c5829118b144776362ec79b1cb141c94ee9e Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Sun, 2 Feb 2025 14:01:16 +0100 Subject: [PATCH 3/3] refactor(utils)!: Rename `FileMatcher.matches` to `matches` This aligns the name of the static functions with the class function which is also called `matches`. Also, this better aligns with framework functions like `Regex.matches`. Signed-off-by: Martin Nonnenmacher --- evaluator/src/main/kotlin/ProjectSourceRule.kt | 6 +++--- helper-cli/src/main/kotlin/commands/ListLicensesCommand.kt | 2 +- helper-cli/src/main/kotlin/utils/PathExcludeGenerator.kt | 4 ++-- model/src/main/kotlin/config/PathExclude.kt | 2 +- model/src/main/kotlin/utils/FindingCurationMatcher.kt | 2 +- utils/common/src/main/kotlin/FileMatcher.kt | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/evaluator/src/main/kotlin/ProjectSourceRule.kt b/evaluator/src/main/kotlin/ProjectSourceRule.kt index 3e16d57380a84..fc89f1729735e 100644 --- a/evaluator/src/main/kotlin/ProjectSourceRule.kt +++ b/evaluator/src/main/kotlin/ProjectSourceRule.kt @@ -70,7 +70,7 @@ open class ProjectSourceRule( fun projectSourceFindDirectories(vararg patterns: String): List = projectSourcesDir.walkBottomUp().filterTo(mutableListOf()) { val path = it.relativeTo(projectSourcesDir).invariantSeparatorsPath - it.isDirectory && FileMatcher.match(patterns.asList(), path) + it.isDirectory && FileMatcher.matches(patterns.asList(), path) } /** @@ -79,7 +79,7 @@ open class ProjectSourceRule( fun projectSourceFindFiles(vararg patterns: String): List = projectSourcesDir.walkBottomUp().filterTo(mutableListOf()) { val path = it.relativeTo(projectSourcesDir).invariantSeparatorsPath - it.isFile && FileMatcher.match(patterns.asList(), path) + it.isFile && FileMatcher.matches(patterns.asList(), path) } /** @@ -87,7 +87,7 @@ open class ProjectSourceRule( */ fun projectSourceGetDetectedLicensesByFilePath(vararg patterns: String): Map> = detectedLicensesForFilePath.filter { (filePath, _) -> - FileMatcher.match(patterns.asList(), filePath) + FileMatcher.matches(patterns.asList(), filePath) } /** diff --git a/helper-cli/src/main/kotlin/commands/ListLicensesCommand.kt b/helper-cli/src/main/kotlin/commands/ListLicensesCommand.kt index 08196bb616316..0ebeb8a721d6a 100644 --- a/helper-cli/src/main/kotlin/commands/ListLicensesCommand.kt +++ b/helper-cli/src/main/kotlin/commands/ListLicensesCommand.kt @@ -180,7 +180,7 @@ internal class ListLicensesCommand : OrtHelperCommand( !offendingOnly || license.decompose().any { it in violatedRulesByLicense } }.mapValues { (license, locations) -> locations.filter { location -> - val isAllowedFile = fileAllowList.isEmpty() || FileMatcher.match(fileAllowList, location.path) + val isAllowedFile = fileAllowList.isEmpty() || FileMatcher.matches(fileAllowList, location.path) val isIncluded = !omitExcluded || !isPathExcluded(provenance, location.path) || ignoreExcludedRuleIds.intersect(violatedRulesByLicense[license].orEmpty()).isNotEmpty() diff --git a/helper-cli/src/main/kotlin/utils/PathExcludeGenerator.kt b/helper-cli/src/main/kotlin/utils/PathExcludeGenerator.kt index 5501a1ccea48e..114cc849eeaa4 100644 --- a/helper-cli/src/main/kotlin/utils/PathExcludeGenerator.kt +++ b/helper-cli/src/main/kotlin/utils/PathExcludeGenerator.kt @@ -59,7 +59,7 @@ internal object PathExcludeGenerator { dirs.forEach { dir -> val (_, reason) = PATH_EXCLUDES_REASON_FOR_DIR_NAME.find { (pattern, _) -> - FileMatcher.match(pattern, File(dir).name, ignoreCase = true) + FileMatcher.matches(pattern, File(dir).name, ignoreCase = true) } ?: return@forEach dirsToExclude += dir to reason @@ -101,7 +101,7 @@ internal object PathExcludeGenerator { internal fun createExcludePatterns(filenamePattern: String, filePaths: Collection): Set { val matchingFiles = filePaths.mapNotNull { filePath -> - File(filePath).takeIf { FileMatcher.match(filenamePattern, it.name) } + File(filePath).takeIf { FileMatcher.matches(filenamePattern, it.name) } }.ifEmpty { return emptySet() } diff --git a/model/src/main/kotlin/config/PathExclude.kt b/model/src/main/kotlin/config/PathExclude.kt index 52b0f6692be50..b9d6cb04cf0a7 100644 --- a/model/src/main/kotlin/config/PathExclude.kt +++ b/model/src/main/kotlin/config/PathExclude.kt @@ -49,7 +49,7 @@ data class PathExclude( * Return true if and only if this [PathExclude] matches the given [path]. */ fun matches(path: String) = - FileMatcher.match( + FileMatcher.matches( pattern = pattern.removePrefix("./"), path = path ) diff --git a/model/src/main/kotlin/utils/FindingCurationMatcher.kt b/model/src/main/kotlin/utils/FindingCurationMatcher.kt index f727b5b618e12..03382116c6cd5 100644 --- a/model/src/main/kotlin/utils/FindingCurationMatcher.kt +++ b/model/src/main/kotlin/utils/FindingCurationMatcher.kt @@ -34,7 +34,7 @@ class FindingCurationMatcher { curation: LicenseFindingCuration, relativeFindingPath: String ): Boolean = - FileMatcher.match( + FileMatcher.matches( pattern = curation.path, path = finding.location.prependedPath(relativeFindingPath) ) diff --git a/utils/common/src/main/kotlin/FileMatcher.kt b/utils/common/src/main/kotlin/FileMatcher.kt index def6c2804000f..39f30413d7a8a 100644 --- a/utils/common/src/main/kotlin/FileMatcher.kt +++ b/utils/common/src/main/kotlin/FileMatcher.kt @@ -23,7 +23,7 @@ import org.springframework.util.AntPathMatcher /** * A class to determine whether paths are matched by globs. It can either be used via its static - * [match][FileMatcher.Companion.match] functions, or (in case different paths have to be matched against the same + * [match][FileMatcher.Companion.matches] functions, or (in case different paths have to be matched against the same * patterns in the same way over and over again) by instantiating it with fixed [patterns], optionally ignoring case. */ class FileMatcher( @@ -47,14 +47,14 @@ class FileMatcher( * Return true if [path] is matched by [pattern], false otherwise. The [path] must use '/' as separators, if it * contains any. */ - fun match(pattern: String, path: String, ignoreCase: Boolean = false) = + fun matches(pattern: String, path: String, ignoreCase: Boolean = false) = if (ignoreCase) matchCaseInsensitive(pattern, path) else matchCaseSensitive(pattern, path) /** * Return true if [path] is matched by any of [patterns], false otherwise. The [path] must use '/' as * separators, if it contains any. */ - fun match(patterns: Collection, path: String, ignoreCase: Boolean = false): Boolean { + fun matches(patterns: Collection, path: String, ignoreCase: Boolean = false): Boolean { // Only decide once for all patterns which function to call. val match = if (ignoreCase) matchCaseInsensitive else matchCaseSensitive