Passing data file as generic file - ant

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">

Related

build.xml:43 compile failed see compiler error output for details

I am trying to compile and build the source files into a jar file using ant from the command line. (windows 7)
However I am getting the following error:
....\build.xml:43: Compile failed see the copiler error output for details
My build file is given below:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="jar.client">
<!--Auto generated ant build file-->
<property environment="env"/>
<property name="axis2.home" value="${env.AXIS2_HOME}"/>
<property name="project.base.dir" value="."/>
<property name="maven.class.path" value=""/>
<property name="name" value="addtaxihire_14cabs"/>
<property name="src" value="${project.base.dir}/src"/>
<property name="test" value="${project.base.dir}/test"/>
<property name="build" value="${project.base.dir}/build"/>
<property name="classes" value="${build}/classes"/>
<property name="lib" value="${build}/lib"/>
<property name="resources" value="${project.base.dir}/resources"/>
<property value="" name="jars.ok"/>
<path id="axis2.class.path">
<pathelement path="${java.class.path}"/>
<pathelement path="${maven.class.path}"/>
<fileset dir="${axis2.home}">
<include name="lib/*.jar"/>
</fileset>
</path>
<target name="init">
<mkdir dir="${build}"/>
<mkdir dir="${classes}"/>
<mkdir dir="${lib}"/>
</target>
<target depends="init" name="pre.compile.test">
<!--Test the classpath for the availability of necesary classes-->
<available classpathref="axis2.class.path" property="stax.available" classname="javax.xml.stream.XMLStreamReader"/>
<available classpathref="axis2.class.path" property="axis2.available" classname="org.apache.axis2.engine.AxisEngine"/>
<condition property="jars.ok">
<and>
<isset property="stax.available"/>
<isset property="axis2.available"/>
</and>
</condition>
<!--Print out the availabilities-->
<echo message="Stax Availability= ${stax.available}"/>
<echo message="Axis2 Availability= ${axis2.available}"/>
</target>
<target depends="pre.compile.test" name="compile.src" if="jars.ok">
<javac debug="on" memoryMaximumSize="256m" memoryInitialSize="256m" fork="true" destdir="${classes}" srcdir="${src}">
<classpath refid="axis2.class.path"/>
</javac>
</target>
<target depends="compile.src" name="compile.test" if="jars.ok">
<javac debug="on" memoryMaximumSize="256m" memoryInitialSize="256m" fork="true" destdir="${classes}">
<src path="${test}"/>
<classpath refid="axis2.class.path"/>
</javac>
</target>
<target depends="pre.compile.test" name="echo.classpath.problem" unless="jars.ok">
<echo message="The class path is not set right! Please make sure the following classes are in the classpath 1. XmlBeans 2. Stax 3. Axis2 "/>
</target>
<target depends="jar.server, jar.client" name="jar.all"/>
<target depends="compile.src,echo.classpath.problem" name="jar.server" if="jars.ok">
<copy toDir="${classes}/META-INF" failonerror="false">
<fileset dir="${resources}">
<include name="*.xml"/>
<include name="*.wsdl"/>
<include name="*.xsd"/>
</fileset>
</copy>
<jar destfile="${lib}/${name}.aar">
<fileset excludes="**/Test.class" dir="${classes}"/>
</jar>
</target>
<target if="jars.ok" name="jar.client" depends="compile.src">
<jar destfile="${lib}/${name}-test-client.jar">
<fileset dir="${classes}">
<exclude name="**/META-INF/*.*"/>
<exclude name="**/lib/*.*"/>
<exclude name="**/*MessageReceiver.class"/>
<exclude name="**/*Skeleton.class"/>
</fileset>
</jar>
</target>
<target if="jars.ok" depends="jar.server" name="make.repo">
<mkdir dir="${build}/repo/"/>
<mkdir dir="${build}/repo/services"/>
<copy file="${build}/lib/${name}.aar" toDir="${build}/repo/services/"/>
</target>
<target if="jars.ok" depends="make.repo" name="start.server">
<java fork="true" classname="org.apache.axis2.transport.http.SimpleHTTPServer">
<arg value="${build}/repo"/>
<classpath refid="axis2.class.path"/>
</java>
</target>
<target if="jars.ok" depends="compile.test" name="run.test">
<path id="test.class.path">
<pathelement location="${lib}/${name}-test-client.jar"/>
<path refid="axis2.class.path"/>
<pathelement location="${classes}"/>
</path>
<mkdir dir="${build}/test-reports/"/>
<junit haltonfailure="yes" printsummary="yes">
<classpath refid="test.class.path"/>
<formatter type="plain"/>
<batchtest fork="yes" toDir="${build}/test-reports/">
<fileset dir="${test}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="clean">
<delete dir="${build}"/>
</target>
</project>
and probably the 43rd-45th lines of the build file are:
<javac debug="on" memoryMaximumSize="256m" memoryInitialSize="256m" fork="true" destdir="${classes}" srcdir="${src}">
<classpath refid="axis2.class.path"/>
</javac>
Thanks in advance for any solution/suggestion.
The problem is not in the build.xml. It's in your java code. This implies the message:
Compile failed see the compiler error output for details

How can I zip each file separately instead of putting in one archive?

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>

Customised ANT task

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.

ant build.xml target to check for debug code

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>

How to macro-ify ant targets?

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>

Resources