ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: How to sort files contained in an Ant fileset?
Date Fri, 07 Mar 2003 22:17:05 GMT
No can do with straight Ant... Dommage :-(

But you can use <script> to sort your fileset. Something along these lines:

<fileset id="fileset.working.xml.files"
         dir="${dir.working}"
         includes="*.xml" />

<script language="javascript"><![CDATA[
  prj = self.getProject();
  fileset = prj.getReference("fileset.working.xml.files");

  scanner = fileset.getDirectoryScanner(prj);
  fromDir = fileset.getDir(prj);
  srcFiles = scanner.getIncludedFiles();

  importPackage(Packages.java.util);
  Arrays.sort(srcFile);

  StringBuffer buffer = new StringBuffer();
  for (int i=0; i<srcFiles.length; ++i) {
    buffer.append(new File(fromDir, srcFiles[i]).toString()).append(' ');
  }

  prj.setNewProperty("working.xml.files", buffer.toString());
]]></script>

<java	classname="com.sun.tgxml.tools.testgen.TestGen" ...>
  ...
  <arg line="${working.xml.files}" />
</java>

Or a custom task. The magic happens in Arrays.sort(). srcFiles is a
String[], and String implements Comparable, so you're in luck, 'cause I
don't know how to implement a Java interface in JavaScript (or even if it's
possible. I know it's possible in Jython).

This is untested. Let me know if it works for you. --DD

-----Original Message-----
From: Joël FÉRAUD [mailto:joel.feraud@france.sun.com] 
Sent: Friday, March 07, 2003 11:42 AM
To: user@ant.apache.org
Cc: Joel.Feraud@Sun.COM; Jean-Francois.Denise@Sun.COM
Subject: How to sort files contained in an Ant fileset?

Hi,

I would like to alphabetically sort the list of files returned by a fileset
so that I can pass this sorted list as parameter of a command where order of
parameters has some impact.

In fact I would like to achieve the same result as the Unix command:
find . -name "*.xml" | sort

For now, I use the build sequence below, but it appears that the list of
files I get in ${working.xml.files} is not alphabetically sorted. I did not
find a way to achieve this with Ant? I would like to avoid to do an exec and
call the Unix sort command...


[...]
	<fileset id="fileset.working.xml.files"
		 dir="${dir.working}" 
		 >
	    <include name="*.xml" />
	</fileset>
	<pathconvert pathsep=" " 
		     property="working.xml.files"
		     refid="fileset.working.xml.files"
		     >
	</pathconvert>
	<java	classname="com.sun.tgxml.tools.testgen.TestGen"
		fork="true"
		failonerror="true"
		>
	    <jvmarg
value="-Dtck.build.propfile=${file.testgen-properties}" />
            <classpath refid="classpath.tobuild.indexes" />
	    <arg       value="-log" />
	    <arg        line="-logfile ${log.build.testgen}" />
	    <arg       value="-debug" />
	    <arg        line="-o ${dir.working}" />
	    <arg        line="${working.xml.files}" />
        </java>
[...]


Thanks,
Joel

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Joel Feraud			Sun Microsystems, Inc.
joel.feraud@sun.com		180, avenue de l'Europe
Tel: +33 476 188 325		ZIRST de Montbonnot
				38334 SAINT-ISMIER Cedex
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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

Mime
View raw message