JaCoCo report looks correct but can not view source - ant

I am new to JaCoCo and trying to figure out why the html report that I am generating is not linked with my source.
The coverage numbers look correct and I can browse down to each class and then each method but I can not see the source. I have tried many different things inside the sourcefiles tag but nothing is working. Has anyone else had this issue? Here is a snippet of my ant script:
...
<test name="test.fw.UITestSuite" todir="${logdir}"/>
</junit>
</jacoco:coverage>
<fail if="TestFailed" status="1" message="UI junit test failure detected"/>
<echo message="${src}"/>
<jacoco:report>
<executiondata>
<file file="jacoco.exec"/>
</executiondata>
<structure name="UI">
<classfiles>
<fileset dir="${build}/fw"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="fw" includes="**./*.java"/>
</sourcefiles>
</structure>
<html destdir="report"/>
</jacoco:report>
</target>
...

Your fileset definition seems odd.
The include must be (the first . is misplaced):
includes="**/*.java
Try simply pointing it to the root of your src dir (there is no need for the includes)
<fileset dir="fw" />
But fw has to be the root of your sources, i.e. it contains the package folders like:
src
-org
-module
-MyClass1.java
-MyClass2.java

I’ve seen this break when using Scala-style package directory names, e.g.,
src/main/java/com.example.foo.bar/Foo.java
for fewer levels of nesting, faster autocompletion, &c., compared to the standard
src/main/java/com/example/foo/bar/Foo.java
Most tools support the first version just fine, but usually if you try it out and everything works fine, by the time you notice something like the jacoco reports not showing the source anymore, you’ve long forgotten the directory name change …

Related

Using Apache Ant to Delete All But Most Recent 3 Directories

I have a scenario in which there is an "archive" directory that contains various subdirectories. I only want to keep the most recent three subdirectories. So, for example I have:
archive/
subA/ [created 1-May-2018]
subB/ [created 2-May-2018]
subC/ [created 3-May-2018]
subD/ [created 4-May-2018]
subE/ [created 5-May-2018]
In other words, I want to be able to select subA and subB (on the basis of their filesystem dates) and delete them -- including all files and subdirectories within them. I can easily do a Python script that does this, but would prefer a pure-Ant solution.
Based on another StackOverflow question (How to delete all but latest 2 files using Ant), I have tried:
<resources id="deleteDirs">
<allbutlast count="3" >
<sort>
<date />
<resources>
<dirset dir="${dir.archive}" includes="*" />
</resources>
</sort>
</allbutlast>
</resources>
<echo message="Delete directories: ${toString:deleteDirs}" />
<delete verbose="true">
<resources refid="deleteDirs" />
</delete>
However this and any other variations I have come up with do not work. Note, however, that the deleteDirs refid when printed out does show what I want selected, but the delete task quietly ignores it.
In briefly examining the source for the delete task, there are comments to the effect that the delete was at some point refactored to also perform the deprecated deltree task (which apparently cannot wrap around a resource, dirset, or path). So, I am guessing that when deltree was brought into delete it still only works with the form:
<delete dir="DIRNAME"/>
and not when wrapping a resource collection.
Is there a pure Ant way to essentially do:
<deltree dir="${dir.archive}/subA" />
<deltree dir="${dir.archive}/subB" />
However, without hard-coding my selection(s) in deltree tasks and allowing Ant to select all but the most recent three directories based on date.
I got stuck on the same problem. I am shocked that this problem is not solved for long. Apparently task does not work with resource collection of type . The only solution to the problem I could figure out is to use ant-contrib and do the follwing:
<for param="folder">
<path>
<allbutlast count="${to.keep.count}">
<sort>
<dirset dir="${dir.archive}" includes="*"/>
</sort>
</allbutlast>
</path>
<sequential>
<delete dir="#{folder}"/>
</sequential>
</for>
If anybody can suggest a solution without using Ant-Contrib, I will be (and I believe not only me) very very grateful.
Of course the perfect solution would be to make this work as follows:
<delete verbose="true">
<allbutlast count="${to.keep.count}">
<sort>
<dirset dir="${dir.archive}" includes="*"/>
</sort>
</allbutlast>
</delete>
but unfortunately this does not work.

