From 299af7a1e965eb966e7f500426922db1cd40c880 Mon Sep 17 00:00:00 2001 From: Claude Warren Date: Fri, 18 Oct 2024 11:30:17 +0100 Subject: [PATCH] changes for RAT --- .../java/org/codehaus/plexus/util/MatchPattern.java | 10 +++++++++- .../org/codehaus/plexus/util/MatchPatterns.java | 12 ++++++++++++ .../org/codehaus/plexus/util/SelectorUtils.java | 13 ++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/MatchPattern.java b/src/main/java/org/codehaus/plexus/util/MatchPattern.java index 4dc757e3..12c12bc7 100644 --- a/src/main/java/org/codehaus/plexus/util/MatchPattern.java +++ b/src/main/java/org/codehaus/plexus/util/MatchPattern.java @@ -58,6 +58,14 @@ private MatchPattern(String source, String separator) { } } + /** + * Gets the source pattern for this matchpattern. + * @return the source string without Ant or Regex pattern markers. + */ + public String getSource() { + return source; + } + public boolean matchPath(String str, boolean isCaseSensitive) { if (regexPattern != null) { return str.matches(regexPattern); @@ -99,7 +107,7 @@ public boolean startsWith(String string) { return source.startsWith(string); } - static String[] tokenizePathToString(String path, String separator) { + public static String[] tokenizePathToString(String path, String separator) { List ret = new ArrayList(); StringTokenizer st = new StringTokenizer(path, separator); while (st.hasMoreTokens()) { diff --git a/src/main/java/org/codehaus/plexus/util/MatchPatterns.java b/src/main/java/org/codehaus/plexus/util/MatchPatterns.java index fd36a9d8..9c14bf00 100644 --- a/src/main/java/org/codehaus/plexus/util/MatchPatterns.java +++ b/src/main/java/org/codehaus/plexus/util/MatchPatterns.java @@ -16,6 +16,18 @@ private MatchPatterns(MatchPattern[] patterns) { this.patterns = patterns; } + /** + * Gets a list of enclosed MatchPattern sources. + * @return A list of enclosed MatchPattern sources. + */ + public List getSources() { + List sources = new ArrayList<>(); + for (MatchPattern pattern : patterns) { + sources.add(pattern.getSource()); + } + return sources; + } + /** *

Checks these MatchPatterns against a specified string.

* diff --git a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java index f5122c78..37d654ab 100644 --- a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java +++ b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java @@ -243,6 +243,17 @@ public static boolean matchPath(String pattern, String str, String separator, bo } } + public static String extractPattern(final String pattern, final String separator) { + if (isRegexPrefixedPattern(pattern)) { + return pattern.substring(REGEX_HANDLER_PREFIX.length(), pattern.length() - PATTERN_HANDLER_SUFFIX.length()); + } else { + String localPattern = isAntPrefixedPattern(pattern) + ? pattern.substring(ANT_HANDLER_PREFIX.length(), pattern.length() - PATTERN_HANDLER_SUFFIX.length()) + : pattern; + return toOSRelatedPath(localPattern, separator); + } + } + private static String toOSRelatedPath(String pattern, String separator) { if ("/".equals(separator)) { return pattern.replace("\\", separator); @@ -253,7 +264,7 @@ private static String toOSRelatedPath(String pattern, String separator) { return pattern; } - static boolean isRegexPrefixedPattern(String pattern) { + public static boolean isRegexPrefixedPattern(String pattern) { return pattern.length() > (REGEX_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1) && pattern.startsWith(REGEX_HANDLER_PREFIX) && pattern.endsWith(PATTERN_HANDLER_SUFFIX);