Tuesday 30 July 2019

Apache Ant Patterns


Apache Ant is used for Java build files. It uses so called "Ant-style" wildcards which have been accepted and are now used by many other tools.

Ant-style wildcards:


?


  • Matches one character (any character except path separators)
  • used to match file names
  • matches one level
  • any character except path separators



  • Matches zero or more characters (not including path separators)
  • used to match file names
  • matches one level
  • any character except path separators


**


  • Matches zero or more path segments (directory tree) 
  • used for folder-names matching
  • includes/matches path separators (slash, /) 
  • matches multiple levels
  • src/**/*.cs will find all cs files in any sub-directory of src



If we have the following tree:

/dir1/dir2/file1.txt
/dir1/dir2/dir3/file2.txt

Ant pattern which filters all .txt files in any subdirectory of a dir2 directory would be:

**/dir/**/*.txt

When ** is used as the name of a directory in the pattern, it matches zero or more directories.

References:


Directory-based Tasks
How do I use Nant/Ant naming patterns?
Pattern matching guide
Learning Ant path style

No comments: