How to remove specific Cobertura warning? - ant

When i am running my ANT build script, Cobertura is complaining with the following warning. With that, i am wondering what it means really and how can i turn it off.
[cobertura-instrument] WARN visitEnd, No line number information found for class com.x.y.z.A. Perhaps you need to compile with debug=true?
ANT sample below:
<target name="instrument" depends="init,compile" >
<delete file="cobertura.ser" />
<delete dir="${instrumented}" />
<cobertura-instrument todir="${instrumented}">
<ignore regex="org.apache.log4j.*" />
<fileset dir="${build}" >
<include name="**/*.class" />
<exclude name="**/Test*.class" />
</fileset>
</cobertura-instrument>
</target>
Please advise.

Setting debuglevel appears to not work for anonymous inner classes (Cobertura 1.9.4.1)?
[cobertura-instrument] WARN visitEnd, No line number information found for class com.test.MyClass$1. Perhaps you need to compile with debug=true?

As suggested here in the cobertura mailing-list, perhaps you can try adding the debug options and see if that helps.
<javac debug="true" debuglevel="vars,lines,source">

Related

How to integrate Ant with Checkstyle and PMD plug-ins in Jenkins

I want to integrate Checkstyle and PMD plug-ins in Jenkins for checking quality code automatically.
I followed the instructions from: http://www.treselle.com/blog/static-code-analysis-jenkins/
My build.xml in workspace was appended those codes:
<taskdef name="checkstyle" classpath="WEB-INF/libs/checkstyle-5.6.jar" classname="com.puppycrawl.tools.checkstyle.CheckStyleTask" />
<target name="checkstyle" description="Generates a report of code convention violations.">
<checkstyle config="sun_checks.xml" failOnViolation="false">
<formatter type="xml" tofile="checkstyle_report.xml" />
<fileset dir="WEB-INF/src" includes="**/*.java" />
</checkstyle>
</target>
<taskdef name="pmd" classpath="WEB-INF/libs/pmd.jar" classname="net.sourceforge.pmd.ant.PMDTask" />
<target name="pmd" depends="compress">
<pmd rulesetfiles="java-imports">
<formatter type="xml" toFile="pmd_report.x.ml" />
<fileset dir="WEB-INF/src">
<include name="**/*.java" />
</fileset>
</pmd>
</target>
I also added enough library, but when I builded Jobs, I got a exception:
taskdef class com.puppycrawl.tools.checkstyle.CheckStyleTask cannot be found using the classloader AntClassLoader[]
Why is there such error? And How do I integrate them correctly?
Thanks a lot!
Try later version of check style as checkstyle-8.0-all.jar.
See example
classname="com.puppycrawl.tools.checkstyle.CheckStyleTask" />
taskdef class com.puppycrawl.tools.checkstyle.CheckStyleTask cannot be found
The class is named CheckstyleAntTask.
See https://github.com/checkstyle/checkstyle/blob/master/config/ant-phase-verify.xml on an example on how to use CheckstyleAntTask.
checkstyle-5.6.jar
I recommend upgrading to a newer version. Checkstyle is currently on version 8.

How to make ant not fail if folder on classpath is not found

I'm trying to modify my ant script so that it will build without error whether or not a local lib folder exists. I want to use the same script on multiple wars, some of which will have WEB-INF/lib, and some of which won't. If the folder exists, include it in the classpath, if not, do not include it. I have tried putting but I can't figure out where it should go. I think this should be a lot simpler than I'm making it out to be but my Googl Fu is failing me.
<property name="local.libs" value="WebContent/WEB-INF/lib" />
<path id="local.libs.path">
<fileset dir="${local.libs}" includes="*.jar" />
</path>
<target name="compile">
<mkdir dir="${build.classes.dir}"/>
<javac srcdir="${src.java.dir}" destdir="${build.classes.dir}" debug="true" includeantruntime="false">
<compilerarg value="-Xlint:-path" />
<classpath refid="local.libs.path" />
<classpath refid="server.libs.path" /> <!-- not referenced in snippet -->
</javac>
</target>
I ended up solving this by making the value of local.libs just WebContent/WEB-INF:
<property name="local.libs" value="WebContent/WEB-INF" />
and then the fileset
<fileset dir="${local.libs}" includes="*lib/*.jar" />
Then it would build whether or not the lib folder existed.

Ant: Source and target files are the same. How to detect a change?

