Skip to content

Commit

Permalink
changes for RAT
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudenw authored and slachiewicz committed Nov 5, 2024
1 parent de43144 commit 299af7a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/main/java/org/codehaus/plexus/util/MatchPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<String> ret = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(path, separator);
while (st.hasMoreTokens()) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/codehaus/plexus/util/MatchPatterns.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getSources() {
List<String> sources = new ArrayList<>();
for (MatchPattern pattern : patterns) {
sources.add(pattern.getSource());
}
return sources;
}

/**
* <p>Checks these MatchPatterns against a specified string.</p>
*
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/org/codehaus/plexus/util/SelectorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 299af7a

Please sign in to comment.