Question

I have an ANT task which uses an RDF file - cpldm.ttl and run a query on it which is present in the file- ASK-ldm.rq. It is done using JAVA ant tasks. The code is given below-

<java classname="arq.sparql" fork="true" outputproperty="javaresult" errorproperty="javaerror1">
 <arg value="--data=${tools.dir}/build-config/SPARQL/cpldm.ttl"/>
 <arg value="--query=${tools.dir}/build-config/SPARQL/ASK-ldm.rq"/>
 <jvmarg value="-Xmx1024M"/>
 <classpath>
   <path> 
     <fileset dir="${jena.dir}/lib">
      <include name="*.jar"/>
     </fileset>
   </path>
 </classpath>
</java>

Now I want extend this by using a set of SPARQL query files (.rq) / fileset. Like 'ASK1-ldm.rq', ASK2-ldm.rq etc and for each of them I want to capture the 'outputproperty' after the query is run on the same RDF file 'cpldm.ttl'

I hope I had been able to explain the challenge proeprly, if not feel free to ask.

After using Simon's suggestion the final code is-

<target name="validation">
  <foreach target="javatask" param="queryFile">
    <fileset dir="${tools.dir}/build-config/SPARQL/Queries">
      <include name="*.rq"/>
    </fileset>
  </foreach>
</target>
<target name="javatask">
   <java classname="arq.sparql" fork="true" outputproperty="javaresult" errorproperty="javaerror1">
       <arg value="--data=${tools.dir}/build-config/SPARQL/cpldm.ttl"/>
       <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}">
       <condition>
        <not>
         <equals arg1="${javaerror1}" arg2=""/>
        </not>
      </condition>
  </fail>
      <echo message="Result for {queryFile} is: ${javaresult}"/>
</target>     

In the out put I am first getting this message-

[foreach] The nested fileset element is deprectated, use a nested path instead

Then in the out put it is showing-

javatask:
 [echo] Result for {queryFile} is: Ask => Yes

First, what does that error message mean, and I want to see the name of the 'queryFile' in the put put so that I know which file gave what result.

Any more help?

Was it helpful?

Solution

If you want to do this without coding java you can achieve the result by wrapping this java task in a macro. That macro can then be called once per file that you want to process. If you don't want to call the macro multiple times by hand you can use the foreach task from ant-contrib.

If you are not against creating your own ant task for this I'd suggest you read "Writing you own task". If you know java it is really not that hard to create Ant tasks. Your own task can be specified in such a way that it handles filesets and calls the original java class for each of them.

Update: An example for foreach can be seen here. As you can see it actually can call a task multiple times, so you don't need to create a macro in that case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top