Create a dirset that includes subfolders of folders

I have a property called source-locations, and it contains a list of folders, separated by commas, where the source code can be found.

source-locations=src,other_src_dir,yet_another_dir 

In one of my ant tasks, I use dirset as follows:

  <dirset dir="${basedir}" includes="${source-locations}"/> 

My problem is that in this case only the directories listed in the source-locations property will be part of dirset, and I also need all the subdirectories of these directories. How can i do this?

Any input is appreciated! Thanks!

+4
source share
2 answers

You can try the following:

 <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="path.antcontrib"/> <target name="test"> <property name="source-locations" value="src,other_src_dir,yet_another_dir"/> <!--Replace comma symbol to the `/**,` string and save new expression in to the source-locations_mod property--> <propertyregex property="source-locations_mod" input="${source-locations}" regexp="," replace="/**," global="true" /> <!--Add finally `/**` string to the source-locations_mod property. Was used var task to prevent property immutable --> <var name="source-locations_mod" value="${source-locations_mod}/**"/> <!--New source-locations_mod property was used--> <dirset id="source.set" dir="${root.folder}" includes="${source-locations_mod}"/> <!--Check the result--> <pathconvert pathsep="${line.separator}" property="dir.name" refid="source.set"> <mapper type="identity" /> </pathconvert> <echo>Folders: ${dir.name}</echo> </target> 

I used propertyregex and var from the Ant-Contrib library.

+1
source

An example is below.

 <mkdir dir="dir1" /> <mkdir dir="dir2" /> <mkdir dir="dir3" /> <mkdir dir="dir1/dir1a" /> <mkdir dir="dir1/dir1b" /> <mkdir dir="dir1/dir1c" /> <mkdir dir="dir2/dir2e" /> <mkdir dir="dir2/dir2f" /> <mkdir dir="dir2/dir2g" /> <mkdir dir="dir3/dir3h" /> <mkdir dir="dir3/dir3i" /> <mkdir dir="dir3/dir3j" /> <property name="source-locations" value="dir1,dir2,dir3" /> <pathconvert property="source-locations_mod" pathsep=","> <regexpmapper from="^(.*)$" to="\1/\*\*" handledirsep="true" /> <map from="${basedir}/" to="" /> <dirset dir="${basedir}" includes="${source-locations}" /> </pathconvert> <echo message="source-locations_mod: ${source-locations_mod}" /> <dirset id="dirset" dir="${basedir}" includes="${source-locations_mod}"/> <property name="dirs" refid="dirset" /> <echo message="dirs: ${dirs}" /> 

+1
source

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


All Articles