Excluding some classes from the cobertura report doesn't work - code-coverage

I tried to exclude some classes from cobertura using:
<cobertura-instrument todir="${voldemort.instrumented.dir}" datafile="${cobertura.instrument.file}">
<classpath refid="tools-classpath" />
<ignore regex=".*\.xsd" />
<fileset dir="${voldemort.dist.dir}/classes">
<include name="**/*.class" />
<exclude name="**/client/protocol/pb/*.class"/>
<exclude name="**/server/http/*.class"/>
</fileset>
</cobertura-instrument>
However, that doesn't work. I don't know where the problem is. Could you help me?

You must do it like this:
<cobertura-instrument todir="${voldemort.instrumented.dir}" datafile="${cobertura.instrument.file}">
<classpath refid="tools-classpath" />
<ignore regex=".*\.xsd" />
<fileset dir="${voldemort.dist.dir}/classes">
<include name="**/*.class" />
</fileset>
<fileset dir="${voldemort.dist.dir}/classes">
<exclude name="**/client/protocol/pb/*.class"/>
</fileset>
<fileset dir="${voldemort.dist.dir}/classes">
<exclude name="**/server/http/*.class"/>
</fileset>
</cobertura-instrument>

Related

How can I pass a union to the war lib element?

I am trying to refactor an ant build.xml file to reduce duplication. Previously the file had a bunch of targets something like this:
<war ...>
<lib dir=${lib}">
<include name="foo.jar"/>
<include name="bar.jar"/>
<include name="qux.jar"/>
</lib>
...
</war>
<jar ...>
...
<manifest>
<attribute name="Class-Path" value="foo.jar bar.jar baz.jar"/>
</manifest>
</jar>
Despite the ant documentation, I got it to the point where it looks more like this:
<fileset id="commonLibs1" dir="${lib}">
<include name="foo.jar"/>
<include name="bar.jar"/>
</fileset>
<union id="clientLibs">
<fileset refid="commonLibs1"/>
<fileset dir="${lib}">
<include name="baz.jar"/>
</fileset>
</union>
<war ...>
<lib dir=${lib}">
<include name="foo.jar"/>
<include name="bar.jar"/>
<include name="qux.jar"/>
</lib>
...
</war>
<manifestclasspath property="tmpClassPath" jarfile="./placeholdername.jar">
<classpath>
<resources refid="clientLibs"/>
</classpath>
</classpath>
<jar ...>
...
<manifest>
<attribute name="Class-Path" value="${tmpClasspath}"/>
</manifest>
</jar>
Which is swell. Now I've almost reached my goal of not having all these jar names copied all over the place:
<fileset id="commonLibs1" dir="${lib}">
<include name="foo.jar"/>
<include name="bar.jar"/>
</fileset>
<union id="clientLibs">
<fileset refid="commonLibs1"/>
<fileset dir="${lib}">
<include name="baz.jar"/>
</fileset>
</union>
<union id="serverLibs">
<fileset refid="commonLibs1"/>
<fileset dir="${lib}">
<include name="qux.jar"/>
</fileset>
</union>
<war ...>
<lib refid="serverLibs"/>
...
</war>
<manifestclasspath property="tmpClassPath" jarfile="./placeholdername.jar">
<classpath>
<resources refid="clientLibs"/>
</classpath>
</classpath>
<jar ...>
...
<manifest>
<attribute name="Class-Path" value="${tmpClasspath}"/>
</manifest>
</jar>
But:
build.xml:1067: serverLibs doesn't denote a zipfileset or a fileset
Is there any way to make this work?
The lib nested element of war only accepts a fileset or a zipfileset. Other resource collections like union are not supported. You may have a few ways to convert it to a fileset. If the union needs to be kept to be used somewhere else, then you can create a path element from it and use the Ant-Contrib pathtofileset task to convert it to a fileset:
<union id="serverLibs">
<fileset refid="commonLibs1"/>
<fileset dir="${lib}">
<include name="qux.jar"/>
</fileset>
</union>
<path id="serverLibsPath">
<resources refid="serverLibs" />
</path>
<pathtofileset pathrefid="serverLibsPath" name="serverLibsFileset" dir="${lib}" />
<war ...>
<lib refid="serverLibsFileset"/>
...
</war>
Or you can skip Ant-Contrib and use mappedresources with the path created above (see this post for an example).
A simpler way (if the union is only used by the war task) is to remove the union and just specify the combination of filesets in multiple lib elements:
<war ...>
<lib refid="commonLibs1"/>
<lib dir="${lib}">
<include name="qux.jar"/>
</lib>
...
</war>

