How to delete the intermediate files generated during EMMA in ant - ant

I have an ant task of emma which generates the code coverage report in HTML. So far so good. But I see intermediate files being generated . Now I need to delete this .Though I have given the task emma clean , I am unable to delete folder which has the name like ${instr.dir.out}. This folder is created in all the components and I am clueless as how can I delete them.

All my ANT builds have a standard "clean" target, designed to clean up any any files or directories created by the build:
<target name="clean" description="Cleanup after build">
<delete dir="${build.dir}"/>
<delete file="${emma.runtime.file"/>
<delete file="${any.other.file.that.needs.to.be.deleted"/>
</target>
If you're an ivy user it's a good idea to create an additional target that purges the download cache:
<target name="clean-all" depends="clean" description="Additionally purge ivy cache">
<ivy:cleancache/>
</target>

#Mike , I got the solution.The problem was with respect to the directory name that I had give. I created a directory with name outinstr_ (_ was a space) and then I actually assigned for dir instr.dir.out ,value = "outinstr" , and here was the fun part ..the value "outinstr" did not had space in it :)... Thanks for helping Mike.... much appreciated

Related

ivy jar located in my dep lib

how can I tell ant to find Ivy's jar in my own lib? ant just kept looking at it's home folder even when I've explicitly told it to find the jar somewhere else.
I would recommend removing the ivy jar from the ANT home directory. (For some very odd reason it's not normally packaged with ANT).
Instead I recommend including a special task to ensure ivy is installed.
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<target name="install-ivy" description="Install ivy" unless="ivy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
Analysis
The ANT manual outlines the order in which jars a loaded by ANT at startup.
-lib jars in the order specified by the -lib elements on the command line
jars from ${user.home}/.ant/lib (unless -nouserlib is set)
jars from ANT_HOME/lib
This will always happen and unfortunately it won't matter what you do inside your build file.....
Jars in the ANT_HOME/lib
In my opinion, putting jars in the ANT_HOME effectively creates a bespoke installation of ANT. It makes your projects less portable across machines, and the customizations are frequently forgotten and undocumented.
So if you have control over the build server I would recommend removing any ANT tasks your find here.
Jars in the ${user.home}/.ant/lib
Placing jars here is less objectionable for the following reasons
Directory owned by the user running the build
Can be ignored at run-time by by using the commandline option -nouserlib
The only jar I put here is ivy... All other jars exist in the ivy cache (including ANT tasks)
You can place Ivy binaries in some folder inside you project folder. For example, in my case, it's etc/build/. I put where ivy.jar and jsch.jar.
After that provide the correct namespace in project defenfition and load Ivy.
<project name="somename" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="ivy-load">
<path id="ivy.lib.path">
<pathelement location="${basedir}/etc/build/ivy.jar"/>
<pathelement location="${basedir}/etc/build/jsch.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>
<target name="ivy-init" depends="ivy-load">
<ivy:settings file="${basedir}/etc/ivysettings/ivysettings.xml"/>
<ivy:resolve conf="${ivy.conf}"/>
</target>
...
</project>

modify temp value to do mutiple build in ant

I want to do multiple builds in ant but the files in /tmp getting cleared by one build and fails the other. How to set a different value for TEMP variable. Tried setting env key="TEMPDIR" path="/tmp/mytemp1", env key="TEMP" path="/tmp/mytemp1", env key="TMP" path="/tmp/mytemp1", env key=" java.io.tmpdir" path="/tmp/mytemp1" but no luck. In short, how can I change value of TEMP for each process?
I would suggest you look at using the standard ANT tempfile task to create temporary files.
A more common approach to this problem is to create a "build" directory in the project workspace and a "clean" target to remove files that are created by the ANT build:
<property name="build.dir" location"build"/>
<property name="classes.dir" location"${build.dir}/classes"/>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}"...
</target>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
To ensure a clean build of the project you run it as follows:
ant clean compile
Update
Other stackoverflow questions related to setting temp directory
not able to change java.io.tmpdir
Environment variable to control java.io.tmpdir?

Ignore full path for specific files when running 'tar' task in ant

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"/>

running specific target in different ant scripts in different directories

