开发者

Ant exclude file based on it's content

Is there any way to exclude files from an ant fileset based on the 开发者_C百科file content?

We do have test servers where code files are mixed up with files that have been generated by a CMS. Usually, the files are placed in different folders, but there is a risk that real code files are in the middle of generated code.

The only way to differentiate generated files is to open the files and look at it's content. If the file contains a keyword, it should be excluded.

Does anyone know a way to perform this with Ant?

From the answer provided by Preet Sangha, Ishould use a filterchain. However, I'm missing a step here.

Let's say I load a text file of exclusions to be performed:

<loadfile property="exclusions" srcFile="exclusions.txt" />

But I don't know how to integrate it into my current copy task:

<copy todir="${test.dir}">
  <fileset dir="${src.dir}">

  </fileset>
</copy>

I tried to add the following exclude to the fileset but it does not do anything:

<exclude name="${exclusions}"/>

I'm sure I'm missing a simple step...


Have a look at the not and contains selectors.

The not selector contains an example of pretty much exactly what you're trying to do.

<copy todir="${test.dir}">
  <fileset dir="${src.dir}">
    <not>
      <contains text="your-keyword-here"/>
    </not>
  </fileset>
</copy>

There's also the containsregexp selector which might be useful if your criteria for exclusion is more complicated.

There's a load more selectors you can use to refine your selection if needed.


I don't know ant but reading the docs....

  • Can you build a files list using a filterchain, and put this into the excludefiles of a fileset?

or

  • perhaps create a fileset with a filterchain that uses a filterreader and linecontainsregexp
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