AlexanderAshitkin commented on code in PR #391:
URL:
https://github.com/apache/maven-build-cache-extension/pull/391#discussion_r2404809759
##########
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java:
##########
@@ -434,6 +440,55 @@ private static String normalizedPath(Path path, Path
baseDirPath) {
return normalizedPath;
}
+ /**
+ * Filters array values based on ignore pattern and converts to string
representation.
+ */
+ private static String filterAndStringifyArray(Object array, String
ignorePattern) {
+ if (ignorePattern == null) {
+ return ArrayUtils.toString(array);
+ }
+
+ java.util.regex.Pattern pattern =
java.util.regex.Pattern.compile(ignorePattern);
+ java.util.List<Object> filtered = new java.util.ArrayList<>();
+
+ int length = java.lang.reflect.Array.getLength(array);
+ for (int i = 0; i < length; i++) {
+ Object element = java.lang.reflect.Array.get(array, i);
+ String elementStr = String.valueOf(element);
+ if (!pattern.matcher(elementStr).find()) {
+ filtered.add(element);
+ }
+ }
+
+ return filtered.toString();
+ }
+
+ /**
+ * Filters an array string representation (e.g., "[a, b, c]") based on
ignore pattern.
+ */
+ private static String filterArrayString(String arrayStr, String
ignorePattern) {
+ if (ignorePattern == null || !arrayStr.startsWith("[") ||
!arrayStr.endsWith("]")) {
+ return arrayStr;
+ }
+
+ java.util.regex.Pattern pattern =
java.util.regex.Pattern.compile(ignorePattern);
+ String content = arrayStr.substring(1, arrayStr.length() - 1);
+ if (content.trim().isEmpty()) {
+ return "[]";
+ }
+
+ String[] elements = content.split(",\\s*");
+ java.util.List<String> filtered = new java.util.ArrayList<>();
+
+ for (String element : elements) {
+ if (!pattern.matcher(element.trim()).find()) {
Review Comment:
I'm not sure about the `find` function applicability here. If someone uses
the pattern `\\d+`, does that person expect to match something like `Maven4`?
An average user, will expect the pattern to strictly match numbers. And if
broader match is required, an user will specify a different pattern, like as
`[A-Za-z]+\\d+`. I'm in favor of `matches` here.
It is better to add a test to capture the expected behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]