I have project directory with set of subproject. Following call doesn't include sources to report:
<dirset id="src.dirset" dir="${prjDir}" >
<include name="**/src" />
</dirset>
<property name="src.dir" refid="src.dirset"/>
<cobertura-report
format="html"
datafile="${cobertura.ser}"
destdir="${testResultsDir}/cobertura-report"
srcdir="${src.dir}"/>
Can be possible to specify source directories using nested dirset instead of filesets:
<cobertura-report
format="html"
datafile="${cobertura.ser}"
destdir="${testResultsDir}/cobertura-report">
<dirset dir="${prjDir}" >
<include name="**/src" />
</dirset>
</cobertura-report>
What version of Cobertura are you using? Dirset support was added to 1.9.1.
Actualy latest version used.
I tried different combination but without results.
From example above:
<dirset id="src.dirset" dir="${prjDir}" >
<include name="**/src" />
</dirset>
<property name="src.dir" refid="src.dirset"/>
<echo>${src.dir}</echo>
[echo] org.eclipse.swordfish.registry.tooling\src;org.eclipse.swordfish.tooling.target\src;org.eclipse.swordfish.tooling.ui\src
Can you provide me valid sample with dirset?
I think that problem is with relative path. Possible solution
<path id="src.dirset">
<dirset dir="${srcDir}/plugins" >
<include name="**/src" />
</dirset>
</path>
But cobertura-report doesn't support the nested "path" element.
The dirset support has a bug: Instead of passing absolute paths to the reporting application it ignores the base directory on the dirset and uses a relative path. That means it will only work as expected if your build is running from the same directory that is set as the base directory on the dirset.
Here is a crude but working fix:
Index: cobertura/src/net/sourceforge/cobertura/ant/CommonMatchingTask.java
--- cobertura/src/net/sourceforge/cobertura/ant/CommonMatchingTask.java (revision 689)
+++ cobertura/src/net/sourceforge/cobertura/ant/CommonMatchingTask.java (working copy)
@@ -174,7 +174,13 @@
*/
throw new BuildException("Dirsets have to come before filesets");
}
- createArgumentsForFilenames( builder, getDirectoryScanner(fileSet).getIncludedDirectories());
+ DirectoryScanner scanner = getDirectoryScanner(fileSet);
+ String[] filenames = scanner.getIncludedDirectories();
+ for (int i = 0; i < filenames.length; i++)
+ {
+ filenames[i] = baseDir(fileSet) + "/" + filenames[i];
+ }
+ createArgumentsForFilenames( builder, filenames);
}
}
}
This is still a problem with the latest version, 1.9.4.1. It does appear there is an absolute pathing problem. Shawn Castrianni spelled it out in his message sent to Cobertura-devel May 2009:
<quote>
Subject: bug in dirset support
After spending several hours struggling with why I could not get the new direst
feature to work to support multiple source directories, I found the problem.
The code change (SVN rev 544 by lewijw) in CommonMatchingTask.java was using:
createArgumentsForFilenames( builder,
getDirectoryScanner(fileSet).getIncludedDirectories());
The problem is getIncludedDirectories() returns names RELATIVE to the dirset's
basedir. Therefore, if you have a multiple dirsets with different basedirs,
those different basedirs are lost and only the relative directory names are
passed to the Main class of the reporting engine. This causes none of the
source files to be found since a relative directory name will assume to be
relative to ${basedir}.
A functional test was created in cobertura/examples/functionaltest1/build.xml
but used ${basedir} as its base directory for the direst:
<target name="coverage-reports-with-dirset"> <run-reports> <dirset dir="${basedir}"> <include
name="**/src" /> </dirset> </run-reports>
this allowed it to work and did not reveal the problem. I believe the fix
should be to change CommonMatchingTask.java to pass in absolute directory names
to the reporting engine Main class. Perhaps something like this:
DirectoryScanner dirscanner = getDirectoryScanner(fileSet); String dirnames[] = dirscanner.getIncludedDirectories(); for(int i = 0 ; i < dirnames.length; i++) { dirnames[i] = dirscanner.getBasedir() + File.separator + dirnames[i]; } createArgumentsForFilenames( builder, dirnames);
</quote>