I am trying to figure out all the directory under my current directory. Current directory may contain files and directories.
In this scenario, I am looking for existing task which can provide me all the sub-directories under current directory.
You need to use the -path option and the -sbudirectory option, like this:
find . -type d -path "./dir1/*.1" -"subdirectory*name" -o -print
<project name="demo" default="run">
<target name="run">
<dirset id="dirs" dir="${basedir}/.."/>
<pathconvert targetos="unix" property="path.unix" refid="dirs"/>
<echo message="${path.unix}"/>
</target>
</project>
Related
I'd like to copy files and subdirectories under directory dir_java, but not the dir_java directory itself and all its parent directories. a.k.a I'd like to get all directory dir_com and its subdirectories to todir in ant copy task.
Is there a way to do this?
temp
\--dir_1
|
\--dir_java
|
\--dir_com
\--dir_2
|
\--dir_java
|
\--dir_com
\--dir_3
|
\--dir_foobar
There is no regularity for dir_1,dir_2,dir_3
I tried below
<copy todir="to_dir" verbose="true" overwrite="true">
<fileset dir="temp" includes="*/dir_java/**" />
</copy>
But I got directories like to_dir/dir_1/dir_java/dir_com.
I want directories like to_dir/dir_com
My best trying was to add a exec task with invoking cp command after above copy task, but only for non windows platform:
<exec executable="/bin/sh">
<arg value="-c"/>
<arg value="cp -R to_dir/*/dir_java/* to_dir"/>
</exec>
Are all of the dir_java directories at the same level in the hierarchy? If so, consider using a <cutdirsmapper>...
[cutdirsmapper] strips a configured number of leading directories from the source file name.
After <cutdirsmapper> removes the leading directories, it will preserve whatever remains of the directory structure...
<copy todir="to_dir" verbose="true" overwrite="true">
<fileset dir="temp" includes="*/dir_java/**" />
<cutdirsmapper dirs="2" />
</copy>
Before running Ant
$ find . -type f
./temp/dir_1/dir_java/dir_com/1.txt
./temp/dir_2/dir_java/dir_com/2.txt
./temp/dir_3/dir_foobar/3.txt
After running Ant
$ find . -type f
./temp/dir_1/dir_java/dir_com/1.txt
./temp/dir_2/dir_java/dir_com/2.txt
./temp/dir_3/dir_foobar/3.txt
./to_dir/dir_com/1.txt
./to_dir/dir_com/2.txt
Notice how 1.txt and 2.txt are still under dir_com after the mapping has been applied.
I have my proj structure like this
myproj
-bin/myproj-run
-bin/myproj-cli
-lib/x.jar
-target/myproj.jar
I want to create a tar.gz that looks like
myproj
-bin/myproj-run
-bin/myproj-cli
-lib/x.jar
-myproj.jar
How do I do it using ant tar task ?
This one should work (I've tested this on my computer and it works):
<project name="tar.test" default="tartest">
<dirname property="basedir" file="${ant.file.tar.test}" />
<target name="tartest">
<tar destfile="${basedir}/files.tar">
<tarfileset dir="${basedir}/myproj">
<exclude name="target/**" />
</tarfileset>
<tarfileset dir="${basedir}/myproj/target"/>
</tar>
</target>
</project>
BTW, you should read tar manual on apache page, you will find there few examples which shoud help you.
I would first <copy> the files to some other directory (e.g., one called 'package') with the folder structure that you want. Then, run <tar> and <gzip>:
<tar destfile="myTar.tar" basedir="package" />
<gzip src="myTar.tar" destfile="myTar.tar.gz"/>
I have a javascript project with the following structure:
root -
/docs
/dist
/source
/resources
/plugins
Code is in source directory and an ant script is executed to generate compressed files in dist directory. All the files are in source control.
I want to run a directory diff before running the ant script to make sure the list of files in source and dist directories are same. If not, stop execution and tell the user to checkin the needed files before running the build.
I am new to ant and am unable to find any documentation to list differences in files list between 2 directories. Appreciate any inputs.
You could try the following. Prints a list of the files to be checked in before failing:
<project name="demo" default="build">
<target name="check">
<apply executable="echo" failonerror="false" resultproperty="files.found">
<arg line="missing file:"/>
<srcfile/>
<fileset id="srcfiles" dir="source" includes="*.txt">
<present present="srconly" targetdir="dist"/>
</fileset>
</apply>
<fail message="Files need to be checked in" if="files.found"/>
</target>
<target name="build" depends="check">
..
..
..
</target>
</project>
Note:
Tested on Linux. Probably won't work on windows.
I am trying to retrieve the list of all zip files present in a directory.
I have a directory ${src} which contains some zip files and I am using the following code
<target name="test">
<dirset id="dist.contents" dir="${src}" includes="*.zip"/>
<property name="prop.dist.contents" refid="dist.contents"/>
<echo message="${prop.dist.contents}" />
</target>
but it only echoes null.
I also tried includes="*" but it didn't make any difference.
I am using Ant version 1.7.0.
As written in the documentation:
A DirSet is a group of directories.
So since you want zip files, you should use a FileSet.
I need a symbolic link selector in Apache Ant.
The following selectors are available to the Core.
Can anyone advise me on writing a <scriptselector> for selecting only the symbolic linked files under a directory? Or any other way?
The reason:
folder
|-- file-0.0.1
|-- file-0.0.2
|-- file-0.0.3
`-- file --> file-0.0.3
I just want to get the file that is symbolically linked by file. In this case file-0.0.3, but the symbolic link can change and I don't want all the other files to be in the Ant <fileset>
Please take a look at :
http://ant.apache.org/manual/Tasks/symlink.html
I don't have a linux machine to test now but I guess that with the something like this :
<symlink action="record" linkfilename="my.links">
<fileset dir="${my.folder}" includes="*"/>
</symlink>
You should be able to record your symlinks into a file and then processing the files as you wish. For example you could then create a list only with the "symlinked" files and iterate over it to do what you want.
EDIT :
For this solution you will need to install the ant-contrib. Just unpack the ant-contrib-1.0b3.jar to your ant/lib directory. Then use the following build.xml file :
<project name="test" default="build">
<!--Needed for antcontrib-->
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<target name="build">
<property name="my.dir" value="/home/stefanos"/>
<exec executable="bash" outputproperty="symlinks" dir="${my.dir}">
<arg value="-c"/>
<arg value="\ls -1 | xargs -l readlink"/>
</exec>
<foreach list="${symlinks}" delimiter="${line.separator}" param="link" target="process.link"/>
</target>
<target name="process.link">
<!--Do whatever you want with the file targeted by the symlink-->
<echo message="Processing link : ${link}"/>
</target>
</project>
The trick is the linux command which returns all the targeted files from the symlinks. Then you just iterate through them with the foreach task and you call a target in which you can do whatever you need with the files.