We are using JiBX. The important thing to know is that JiBX modifies the already compiled class files.
We do our compile:
<javac destdir="${main.destdir}">
<src path="${main.srcdir}"/>
<classpath refid="main.classpath"/>
</javac>
Then, we call JiBX:
<jibx load="true"
binding="{$binding.file}">
<classpath refid="main.classpath"/>
<classpath refid="main.destdir.classpath"/>
</jibx>
This uses an XML file that updates the classfiles compiled by <javac> above. The problem is how do I know that the files have been compiled, but not processed by JiBX? I'd like to put some logic in my program, so that files are not updated twice by JiBX. Besides, it's bad form to duplicate work that already been done.
After the jibx build step, generate a marker file, e.g.
<touch file="${target.dir}/jibx.marker" />
Only perform the jibx build step if that marker file is older than the .class files (indicating that the javac ran more recently than the last jibx).
For that bit of logic, you can use the traditional ant way:
<uptodate property="jibx.uptodate" targetfile="${target.dir}/jibx.marker">
<srcfiles dir="${main.destdir}" includes="...../*.class" />
</uptodate>
And then use the property with an unless clause when invoking the jixb target.
Or, you can use Antcontrib's outofdate alternative:
<outofdate>
<sourcefiles>
<fileset dir="${main.destdir}" includes="...../*.class" />
</sourcefiles>
<targetfiles>
<fileset dir="${target.dir}" includes="jibx.marker"/>
</targetfiles>
<sequential>
<jibx load="true"
binding="{$binding.file}">
<classpath refid="main.classpath"/>
<classpath refid="main.destdir.classpath"/>
</jibx>
</sequential>
</outofdate>
I'm giving this to Patrice M. because his suggestion put me on the right track. However, it didn't quite work out as he stated. (Sorry, if I got he pronoun wrong, but Patrice can be both a male or female name.)
What I had to do was create two watch files: One for the Java compile, and one for the JiBX changes.
<!-- Check if Javac is out of date. If so, create javac watcher -->
<outofdate verbose="true">
<sourcefiles>
<fileset dir="${main.srcdir}">
<include name="*.java"/>
</fileset>
</sourcefiles>
<mapper type="regexp"
from="${main.srcdir}/(.*)\.java"
to="${main.destdir}/(\1).class"/>
<sequential>
<echo message="Java compiled"/>
<echo message="Java compiled"
file="${target.dir}/${javac.monitor.file}"/>
</sequential>
</outofdate>
<javac destdir="${main.destdir}"
debug="${javac.debug}">
<src path="${main.srcdir}"/>
<classpath refid="main.classpath"/>
</javac>
<!-- Compare javac and jibx monitoring file -->
<!-- If out of date, rerun jibx -->
<outofdate>
<sourcefiles>
<fileset dir="${target.dir}">
<include name="${javac.monitor.file}"/>
</fileset>
</sourcefiles>
<targetfiles>
<fileset dir="${target.dir}">
<include name="${jibx.monitor.file}"/>
</fileset>
</targetfiles>
<sequential>
<jibx load="true"
binding="${target.dir}/binding-gg.xml">
<classpath refid="main.classpath"/>
<classpath refid="main.destdir.classpath"/>
</jibx>
<!-- Create JiBX monitoring file -->
<echo message="Compiled and JiBX"
file="${target.dir}/${jibx.monitor.file}"/>
</sequential>
</outofdate>
I create the javac monitoring file if the source is out of date with the classes because that's when I compile. I have to create the JiBX outofdate monitoring file only when I run JiBX and that's inside the <outofdate> for JiBX.
I guess I could also put a source on the XML JiBX files too just to be sure.

Could not initialize class net.sourceforge.pmd.lang.xpath.Initializer

