I have a ANT build.xml file which goes like this-
<?xml version="1.0"?>
<project name="apache-jena-2.10.0" basedir="." default="notifyme">
<target name="notifyme">
<java classname-"arq.sparql" fork="true">
<arg value="--data=C:\apache-jena-2.10.0\test.ttl"/>
<arg value="--query=C:\apache-jena-2.10.0\ASKTest.rq"/>
<jvmarg value="-Xmx1024M"/>
<classpath>
<path>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
</classpath>
</java>
</target>
</project>
This build.xml basically run a query and return a specefic result.
The result comes like this-
notifyme:
[java] Ask =>No
BUILD SUCCESSFUL
Total time : 1second
Now my question is there any way I can make the build fail if Ask => No, if yes can any one please help me to customise the ANT build file.
Kind regards
Som
Use the resultproperty attribute for java task. It will store standard out in the given property. Then us the fail task, with conditions task:
<?xml version="1.0"?>
<project name="apache-jena-2.10.0" basedir="." default="notifyme">
<target name="notifyme">
<java classname-"arq.sparql" fork="true" failonerror="false" outputproperty="javaresult">
<arg value="--data=C:\apache-jena-2.10.0\test.ttl"/>
<arg value="--query=C:\apache-jena-2.10.0\ASKTest.rq"/>
<jvmarg value="-Xmx1024M"/>
<classpath>
<path>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
</classpath>
</java>
<fail>
<condition>
<matches string="${javaresult} pattern="No"/>
</condition>
</fail>
</target>
</project>
Did not test it. But you can get the idea.
Related
I have 3 files (eg: m1.txt, m2.txt and m3.txt) in my /tmp/ folder. How can I zip each files as m1.zip, m2.zip and m3.zip?
I used the following coding, but didn't work:
<target name="xzipit">
<foreach target="zipone" param="Files">
<path>
<fileset dir="/tmp/" excludes="*.zip"
includes="*.txt" casesensitive="no" />
</path>
</foreach>
</target>
<target name="zipone">
<zip destfile="${Files}" basedir="/tmp/">
</zip>
</target>
Note use of fileset id, refid usage below and also on specifying includesfile to zip ant task
<fileset dir="/tmp" excludes="*.zip" includes="*.txt" id="zip.fileset.id" casesensitive="no" />
<pathconvert property="zipFileSetProp" refid="zip.fileset.id">
<mapper>
<flattenmapper/>
</mapper>
</pathconvert>
<for list="${zipFileSetProp}" param="fileToZip" delimiter=";">
<sequential>
<echo>fileToZip #{fileToZip}</echo>
<zip destfile="/tmp/#{fileToZip}.zip" basedir="/tmp/" includesfile="/tmp/#{fileToZip}"/>
</sequential>
</for>
I got one more answer to solve this.
<project name="texzip" basedir="." default="zipit">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="/tmp/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<target name="zipit">
<foreach target="zipone" param="Files">
<path>
<fileset dir="/tmp/" excludes="*.zip" includes="*.txt" casesensitive="no" />
</path>
</foreach>
</target>
<target name="zipone">
<basename property="basename" file="${Files}" suffix="txt"/>
<zip destfile="${basename}.zip">
<zipfileset dir="." includes="${basename}.txt"/>
</zip>
</target>
</project>
I have ANT build file having these two tasks-
<target name="ldm-validation">
<property name="graphFile" value="${tools.dir}/build-config/SPARQL/*.ttl"/>
<record name="${tools.dir}/build-config/SPARQL/BuildLog.txt" action="start"/>
<foreach target="jena-sparql-validation" param="queryFile">
<path>
<fileset dir="${tools.dir}/build-config/SPARQL/Queries">
<include name="*.rq"/>
</fileset>
</path>
</foreach>
<record name="${tools.dir}/build-config/SPARQL/BuildLog.txt" action="stop"/>
</target>
<target name="jena-sparql-validation">
<java classname="arq.sparql" fork="true" outputproperty="javaresult" errorproperty="javaerror1">
<arg value="--data=${graphFile}"/>
<arg value="--query=${queryFile}"/>
<jvmarg value="-Xmx1024M"/>
<classpath>
<path>
<fileset dir="${jena.dir}/lib">
<include name="*.jar"/>
</fileset>
</path>
</classpath>
</java>
<fail message="Error at: ${javaerror1} in ${queryFile}">
<condition>
<not>
<equals arg1="${javaerror1}" arg2=""/>
</not>
</condition>
</fail>
<echo message="Result for ${queryFile} is: ${javaresult}"/>
</target>
But when I am running this it is always failing saying that -
C:\CI-POC\tools\build-config\validate.all.xml:41: Error at: Failed to load data
It is unable to get the Data file using the Property name 'graphFile'. I am not sure what is going wrong. Can any one help.
Try calling the build as follows:
ant ldm-validation jena-sparql-validation
so that the values of the properties graphFile and queryFile are set.
Another option is to create a dependency between the two targets.
<target name="jena-sparql-validation" depends="ldm-validation">
Selenium - ANT -TestNG
I have written a build.xml, where it produces a error stating " classname attribute of taskdef element is undefined "
Here is my build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name ="AutomationScripts" default="test" basedir=".">
<echo message ="Testing selenium server... Plz wait"/>
<target name="startServer">
<echo message ="Start selenium server... Plz wait"/>
<java jar="..\lib\selenium-server-standalone-2.19.0.jar" fork="true">
<jvmarg value="-Dhttp.proxyHost=192.168.0.200"/>
<jvmarg value="-Dhttp.proxyPort=3128"/> </java>
<echo message ="Started selenium server"/>
</target>
<target name="test" depends="startServer">
<echo message="Test run. Please wait"/>
<mkdir dir="out" />
<java classname="RosettastoneMain" classpath="..\AutomationScripts\bin"
dir="C:\Program Files\Java\jdk1.6.0_11\bin">
<classpath>
<fileset dir="..\AutomationScripts\lib" includes="*.*"/>
</classpatha></java>
<taskdef name="testng" classpath="org.testng.TestNG"> ---------> It produces
error in this stmt
<classpath>
<pathelement location="../lib/testng-6.2.jar"/>
</classpath>
</taskdef>
<property name="testng.output.dir" value="testngOutput"/>
<path id="classes">
<fileset dir="../lib">
<include name="*.jar"/>
</fileset>
<pathelement location="${bin.dir}"/>
</path>
<mkdir dir="${testng.output.dir}"/>
<testng outputdir="${testng.output.dir}" classpathref="classes">
<xmlfileset dir="." includes="testng.xml"/>
</testng> </target>
<target name="stopServer">
<echo message="stop selenium server. Plz wait"/>
<get taskname="selenium-shutdown"
src="http://localhost:4444/selenium-server-standalone-2.0rc2/driver/?cmd=shutDown"
dest="./out/sever.stop.status.txt" ignoreerrors="true"/>
</target>
</project>
Can any one help me out
thanks in advance
You need to specify the class implementing the data type in the 'classname' attribute.
According to the Ant taskdef documentation (and more specifically typedef), this task has two required attributes - 'name' and 'classname', unless 'file' or 'resource' have been specified. The attribute 'classpath' only defines the locations where the class specified in 'classname' can be found.
When debugging it's quite common for me to use things such as Zend_Debug and die() in the PHP to locate an issue. Occasionally I forget to take these out before committing my code. So I was wondering...
How do I write an ant build.xml target which checks all the files in my application for specific strings and fails if they have been found?
Basically, I'm after a reverse grep command which fails when it finds a string.
Any ideas?
Also, given my build.xml file looks like this (I've removed most of my targets to make it short), how do I make it work?
I don't know how ant works, so I'm after a 'drop-in' solution or good instructions.
<?xml version="1.0" encoding="UTF-8"?>
<project name="API" default="build" basedir=".">
<property name="source" value="application"/>
<target name="build" depends="prepare,lint,phpcpd,phpdox,phpunit,phpcb"/>
<target name="clean" description="Cleanup build artifacts">
<delete dir="${basedir}/build/api"/>
</target>
<target name="lint">
<apply executable="php" failonerror="true">
<arg value="-l" />
<fileset dir="${basedir}/${source}">
<include name="**/*.php" />
</fileset>
<fileset dir="${basedir}/tests">
<include name="**/*.php" />
</fileset>
</apply>
</target>
</project>
Within the lint target (after the apply element) add
<fileset id="die-files" dir="${basedir}/${source}">
<include name="**/*.php" />
<contains text="die()"/>
</fileset>
<fail message="The following files contain "die()": ${ant.refid:die-files}">
<condition>
<resourcecount when="greater" count="0" refid="die-files"/>
</condition>
</fail>
If you can use ant-contrib than:
<for param="file">
<path>
<fileset dir="/path/to/application/"/>
</path>
<sequential>
<if>
<contains string="#{file}" substring="bad elements"/>
<then>
<fail>warning! substring is present in directory</fail>
</then>
</if>
</sequential>
</for>
I want to be able to have different targets doing nearly the same thing, as so:
ant build <- this would be a normal (default) build
ant safari <- building the safari target.
The targets look like this:
<target name="build" depends="javac" description="GWT compile to JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="${lhs.target}"/>
</java>
</target>
<target name="safari" depends="javac" description="GWT compile to Safari/JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="${lhs.safari.target}"/>
</java>
</target>
(Nevermind the first thought that strikes: throw out ant! That's not an option just yet.) I tried using macrodef, but got a strange error message (even though the message didn't imply it, it think it had to do with putting a target in sequential). I don't want write a cmdline as so: ant -Dwhatever=nevermind. Any ideas?
My first try (without being able to test it at the moment):
<target name="build" depends="javac, create.mymacro" description="GWT compile to JavaScript">
<mymacro target="${lhs.target}"/>
</target>
<target name="safari" depends="javac, create.mymacro" description="GWT compile to Safari/JavaScript">
<mymacro target="${lhs.safari.target}"/>
</target
<target name="create.mymacro">
<macrodef name="mymacro">
<attribute name="target" default="${lhs.target}"/>
<sequential>
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg value="#{target}"/>
</java>
</sequential>
</macrodef>
</target>