<project name="XQTS" basedir="." default="store">
    <!-- $Id: build.xml 4552 2006-10-11 21:28:03Z wolfgang_m $ -->

    <!-- import default properties from file -->
    <xmlproperty file="config.xml"/>

    <property name="server.dir" value="../.."/>

    <path id="classpath.core">
        <fileset dir="${server.dir}/lib/core">
            <include name="*.jar"/>
        </fileset>
        <pathelement path="${server.dir}/exist.jar"/>
        <pathelement path="${server.dir}/exist-optional.jar"/>
    </path>
    
    <typedef resource="org/exist/ant/antlib.xml" uri="http://exist-db.org/ant">
        <classpath refid="classpath.core"/>
    </typedef>

    <available file="${config.basedir}" property="xqts.present"/>
    <available file="${server.dir}/src/org/exist/numbering/NodeId.java" property="exist.dln"/>

    <target name="store" xmlns:xmldb="http://exist-db.org/ant" if="xqts.present"  depends="check-files">
        <echo message="XQuery Test Suite (XQTS) Setup"/>
        <echo message="---------------------------------"/>
        <echo message="Loading XQTS sources from directory: ${config.basedir}"/>
        
        <xmldb:store uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/system/config/db"
    		user="admin" password=""
    		createcollection="true">
            <fileset dir=".">
                <include name="xqts.xconf"/>
            </fileset>
        </xmldb:store>
    	
        <xmldb:store uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/XQTS" createcollection="true">
            <fileset dir=".">
                <include name="config.xml"/>
                <include name="stylesheets/*.xsl"/>
            </fileset>
        </xmldb:store>

        <!-- xmldb:store uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/XQTS/ReportingResults" createcollection="true">
            <fileset dir=".">
                <include name="collectresults.xql"/>
            </fileset>
        </xmldb:store-->
        
        <xmldb:store uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/XQTS/ReportingResults" createcollection="true">
            <fileset dir="${config.basedir}/ReportingResults">
                <include name="XQTSResult.xsd"/>
                <include name="XQTSResults.xsl"/>
                <include name="Results.xml"/>
            </fileset>
        </xmldb:store>
        
        <xmldb:store uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/XQTS" createcollection="true">
            <fileset dir="${config.basedir}">
                <include name="XQTSCatalog.xml"/>
            </fileset>
        </xmldb:store>

        <xmldb:store uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/XQTS/TestSources" createcollection="true">
            <fileset dir="${config.basedir}/TestSources">
                <include name="*"/>
                <!-- This list should be not very long -->
                <exclude name="fsx.xml"/> <!-- Irregular file --> 
                <exclude name="orders"/>  <!-- No Mime type   -->
                <exclude name="strong-queries-results-q2.xsd"/> <!-- syntax eror -->
                <exclude name="strong-queries-results-q3.xsd"/> <!-- syntax eror -->
            </fileset>
        </xmldb:store>
        
        <echo>The files strong-queries-results-q2.xsd and strong-queries-results-q3.xsd in ${config.basedir}/TestSources cannot be uploaded because they have content in prolog. Please remove first line.</echo>
        <xmldb:store uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/XQTS/TestSources" createcollection="true">
            <fileset dir="${config.basedir}/TestSources">
                <include name="strong-queries-results-q2.xsd"/> 
                <include name="strong-queries-results-q3.xsd"/> 
            </fileset>
        </xmldb:store>
        
        <xmldb:store uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/XQTS/TestSources" createcollection="true" type="xml">
            <fileset dir="${config.basedir}/TestSources">
                <include name="orders"/>
            </fileset>
        </xmldb:store>
        
        <antcall target="dln-add"/>
    </target>

    <target name="dln-add" if="exist.dln" xmlns:xmldb="http://exist-db.org/ant">
      <xmldb:store uri="xmldb:exist://localhost:8080/exist/xmlrpc/db/XQTS/TestSources" createcollection="true">
        <fileset dir="${config.basedir}/TestSources">
          <include name="fsx.xml"/>
        </fileset>
      </xmldb:store>
    </target>
    
    
    <target name="check-files" unless="xqts.present">
        <echo message="The XQTS sources could not be found in directory {$config.basedir}. Please edit"/>
        <echo message="webapp/xqts/config.xml and check the path specified via the"/>
        <echo message="&lt;basedir&gt; element."/>
    </target>
</project>