how to reuse the definition of a number of filesets?

I have a number of tasks in my build.xml that all utilize the same set of filesets. E.g. something like the following (I've retain the actual names of the tasks - related to the cobertura coverage tool - but the nature of the enveloping task is immaterial to this question).
<target name="coverage-report">
<cobertura:cobertura-report destdir="${coverage.xml.dir}" format="xml">
<fileset dir="${src.dir}">
<include name="**/*.java" />
</fileset>
<fileset dir="${componentFoo.dir}/src">
<include name="**/*.java" />
</fileset>
</cobertura:cobertura-report>
</target>
<target name="summary-coverage-report">
<cobertura:cobertura-report destdir="${coverage.summaryxml.dir}" format="summaryXml">
<fileset dir="${src.dir}">
<include name="**/*.java" />
</fileset>
<fileset dir="${componentFoo.dir}/src">
<include name="**/*.java" />
</fileset>
</cobertura:cobertura-report>
</target>
<target name="alternate-coverage-report">
<cobertura:cobertura-report destdir="${coverage.html.dir}">
<fileset dir="${src.dir}">
<include name="**/*.java"/>
</fileset>
<fileset dir="${componentFoo.dir}/src">
<include name="**/*.java" />
</fileset>
</cobertura:cobertura-report>
</target>
What I would like to do is to be able to define once this recurring set of filesets and reuse it. Now, there's a related SO question on how to use the same fileset in multiple places but that's not working here as I have a number of filesets, not just one. I also tried wrapping the filesets inside a macrodef and expanding the macrodef when needed but I get the message that the these tasks "don't support the nested [name of macrodef] element". So I guess macrodefs in Ant can only be used as high-level tasks and cannot be expanded in arbitrary places.
So is there a way to reuse a definition of a number of filesets in Ant?
This would be easy if the cobertura tasks accepted arbitrary resource collections instead of being hard-coded to just fileset - it may be worth submitting a feature request to this end. For example with a copy task:
<resources id="filesets">
<fileset dir="${src.dir}">
<include name="**/*.java" />
</fileset>
<fileset dir="${componentFoo.dir}/src">
<include name="**/*.java" />
</fileset>
</resources>
<copy todir="dest">
<resources refid="filesets"/>
</copy>
You can fall back to the purely XML-level and use an entity reference:
<!DOCTYPE project [
<!ENTITY cobFilesets '<fileset dir="${src.dir}">
<include name="**/*.java" />
</fileset>
<fileset dir="${componentFoo.dir}/src">
<include name="**/*.java" />
</fileset>'>
]>
<project ....>
<target name="coverage-report">
<cobertura:cobertura-report destdir="${coverage.xml.dir}" format="xml">
&cobFilesets;
</cobertura:cobertura-report>
</target>
</project>

Ant war and ear is not generating

I am new to this ant I wrote athe following build.xml file for generating war and ear. it is showing build successfull. but it not generating any war/ear file. I mentioned my script below. please help me what changes i have to do..
Thanks in advance....
<property name="src" value="src"/>
<property name="dst" value="web"/>
<property name="classes" value="WEB-INF/classes"/>
<property name="archiveName" value="medcardets"/>
<property name="archive" value="BuildArchive"/>
<fileset id="lib" dir="${dst}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<fileset id="war.file" dir="/">
<include name="${archiveName}.war"/>
</fileset>
<fileset id="ear.file" dir="/">
<include name="${archiveName}.war"/>
</fileset>
<fileset id="lib.rules" dir="${dst}/WEB-INF/lib/rules">
<include name="*.jar"/>
</fileset>
<fileset id="lib.j2ee" dir="j2ee">
<include name="*.jar"/>
</fileset>
<target name="clear">
<delete dir="${dst}/${classes}"/>
<delete dir="${archive}"/>
</target>
<target name="build" depends="clear">
<mkdir dir="${dst}/${classes}"/>
<javac srcdir="${src}" destdir="${dst}/${classes}" debug="on" debuglevel="lines,vars,source">
<classpath>
<fileset refid="lib"/>
<fileset refid="lib.rules"/>
<fileset refid="lib.j2ee"/>
</classpath>
</javac>
<copy todir="${dst}/${classes}">
<fileset dir="${src}">
<exclude name="**/CVS"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
Your question implies that you have written code that you expect to generate a WAR, but you have no instruction to do so. I see from your comment you are actually asking what the command should be.
Most important: I hope we are all new to things, after 35 years in the industry I learn something every day. Why did you ask the question rather than google? Learning to search is the most important skill. Google ant task WAR gives this task with an example:
<war destfile="myapp.war" webxml="src/metadata/myapp.xml">
<fileset dir="src/html/myapp"/>
<fileset dir="src/jsp/myapp"/>
<lib dir="thirdparty/libs">
<exclude name="jdbc1.jar"/>
</lib>
<classes dir="build/main"/>
<zipfileset dir="src/graphics/images/gifs"
prefix="images"/>
</war>
and a similar entry for EAR:
<ear destfile="${build.dir}/myapp.ear" appxml="${src.dir}/metadata/application.xml">
<fileset dir="${build.dir}" includes="*.jar,*.war"/>
</ear>

Is it possible to have a fileset with multiple source directories?

I have some ant logic that looks like this:
<copy todir="src_#{version}" flatten="true">
<fileset dir="${generic-libs.source}\prolo">
<include name="**/*.c"/> <!-- all .c files including subfolders -->
<include name="**/*.h"/> <!-- all .h files including subfolders -->
<exclude name="**/test/*.*" /> <!-- exclude test (sub)folders -->
<exclude name="**/test*.*" /> <!-- exclude remaining test sources -->
</fileset>
<fileset dir="${generic-libs.source}\genlo">
<include name="**/*.c"/>
<include name="**/*.h"/>
<exclude name="**/test/*.*" />
<exclude name="**/test*.*" />
</fileset>
<fileset dir="${generic-libs.source}\ptclo">
<include name="**/*.c"/>
<include name="**/*.h"/>
<exclude name="**/test/*.*" />
<exclude name="**/test*.*" />
</fileset>
...
</copy>
The ... has 10 more identical constructs.
The contents of the fileset tag are always the same, so I guess there has to be a way to shorten this?
Ant 1.9.4 introduced multirootfileset for that purpose :
A new resourcecollection type acts like a union of <fileset>s and <dirset>s that share the same configuration but have different base directories.
In your case something like :
<multirootfileset basedirs="${generic-libs.source}\prolo,${generic-libs.source}\genlo,${generic-libs.source}\ptclo">
<include name="**/*.c"/>
<include name="**/*.h"/>
<exclude name="**/test/*.*"/>
<exclude name="**/test*.*"/>
</multirootfileset>

ANT: several filesets for the javac task

I have a ANT build file with two different filesets:
<fileset id="fs1"> <include name="source1\**" /> </fileset>
<fileset id="fs2"> <include name="source2\**" /> </fileset>
and want to use both of them in the same javac task.
Of course, I could write
<javac ...>
<include name="source1\**" />
<include name="source2\**" />
</javac>
but I want the selection of the files occurs outside, because my javac-task will be called several times with different parameters.
A solution would be to copy all the files in a temp directory and call javac on it. But you will admit it is not very satisfying...
More over: is there a solution to concatenate two filesets in a single one?
I've found a solution, using patternset.
<patternset id="ps1"> <include name="source1\**" /> </patternset>
<patternset id="ps2"> <include name="source2\**" /> </patternset>
<javac ...>
<patternset>
<patternset refid="ps1" />
<patternset refid="ps2" />
</patternset>
</javac>

Resources