org.sonar.api.utils
Class WildcardPattern

java.lang.Object
  extended by org.sonar.api.utils.WildcardPattern

public class WildcardPattern
extends Object

Implementation of Ant-style matching patterns. Contrary to other implementations (like AntPathMatcher from Spring Framework) it is based on Java Regular Expressions. To increase performance it holds an internal cache of all processed patterns.

Following rules are applied:

Some examples of patterns:

Another implementation, which is also based on Java Regular Expressions, can be found in FileUtil from IntelliJ OpenAPI.

Since:
1.10

Constructor Summary
protected WildcardPattern(String pattern, String directorySeparator)
           
 
Method Summary
static WildcardPattern create(String pattern)
          Creates pattern with "/" as a directory separator.
static WildcardPattern[] create(String[] patterns)
          Creates array of patterns with "/" as a directory separator.
static WildcardPattern create(String pattern, String directorySeparator)
          Creates pattern with specified separator for directories.
 boolean match(String value)
          Returns true if specified value matches this pattern.
static boolean match(WildcardPattern[] patterns, String value)
          Returns true if specified value matches one of specified patterns.
 String toString()
          Returns string representation of this pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WildcardPattern

protected WildcardPattern(String pattern,
                          String directorySeparator)
Method Detail

toString

public String toString()
Returns string representation of this pattern.

Overrides:
toString in class Object
Since:
2.5

match

public boolean match(String value)
Returns true if specified value matches this pattern.


match

public static boolean match(WildcardPattern[] patterns,
                            String value)
Returns true if specified value matches one of specified patterns.

Since:
2.4

create

public static WildcardPattern create(String pattern)
Creates pattern with "/" as a directory separator.

See Also:
create(String, String)

create

public static WildcardPattern[] create(String[] patterns)
Creates array of patterns with "/" as a directory separator.

See Also:
create(String, String)

create

public static WildcardPattern create(String pattern,
                                     String directorySeparator)
Creates pattern with specified separator for directories.

This is used to match Java-classes, i.e. org.foo.Bar against org/**. However usage of character other than "/" as a directory separator is misleading and should be avoided, so method create(String) is preferred over this one.

Also note that no matter whether forward or backward slashes were used in the antPattern the returned pattern will use directorySeparator. Thus to match Windows-style path "dir\file.ext" against pattern "dir/file.ext" normalization should be performed.



Copyright © 2009-2013 SonarSource. All Rights Reserved.