ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jim Fuller" <jim.ful...@ruminate.co.uk>
Subject RE: Telling DirectoryScanner to scan each directory separately.
Date Mon, 26 Jan 2004 08:59:54 GMT


> -----Original Message-----
> From: Antony paul [mailto:antonypaul24@hotmail.com] 
> Sent: 26 January 2004 05:42
> Subject: Telling DirectoryScanner to scan each directory separately.

>    I am writing a custom task which needs to get the list of 
> included files 
> for each directory but not any subdirectory and files inside 
> it. First I 
> have to get all included directories which is set in the 
> build file. Then I 
> will scan each individual directory to get the included files. While 
> scanning a directory I dont want to get any subdirectory name 
> or files in 
> subdirectory. How to do this.

There was a question last week on this, I will repeat my answer....avoid
using matchingtask.

Here is an example that takes a fileset;


import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;


public class AntFileSetTest extends Task{
	private Vector filesets = new Vector();

    public void addFileset(FileSet fileset) {
        filesets.add(fileset);
    }

    public void execute(){

   log("executing Xindice Ant Task");



int fileCount = 0;
int successCount = 0;

Enumeration enum = filesets.elements();

while(enum.hasMoreElements()){

	FileSet fileset = (FileSet) enum.nextElement();
	DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
	String[] files = ds.getIncludedFiles();

        for(int i=0; i<files.length; i++) {

			fileCount++;

			File f = new File(fileset.getDir( getProject()
),files[i]);

			if (process(f)){
				successCount++;
			}
		}

}

System.out.println("task working properly");
}

protected boolean process(File file){
        System.out.println("file processed");
        return true;
}


}

The process method will do something on the individual file, whereas the
enum snippet does the hard work in the execute method.

>   I am using 1.5.4. Custome task is extending MatchingTask. 
> Also a minor 
> problem. I am using the same build file to compile and run 
> the custom task. 
> First compile, make it a jar, copy the jar file to 
> ANT_HOME\lib directory 
> then call the target to run the task. If I run the task in 
> one step it will 
> run the old class file. I have to launch ant a second time to 
> run the newly 
> copied task. Is it possible to compile and run it in one step ?.

Without seeing your build file, I can only assume that you are not
explicitly defining the classpath. 

Gl, jim fuller



> 
> rgds
> Antony Paul


> 
> _________________________________________________________________
> Let the new MSN Premium Internet Software make the most of 
> your high-speed 
> experience. http://join.msn.com/?pgmarket=en-us&page=byoa/prem&ST=1
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message