Listing all files and subdirectories with ant

I am trying to create an rpm package using ant task , for which I need to create a specfile that will have all the file names in the following format

 %attr(0755, root, root) %dir dir1 %attr(0755, root, root) %dir dir1/dir2 %attr(0755, root, root) %dir dir1/dir2/dir3 %attr(0500, root, root) dir1/file1 %attr(0500, root, root) dir1/dir2/file1 

I have such a directory structure created during my build process, but using ant I cannot list all the files and directories that I can write to my specfile

The following is what I was trying to list, but it does not distinguish between files and directory, in addition, I need a way to iterate over the list.

 <fileset id="dist.contents" dir="${nativePackageDir}" includes="**"/> | <property name="prop.dist.contents" refid="dist.contents"/> | <target name="javaobject-library" depends="props"> <echo>${prop.dist.contents}</echo> 
+4
source share
2 answers

You just need to write the implementation of the ant task to java , to which you will provide the input directory and the path of the specification file that you want to write as parameters.

I find it better and more manageable to have reusable ant tasks in java, instead of having giant ant xml files.

+1
source
 <dirset id="dist.contents" dir="${nativePackageDir}" includes="*"/> <property name="prop.dist.contents" refid="dist.contents"/> <echo>${prop.dist.contents}</echo> 

Using dirset instead of a set of files should fix your problem.

+21
source

Source: https://habr.com/ru/post/1411691/


All Articles