Im new to ANT:
Im trying to debug an ANT script which is concatenating followed by editing the same file recursively. when I try to run this, 5 out of 10 builds failed with the following error
java.io.FileNotFoundException:{PATH TO FILE}\file.xml (Access is denied)
I tried adding delay before and after each step.still, no luck
Any help here would be appreciated.
<target name="concatxml">
<sleep seconds="1" />
<echo message="Concatenating file..." />
<concat destfile="${location}/file.xml">
<filelist dir="." files="${loc1}/file1.xml,${loc2}/file2.xml" />
</concat>
<echo message="Concatenating completed" />
<sleep seconds="1" />
<echo message="doImportReq.xml is released for concatenating..." />
</target>
<target name="replacevalxml">
<sleep seconds="1" />
<echo message="Replace initiated" />
<replace file="${location}/file.xml" token="#DOMAIN#" value="${dev}" />
<echo message="...replace completed />
<sleep seconds="1" />
</target>
I noticed this:
files="${loc1}/file1.xml,{loc2}/file2.xml"
That should be ${loc2} and not {loc2}. I don't know if that's a problem or not...
Related
I am using the following code with the idea of finding a file in a directory that is also part of a list in a file:
<loadfile property="ReportFileContent" srcFile="${ReportFile}"/>
<for param="file">
<path>
<fileset dir="${MainDir}" includes="**/**"/>
</path>
<sequential>
<basename file="#{file}" property="#{file}" />
<condition property="found-file${index2}">
<matches pattern="#{file}" string="${ReportFileContent}"/>
</condition>
<if>
<isset property="found-file${index2}"/>
<then>
<echo message=" Found file #{file}" level="warning" />
</then>
<else>
<echo message="Not Found file #{file}" level="warning" />
</else>
</if>
<math result="index2" operand1="${index2}" operation="+" operand2="1" datatype="int" />
</sequential>
</for>
The command is not working though as it is not finding the file that is available in ${ReportFileContent}.
The content of the ReportFileContent property is the following:
c:\___tools\test\file1.txt;2
c:\___tools\test\file2.txt;2
c:\___tools\test\file3.txt;2
Any idea why the condition is not working correctly?
Thanks
Tony
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.
I want create an ant build that creates a reference tag to a given project, but I'm getting an error:
Cannot find javahl, svnkit nor command line svn client
My build.xml:
<property name="tag.name" value="...." />
<path id="path.svnant">
<pathelement location="${basedir}/svnant.jar" />
<pathelement location="${basedir}/svnClientAdapter.jar" />
</path>
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="..." />
<path id="svnant.classpath">
<fileset dir="${svnant.lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="svntag" description="tags individual project using svnant task">
<property name="svn.tag.message" value="Tagging Project ${project.name} with tag name ${tag.name} from trunk " />
<property name="src.url" value="${svn.base.url}/${project.name}/trunk/" />
<property name="dest.url" value="${svn.base.url}/${project.name}/tags/${tag.name}" />
<echo message="${svn.project.base.path}" />
<echo message="${svn.tag.message}" />
<echo message="${src.url}" />
<echo message="${dest.url}" />
<svnSetting javahl="false" svnkit="true" username="...." password="...." id="svn.settings" />
<svn>
<copy srcUrl="${src.url}" destUrl="${dest.url}" message="${svn.tag.message}" />
</svn>
</target>
See another question for details Cannot find javahl, svnkit nor command line svn client
I recommend you to use SVNKit (http://svnkit.com/kb/user-guide-svnant.html) because it's pure java SVN implementation so can be run on platforms where java exists.
I am trying to write a ant script to automate the update process of our web application.
When some files is going to be updated, I need to backup that file. my question is how to copy that file to backup directory and also create the directory structure relative to the root directory of my web application?
for example:
${WEB_APP_ROOT}/dir1/file1
${WEB_APP_ROOT}/dir2/subdir1/file2
copied to backup folder should be:
${BACK_UP_DIR}/dir1/file1
${BACK_UP_DIR}/dir2/subdir1/file2
currently, I can only copy all files to backup folder, but if two file with same name but located in different folder will cause problem.
my ant code:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- 对公信贷自动更新Ant任务脚本 created by ggfan#bgzchina.com at 2013.11.14 -->
<project default="patch" basedir=".">
<!-- 引入Weblogic安装目录下的antcontrib包,才能使用if,foreach,propertyregex-->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="/home/weblogic/Oracle/Middleware/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar" />
</classpath>
</taskdef>
<!-- 发布目标路径 -->
<property name="target_dir" value="/home/weblogic/amarsoft/ccms/war/CCMS" />
<!-- 数据库连接配置属性 -->
<property name="db_driver" value="oracle.jdbc.OracleDriver" />
<property name="db_url" value="jdbc:oracle:thin:#10.53.1.116:1521:credit" />
<property name="db_user" value="als_sit" />
<property name="db_pswd" value="als_sit" />
<!-- WLST配置 -->
<property name="wl_target_server" value="AdminServer" />
<property name="wl_admin_url" value="t3://10.53.1.117:7001" />
<property name="wl_user" value="weblogic" />
<property name="wl_pswd" value="weblogic123" />
<property name="wl_app_name" value="CCMS" />
<target name="patch">
<!-- 检查是否存在WEB-INF目录,如果有则说明更新了配置文件或者JAVA类需要重新加载应用 -->
<available file="${patch_dir}/WebRoot/WEB-INF" type="dir" property="WEB-INF.present"/>
<!-- 检查是否存在数据库更新脚本 -->
<available file="${patch_dir}/update.sql" type="file" property="sql.present"/>
<!-- 创建备份目录 -->
<mkdir dir="${patch_dir}/backup" />
<!-- 针对单个文件,检查是否更新还是新增,如果是更新则要先备份 -->
<foreach target="move-to-backup" param="theFile">
<path>
<fileset dir="${patch_dir}/WebRoot" />
</path>
</foreach>
<!-- 提醒用户检查更新列表预览 -->
<input message="Is patching preview above correct?" validargs="y,n" addproperty="patch.continue" />
<!-- 用户确认无误则更新 -->
<if>
<equals arg1="${patch.continue}" arg2="y" />
<then>
<!-- 存在WEB-INF目录,则先停止应用 -->
<if>
<equals arg1="${WEB-INF.present}" arg2="true" />
<then>
<echo message="Directory [WEB-INF] found in patching dir, application will be stoped" />
<wldeploy action="stop" graceful="true" name="${wl_app_name}" user="${wl_user}" password="${wl_pswd}"
verbose="true" adminurl="${wl_admin_url}" targets="${wl_target_server}" />
</then>
</if>
<copy todir="${target_dir}" verbose="true">
<fileset dir="${patch_dir}/WebRoot/" />
</copy>
<!-- 存在数据库更新脚本则执行 -->
<if>
<equals arg1="${sql.present}" arg2="true" />
<then>
<sql driver="${db_driver}" url="${db_url}" userid="${db_user}" password="${db_pswd}">
<classpath>
<pathelement location="/home/weblogic/Oracle/Middleware/wlserver_10.3/server/lib/ojdbc6.jar" />
</classpath>
<transaction src="${patch_dir}/update.sql"/>
</sql>
</then>
</if>
<!-- 更新完成后,重启应用 -->
<if>
<equals arg1="${WEB-INF.present}" arg2="true" />
<then>
<echo message="Application will be started again." />
<wldeploy action="start" name="${wl_app_name}" user="${wl_user}" password="${wl_pswd}"
verbose="true" adminurl="${wl_admin_url}" targets="${wl_target_server}" />
</then>
</if>
<echo message="Patching done! " />
</then>
</if>
</target>
<target name="move-to-backup">
<propertyregex property="target.file" input="${theFile}" regexp=".+/${patch_dir}/WebRoot/(.+)" replace="${target_dir}/\1" casesensitive="true" />
<available file="${target.file}" type="file" property="target.file.exist" />
<if>
<equals arg1="${target.file.exist}" arg2="true" />
<then>
<echo message="[UPDATE] ${target.file}" />
<copy todir="${patch_dir}/backup" verbose="false">
<fileset file="${target.file}" />
</copy>
</then>
<else>
<echo message="[ADD ] ${target.file}" />
</else>
</if>
</target>
</project>
In your target move-to-backup you have this copy task:
<copy todir="${patch_dir}/backup" verbose="false">
<fileset file="${target.file}" />
</copy>
When you define a fileset as a single file, it uses the directory containing the file as the base directory for the fileset, and the path to the file is relative to that: simply the name of the file.
You can do something like this instead, so that the path to the file to be copied is relative to the root of your application:
<copy todir="${patch_dir}/backup" verbose="false">
<fileset dir="${WEB_APP_ROOT}">
<include name="${target.file}" />
</fileset>
</copy>
If your file was
${WEB_APP_ROOT}/x/y/z/file.txt
It would then be copied to
${patch_dir}/backup/x/y/z/file.txt
How do I setup an Ant task to generate Emma code coverage reports?
To answer questions about where the source and instrumented directories are (these can be switched to whatever your standard directory structure is):
<property file="build.properties" />
<property name="source" location="src/main/java" />
<property name="test.source" location="src/test/java" />
<property name="target.dir" location="target" />
<property name="target" location="${target.dir}/classes" />
<property name="test.target" location="${target.dir}/test-classes" />
<property name="instr.target" location="${target.dir}/instr-classes" />
Classpaths:
<path id="compile.classpath">
<fileset dir="lib/main">
<include name="*.jar" />
</fileset>
</path>
<path id="test.compile.classpath">
<path refid="compile.classpath" />
<pathelement location="lib/test/junit-4.6.jar" />
<pathelement location="${target}" />
</path>
<path id="junit.classpath">
<path refid="test.compile.classpath" />
<pathelement location="${test.target}" />
</path>
First you need to setup where Ant can find the Emma libraries:
<path id="emma.lib" >
<pathelement location="${emma.dir}/emma.jar" />
<pathelement location="${emma.dir}/emma_ant.jar" />
</path>
Then import the task:
<taskdef resource="emma_ant.properties" classpathref="emma.lib" />
Then instrument the code:
<target name="coverage.instrumentation">
<mkdir dir="${instr.target}"/>
<mkdir dir="${coverage}"/>
<emma>
<instr instrpath="${target}" destdir="${instr.target}" metadatafile="${coverage}/metadata.emma" mode="copy">
<filter excludes="*Test*"/>
</instr>
</emma>
<!-- Update the that will run the instrumented code -->
<path id="test.classpath">
<pathelement location="${instr.target}"/>
<path refid="junit.classpath"/>
<pathelement location="${emma.dir}/emma.jar"/>
</path>
</target>
Then run a target with the proper VM arguments like:
<jvmarg value="-Demma.coverage.out.file=${coverage}/coverage.emma" />
<jvmarg value="-Demma.coverage.out.merge=true" />
Finally generate your report:
<target name="coverage.report" depends="coverage.instrumentation">
<emma>
<report sourcepath="${source}" depth="method">
<fileset dir="${coverage}" >
<include name="*.emma" />
</fileset>
<html outfile="${coverage}/coverage.html" />
</report>
</emma>
</target>
The User Guide has a good example of how to set up your build script so that you not only seperate the instrumented code from the execution, but it's also all contained in the same <target> so that you don't have to run a series of different targets, but instead you can just do something like ant emma tests (if ant tests was how you normally ran your unit tests, for example).
Here's their example:
<target name="emma" description="turns on EMMA instrumentation/reporting" >
<property name="emma.enabled" value="true" />
<!-- EMMA instr class output directory: -->
<property name="out.instr.dir" value="${basedir}/outinstr" />
<mkdir dir="${out.instr.dir}" />
</target>
<target name="run" depends="init, compile" description="runs the examples" >
<emma enabled="${emma.enabled}" >
<instr instrpathref="run.classpath"
destdir="${out.instr.dir}"
metadatafile="${coverage.dir}/metadata.emma"
merge="true"
/>
</emma>
<!-- note from matt b: you could just as easily have a <junit> task here! -->
<java classname="Main" fork="true" >
<classpath>
<pathelement location="${out.instr.dir}" />
<path refid="run.classpath" />
<path refid="emma.lib" />
</classpath>
<jvmarg value="-Demma.coverage.out.file=${coverage.dir}/coverage.emma" />
<jvmarg value="-Demma.coverage.out.merge=true" />
</java>
<emma enabled="${emma.enabled}" >
<report sourcepath="${src.dir}" >
<fileset dir="${coverage.dir}" >
<include name="*.emma" />
</fileset>
<txt outfile="${coverage.dir}/coverage.txt" />
<html outfile="${coverage.dir}/coverage.html" />
</report>
</emma>
</target>
Emma 2.1 introduces another way of obtaining runtime coverage information (.ec file). One can remotely request the data from the given port of the computer where an instrumented application is runnig. So there's no need to stop VM.
To get the file with runtime coverage data you need to insert the following snippet in your Ant script between running of your tests and generating coverage report:
<emma>
<ctl connect="${emma.rt.host}:${emma.rt.port}" >
<command name="coverage.get" args="${emma.ec.file}" />
<command name="coverage.reset" />
</ctl>
</emma>
Other steps are similar to Emma 2.0. They are perfectly described in previous post
More information on Emma 2.1 features: http://sourceforge.net/project/shownotes.php?group_id=108932&release_id=336859