I am using jacoco with Ant and with the build.xml given below. I want to exclude eQMIUtil class from util.3.5 jar. But I am getting all the methods while generating report. Is there any way I can get a solution for this. What does **<arg value= "2*3+4">** actually do?
<description>
Example Ant build file that demonstrates how a JaCoCo coverage report
can be itegrated into an existing build in three simple steps.
</description>
<!-- property name="src.dir" location="./src/main/java" />
<property name="result.dir" location="./target" />
<property name="result.classes.dir" location="${result.dir}/classes" />
<property name="result.report.dir" location="${result.dir}/site/jacoco" />
<property name="result.exec.file" location="${result.dir}/jacoco.exec" /-->
<property name="activity.src.dir" location="./src/MIActivities" />
<property name="modules.src.dir" location="./src/Modules" />
<property name="plugins.src.dir" location="./src/Plugins" />
<property name="classes.src.dir" location="F:/jacoco/test/classes" />
<property name="result.dir" location="./target" />
<property name="result.classes.dir" location="${result.dir}/classes" />
<property name="result.Activities.dir" location="F:/Tomcat/apache-tomcat6/webapps/MI35PCQA01P/Activities" />
<property name="result.report.dir" location="F:/Jacoco/test/target/site" />
<property name="result.exec.file1" location="F:/Jacoco/jacoco.exec" />
<property name="project.parent.build.directory" location="C:/MIWork/Jacoco/Coverage" />
<!-- Step 1: Import JaCoCo Ant tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="F:/Jacoco/jacoco-0.7.5.201505241946/lib/jacocoant.jar" />
</taskdef>
<target name="clean">
<delete dir="${result.report.dir}" />
</target>
<target name="report" >
<jacoco:report>
<executiondata>
<file file="${result.exec.file1}"/>
</executiondata>
<structure name="Example Project">
<classfiles>
<fileset file="${classes.src.dir}/util-3.5.jar" >
<exclude name="**/*eQMIUtil*.class"/>
</fileset>
</classfiles>
<sourcefiles encoding="UTF-8">
</sourcefiles>
</structure>
<html destdir="${result.report.dir}"/>
</jacoco:report>
</target>
<target name="test" depends="report">
<!-- Step 2: Wrap test execution with the JaCoCo coverage task -->
<jacoco:coverage destfile="${result.exec.file}">
<java classname="org.jacoco.examples.parser.Main" fork="true">
<classpath path="${result.classes.dir}" />
<arg value="2 * 3 + 4"/>
<arg value="2 + 3 * 4"/>
<arg value="(2 + 3) * 4"/>
<arg value="2 * 2 * 2 * 2"/>
<arg value="1 + 2 + 3 + 4"/>
<arg value="2 * 3 + 2 * 5"/>
</java>
</jacoco:coverage>
</target>
<target name="finalreport" depends="test">
<!-- Step 3: Create coverage report -->
<jacoco:report>
<!-- This task needs the collected execution data and ... -->
<executiondata>
<file file="${result.exec.file}" />
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}" />
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}" />
<csv destfile="${result.report.dir}/report.csv" />
<xml destfile="${result.report.dir}/report.xml" />
</jacoco:report>
</target>
<target name="rebuild" depends="clean,report" />
Instead of nesting a <fileset> under <jacoco:report>, you can nest a <zipfileset> instead.
This...
<jacoco:report>
...
<structure name="Example Project">
<classfiles>
<fileset file="${classes.src.dir}/util-3.5.jar" >
<exclude name="**/*eQMIUtil*.class"/>
</fileset>
</classfiles>
...
</structure>
...
</jacoco:report>
...should become...
<jacoco:report>
...
<structure name="Example Project">
<classfiles>
<zipfileset src="${classes.src.dir}/util-3.5.jar">
<exclude name="**/*eQMIUtil*.class"/>
</zipfileset>
</classfiles>
...
</structure>
...
</jacoco:report>
<zipfileset> works because JAR files are also ZIP files.
Related
Below is my Build.xml file. when i compile my project it shows Build Success but when i run it then Build Failed "failed to create task or type testng" Cause: the name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
<?xml version="1.0" encoding="UTF-8"?>
<project name="projectName" default="clean" basedir="C:\Users\saad bin usman\workspace\testNG"> <!-- dot indicates that basedir is pointing towards project root directory -->
<!-- ========== Initialize Properties =================================== -->
<property name="ws.home" value="${basedir}" />
<property name="ws.jars" value="D:\jars" />
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="ng.result" value="test-output"/>
<echo> value of base dir = ${basedir} </echo>
<!-- properties for copying the results -->
<tstamp>
<format property="year" pattern="yyyy" />
<format property="DSTAMP" pattern="yyyy-MM-dd" />
<format property="TSTAMP" pattern="HH:mm:ss" />
<format property="dateversion" pattern="yyyy.MM.dd.HH:mm:ss" />
<format property="time.stamp" pattern="yyyy-MM-dd_HH-mm-ss aa_"/>
</tstamp>
<property name="testng.report.dir" value="${ws.home}/testngReports/${time.stamp}"/>
<property name="testngXslt.report.dir" value="${ws.home}/testngXsltReports/${time.stamp}"/>
<!-- ====== For setting the classpath ==== -->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes = "*.jar"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars" />
</target>
<!-- ============ Initializing other stuff =========== -->
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM-dd-yyyy (HH-mm-ss)"/>
</tstamp>
<condition property="ANT"
value="$(env.ANT_HOME)/bin/ant.bat"
else="$(env.ANT_HOME)/bin/ant">
<!-- os family="windows" /-->
<os family="mac" />
</condition>
<!--
<!- use direct path for classpath if you don't prefer to use 'lib' directory: classpath="/Users/yash/Documents/Jar Files/testng-6.8.jar" ->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="./lib/testng.jar"/>
</classpath>
</taskdef>
-->
</target>
<target name="all">
</target>
<!-- cleaning the destination folders -->
<target name="clean">
<echo message="deleting existing build directory"/>
<delete dir="${test.dest}"/>
</target>
<!-- target for compiling the java files -->
<target name="compile" depends="init, clean">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory....."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath-------: ${test.classpath}"/>
<echo message="compiling....."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
classpath="${test.classpath}"
includeantruntime="true"/>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<!-- ========== Test executions & Generating reports using Testng utility for multiple suites ============== -->
<!-- run -->
<target name="run" depends="compile">
<taskdef resource="testngtasks" classpath="D:\saad bin usman\saad's doc\softwares\eclipse\plugins\org.testng.eclipse_6.9.8.201510130443\lib\*.jar" />
<testng classpath="classpath.test" suitename="smsweb" outputDir="test-output" >
<xmlfileset dir="${ws.home}" includes="testng.xml" />
</testng>
</target>
<target name="testngReportCopyAndReportParser">
<!-- Copy to TestNG report directory-->
<mkdir dir="${testngDir}">
</mkdir>
<!-- to copy previous suite result to TestNG report directory -->
<copy todir="${testngDir}">
<fileset dir="test-output"/>
</copy> <!-- end of Testng Report -->
</target>
<!-- ========== Test executions & Generating reports using Testng XSLT utility for multiple suites ============== -->
<!-- run -->
<target name="runAsTestngXslt" depends="compile">
<!--suite 1 begin -->
<property name="suite.web.CopyRegressionCustomer" value="CopyRegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="CopyRegressionCustomer" outputDir="test-output" >
<xmlfileset dir="." includes="webSuites/CopyRegressionCustomer.xml" />
</testng>
<antcall target="testngXsltReportCopy">
<param name="testngXsltDir" value="${testngXslt.report.dir}${suite.web.CopyRegressionCustomer}"/>
</antcall>
<!--suite 2 begin -->
<property name="suite.web.Copy2RegressionCustomer" value="Copy2RegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="Copy2RegressionCustomer" outputDir="test-output" >
<xmlfileset dir="." includes="webSuites/Copy2RegressionCustomer.xml" />
</testng>
<antcall target="testngXsltReportCopy">
<param name="testngXsltDir" value="${testngXslt.report.dir}${suite.web.Copy2RegressionCustomer}"/>
</antcall>
</target>
<target name="testngXsltReportCopyAndReportParser">
<!-- Copy to TestNG report directory-->
<mkdir dir="${testngXsltDir}">
</mkdir>
<!-- to copy previous suite result to TestngXslt report folder -->
<xslt in="${ws.home}/test-output/testng-results.xml" style="src/xslt/testng-results.xsl"
out="${testngXsltDir}/index.html" classpathref="test.c" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${testngXsltDir}" />
<param name="testNgXslt.showRuntimeTotals" expression="true" />
<param name="testNgXslt.sortTestCaseLinks" expression="true" />
<param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS,CONF,BY_CLASS" />
</xslt> <!-- end of TestngXslt Report -->
</target>
<path id="test.c">
<fileset dir="${ws.jars}" includes="*.jar">
<include name="mail.jar"/>
<include name="activation-1.0.2.jar"/>
</fileset>
</path>
<!-- ========== Generating reports using Testng XSLT utility for single suite only ============== -->
<target name="report" depends="run">
<!-- TestngXslt report -->
<mkdir dir="${testngXslt.report.dir}">
</mkdir>
<!-- to copy previous suite result to TestngXslt report folder -->
<xslt in="${ws.home}/test-output/testng-results.xml" style="src/xslt/testng-results.xsl"
out="${testngXslt.report.dir}/index.html" classpathref="test.c" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${testngXslt.report.dir}" />
<param name="testNgXslt.showRuntimeTotals" expression="true" />
<param name="testNgXslt.sortTestCaseLinks" expression="true" />
<param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS,CONF,BY_CLASS" />
</xslt> <!-- end of TestngXslt Report -->
</target>
<target name="RunAndViewReport" depends="report">
<exec executable="${browser}" spawn="yes">
<arg line="'file:///${testngXslt.report.dir}/index.html'" />
</exec>
</target>
<target name="sendMail" depends="RunAndViewReport">
<zip destfile="${testngXslt.report.dir}/Report.zip" basedir="${testngXslt.report.dir}"/>
<mail mailhost="smtp.gmail.com" mailport="465" subject="Notification of TESTNG build result" ssl="false" user="automationmoolya#gmail.com" password="moolya#universe">
<from address="automationmoolya#gmail.com"/>
<to address="yagnesh#moolya.com"/>
<message>The build has finished. A details report of this build is attached</message>
<attachments>
<fileset dir="testngXslt.report.dir">
<include name="**/*.zip"/>
</fileset>
</attachments>
</mail>
</target>
<target name="install-jars" description="Install ANT optional jars">
<get dest="${ws.home}/lib/mail.jar" src="file:///${ws.home}/lib/mail.jar"/>
<fileset dir="${ws.jars}" includes="*.jar">
<include name="mail.jar"/>
<include name="activation-1.0.2.jar"/>
</fileset>
</target>
</project>
use run like below
<!-- run -->
<target name="run" depends="compile">
<testng classpath="${test.classpath}:${test.dest}">
<xmlfileset dir="${ws.home}" includes="testng.xml"/>
</testng>
</target>
Your taskdef is nested inside the task you're trying to use. That's now how it works. Define the task first, then run it.
<taskdef resource="testngtasks" classpath="/full/path/to/testng.jar" />
<testng classpathref="classpath.test" suitename="smsweb" outputDir="test-output" >
<xmlfileset dir="${ws.home}" includes="testng.xml" />
</testng>
I got a Spring project built using Ant that fails when executed on Jenkins, but not when I run the exact same Ant target from Eclipse (Ant view).
Jenkins version is 2.19.4
Jenkins Console Output excerpt
Started by user Morin, Charles
Building in workspace D:\APPS\jenkins-2.19.4\workspace\MY-PROJECT
Using locally configured password for connection to :pserver:MY-SERVICE-ACCOUNT#MY-CVS-SERVER:D:/DATA/REPOSITORIES/MY-CVS-REPO
cvs update -d -P -r HEAD -D 26 Jan 2017 10:09:39 -0500 MY-PROJECT
Using locally configured password for connection to :pserver:MY-SERVICE-ACCOUNT#MY-CVS-SERVER:D:/DATA/REPOSITORIES/MY-CVS-REPO
cvs rlog -S -d25 Jan 2017 00:08:54 -0500<26 Jan 2017 10:09:39 -0500 MY-PROJECT
[MY-PROJECT] $ cmd.exe /C "D:\APPS\jenkins-2.19.4\ant\bin\ant.bat -file build.xml compile && exit %%ERRORLEVEL%%"
Buildfile: build.xml
[echo] ========================================================================
[echo] *** Starting MY-PROJECT build
[echo] ========================================================================
print-version:
[echo] Java/JVM version: 1.6
[echo] Java/JVM detailed version: 1.7.0_25
create-directories:
compile:
[javac] Compiling 41 source files to D:\APPS\jenkins-2.19.4\workspace\MY-PROJECT\target\classes
[javac] Note: Hibernate JPA 2 Static-Metamodel Generator 5.1.0.Final
[javac] D:\APPS\jenkins-2.19.4\workspace\MY-PROJECT\src\path\to\my\class\MyClass.java:28: error: cannot find symbol
[javac] import path.to.my.class.MyClass_;
[javac] ^
[javac] symbol: class MyClass_
[javac] location: package path.to.my.class
The problem is that my JPA metamodels are not being found during the compilation. However, we can see the following line that confirms the generation of JPA Metamodels:
Note: Hibernate JPA 2 Static-Metamodel Generator 5.1.0.Final
The only difference I can see is in the print-version Ant target. When executed locally, I got this:
print-version:
[echo] Java/JVM version: 1.7
[echo] Java/JVM detailed version: 1.7.0_25
I also have several other projects with the exact same setup, and I don't have that issue.
build.xml
<?xml version="1.0" encoding="utf-8"?>
<project name="MY-PROJECT" default="create-war-and-deploy-to-jboss" basedir="." xmlns:sonar="antlib:org.sonar.ant" xmlns:jacoco="antlib:org.jacoco.ant">
<property name="verbose" value="false" />
<property name="javaVersion" value="1.7" />
<!-- Provides access to OS environment variables (eg: env.USERNAME) -->
<property environment="env" />
<!-- Application's directories -->
<property name="dir.build" value="${basedir}/build" />
<property name="dir.src" value="${basedir}/src" />
<property name="dir.dist" value="${basedir}/dist" />
<property name="dir.lib" location="${basedir}/lib" />
<property name="dir.target" value="${basedir}/target" />
<property name="dir.build.classes" value="${dir.target}/classes" />
<property name="dir.test" value="${basedir}/test" />
<property name="dir.web" value="${basedir}/WebContent" />
<property name="dir.webinf.lib" value="${dir.web}/WEB-INF/lib" />
<!-- Loading the application.properties file -->
<property file="${dir.src}/resources/application.properties" prefix="app." />
<!-- Loading the build.properties file -->
<property file="build.properties" prefix="buildProp." />
<tstamp>
<format property="build.time" pattern="yyyy-MM-dd HH:mm" />
</tstamp>
<echo message="========================================================================" />
<echo message="*** Starting ${app.name} build " />
<echo message="========================================================================" />
<!-- JBoss directories -->
<property name="dir.jboss" value="${buildProp.jboss.home}" />
<property name="dir.jboss.domain" value="${dir.jboss}/${buildProp.jboss.domain}" />
<property name="dir.jboss.libs" value="${dir.jboss}/${buildProp.jboss.libs}" />
<property name="dir.jboss.deploy" value="${dir.jboss.domain}/${buildProp.jboss.deploy}" />
<!-- Path for unit tests -->
<path id="run.classpath.tests">
<pathelement path="${dir.build.classes}" />
<pathelement path="${dir.test}/build/classes" />
<path refid="compile.classpath.tests" />
</path>
<!-- Provided dependencies from the container -->
<path id="compile.classpath.server">
<fileset dir="${dir.lib}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- Dependencies specific to this application -->
<path id="compile.classpath.web">
<fileset dir="${dir.web}/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>
</path>
<path id="compile.classpath.target">
<fileset dir="${dir.lib}">
<include name="hibernate-jpamodelgen-5.1.0.Final.jar" />
</fileset>
<fileset dir="${dir.target}">
<include name="**/*.java" />
</fileset>
</path>
<!-- Dependencies specifically for unit testing purposes -->
<path id="compile.classpath.tests">
<fileset dir="${dir.test}/lib/">
<include name="junit-4.6.jar" />
<include name="mockito-all-1.9.5.jar" />
</fileset>
<fileset dir="${dir.webinf.lib}" />
<pathelement location="${dir.build.classes}" />
<path refid="compile.classpath.server" />
</path>
<!-- PRINT-VERSION -->
<target name="print-version">
<echo>Java/JVM version: ${ant.java.version}</echo>
<echo>Java/JVM detailed version: ${java.version}</echo>
</target>
<!-- BUILD-DISTRIBUTION -->
<target
name="build-distribution"
description="Generate Deployment unit and stage to appserver directory."
depends="
clean,
run-unit-tests,
create-war,
run-sonarqube-analysis">
<manifest file="${dir.web}/META-INF/MANIFEST.MF">
<attribute name="Manifest-Version" value="1.0" />
<attribute name="Ant-Version" value="1.7.0" />
<attribute name="Created-By" value="${env.USERNAME}" />
<attribute name="Implementation-Title" value="${app.name}" />
<attribute name="Implementation-Version" value="${app.version}" />
<attribute name="Implementation-Vendor" value="Canada Revenue Agency" />
<attribute name="Implementation-Date" value="${build.time}" />
<attribute name="Built-By" value="${env.USERNAME}" />
<attribute name="Dependencies" value="org.hibernate" />
</manifest>
<propertyfile file="${dir.src}/resources/application.properties">
<entry key="lastUpdate" value="${build.time}" />
</propertyfile>
</target>
<!-- CLEAN -->
<target name="clean"
description="Cleans up build-related temporary directories."
depends="delete-directories" />
<!-- CREATE-DIRECTORIES -->
<target name="create-directories" >
<mkdir dir="${dir.build}" />
<mkdir dir="${dir.dist}" />
<mkdir dir="${dir.build.classes}" />
<mkdir dir="${dir.web}/WEB-INF/classes" />
<mkdir dir="${dir.test}/build" />
<mkdir dir="${dir.test}/build/classes" />
<mkdir dir="${dir.test}/reports" />
</target>
<!-- DELETES-DIRECTORIES -->
<target name="delete-directories">
<delete dir=".sonar" />
<!-- /build -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.build}" includes="**/*" />
<exclude name=".cvsignore" />
</delete>
<!-- /dist -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.dist}" includes="**/*" />
<exclude name=".cvsignore" />
</delete>
<!-- /WEB-INF/classes -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.web}/WEB-INF/classes">
<include name="**/*" />
</fileset>
<fileset dir="${dir.web}/WEB-INF/src">
<include name="**/*" />
</fileset>
</delete>
<!-- /target -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.target}" includes="**/*" />
<exclude name=".cvsignore" />
</delete>
<!-- /test/build -->
<delete dir="${dir.test}/build" />
<!-- /test/reports -->
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${dir.test}/reports" />
</delete>
<!-- Existing WAR file and JBoss marker files -->
<delete dir="${dir.jboss.deploy}/${app.name}.war" />
<delete file="${dir.jboss.deploy}/${app.name}.war" />
<delete file="${dir.jboss.deploy}/${app.name}.war.deployed" />
</target>
<!-- COMPILE -->
<target name="compile" depends="print-version,create-directories">
<javac destdir="${dir.build.classes}" verbose="${verbose}" debug="on" fork="true" failonerror="true" source="${javaVersion}" target="${javaVersion}" includeantruntime="false">
<classpath>
<path refid="compile.classpath.server" />
<path refid="compile.classpath.target" />
<path refid="compile.classpath.web" />
</classpath>
<src path="${dir.src}" />
<compilerarg value="-Xlint:deprecation" />
<compilerarg value="-Xlint:unchecked" />
</javac>
<!--copy property files to classes directory -->
<copy todir="${dir.build.classes}">
<fileset dir="${dir.src}">
<include name="**/*.properties" />
<include name="META-INF/**/*" />
</fileset>
</copy>
</target>
<!-- COMPILE-TESTS -->
<target name="compile-tests" depends="create-directories,compile">
<javac srcdir="${dir.test}/src" destdir="${dir.test}/build/classes" verbose="${verbose}" debug="on" fork="true" source="${javaVersion}" target="${javaVersion}" includeantruntime="false">
<classpath refid="compile.classpath.tests" />
<compilerarg value="-Xlint:deprecation" />
<compilerarg value="-Xlint:unchecked" />
</javac>
</target>
<!-- RUN-UNIT-TESTS -->
<target name="run-unit-tests" depends="compile-tests" description="Runs all unit test classes under the test package.">
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="test/lib/org.jacoco.ant-0.7.2.201409121644.jar"/>
<classpath path="test/lib/org.jacoco.agent_0.7.2.201409121644.jar"/>
<classpath path="test/lib/org.jacoco.core_0.7.2.201409121644.jar"/>
<classpath path="test/lib/org.jacoco.report_0.7.2.201409121644.jar"/>
</taskdef>
<jacoco:coverage destfile="${dir.target}/jacoco.exec">
<junit fork="true" printsummary="yes" haltonfailure="yes" showoutput="no">
<classpath refid="run.classpath.tests" />
<formatter type="xml" />
<batchtest fork="yes" todir="${dir.test}/reports">
<fileset dir="${dir.test}/src">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
<!-- CREATE-WAR -->
<target name="create-war" description="Creates a WAR file including all compiled classes and resources." depends="compile">
<war destfile="dist/${app.name}.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent" />
<classes dir="${dir.build.classes}" />
</war>
</target>
<!-- CREATE-WAR-AND-DEPLOY -->
<target name="create-war-and-deploy-to-jboss" description="Creates a WAR file including all compiled classes and resources, and deploys the app to jboss" depends="create-war,deploy-to-jboss" />
<!-- RUN-SONARQUBE -->
<target name="run-sonarqube-analysis" description="Runs the SonarQube analysis and updates statistics on the server." depends="create-war">
<property file="sonar.properties" prefix="sonar." />
<!-- SonarQube properties -->
<property name="sonar.exclusions" value="${sonar.exclusions}" />
<property name="sonar.host.url" value="${sonar.host.url}" />
<property name="sonar.jacoco.reportPath" value="${sonar.jacoco.reportPath}" />
<property name="sonar.java.binaries" value="${sonar.java.binaries}" />
<property name="sonar.java.coveragePlugin" value="${sonar.java.coveragePlugin}" />
<property name="sonar.java.libraries" value="${sonar.java.libraries}" />
<property name="sonar.java.source" value="${javaVersion}" />
<property name="sonar.junit.reportsPath" value="${sonar.junit.reportsPath}" />
<property name="sonar.projectKey" value="${sonar.projectKey}" />
<property name="sonar.projectVersion" value="${app.version}" />
<property name="sonar.projectName" value="${sonar.projectName}" />
<property name="sonar.sources" value="${sonar.sources}" />
<property name="sonar.sourceEncoding" value="${sonar.sources.sourceEncoding}" />
<property name="sonar.tests" value="${sonar.tests}" />
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="${dir.lib}/sonarqube-ant-task-2.4.1.jar" />
</taskdef>
<sonar:sonar/>
</target>
<!-- DEPLOY-TO-JBOSS -->
<target name="deploy-to-jboss" depends="create-war">
<!--delete war file if it already exists and was copied over, we need a directory now-->
<delete file="${dir.jboss.deploy}/${app.name}.war" />
<delete file="${dir.jboss.deploy}/${app.name}.war.deployed" />
<!-- copy all of the files except one that will trigger the deployment -->
<copy todir="${dir.jboss.deploy}">
<fileset file="${dir.dist}/${app.name}.war" />
</copy>
</target>
</project>
Thank you
From Manage Jenkins-->Configure System--JDK section, add both JDKs to JDK Installation. From your Job Configuration, in the JDK section, explicitly choose the 1.7 JDK.
Hello, the problem is ,that i cannot trigger ANT run command in my
project , it gives me error. when i trigger ANT clean and ANT compile
, BUILD SUCCESS.
BUILD.XML CODE ERROR LINES
Getting the error on line :2
<!-- run -->
<target name="run" depends="compile">
<testng classpath="${test.classpath}:${test.dest}" suitename="suite1" outputDir="test-output" >
<xmlfileset dir="${ws.home}" includes="TestNG.xml" />
</testng>
<!--suite 1 begin -->
<property name="suite.web.CopyRegressionCustomer" value="CopyRegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="CopyRegressionCustomer" outputDir="test-output" >
<xmlfileset dir="${ws.home}" includes="TestNG.xml" />
</testng>
<antcall target="testngReportCopy">
<param name="testngDir" value="${testng.report.dir}${suite.web.CopyRegressionCustomer}"/>
</antcall>
ERROR LOG:
Problem: failed to create task or type testng
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
FULL BUILD.xml CODE
<?xml version="1.0" encoding="UTF-8"?>
<project name="projectName" default="clean" basedir="."> <!-- dot indicates that basedir is pointing towards project root directory -->
<!-- ========== Initialize Properties =================================== -->
<property name="ws.home" value="${basedir}" />
<property name="ws.jars" value="/Users/mac/Downloads/selenium-2.47.1" />
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="ng.result" value="test-output"/>
<echo> value of base dir = ${basedir} </echo>
<!-- properties for copying the results -->
<tstamp>
<format property="year" pattern="yyyy" />
<format property="DSTAMP" pattern="yyyy-MM-dd" />
<format property="TSTAMP" pattern="HH:mm:ss" />
<format property="dateversion" pattern="yyyy.MM.dd.HH:mm:ss" />
<format property="time.stamp" pattern="yyyy-MM-dd_HH-mm-ss aa_"/>
</tstamp>
<property name="testng.report.dir" value="${ws.home}/testngReports/${time.stamp}"/>
<property name="testngXslt.report.dir" value="${ws.home}/testngXsltReports/${time.stamp}"/>
<!-- ====== For setting the classpath ==== -->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes = "*.jar"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars" />
</target>
<!-- ============ Initializing other stuff =========== -->
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM-dd-yyyy (HH-mm-ss)"/>
</tstamp>
<condition property="ANT"
value="$(env.ANT_HOME)/bin/ant.bat"
else="$(env.ANT_HOME)/bin/ant">
<!-- os family="windows" /-->
<os family="mac" />
</condition>
<!--
<taskdef name="testng" classpath="/Users/mac/Downloads/selenium-2.47.1" classname="org.testng.TestNGAntTask" />
<!- use direct path for classpath if you don't prefer to use 'lib' directory: classpath="/Users/yash/Documents/Jar Files/testng-6.8.jar" ->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="./lib/testng.jar"/>
</classpath>
</taskdef>
-->
</target>
<target name="all">
</target>
<!-- cleaning the destination folders -->
<target name="clean">
<echo message="deleting existing build directory"/>
<delete dir="${test.dest}"/>
</target>
<!-- target for compiling the java files -->
<target name="compile" depends="init, clean">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory....."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath-------: ${test.classpath}"/>
<echo message="compiling....."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
classpath="${test.classpath}"
includeantruntime="true"/>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<!-- ========== Test executions & Generating reports using Testng utility for multiple suites ============== -->
<!-- run -->
<target name="run" depends="compile">
<testng classpath="${test.classpath}:${test.dest}" suitename="suite1" outputDir="test-output" >
<xmlfileset dir="${ws.home}" includes="TestNG.xml" />
</testng>
<!--suite 1 begin -->
<property name="suite.web.CopyRegressionCustomer" value="CopyRegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="CopyRegressionCustomer" outputDir="test-output" >
<xmlfileset dir="${ws.home}" includes="TestNG.xml" />
</testng>
<antcall target="testngReportCopy">
<param name="testngDir" value="${testng.report.dir}${suite.web.CopyRegressionCustomer}"/>
</antcall>
<!--suite 2 begin -->
<property name="suite.web.Copy2RegressionCustomer" value="Copy2RegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="Copy2RegressionCustomer" outputDir="test-output" >
<xmlfileset dir="." includes="webSuites/Copy2RegressionCustomer.xml" />
</testng>
<antcall target="testngReportCopy">
<param name="testngDir" value="${testng.report.dir}${suite.web.Copy2RegressionCustomer}"/>
</antcall>
</target>
<target name="testngReportCopyAndReportParser">
<!-- Copy to TestNG report directory-->
<mkdir dir="${testngDir}">
</mkdir>
<!-- to copy previous suite result to TestNG report directory -->
<copy todir="${testngDir}">
<fileset dir="test-output"/>
</copy> <!-- end of Testng Report -->
</target>
<!-- ========== Test executions & Generating reports using Testng XSLT utility for multiple suites ============== -->
<!-- run -->
<target name="runAsTestngXslt" depends="compile">
<!--suite 1 begin -->
<property name="suite.web.CopyRegressionCustomer" value="CopyRegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="CopyRegressionCustomer" outputDir="test-output" >
<xmlfileset dir="." includes="webSuites/CopyRegressionCustomer.xml" />
</testng>
<antcall target="testngXsltReportCopy">
<param name="testngXsltDir" value="${testngXslt.report.dir}${suite.web.CopyRegressionCustomer}"/>
</antcall>
<!--suite 2 begin -->
<property name="suite.web.Copy2RegressionCustomer" value="Copy2RegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="Copy2RegressionCustomer" outputDir="test-output" >
<xmlfileset dir="." includes="webSuites/Copy2RegressionCustomer.xml" />
</testng>
<antcall target="testngXsltReportCopy">
<param name="testngXsltDir" value="${testngXslt.report.dir}${suite.web.Copy2RegressionCustomer}"/>
</antcall>
</target>
<target name="testngXsltReportCopyAndReportParser">
<!-- Copy to TestNG report directory-->
<mkdir dir="${testngXsltDir}">
</mkdir>
<!-- to copy previous suite result to TestngXslt report folder -->
<xslt in="${ws.home}/test-output/testng-results.xml" style="src/xslt/testng-results.xsl"
out="${testngXsltDir}/index.html" classpathref="test.c" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${testngXsltDir}" />
<param name="testNgXslt.showRuntimeTotals" expression="true" />
<param name="testNgXslt.sortTestCaseLinks" expression="true" />
<param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS,CONF,BY_CLASS" />
</xslt> <!-- end of TestngXslt Report -->
</target>
<path id="test.c">
<fileset dir="${ws.jars}" includes="*.jar">
<include name="mail.jar"/>
<include name="activation-1.0.2.jar"/>
</fileset>
</path>
<!-- ========== Generating reports using Testng XSLT utility for single suite only ============== -->
<target name="report" depends="run">
<!-- TestngXslt report -->
<mkdir dir="${testngXslt.report.dir}">
</mkdir>
<!-- to copy previous suite result to TestngXslt report folder -->
<xslt in="${ws.home}/test-output/testng-results.xml" style="src/xslt/testng-results.xsl"
out="${testngXslt.report.dir}/index.html" classpathref="test.c" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${testngXslt.report.dir}" />
<param name="testNgXslt.showRuntimeTotals" expression="true" />
<param name="testNgXslt.sortTestCaseLinks" expression="true" />
<param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS,CONF,BY_CLASS" />
</xslt> <!-- end of TestngXslt Report -->
</target>
<target name="RunAndViewReport" depends="report">
<exec executable="${browser}" spawn="yes">
<arg line="'file:///${testngXslt.report.dir}/index.html'" />
</exec>
</target>
<target name="sendMail" depends="RunAndViewReport">
<zip destfile="${testngXslt.report.dir}/Report.zip" basedir="${testngXslt.report.dir}"/>
<mail mailhost="smtp.gmail.com" mailport="465" subject="Notification of TESTNG build result" ssl="false" user="automationmoolya#gmail.com" password="moolya#universe">
<from address="automationmoolya#gmail.com"/>
<to address="yagnesh#moolya.com"/>
<message>The build has finished. A details report of this build is attached</message>
<attachments>
<fileset dir="testngXslt.report.dir">
<include name="**/*.zip"/>
</fileset>
</attachments>
</mail>
</target>
<target name="install-jars" description="Install ANT optional jars">
<get dest="${ws.home}/lib/mail.jar" src="file:///${ws.home}/lib/mail.jar"/>
<fileset dir="${ws.jars}" includes="*.jar">
<include name="mail.jar"/>
<include name="activation-1.0.2.jar"/>
</fileset>
</target>
</project>
Take a closer look at your ant-script, it use to define a TestNG ant task as:
<taskdef resource="testngtasks" classpath="testng.jar"/>
But in your case, you have this definition commented:
<!--
<taskdef name="testng" classpath="/Users/mac/Downloads/selenium-2.47.1" classname="org.testng.TestNGAntTask" />
<!- use direct path for classpath if you don't prefer to use 'lib' directory: classpath="/Users/yash/Documents/Jar Files/testng-6.8.jar" ->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="./lib/testng.jar"/>
</classpath>
</taskdef>
-->
You need to uncomment it or add a new one defenition to your script.
When i am trying to gt sonar code coverage of my project through jenkins, i am getting the following error:
Could not load definitions from resource org/jacoco/ant/antlib.xml. It could not be found.
but when i am executing it through eclipse it does not show any error. code is same in both case and i have checked that in case of jenkins jacocoant.jar is included.
here is my code:
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="../monet-main/lib/dev/sonar/jacocoant.jar" />
</taskdef>
<property name="sonar.tests" value="test" />
<property name="sonar.dynamicAnalysis" value="reuseReports" />
<property name="sonar.surefire.reportsPath" value="output/site/jacoco" />
<property name="sonar.java.coveragePlugin" value="jacoco" />
<property name="sonar.jacoco.reportPath" value="output/jacoco.exec" />
<target name="test">
<mkdir dir="output/report/junit" />
<javac debug="true" includeantruntime="false" nowarn="true" debuglevel="${debuglevel}" destdir="bin"
encoding="UTF-8" source="1.6" target="1.6" srcdir="test">
<classpath refid="monet-service.classpath" />
</javac>
<jacoco:coverage destfile="${result.exec.file}">
<junit haltonfailure="yes" fork="true">
<classpath>
<path refid="monet-service.classpath" />
<pathelement path="bin" />
</classpath>
<formatter type="plain" usefile="false" />
<formatter type="xml" />
<batchtest fork="yes" todir="output/report/junit">
<fileset dir="test">
<include name="**/CommonTest.java" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
<target name="testReport" depends="test">
<!-- Step 3: Create coverage report -->
<jacoco:report>
<executiondata>
<file file="${result.exec.file}" />
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.dir}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}" />
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}" />
<csv destfile="${result.report.dir}/report.csv" />
<xml destfile="${result.report.dir}/report.xml" />
</jacoco:report>
</target>
<!-- Define the SonarQube target -->
<target name="sonar" depends="testReport">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- Update the following line, or put the "sonar-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
<classpath path="../monet-main/lib/dev/sonar/sonar-ant-task-2.2.jar" />
</taskdef>
<!-- Execute the SonarQube analysis -->
<sonar:sonar/>
</target>
Is there any problem..
I have to setup jacoco with wildfly.
i have provided java opts in standalone.bat.
i have jcoco ant tasks for coverage and report.
i am getting test code coverage always 0%.
my junits extend cactus servertest.
if i do not extend servertest(cactus) i will get code coverage as 100% else 0%.
In the sessions.html i do not find classes.
standalone.bat configuration.
http://www.eclemma.org/jacoco/trunk/doc/agent.html
jcoco ant tasks.
http://www.eclemma.org/jacoco/trunk/doc/ant.html
standalone.bat
set "JAVA_OPTS=-Dprogram.name=%PROGNAME% %JAVA_OPTS% -javaagent:{myhome.dir}/jacocoagent.jar=destfile={myhome.dir}/jacoco.exec,excludes=${jboss.home.dir}/modules/**/*,classdumpdir={myhome.dir}/dump,dumponexit=false,append=false"
ant tasks:
<target name="test">
<delete file="jacoco.exec" />
<delete dir="${project.dir}/junit" />
<mkdir dir="${project.dir}/junit/result" />
<mkdir dir="${project.dir}/junit/report" />
<jacoco:coverage>
<junit fork="true" maxmemory="512M" printsummary="true" haltonerror="false" haltonfailure="false" showoutput="yes">
<jvmarg line="${cactus.args}" />
<classpath>
<path refid="build.classpath1" />
</classpath>
<formatter type="xml" />
<batchtest todir="${project.dir}/junit/result">
<fileset dir="{JBOSS.HOME}\standalone\deployments\flexnet.ear\flexnet.war\WEB-INF\classes" includes="**/DumyTest*" excludes="${test.exclude.files}" />
</batchtest>
</junit>
</jacoco:coverage>
<junitreport tofile="TestResults.xml" todir="${project.dir}/junit/result">
<fileset dir="${project.dir}/junit/result" />
<report format="frames" todir="${project.dir}/junit/report" />
</junitreport>
</target>
<target name="test-coverage-report">
<delete dir="${project.dir}/code-coverage" />
<jacoco:report>
<executiondata>
<file file="jacoco.exec" />
</executiondata>
<structure name="Code Coverage Results">
<group name="FNO">
<classfiles>
<fileset dir="{JBOSS.HOME}\standalone\deployments\flexnet.ear\flexnet.war\WEB-INF\classes" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}" />
<fileset dir="${testsrc.dir}" />
</sourcefiles>
</group>
</structure>
<html destdir="${project.dir}/code-coverage" />
</jacoco:report>
</target>
Any insight on this issue.please
it was type error.
Just Adding *
* helped me to resolve issue.
When i looked classdump i found classes which were not required.
when i added includes only required classes were added.