We have a large amount of apps. They all have a build.xml file located in the projects base directory. I am trying to create an ant script that will go through and call a specific target on each of the build.xml files in all the projects.
Here are the issues:
Some of the projects are in deeper directories than others.
Only some of the projects need to be built at a time.
I was trying to use subant + antfile and defining a CSV of file paths in a properties file, but this did not work. Below is what i have and the error i am getting.
If there is a better way to do this or you know what my problem is, please let me know! Thanks!
This is the property defined in a property file. I am wanting the person running the script to add the file paths in here that are relative to the current location of the script they are running.
projects.to.build=
This is the subant task i am trying to use in the main build script.
<filelist
id="projectNames"
dir="${basedir}"
files="${projects.to.build}"
/>
<target name="debugAll" description="Builds all the projects listed in the projectNames.properties file.">
<subant target="debug" antfile="${projects.to.build}">
</subant>
</target>
Here is the error i get when i try to run the build script when there are projects defined in the properties file. I am using the relative path. For example: ..\Apps\AnApp1\build.xml,..\Apps\AnApp2\build.xml,..\OtherApps\foo\AnotherApp1\build.xml
"No Build Path Specified" (at my subant task)
You specified the antfile attribute, so ANT was expecting to a single build.xml file.
The subant documentation describes how you can use a fileset as child parameter.
Here's an example:
<project name="Subant demo" default="run-debug-target">
<target name="run-debug-target">
<subant target="debug">
<fileset dir="." includes="**/build.xml" excludes="build.xml"/>
</subant>
</target>
</project>
Update
Alternatively a filelist could be used:
<project name="Dry run" default="run">
<target name="run">
<subant target="test">
<filelist dir="projects" files="one/build.xml,two/build.xml,three/build.xml,four/build.xml"/>
</subant>
</target>
</project>
Processing the following build files:
projects/one/build.xml
projects/two/build.xml
projects/three/build.xml
projects/four/build.xml
Is it possible to run the target in the all the build files concurrently ?
E.g.
<project name="Dry run" default="run">
<target name="run">
<subant target="test">
<filelist dir="projects" files="one/build.xml,two/build.xml,three/build.xml,four/build.xml"/>
</subant>
</target>
</project>
In this example, is there any way to run target "test" present in all the build files (one/build.xml,two/build.xml,three/build.xml,four/build.xml) concurrently ?

Ant: "Duplicated project name in import" with imported build file

I have several build files which all import the same base build file, like this:
base.xml:
<project name="base">
<!-- does not define a 'build' target -->
</project>
buildA.xml:
<project name="buildA">
<import file="base.xml" />
<target name="build">
<ant antfile="buildB.xml" target="build"
inheritall="false" inheritrefs="false" />
</target>
</project>
buildB.xml:
<project name="buildB">
<import file="base.xml" />
<target name="build">
...snip...
</target>
</project>
(Module A depends on module B.)
Now, the above calling of B's build target from buildA.xml gives the following error:
Duplicated project name in import. Project base defined first in buildA.xml and again in buildB.xml
Since both buildA.xml and buildB.xml inherit the same base.xml, this seems unavoidable.
How could I get rid of this error?
Based on sudocode's answer, I solved the problem. Because the absolute path to base.xml is different in both cases, Ant does not recognize it as the same file. Even though inheritAll is set to false, the context of the calling task is preserved and this causes the name clash.
To solve this, one can omit the name attribute from base.xml. Since Ant 1.8, the import task has an attribute as, which can be used to reference base targets when the base project is nameless. If you don't override any targets, you can use include instead of import. I'm on 1.7, so that does not help me.
For previous versions of Ant, you can go through an exec call to prevent proliferation of the Ant context entirely (then you get two running Ant instances). Better yet, find a way to import the exact same base.xml (with the same absolute path) in both files.
Are you using Ant 1.6? This resolved Ant bug looks like the same issue.
EDIT
I tried to reproduce the dir structure you refer to in your recent comment.
./base.xml
./buildA
./buildA/buildA.xml
./buildB
./buildB/buildB.xml
And amended the build files accordingly, e.g.
<project name="buildA">
<import file="../base.xml"/>
<target name="build">
<ant antfile="../buildB/buildB.xml" target="build" inheritall="false" inheritrefs="false"/>
</target>
</project>
I still get no build error for the following with ant 1.8.2 or 1.7.1:
ant -f buildA/buildA.xml build

Resources