<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!--                                                                         -->
<!-- Generate XQueryX documents for all XQuery files in the test suite       -->
<!--                                                                         -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

<!--

Please proceed with the following steps:

1) get necessary files by executing one of the following:
   a) ant getPrivateFiles
      this requires providing your username and password, as follows
         ant getPrivateFiles -Dusername=... -Dpassword=...
   b) ant getPublicFiles
2) generate the XQueryX files, identifying the XQTS test catalog
   ant -DsourceDir=...

-->



<project name="Generate XQueryX" default="genAll">
   
   <description>Generate XQueryX documents corresponding to XQuery expressions used in test cases.</description>
   
   <property
      name="sourceDir"
      value="..\..\TestSuiteStagingArea\"
      />
   
   <!-- Derived properties -->
   
   <property
      name="TestSourcesDir"
      value="${sourceDir}TestSources\"
      />
   
   <property
      name="QueryDir"
      value="${sourceDir}Queries\"
      />
   
   <property
      name="XQueryDir"
      value="${sourceDir}Queries\XQuery\"
      />
   
   <property
      name="XQueryXDir"
      value="${sourceDir}Queries\XQueryX\"
      />
   
   <!-- XQueryX schema files -->
   
   <property
      name="XQueryXSchema"
      value="http://www.w3.org/2005/XQueryX"/>
   
   <property
      name="XQueryXSchemaFile"
      value="file:temp/xqueryx.xsd"/>
   
   <property
      name="XQueryXSchemaLocation"
      value="${XQueryXSchema} ${XQueryXSchemaFile}"/>
   
   
   
   
   <target name="getPublicFiles" description="get public XQuery parser and schema files">
      <mkdir dir="temp" />
      <get
         src="http://www.w3.org/2010/02/qt-applets/xquery11/applet.jar"
         dest="temp/applet.jar" />
      <get
         src="http://www.w3.org/2005/XQueryX/xqueryx.xsd"
         dest="temp/xqueryx.xsd" />
      
      <delete file="temp/applet-ant.zip" />
   </target>   

   
   <target name="getPrivateFiles" description="get private XQuery parser and schema files">
      <mkdir dir="temp" />
      <get
         src="http://www.w3.org/XML/Group/qtspecs/specifications/grammar-11/parser/applets/xquery11/applet.jar"
         dest="temp/applet.jar"
         username="${username}"
         password="${password}" />

      <get
         src="http://www.w3.org/XML/Group/qtspecs/specifications/xqueryx-11/src/xqueryx.xsd"
         dest="temp/xqueryx.xsd"
         username="${username}"
         password="${password}" />
      
      <delete file="temp/applet-ant.zip" />
   </target>   
   
   
   <target name="checkBuild">
      <uptodate property="buildNotRequired" targetfile="temp/applet-ant.zip">
         <srcfiles dir="." includes="*.java" />
      </uptodate>
   </target>
   
   
   <target name="clean" description="Remove all generated files">
      <delete dir="temp" />
   </target>
   
   
   <target name="compile" depends="checkBuild" unless="buildNotRequired" >
      
      <fail message="Necessary XQuery files are missing.">
         <condition>
            <not>
               <resourcecount count="1">
                  <dirset dir="." includes="temp" />                  
               </resourcecount>
            </not>
         </condition>
      </fail>
      
      <javac classpath="temp/applet.jar" srcdir="." includes="*.java" destdir="temp" target="1.4"/>
   </target>
   
   
   <target name="build" depends="checkBuild, compile" unless="buildNotRequired" >
      <zip destfile="temp/applet-ant.zip">
         <fileset dir="temp" includes="**/*.class" />
         <zipfileset src="temp/applet.jar" />
      </zip>
   </target>
   
   
   <target name="declare" depends="build">
      <taskdef name="generateXQueryX" classname="org.w3.xqtools.GenXQueryXTask">
         <classpath>
            <pathelement location="temp/applet-ant.zip"/>
         </classpath>
      </taskdef>
   </target>
   
   
   
   <target name="genAll" depends="genModules, genQueries" description="Generate all XQueryX files">      
   </target>


   <target name="genQueries" depends="declare, parseErrors, XQST0087Errors, otherErrors" description="Generate the XQueryX files">      
      
      <fail message="sourceDir property must be set.">
         <condition>
            <not>
               <isset property="sourceDir" />
            </not>
         </condition>
      </fail>
      
      <!-- transform all xquery's, except those listed in parse_errors.txt and -->
      <!-- other_errors.txt                                                    -->
      
      <generateXQueryX dest="${XQueryXDir}">
         <fileset  dir="${XQueryDir}" includes="**/*.xq">
            <patternset>
               <excludesfile name="other_errors.txt" />
               <excludesfile name="temp/parse_errors.txt" />
               <excludesfile name="temp/xqst0087_errors.txt" />
               <excludesfile name="temp/other_errors.txt" />
            </patternset>
         </fileset>
         
         <mapper>
            <regexpmapper handledirsep="yes" from="^(.*)\.xq$$" to="\1.xqx" />            
         </mapper>
         
      </generateXQueryX>
      
   </target>
   

   <target name="genModules" depends="declare" description="Generate the XQueryX files for modules">      
      
      <generateXQueryX dest="${TestSourcesDir}">
         <fileset  dir="${TestSourcesDir}" includes="*.xq" />
         
         <mapper>
            <regexpmapper handledirsep="yes" from="^(.*)\.xq$$" to="\1.xqx" />            
         </mapper>
         
      </generateXQueryX>
      
   </target>
   

   <target name="deleteExistingXQueryX" description="Delete existing XQueryX files">      
      
      <fail message="sourceDir property must be set.">
         <condition>
            <not>
               <isset property="sourceDir" />
            </not>
         </condition>
      </fail>
      
      <delete>
         <fileset dir="${XQueryXDir}" includes="**/*.xqx" />
      </delete>
      
   </target>
   

   <target name='validateXQueryX' description="Validate XQueryX files">
      
      <fail message="sourceDir property must be set.">
         <condition>
            <not>
               <isset property="sourceDir" />
            </not>
         </condition>
      </fail>


      <schemavalidate fullchecking="yes">
         <fileset dir="${XQueryXDir}" includes="**/*.xqx"/>
         <schema namespace="http://www.w3.org/2005/XQueryX" file="temp/xqueryx.xsd" />
      </schemavalidate>

      <schemavalidate fullchecking="yes">
         <fileset dir="${TestSourcesDir}" includes="*.xqx"/>
         <schema namespace="http://www.w3.org/2005/XQueryX" file="temp/xqueryx.xsd" />
      </schemavalidate>
   </target>
   
      
   <target
      name="parseErrors" 
      description="Build a list of XQuery files with parse errors">
      
      <xslt
         in="${sourceDir}XQTSCatalog.xml"
         destdir="."
         basedir="."
         style="parse_errors.xsl"
         out="temp/parse_errors.txt"
         />
      
   </target>

   <target
      name="XQST0087Errors" 
      description="Build a list of XQuery files with XQST0087 errors">
      
      <xslt
         in="${sourceDir}XQTSCatalog.xml"
         destdir="."
         basedir="."
         style="xqst0087_errors.xsl"
         out="temp/xqst0087_errors.txt"
         />
      
   </target>

   <target
      name="otherErrors" 
      description="Build a list of XQuery files with other errors ... where schema validation would fail">
      
      <xslt
         in="${sourceDir}XQTSCatalog.xml"
         destdir="."
         basedir="."
         style="other_errors.xsl"
         out="temp/other_errors.txt"
         />
      
   </target>

</project>