Here is my pmd script for ant build.xml
<property name="pmd.dir" value="${basedir}/pmd" /><!-- directory that contains pmd.jar -->
<property name="pmd.test.results" location="${build.dir}/pmd"/>
<path id="pmd.lib" >
<fileset dir="${pmd.dir}">
<include name="*.jar"/>
<exclude name="/rulesets" />
</fileset>
</path>
<target name="pmd" depends="compile" >
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.lib"/>
<pmd shortFilenames="true">
<ruleset>b</ruleset>
<formatter type="text" toFile="pmd-ant-results.txt"/>
<fileset dir="src">
<include name="**/*.java"/>
</fileset>
</pmd>
</target>
Here is a screen shot of my projects explorer, here is a pastebin link to ruleset.xml
(source: iforce.co.nz)
And here is the error
pmd:
BUILD FAILED
C:\Users\Michael\Desktop\log4jassignment.s06005586\build.xml:112: Can't find resource ruleset/java/basic.xml. Make sure the resource is a valid file or URL or is on the CLASSPATH. Here's the current classpath: C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-antlr.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-apache-bcel.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-apache-bsf.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-apache-log4j.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-apache-oro.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-apache-regexp.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-apache-resolver.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-apache-xalan2.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-commons-logging.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-commons-net.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-jai.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-javamail.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-jdepend.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-jmf.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-jsch.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-junit.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-junit4.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-launcher.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-netrexx.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-swing.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant-testutil.jar;C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib\ant.jar;C:\Program Files\eclipse\configuration\org.eclipse.osgi\bundles\57\2.cp\lib\antdebug.jar;C:\Program Files\eclipse\configuration\org.eclipse.osgi\bundles\57\2.cp\lib\remote.jar;C:\Program Files\eclipse\configuration\org.eclipse.osgi\bundles\58\2.cp\lib\remoteAnt.jar;C:\Program Files\Java\jdk1.6.0_25\lib\tools.jar;C:\Program Files\eclipse\plugins\org.eclipse.swt.win32.win32.x86_64_3.100.0.v4233d.jar;C:\Users\Michael\Desktop\log4jassignment.s06005586\tools\jdepend-2.9.1.jar
The main problem I'm having is lack of information regarding pmd and ant (its terrible there is nothing out there) so I'm pretty much lost at this point at what I'm doing wrong... I'm pretty sure I havent set up my rulesets correctly (but there isn't a way to tell because of this lack of information for ant/pmd implementations)....
The error clearly says...
BUILD FAILED C:\Users\Michael\Desktop\log4jassignment.s06005586\build.xml:112: Can't find resource ruleset/java/basic.xml
and I don't see java folder inside ruleset. So get the folder and files in right place and then see whether it works or not

What does the Ant warning "Reference * has not been set at runtime..." mean?

Since the upgrade from Ant 1.6.5 to 1.7.1, my build output starts off with:
Warning: Reference project.classpath has not been set at runtime, but was found during
build file parsing, attempting to resolve. Future versions of Ant may support
referencing ids defined in non-executed targets.
Warning: Reference project.test.classpath has not been set at runtime, but was found during
build file parsing, attempting to resolve. Future versions of Ant may support
referencing ids defined in non-executed targets.
I have problems understanding this and why it is outputted, let alone trying to get rid of it. Any help would be appreciated!
EDIT:
Classpath is defined:
<path id="project.classpath">
<pathelement path="./${build.dir}" />
<path refid="libs.ant" />
<fileset dir="${lib.dir}/dependencies/bar" includes="compile/*.jar" />
<fileset dir="${lib.dir}/dependencies/foo" includes="provided/*.jar" />
</path>
<!-- The classpath for compiling this projects' tests -->
<path id="project.test.classpath">
<path refid="project.classpath" />
<fileset dir="${lib.dir}/dependencies/bar" includes="test/*.jar" />
<fileset dir="${lib.dir}/dependencies/foo" includes="test/*.jar" />
</path>
<property name="project.classpath" refid="project.classpath" />
It is referenced (e.g. in ) in this way:
<classpath refid="project.classpath"/>
I had the same issue before. Just make sure the "project.classpath" is defined in the beginning of the build file before other targets reference it. Also your "libs.ant" path should be defined before "project.classpath".
In Ant 1.8 this will actually be error instead of warning.
You can set classpath in the build file as following, to get rid of this warning. See reference. http://ant.apache.org/manual/using.html
<project ... >
<path id="project.class.path">
<pathelement location="lib/"/>
<pathelement path="${java.class.path}/"/>
<pathelement path="${additional.path}"/>
</path>
<target ... >
<rmic ...>
<classpath refid="project.class.path"/>
</rmic>
</target>
<target ... >
<javac ...>
<classpath refid="project.class.path"/>
</javac>
</target>
</project>
Unless this is a typo, it looks like trouble. You really should rename one for clarity even if it isn't the cause of the warning. It still sounds like project.classpath is defined in different targets and they are called in the wrong order. You may need to show more code for more help.
<property name="project.classpath" refid="project.classpath" />

Resources