Ant script - recursively copying files by patterns in (sub)folders

Hi folks,

I have following ant script which copy files by patterns given in .cvsignore :

<project default="compile">

<target name="compile">

<copy todir="c:\temp\output">

<fileset dir=".">

<includesfile name=".cvsignore"/>

</fileset>

</copy>

</target>

</project>

Everything works well but it copies only files in root (.) directory not in its subdirectories. Can you help me?

[628 byte] By [janzitniaka] at [2007-11-27 5:47:12]
# 1
Your fileset is slightly wrong. Try:<fileset dir="."> <include name="**/*" /></fileset>
georgemca at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 2
Hi,thx for you super fast question! But I need copy only patterns given in .cvsignore file.
janzitniaka at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 3
<include name="**/*.cvsignore"/>-
YoGeea at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 4

It doesn't help me. I need explain more. In that .cvsignore file I have following:

*.bat

*.exe

The part of ant script that reads all patterns in .cvsignore file is following:

<fileset dir=".">

<includesfile name=".cvsignore"/>

</fileset>

It copies all *.bat and *.exe files (which are found in .cvsignore file) from "dir" (.) directory and copy to target one. But it doesn't copy specific files in subdirectories. This I need resolve. Thx.

janzitniaka at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 5

> It doesn't help me. I need explain more. In that

> .cvsignore file I have following:

> *.bat

> *.exe

>

> The part of ant script that reads all patterns in

> .cvsignore file is following:

> > <fileset dir=".">

><includesfile name=".cvsignore"/>

> </fileset>

>

>

> It copies all *.bat and *.exe files (which are found

> in .cvsignore file) from "dir" (.) directory and copy

> to target one. But it doesn't copy specific files in

> subdirectories. This I need resolve. Thx.

To my knowledge, you can't do that. You'll need one target that iterates over the directory structure, looking for .cvsignore files, and passing that file and the directory location into another target that does the copying. Or you could write your own task that does it. Why d'you need to copy stuff that .cvsignore lists, anyway? There may be a simpler solution than this

georgemca at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 6
We have one big project that includes binaries and source code in deep hierarchy. We need separate this content into 'bin' and 'src' folder. All binary extensions (patterns) are defined in .cvsignore file. We decided use ant script to do this.
janzitniaka at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 7

> We have one big project that includes binaries and

> source code in deep hierarchy. We need separate this

> content into 'bin' and 'src' folder. All binary

> extensions (patterns) are defined in .cvsignore file.

> We decided use ant script to do this.

Dude...

You're deer hunting with a hammer. If I were the admin of the project, I'd probably have separated out the binary resource files and the source files at the very beginning just on principle. I don't think I would have binary and source files in the same directory, for certain.

Ant just isn't made for this type of thing.

kevjavaa at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 8

> We have one big project that includes binaries and

> source code in deep hierarchy. We need separate this

> content into 'bin' and 'src' folder. All binary

> extensions (patterns) are defined in .cvsignore file.

> We decided use ant script to do this.

Those binary extensions are in .cvsignore by coincidence, I wouldn't rely on that

Anyways, are you using ant to build this frankenproject, or just to untangle this stuff? If I understand correctly, your project has got source code and binaries mixed together in the one place. What binaries? Compiled from your source? Images? Dependencies? You don't say. Rather than patch over the problem with added Ant work to move things about, I'd start again. Write the ant script to actually build the project as it should be, and transfer the source code to the src directory by hand. The binaries? That depends what they are. Anything you can re-create, or download again, just delete it.

georgemca at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 9
Your response didn't help me. We got project in that structure because we are outsourcing company.
janzitniaka at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 10
> Your response didn't help me. We got project in that> structure because we are outsourcing company.Well, I'd also be quite frustrated if I was disallowed from basic refactoring of a project when I took it over.
kevjavaa at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 11

> Your response didn't help me. We got project in that

> structure because we are outsourcing company.

That doesn't explain why the response (which response) doesn't help. I'd forget all about writing extra ant scripts to cope with this mess, and just start again. Trust me, it'll be a lot quicker and safer

georgemca at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 12
Binaries: pictures, jars, tgz, zips, ... I need untangle stuff of frankenproject :-D We got the project structure with that mess. We need to separate that stuff and from src we'll prepare our build environment.
janzitniaka at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 13

> Binaries: pictures, jars, tgz, zips, ... I need

> untangle stuff of frankenproject :-D We got the

> project structure with that mess. We need to separate

> that stuff and from src we'll prepare our build

> environment.

No need for tricky untangling in one shot, do it in baby steps, that way you should avoid the disaster that tackling something like this in one go invariably brings. You've got 4 kinds of file here. Source code, object code (.class files), binary resources (images etc) and dependencies. So, move your source code into a new src directory. From what you've posted, you know how to get ant to do this for you. Then, move the dependencies into a lib directory. Then delete all .class files. All you're left with is the binary resources, which you can then move to a resource directory. Then write some decent ant scripts :-)

But don't try and cleverly do this in one go, because all it takes is one of the many .cvsignore files to be slightly different and you could be bang in trouble

georgemca at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 14
You need to change your .cvsignore file like this:**/*.exe**/*.batetc.no Spaces at beginning/end!The cvsignore will fail with cvs I think, maybe an ant filterchain can do the job...Jaro
Superyaroa at 2007-7-12 15:31:19 > top of Java-index,Java Essentials,Java Programming...
# 15

> You need to change your .cvsignore file like this:

> **/*.exe

> **/*.bat

> etc.

>

> no Spaces at beginning/end!

> The cvsignore will fail with cvs I think, maybe an

> ant filterchain can do the job...

>

> Jaro

You're right. CVS will no longer consider that a valid .cvsignore

Hopefully he's abandoned the plan to automate this anyway. Too many ways it can go wrong!

georgemca at 2007-7-21 21:35:07 > top of Java-index,Java Essentials,Java Programming...