<?xml version="1.0"?>
<!--
 * Copyright 2002-2004  The Apache Software Foundation
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.

-->
<project name="JS" default="all">
    <import file="clover.xml"/>
	<import file="api.xml"/>

    <property name="build.js" location="${build}/js"/>
    <property name="build.js.src" location="${build.js}/src"/>
    <property name="build.js.db" location="${build.js}/db"/>
    <property name="build.js.db.db" location="${build.js.db}/db"/>
    <property name="build.js.classes" location="${build.js}/classes"/>
    <property name="build.js.test.classes" location="${build.js}/test/classes"/>
    <property name="build.js.src" location="${build}/src"/>
    <property name="build.js.reports" location="${build.js}/reports"/>

    <property name="jdbc.driver" value="org.hsqldb.jdbcDriver"/>
    <property name="jdbc.url" value="jdbc:hsqldb:${build.js.db.db}"/>
    <property name="jdbc.user" value="sa"/>
    <property name="jdbc.password" value=""/>
    <property name="src.js" location="${basedir}/src/js"/>

    <path id="js.class.path">
      <pathelement location="${preqs}/log4j-1.2.8.jar"/>
      <pathelement location="${preqs}/ant-1.5.4.jar"/>
      <pathelement location="${preqs}/junit.jar"/>
      <pathelement location="${preqs}/antlr.jar"/>
      <pathelement location="${dist}/jaxmeapi-${version}.jar"/>
    </path>

    <path id="js.test.path">
        <path refid="js.class.path"/>
        <pathelement location="${preqs}/hsqldb-1.7.1.jar"/>
        <pathelement location="${dist}/jaxmejs-${version}.jar"/>
        <pathelement location="${build.js.test.classes}"/>
    </path>

    <target name="JS.clean">
        <delete dir="${build.js}"/>
    </target>

    <target name="dirs">
        <mkdir dir="${build.js.classes}"/>
        <mkdir dir="${build.js.src}"/>
        <mkdir dir="${build.js.test.classes}"/>
    </target>

    <target name="JS.antlr" depends="dirs">
        <java classname="antlr.Tool" failonerror="true">
            <classpath>
                <pathelement location="${preqs}/antlr.jar"/>   
            </classpath>
            <arg line="-o ${build.js.src}/org/apache/ws/jaxme/js/jparser"/>
            <arg file="${src.js}/org/apache/ws/jaxme/js/jparser/java15.g"/>
        </java>
    </target>
   
    <target name="JS.compile" depends="JS.antlr,init">
        <javac destdir="${build.js.classes}" debug="${debug}"
            source="1.3" target="1.3"
            optimize="${optimize}" classpathref="js.class.path">
            <src>
                <pathelement location="${src.js}"/>
                <pathelement location="${build.js.src}"/>
            </src>
            <exclude name="org/apache/ws/jaxme/js/junit/**/*.java"/>
            <exclude name="org/apache/ws/jaxme/logging/JavaUtilLogger*"
                unless="have14"/>
        </javac>
        <copy todir="${build.js.classes}">
            <fileset dir="${src.js}" includes="**/*.properties"/>
        </copy>
    </target>

    <target name="JS.jar" depends="JS.compile">
        <jarzip filename="jaxmejs" srcdir="${src.js}"
            classesdir="${build.js.classes}"/>
    </target>

    <target name="JS.taskdef" depends="JS.jar">
        <taskdef resource="org/apache/ws/jaxme/js/pattern/ant.properties"
            classpathref="js.test.path"/>
    </target>

    <target name="JS.generate.proxy" depends="dirs,JS.taskdef">
        <proxyGenerator targetClass="org.apache.ws.jaxme.js.junit.ObservableList"
                    extendedClass="java.util.Observable" destDir="${build.js.src}">
            <implementedInterface mandatory="true" interface="java.util.List"/>
        </proxyGenerator>
    </target>

    <target name="JS.generate.enum" depends="JS.taskdef">
        <enumGenerator targetClass="org.apache.ws.jaxme.js.junit.EnumExample"
                   destDir="${build.js.src}">
            <item name="JOE" value="John Doe"/>
            <item name="POPEYE" value="Olivia's Lover"/>
            <item name="DONALD" value="The Duck King"/>
        </enumGenerator>
    </target>

    <target name="JS.check.db">
        <uptodate property="exists.db"
           srcfile="${src.js}/org/apache/ws/jaxme/js/junit/create.sql"
        targetfile="${build.js.db.db}.properties"/>
    </target>

    <target name="JS.generate.db" depends="JS.check.db" unless="exists.db">
    	<delete dir="${build.js.db}"/>
        <mkdir dir="${build.js.db}"/>
        <sql
            src="${src.js}/org/apache/ws/jaxme/js/junit/create.sql"
            driver="${jdbc.driver}"
            url="${jdbc.url}"
            userid="${jdbc.user}"
            password="${jdbc.password}" 
            classpathref="js.test.path"
            autocommit="true"/>
    </target>

    <target name="JS.generate.version" depends="JS.generate.db">
        <versionGenerator
                   driver="${jdbc.driver}"
                      url="${jdbc.url}"
                     user="${jdbc.user}"
                 password="${jdbc.password}"
                   tables="MAIN SUB SUBSUB"
                verColumn="VER"
              targetClass="org.apache.ws.jaxme.js.junit.MAINCloner"
        generatingLogging="true"
                  destDir="${build.js.src}"/>
    </target>

    <target name="JS.generate.xmlrpc" depends="JS.taskdef">
        <xmlRpcGenerator
                targetPackage="org.apache.ws.jaxme.js.junit.xmlrpcclient"
                      destDir="${build.js.src}">
            <dispatcher name="org.apache.ws.jaxme.js.junit.xmlrpcclient.Dispatcher"
                implementingXmlRpcHandler="false"/>
            <serverClasses dir="${src.js}" includes="**/XmlRpcClientTestRemoteClass.java"/>
        </xmlRpcGenerator>   
    </target>

    <target name="JS.generate.compile"
           depends="dirs,JS.generate.proxy,JS.generate.enum,JS.generate.version,JS.generate.xmlrpc">
        <javac destdir="${build.js.test.classes}"
            debug="${debug}" optimize="${optimize}"
            includes="org/apache/ws/jaxme/js/junit/**/*"
            source="1.3" target="1.3"
            classpathref="js.test.path">
          <src path="${src.js}"/>
          <src path="${build.js.src}"/>
        </javac>
    </target>

    <target name="JS.generate" depends="API.all,JS.generate.compile"/>

    <target name="all" depends="JS.generate"/>

    <target name="test" depends="JS.generate">
        <runtests reportsdir="${build.js.reports}" classpathref="js.test.path">
            <tests>
                <fileset dir="${src.js}">
                    <include name="org/apache/ws/jaxme/js/junit/**/*Test.java"/>
                    <include name="org/apache/ws/jaxme/sqls/junit/**/*Test.java"/>
                </fileset>
            </tests>
            <properties>
                <sysproperty key="jdbc.driver" value="${jdbc.driver}"/>
                <sysproperty key="jdbc.url" value="${jdbc.url}"/>
                <sysproperty key="jdbc.user" value="${jdbc.user}"/>
                <sysproperty key="jdbc.password" value="${jdbc.password}"/>
            	<sysproperty key="js.src" value="${src.js}"/>
            </properties>
        </runtests>
    </target>

    <target name="JS.antlr.test" depends="JS.jar">
        <java classname="org.apache.ws.jaxme.js.util.JavaParser">
            <classpath>
                <pathelement location="dist/jaxmejs-${version}.jar"/>
                <pathelement location="${preqs}/antlr.jar"/>   
            </classpath>
            <arg file="src/js/org/apache/ws/jaxme/sqls/impl/SQLGeneratorImpl.java"/>   
        </java>
    </target>
</project>
