Skip to content

Commit b3020f5

Browse files
committed
refactor(utils)!: Rename FileMatcher.matches to match
This aligns the name of the class function with the static functions which are also called `match`. Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
1 parent 78c5cfc commit b3020f5

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

model/src/main/kotlin/ScanSummary.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ data class ScanSummary(
140140
val matcher = FileMatcher(ignorePatterns)
141141

142142
return copy(
143-
licenseFindings = licenseFindings.filterTo(mutableSetOf()) { !matcher.matches(it.location.path) },
144-
copyrightFindings = copyrightFindings.filterTo(mutableSetOf()) { !matcher.matches(it.location.path) },
145-
snippetFindings = snippetFindings.filterTo(mutableSetOf()) { !matcher.matches(it.sourceLocation.path) },
146-
issues = issues.filter { it.affectedPath == null || !matcher.matches(it.affectedPath) }
143+
licenseFindings = licenseFindings.filterTo(mutableSetOf()) { !matcher.match(it.location.path) },
144+
copyrightFindings = copyrightFindings.filterTo(mutableSetOf()) { !matcher.match(it.location.path) },
145+
snippetFindings = snippetFindings.filterTo(mutableSetOf()) { !matcher.match(it.sourceLocation.path) },
146+
issues = issues.filter { it.affectedPath == null || !matcher.match(it.affectedPath) }
147147
)
148148
}
149149
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class FileArchiver(
7777
directory.packZip(zipFile, overwrite = true) { file ->
7878
val relativePath = file.relativeTo(directory).invariantSeparatorsPath
7979

80-
matcher.matches(relativePath).also { result ->
80+
matcher.match(relativePath).also { result ->
8181
logger.debug {
8282
if (result) {
8383
"Adding '$relativePath' to archive."

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class PathLicenseMatcher(licenseFilePatterns: LicenseFilePatterns = LicenseFileP
7878
require(relativeFilePaths.none { it.startsWith("/") })
7979

8080
fun filePathsByDir(matcher: FileMatcher): Map<String, Set<String>> =
81-
relativeFilePaths.filter { matcher.matches("/$it") }.groupBy {
81+
relativeFilePaths.filter { matcher.match("/$it") }.groupBy {
8282
File("/$it").parentFile.invariantSeparatorsPath
8383
}.mapValues { it.value.toSet() }
8484

scanner/src/main/kotlin/utils/FileListResolver.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private val IGNORED_DIRECTORY_MATCHER by lazy {
9797

9898
private fun createFileList(dir: File): FileList {
9999
val files = dir.walk().onEnter {
100-
!IGNORED_DIRECTORY_MATCHER.matches(it.relativeTo(dir).invariantSeparatorsPath) && !it.isSymbolicLink()
100+
!IGNORED_DIRECTORY_MATCHER.match(it.relativeTo(dir).invariantSeparatorsPath) && !it.isSymbolicLink()
101101
}.filter {
102102
it.isFile && !it.isSymbolicLink()
103103
}.mapTo(mutableSetOf()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ class FileMatcher(
7070
* Return true if [path] is matched by any of [patterns], false otherwise. The [path] must use '/' as separators,
7171
* if it contains any.
7272
*/
73-
fun matches(path: String): Boolean = patterns.any { pattern -> match(pattern, path) }
73+
fun match(path: String): Boolean = patterns.any { pattern -> match(pattern, path) }
7474
}

utils/common/src/test/kotlin/FileMatcherTest.kt

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,66 +27,66 @@ class FileMatcherTest : StringSpec({
2727
val matcher = FileMatcher("a/LICENSE", "b/LICENSE")
2828

2929
with(matcher) {
30-
matches("a/LICENSE") shouldBe true
31-
matches("b/LICENSE") shouldBe true
32-
matches("c/LICENSE") shouldBe false
30+
match("a/LICENSE") shouldBe true
31+
match("b/LICENSE") shouldBe true
32+
match("c/LICENSE") shouldBe false
3333
}
3434
}
3535

3636
"Patterns with globs should be matched" {
3737
val matcher = FileMatcher("*.md", "dir/*.txt")
3838

3939
with(matcher) {
40-
matches("README.md") shouldBe true
41-
matches("dir/info.txt") shouldBe true
42-
matches("root.txt") shouldBe false
43-
matches("dir/doc.md") shouldBe false
40+
match("README.md") shouldBe true
41+
match("dir/info.txt") shouldBe true
42+
match("root.txt") shouldBe false
43+
match("dir/doc.md") shouldBe false
4444
}
4545
}
4646

4747
"A globstar should match zero or more directories" {
4848
val matcher = FileMatcher("**/src/**")
4949

5050
with(matcher) {
51-
matches("project/src/main") shouldBe true
52-
matches("project/src") shouldBe true
53-
matches("src/main") shouldBe true
54-
matches("a/project/src/main/kotlin") shouldBe true
55-
matches("src") shouldBe true
56-
matches("./src") shouldBe true
57-
matches("srcs") shouldBe false
51+
match("project/src/main") shouldBe true
52+
match("project/src") shouldBe true
53+
match("src/main") shouldBe true
54+
match("a/project/src/main/kotlin") shouldBe true
55+
match("src") shouldBe true
56+
match("./src") shouldBe true
57+
match("srcs") shouldBe false
5858
}
5959
}
6060

6161
"Glob and globstar can be combined" {
6262
val matcher = FileMatcher("*/**/examples")
6363

6464
with(matcher) {
65-
matches("project/examples") shouldBe true
66-
matches("project/subproject/examples") shouldBe true
67-
matches("examples") shouldBe false
68-
matches("project/examples/hello") shouldBe false
65+
match("project/examples") shouldBe true
66+
match("project/subproject/examples") shouldBe true
67+
match("examples") shouldBe false
68+
match("project/examples/hello") shouldBe false
6969
}
7070
}
7171

7272
"Matching should adhere ignoring case" {
7373
FileMatcher("LICENSE", ignoreCase = false).apply {
74-
matches("LICENSE") shouldBe true
75-
matches("license") shouldBe false
74+
match("LICENSE") shouldBe true
75+
match("license") shouldBe false
7676
}
7777

7878
FileMatcher("LICENSE", ignoreCase = true).apply {
79-
matches("LICENSE") shouldBe true
80-
matches("license") shouldBe true
79+
match("LICENSE") shouldBe true
80+
match("license") shouldBe true
8181
}
8282
}
8383

8484
"Groups of subpatterns can be matched" {
8585
FileMatcher("*.{:java|class}", ignoreCase = false).apply {
86-
matches("x.java") shouldBe true
87-
matches("x.class") shouldBe true
88-
matches("x.cpp") shouldBe false
89-
matches("dir/x.java") shouldBe false
86+
match("x.java") shouldBe true
87+
match("x.class") shouldBe true
88+
match("x.cpp") shouldBe false
89+
match("dir/x.java") shouldBe false
9090
}
9191
}
9292
})

0 commit comments

Comments
 (0)