Skip to content

Commit 1907d0d

Browse files
authored
Always create a new group matcher and add exception details (#103)
* Always create a new group matcher and add exception details * remove matcher reset since we always create a new group matcher
1 parent f8c6c91 commit 1907d0d

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/main/kotlin/nebula/plugin/resolutionrules/alignRule.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ data class AlignRule(val name: String?,
6262
fun ruleMatches(dep: ModuleVersionIdentifier) = ruleMatches(dep.group, dep.name)
6363

6464
fun ruleMatches(inputGroup: String, inputName: String): Boolean {
65-
if (groupMatcher == null) {
66-
groupMatcher = safelyCreatesMatcher(group, inputGroup, "group")
67-
includesMatchers = includes.map { safelyCreatesMatcher(it, inputName, "includes") }
68-
excludesMatchers = excludes.map { safelyCreatesMatcher(it, inputName, "excludes") }
69-
}
65+
groupMatcher = safelyCreatesMatcher(group, inputGroup, "group")
66+
includesMatchers = includes.map { safelyCreatesMatcher(it, inputName, "includes") }
67+
excludesMatchers = excludes.map { safelyCreatesMatcher(it, inputName, "excludes") }
68+
7069

7170
return safelyMatches(groupMatcher!!, inputGroup, "group") &&
7271
(includes.isEmpty() || includesMatchers.any { safelyMatches(it, inputName, "includes") }) &&
@@ -78,16 +77,16 @@ data class AlignRule(val name: String?,
7877
it.toPattern().matcher(input)
7978
} catch (e: Exception) {
8079
throw java.lang.IllegalArgumentException("Failed to use regex '$it' from type '$type' to create matcher for '$input'\n" +
81-
"Rule: ${this}")
80+
"Rule: ${this}", e)
8281
}
8382
}
8483

8584
private fun safelyMatches(it: Matcher, input: String, type: String): Boolean {
8685
return try {
87-
it.matches(input)
86+
it.matches()
8887
} catch (e: Exception) {
8988
throw java.lang.IllegalArgumentException("Failed to use matcher '$it' from type '$type' to match '$input'\n" +
90-
"Rule: ${this}")
89+
"Rule: ${this}", e)
9190
}
9291
}
9392
}
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package nebula.plugin.resolutionrules
22

3-
import java.util.regex.Matcher
4-
53
inline fun <T, R> Collection<T>.mapToSet(transform: (T) -> R): Set<R> {
64
return mapTo(LinkedHashSet<R>(size), transform)
75
}
8-
9-
fun Matcher.matches(input: CharSequence) =
10-
reset(input).matches()

0 commit comments

Comments
 (0)