From 2b68c66ada09a3d11a08d09a7be7fc30faa87073 Mon Sep 17 00:00:00 2001 From: Claude Warren Date: Sat, 19 Oct 2024 12:23:26 +0100 Subject: [PATCH] updated documentation --- .../codehaus/plexus/util/MatchPattern.java | 2 +- .../codehaus/plexus/util/SelectorUtils.java | 31 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/MatchPattern.java b/src/main/java/org/codehaus/plexus/util/MatchPattern.java index 12c12bc7..4c276f3b 100644 --- a/src/main/java/org/codehaus/plexus/util/MatchPattern.java +++ b/src/main/java/org/codehaus/plexus/util/MatchPattern.java @@ -59,7 +59,7 @@ private MatchPattern(String source, String separator) { } /** - * Gets the source pattern for this matchpattern. + * Gets the source pattern for this match pattern. * @return the source string without Ant or Regex pattern markers. */ public String getSource() { diff --git a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java index 37d654ab..3f767b14 100644 --- a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java +++ b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java @@ -139,7 +139,7 @@ public static boolean matchPatternStart(String pattern, String str, boolean isCa } } - static boolean isAntPrefixedPattern(String pattern) { + public static boolean isAntPrefixedPattern(String pattern) { return pattern.length() > (ANT_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1) && pattern.startsWith(ANT_HANDLER_PREFIX) && pattern.endsWith(PATTERN_HANDLER_SUFFIX); @@ -243,17 +243,6 @@ 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); @@ -719,4 +708,22 @@ public static String removeWhitespace(String input) { } return result.toString(); } + + /** + * Extract the pattern without the Regex or Ant prefix. In the case of Ant style matches ensure + * that the path uses specified separator. + * @param pattern the pattern to extract from. + * @param separator the system file name separator in the pattern. + * @return The pattern without the Regex or Ant prefix. + */ + 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); + } + } }