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

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?

Related

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

ANT GUI with path validation task

I've recently been experimenting with an ANT script for setting up a small application (with various paths and other variables) using AntForm. AntForm has a file selector, but I would have to write something custom to validate the path (i.e., make sure it is the path to the thing that I asked the user for). I was wondering if anyone had experience with using using AntForm in this way. What I want is something like a Wizard page with a file selector, and when the user clicks "next" or when the file is selected some sort of a validation task is executed, and the wizard proceeds from there. The absolute best would be if I could gray out the "next" button or add an "invalid path" message, but that's getting a little complicated for what it seems that AntForm was designed for. Below is an example XML file to get started. Note that it expects AntForm.jar to be in the ./bin directory.
<?xml version="1.0"?>
<project name="My App Setup" default="getPath" basedir=".">
<property name="app.dir" value="${user.home}/appXYZ"/>
<path id="runtime.cp">
<pathelement location="bin/"/>
<fileset dir="lib" includes="antform.jar"/>
</path>
<taskdef name="antform" classname="com.sardak.antform.AntForm"
classpathref="runtime.cp"/>
<taskdef name="antmenu" classname="com.sardak.antform.AntMenu"
classpathref="runtime.cp"/>
<!-- test wizard behaviour, step 1 -->
<target name="getPath"
description="Check for App XYZ in path">
<antform title="Choose directory of app xyz"
lookAndFeel="com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
okMessage="Next"
nextTarget="wizard2"
>
<fileSelectionProperty
label="App XYZ Distribution"
property="app.dir"
directoryChooser="true" />
<!-- TODO: how to validate and choose where to go from this form? -->
</antform>
</target>
<!-- test wizard behaviour, step 1 -->
<target name="wizard2"
description="continue setup">
<antform title="did we validate?"
lookAndFeel="com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
okMessage="Finish"
previousTarget="getPath"
>
<label>Did we validate the path before we got here?</label>
</antform>
</target>
</project>

How to validate an xml file in ant?

this is my xml file
<contacts>
<contact>
<firstname>Edwin</firstname>
<lastname>Dankert</lastname>
</contact>
</contacts>
i want to validate it in ant,my target is
<target name="WellFormed">
<xmlvalidate file="contacts.xml"/>
<echo>WELL FORMED</echo>
</target>
C:\work\build\XML_VALIDATION>ant
Buildfile: C:\work\build\XML_VALIDATION\build.xml
<==========================ANT OUTPUT=============================>
WellFormed:
[xmlvalidate] contacts.xml:1:11: Document root element "contacts", must match DOCTYPE root "null".
[xmlvalidate] contacts.xml:1:11: Document is invalid: no grammar found.
BUILD FAILED
C:\work\build\XML_VALIDATION\build.xml:4: C:\work\build\XML_VALIDATION\contacts.xml is not a valid XML document.
i am not checking it against any xsd,can anyone help me in finding what changes i need to insert into the xml.
If you just want to make sure your XML is well-formed, then add the lenient attribute to your xmlvalidate task as follows.
<xmlvalidate file="contacts.xml" lenient="yes"/>
Your build file is not valid, you need to start with
<?xml version="1.0"?>
<project name="name">
<target name="target-name">
...
</target>
</project>
A google search for sample Ant build file will provide all you need to understand build files. This link will help too.

JaCoCo report looks correct but can not view source

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 …

Find all directories in which a file exists, such that the file contains a search string

I have a directory tree that I need to process as follows:
I have a certain file that needs to be copied to a select few sub directories
A sub directory of interest is one that contains a file within which I can regex match a known search string
Ideally I would like to:
Perform a regex match across all files within a directory
If the regex matches, copy the file to that directory
The trouble is that I am quite new to ANT and I'm having difficulties finding my way around. I can't find any tasks in the docs about per directory operations based on regex search. The closest thing I've found is a regex replace task (<replaceregexp>) that can search and replace patterns across files.
Is this even possible? I'd really appreciate a sample to get started with. I apologize for requesting code - I simply don't know how to begin composing the tasks together to achieve this.
Alternatively I have the option of hardcoding all the copy operations per directory, but it would mean manually keeping everything in sync as my project grows. Ideally I'd like to automate it based on the regex search/copy approach I described.
Thanks!
Your requirement is a bit non-standard, so I've solved it using a custom Groovy task.
Here's a working example:
<project name="find-files" default="copy-files">
<!--
======================
Groovy task dependency
======================
-->
<path id="build.path">
<pathelement location="jars/groovy-all-1.8.6.jar"/>
</path>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<!--
=========================
Search for matching files
=========================
-->
<target name="search-files">
<fileset id="filesContainingSearchString" dir="src">
<include name="**/*.txt"/>
<containsregexp expression="[4-6]\.[0-9]"/>
</fileset>
</target>
<!--
===================================
Copy file into each directory found
===================================
-->
<target name="copy-files" depends="search-files">
<groovy>
project.references.filesContainingSearchString.each { file ->
def dir = new File(file.toString()).parent
ant.copy(file:"fileToBeCopied.txt", toDir:dir)
}
</groovy>
</target>
</project>
Notes:
Groovy jar can be downloaded from Maven Central
Use the copy task with a fileset and regular expression selector :
<copy todir="your/target/dir">
<fileset dir="rootdir/of/your/directorytree" includes="**/*.txt">
<containsregexp expression="[4-6]\.[0-9]"/>
</fileset>
</copy>
This example is taken from the ant manual and slightly adapted.
Means select all files with .txt extension anywhere beyond rootdir/of/your/directorytree that match the regular expression (have a 4,5 or 6 followed by a period and a number from 0 to 9) and copy them to your/target/dir.
Just adapt it for your needs.

Resources