In ant, how does one create and use a 'library' of targets?

To eliminate redundancy in my ant build.xml files, I decided out-factor the repeated targets into mytargets.xml file, publish it to to the artifact repository, and then import it in the following way:
<import>
<url url="http://mycompany.com/artifacts/mycompany.com/mytargets/1.2.3/mytargets-1.2.3.xml"/>
</import>
There are two things I don't like about this approach:
mytargets-1.2.3.xml never appears anywhere on the disk where I can easily look at it.
I absolutely need access to http://mycompany.com/artifacts in order to do anything in the project---it completely undermines offline work.
So, I tried creating a setup target to fetch a local copy of mytargets.xml and adjusted my <import> to use this local copy.
<import file="${basedir}/antlib/mytargets/mytargets.xml"/>
However, as you have probably guessed, I cannot even execute my setup my target after adjusting my <import> in this way because the file does not yet exist:
Buildfile: /home/me/myproject/build.xml
BUILD FAILED
/home/me/myproject/build.xml:265: Cannot find /home/me/myproject/antlib/mytargets/mytargets.xml imported from /home/me/myproject/build.xml
Adding optional="true" to the <import> only defers the problem to the first target that depends upon mytargets.xml.
I looked at https://ant.apache.org/manual/Types/antlib.html, but this approach does not appears to permit you to define a <target>.
So, how does someone share bits of ant XML across multiple projects? Am I already doing it the 'one true way'? Or, is there a better way?
If you're mainly just trying to avoid download the remote copy when you have a local copy already available, you can try something like this:
<condition property="mytargets.xml.available">
<available file="${basedir}/antlib/mytargets/mytargets.xml" />
</condition>
<target name="setup" unless="mytargets.xml.available">
<get
src="http://mycompany.com/artifacts/mycompany.com/mytargets/1.2.3/mytargets-1.2.3.xml"
dest="${basedir}/antlib/mytargets"
/>
</target>
<target name="main" depends="setup">
<import file="${basedir}/antlib/mytargets/mytargets.xml" />
...
</target>
So, it seems to me that <target> is inherently local and not intended for reuse. On the other hand, <macrodef> appears intended for reuse.
Here is the 'library', mymacros.xml:
<?xml version="1.0"?>
<antlib>
<macrodef name="mymacro">
...
</macrodef>
</antlib>
Here is the client, myproject/build.xml:
<?xml version="1.0"?>
<project name="myproject">
<target name="mytarget">
<mymacro/>
</target>
<taskdef file="mymacros.xml"/>
</project>
Unlike <import> and <include>, <taskdef> will not cause the build to fail immediately if mymacros.xml is missing, which gives you the opportunity to download it.

What is source data for the report generated by junitreport ant task?

The JUnit official documentation states:
junitreport collects individual xml files generated by the JUnit task using the nested element.
Other part of the same page states:
<junitreport todir="./reports">
<fileset dir="./reports">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="./report/html"/>
</junitreport>
would generate a TESTS-TestSuites.xml file in the directory reports
and generate the default framed report in the directory report/html.
Let's say, I have file TEST-all.xml generated by junit task in the "reports" directory. I want to use it as data source for junitreport task:
<fileset dir="./reports">
<include name="TEST-all*.xml"/>
</fileset>
I would expect html report based on my data will be generated.
I tried to do it. Empty TESTS-TestSuites.xml file was generated and as a result empty html file.
Two documentation statements I quoted above somehow contradict each other: the first one says it will use already generated files to create a report and the second one says it will generate new file. Can somebody explain how it works? How can I control what data source will be used to generate html report?
Thanks.
Try running ant with -debug. I suspect
<include name="TEST-all*.xml"/>
is not matching any files. Please try with
<fileset dir="./reports">
<include name="TEST-*.xml"/>
</fileset>
Well, I figured out what was the problem: file TEST-all.xml was generated in wrong format. It seems the correct format is:
<testsuite>
<testcase classname="..." name="..." ...>
<properties>
<property name="..."/>
</properties>
</testcase>
</testsuite>
It didn't solve the problem completely though. The html report is still not generated properly:
In spite the fact that file TESTS-TestSuits.xml is not empty now and contains all necessary tests' information, main page of HTML report (index.html) still shows 0 tests.
If I click the link in Tests column (0 in this case) it opens list of tests, but if I try to open individual test in this page, I get "File not found" error.
I suspect the problem is still with the format of TEST-all.xml. I was looking for the description of the format, but found only pieces of information here and there. Any ideas?

