tags:

views:

38

answers:

3

Hi! I want to add a copyright notice to a series of files generated in an Ant build. What's the easiest way to do it?

I thought about using <concat> but I don't understand how to run it on a fileset without concatenating all the files in the fileset.

Thanks!

A: 

One option might be to use <concat> but within an antcontrib <foreach> task.

Jon Skeet
+2  A: 

If you only want to selectively add the copyright the use a copy command that replaces @COPYRIGHT@ tokens within the files.

  <copy todir="../backup/dir">
    <fileset dir="src_dir"/>
    <filterset>
      <filter token="COPYRIGHT" value="This text is my copyright!"/>
    </filterset>
  </copy>
Mark O'Connor
The problem is that my code is in javascript and compressors remove all comments, so I can't use tokens :(
juandopazo
Isn't a copyright notice a form of comment? Sorry I don't understand what problem you're trying to solve
Mark O'Connor
Javascript minifiers remove all comments, so they are removing the copyright notice from my files. I want to add it again after the minification process.
juandopazo
Now I understand. In that case Alexander's answer is the best solution. If you want more control over which files are modified checkout the fileset selector documentation: http://ant.apache.org/manual/Types/selectors.html
Mark O'Connor
+1  A: 

Looks like <concatfilter> may be your friend.

<echo message="/* Copyright text */${line.separator}" file="copyright.txt"/>

<copy todir="dest_dir">
  <fileset dir="src_dir"/>
  <filterchain>
    <concatfilter prepend="copyright.txt"/>
  </filterchain>
</copy>
Alexander Pogrebnyak
This looks like a nice solution. I'll try it out!
juandopazo