Ant Pattern Matching - * vs. **

2019-06-18 04:54发布

We are using TeamCity to produce *.nupkg artifacts which we don't want to be cleaned up. TeamCity provides a field where you can specify an ANT-style pattern for indicating which files you do or don't want to be cleaned up. Let's assume for a second that we have the following files which we do not want to be cleaned up:

/a.nupkg
/dir1/b.nupkg
/dir1/dir2/c.nupkg

Does the *.nupkg pattern match .nupkg files both in the root directory AND all child directories or do need to use **.*nupkg to traverse all directories?

I read the following documentation but this is still ambiguous to me: http://ant.apache.org/manual/dirtasks.html#patterns

If there is an Ant-Pattern tester (similar to http://regexpal.com/) that would be amazing.

2条回答
我想做一个坏孩纸
2楼-- · 2019-06-18 05:13

For testing of your patterns a simple way is to echo your fileset contents to stdout or to file, f.e. :

<project>
  <fileset dir="..." id="foobar">
   <include name="..."/>
   <!-- .. -->
  </fileset>

  <!-- simple echo -->
  <echo>${toString:foobar}</echo>

  <!-- use pathconvert for listing files line by line -->
  <pathconvert property="foo" pathsep="${line.separator}" refid="foobar"/>

  <!-- simple echo -->
  <echo>${foo}</echo>

  <!-- print to file -->
  <echo file="whatever.txt">${foo}</echo>

  <!-- use nested mapper if you need only basename -->
  <pathconvert property="fooflat" pathsep="${line.separator}" refid="foobar">
   <mapper>
    <flattenmapper />
   </mapper>
  </pathconvert>

  <echo>$${fooflat} => ${line.separator}${fooflat}</echo>

  <!-- to combine several filesets use -->
  <path id="fooo">
   <fileset dir="...">
    <include name=".."/>
   </fileset>
   <fileset>
     <!-- ... -->
   </fileset>
   <fileset>
     <!-- ... -->
   </fileset>
    <!-- ... -- >
  </path>

  <echo>$${fooo} => ${fooo}</echo>

</project>
查看更多
Juvenile、少年°
3楼-- · 2019-06-18 05:27

To match all files, in all directories (from the base directory and deeper)

**/*.nupkg

Will match

sample.nupkg
sample-2.nupkg
tmp/sample.nupkg
tmp/other.nupkg
other/new/sample.nupkg

** will match any directory (multiple directories deep).

*.nupkg will match any file with the nupkg extension. Or just * will match any file or any directory (but just a single directory deep).

PS: There is no Ant Pattern Tester.

查看更多
登录 后发表回答