yguard not updating properties file in the jar

I have jar file having some properties files in it like log4j.properties and config.properties. Following is my ant script for yguard. Everything else is working but the properties file updation.
<target name="yguard">
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="lib/yguard.jar" />
<yguard>
<inoutpairs resources="none">
<fileset dir="${basedir}">
<include name="MyApp.jar" />
</fileset>
<mapper type="glob" from="MyApp.jar" to="MyAppObs.jar" />
</inoutpairs>
<externalclasses>
<pathelement location="lib/log4j-1.2.17.jar" />
</externalclasses>
<rename conservemanifest="true" mainclass="com.amit.Application" >
<adjust replaceContent="true" >
<include name="**/*.properties" />
</adjust>
</rename>
</yguard>
</target>
config.properties file
com.amit.Application.param1 = something
I found some question in stackoverflow but they didn't help. One place it was mentioned that the file (like jsp, xml, properties) should be in the jar file which I already have. But my yguard obfuscated file just get the files copied as it is.
I tried many combinations with rename & adjust tags but nothing worked for me.
Following post I already visited
Is it possible to manage logs through Obfuscation with yGuard?
How to include obfuscated jar file into a war file
Apparently you want yGuard to obfuscate the name of the field param1, because com.amit.Application is obviously your entry point and yGuard excludes the given main class automatically. So basically you want the outcome to be something like
com.amit.Application.AÖÜF = something
This isn't possible, because yGuard can only adjust class names in property files, as state here: yGuard Manual

What are the custom targets you all run when using ant to build project?

I am thinking of running this custom targets to find out more about my project build status
- jalopy
- jdepend
- cvs tagdiff report
- custom task for NoUnit
- generate UML diagram. ESS-Model
What are your views?
I think that it's a great idea and use it myself. That way I'll never forget to run it.
I also keep the reports for a decent amount of time and eventually create a spreadsheet of "progress".
In your main ant task - call another task to do "whatever"
and
JDepend.xml ...
<target name="statsAll">
<!-- master file that describes where everything is -->
<property file="./ant/ant-global.properties" prefix="ant-global" />
<tstamp>
<format property="gen.time" pattern="yyyyMMdd_hh"/>
</tstamp>
<echo message="LOG:./ant/logs/jdepend.${version.FILETAG}.${gen.time}.rpt"/>
<!-- generate stats to see if we're improving -->
<jdepend
outputfile="./ant/logs/jdepend.${version.FILETAG}.${gen.time}.rpt" >
<exclude name="java.*"/>
<exclude name="javax.*"/>
<classespath>
<pathelement location="./jar" />
</classespath>
<classpath location="./jar" />
</jdepend>
</target>
<target name="doJDepend" depends="getVersion,statsAll">
<echo message="FTP'ing report"/>
<ftp verbose="yes" passive="yes" depends="yes"
remotedir="/videojet/metrics" server="xxxxx"
userid="xxxx" password="xxxxx"
binary="no"
systemTypeKey="UNIX">
<fileset dir="./ant/logs/" casesensitive="no">
<include name="**/jdepend.${version.FILETAG}*.rpt"/>
<exclude name="**/*.txt"/>
</fileset>
</ftp>
</target>
Magic build machine
I second the 'good idea' part, although for a project of reasonable size you might want to make it part of an automated build, like one of the CI Servers (Bamboo, Contiuum).
You might also consider a code coverage tool to see how your test coverage is going.
This will ensure the reports get run on a regular basis, could give you somewhere to publish them and won't slow down the developer's quick turnaround development cycle.
I also think some reports about your project are a good idea. My template-project for an ant-build-script (Antiplate) has at the moment the following reports: Junitreport, emma-report, PMD, CPD and Checkstyle. I'm thinking about including a JDepend-report.
At work we use these templates and using Hudson as continuous-integration-system. Hudson creates wonderful graphs for these reports and how the measures changed with the builds.

Resources