Skip to content

Commit 48b638f

Browse files
committed
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 <[email protected]>
1 parent ad803a0 commit 48b638f

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

evaluator/src/main/kotlin/ProjectSourceRule.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ open class ProjectSourceRule(
7070
fun projectSourceFindDirectories(vararg patterns: String): List<File> =
7171
projectSourcesDir.walkBottomUp().filterTo(mutableListOf()) {
7272
val path = it.relativeTo(projectSourcesDir).invariantSeparatorsPath
73-
it.isDirectory && FileMatcher.match(patterns.asList(), path)
73+
it.isDirectory && FileMatcher.matches(patterns.asList(), path)
7474
}
7575

7676
/**
@@ -79,15 +79,15 @@ open class ProjectSourceRule(
7979
fun projectSourceFindFiles(vararg patterns: String): List<File> =
8080
projectSourcesDir.walkBottomUp().filterTo(mutableListOf()) {
8181
val path = it.relativeTo(projectSourcesDir).invariantSeparatorsPath
82-
it.isFile && FileMatcher.match(patterns.asList(), path)
82+
it.isFile && FileMatcher.matches(patterns.asList(), path)
8383
}
8484

8585
/**
8686
* Return the detected licenses for any file matching the given [glob expressions][patterns].
8787
*/
8888
fun projectSourceGetDetectedLicensesByFilePath(vararg patterns: String): Map<String, Set<String>> =
8989
detectedLicensesForFilePath.filter { (filePath, _) ->
90-
FileMatcher.match(patterns.asList(), filePath)
90+
FileMatcher.matches(patterns.asList(), filePath)
9191
}
9292

9393
/**

helper-cli/src/main/kotlin/commands/ListLicensesCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ internal class ListLicensesCommand : OrtHelperCommand(
180180
!offendingOnly || license.decompose().any { it in violatedRulesByLicense }
181181
}.mapValues { (license, locations) ->
182182
locations.filter { location ->
183-
val isAllowedFile = fileAllowList.isEmpty() || FileMatcher.match(fileAllowList, location.path)
183+
val isAllowedFile = fileAllowList.isEmpty() || FileMatcher.matches(fileAllowList, location.path)
184184

185185
val isIncluded = !omitExcluded || !isPathExcluded(provenance, location.path) ||
186186
ignoreExcludedRuleIds.intersect(violatedRulesByLicense[license].orEmpty()).isNotEmpty()

helper-cli/src/main/kotlin/utils/PathExcludeGenerator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal object PathExcludeGenerator {
5959

6060
dirs.forEach { dir ->
6161
val (_, reason) = PATH_EXCLUDES_REASON_FOR_DIR_NAME.find { (pattern, _) ->
62-
FileMatcher.match(pattern, File(dir).name, ignoreCase = true)
62+
FileMatcher.matches(pattern, File(dir).name, ignoreCase = true)
6363
} ?: return@forEach
6464

6565
dirsToExclude += dir to reason
@@ -101,7 +101,7 @@ internal object PathExcludeGenerator {
101101

102102
internal fun createExcludePatterns(filenamePattern: String, filePaths: Collection<String>): Set<String> {
103103
val matchingFiles = filePaths.mapNotNull { filePath ->
104-
File(filePath).takeIf { FileMatcher.match(filenamePattern, it.name) }
104+
File(filePath).takeIf { FileMatcher.matches(filenamePattern, it.name) }
105105
}.ifEmpty {
106106
return emptySet()
107107
}

model/src/main/kotlin/config/PathExclude.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ data class PathExclude(
4949
* Return true if and only if this [PathExclude] matches the given [path].
5050
*/
5151
fun matches(path: String) =
52-
FileMatcher.match(
52+
FileMatcher.matches(
5353
pattern = pattern.removePrefix("./"),
5454
path = path
5555
)

model/src/main/kotlin/utils/FindingCurationMatcher.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class FindingCurationMatcher {
3434
curation: LicenseFindingCuration,
3535
relativeFindingPath: String
3636
): Boolean =
37-
FileMatcher.match(
37+
FileMatcher.matches(
3838
pattern = curation.path,
3939
path = finding.location.prependedPath(relativeFindingPath)
4040
)

utils/common/src/main/kotlin/FileMatcher.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import org.springframework.util.AntPathMatcher
2323

2424
/**
2525
* A class to determine whether paths are matched by globs. It can either be used via its static
26-
* [match][FileMatcher.Companion.match] functions, or (in case different paths have to be matched against the same
26+
* [match][FileMatcher.Companion.matches] functions, or (in case different paths have to be matched against the same
2727
* patterns in the same way over and over again) by instantiating it with fixed [patterns], optionally ignoring case.
2828
*/
2929
class FileMatcher(
@@ -47,14 +47,14 @@ class FileMatcher(
4747
* Return true if [path] is matched by [pattern], false otherwise. The [path] must use '/' as separators, if it
4848
* contains any.
4949
*/
50-
fun match(pattern: String, path: String, ignoreCase: Boolean = false) =
50+
fun matches(pattern: String, path: String, ignoreCase: Boolean = false) =
5151
if (ignoreCase) matchCaseInsensitive(pattern, path) else matchCaseSensitive(pattern, path)
5252

5353
/**
5454
* Return true if [path] is matched by any of [patterns], false otherwise. The [path] must use '/' as
5555
* separators, if it contains any.
5656
*/
57-
fun match(patterns: Collection<String>, path: String, ignoreCase: Boolean = false): Boolean {
57+
fun matches(patterns: Collection<String>, path: String, ignoreCase: Boolean = false): Boolean {
5858
// Only decide once for all patterns which function to call.
5959
val match = if (ignoreCase) matchCaseInsensitive else matchCaseSensitive
6060

0 commit comments

Comments
 (0)