<!--
 * 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="PM" default="all">
    <import file="jm.xml"/>

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

    <property name="jdbc.pm.driver" value="org.hsqldb.jdbcDriver"/>
    <property name="jdbc.pm.url" value="jdbc:hsqldb:${build.pm.db}/db"/>
    <property name="jdbc.pm.user" value="sa"/>
    <property name="jdbc.pm.password" value=""/>
   
    <path id="pm.class.path">
        <pathelement location="${preqs}/junit.jar"/>
        <pathelement location="${dist}/jaxmeapi-${version}.jar"/>
        <pathelement location="${dist}/jaxmejs-${version}.jar"/>
        <pathelement location="${dist}/jaxmexs-${version}.jar"/>
        <pathelement location="${dist}/jaxme2-${version}.jar"/>
        <pathelement location="${preqs}/beaver.jar"/>   
        <pathelement location="${preqs}/hsqldb-1.7.1.jar"/>
        <pathelement location="${preqs}/ant.jar"/>
        <pathelement location="${preqs}/xml-apis-1.3.02.jar"/>
        <pathelement location="${preqs}/xercesImpl.jar"/>
        <pathelement location="${preqs}/xmldb-api-20021118.jar"/>
        <!-- These aren't in the CVS and aren't necessary for the build -->
        <pathelement location="${preqs}/TaminoAPI4J.jar"/>
        <pathelement location="${preqs}/TaminoJCA.jar"/>
    </path>

    <path id="pm.runtime.path">
        <path refid="pm.class.path"/>
        <pathelement location="${dist}/jaxmepm-${version}.jar"/>
    </path>

	<available classname="com.softwareag.tamino.db.api.objectModel.sax.TSAXDocument"
		        property="have.inoapi4j"
		    classpathref="pm.class.path"/>

    <target name="clean">
        <delete dir="${build.pm}"/>
        <delete dir="${dist}" includes="jaxmepm*"/>
    </target>

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

    <target name="PM.compile" depends="dirs,JM.all">
        <javac classpathref="pm.class.path" debug="${debug}"
            optimize="${optimize}" destdir="${build.pm.classes}"
            source="1.3" target="1.3"
            srcdir="${src.pm}">
            <exclude name="org/apache/ws/jaxme/pm/junit/**/*"/>
            <exclude name="org/apache/ws/jaxme/**/api4j/*" unless="have.inoapi4j"/>
            <exclude name="org/apache/ws/jaxme/pm/ino/URLEncoder14.java" unless="have14"/>   
        </javac>
        <jarzip filename="jaxmepm" srcdir="${src.pm}" classesdir="${build.pm.classes}"/>
    </target>

    <target name="PM.check.db">
        <uptodate property="PM.uptodate.db" srcfile="src/test/pm/initdb.sql" targetfile="${build.pm.db}/db.properties"/>
    </target>

    <target name="PM.init.db" depends="PM.check.db" unless="PM.uptodate.db">
    	<delete dir="${build.pm.db}"/>
        <mkdir dir="${build.pm.db}"/>
    	<sql classpathref="pm.runtime.path" driver="${jdbc.pm.driver}"
	        password="${jdbc.pm.password}" src="src/test/pm/initdb.sql"
	       url="${jdbc.pm.url}" userid="${jdbc.pm.user}"/>
    </target>

    <target name="all" depends="PM.compile"/>

    <target name="PM.taskdef" depends="JM.all">
        <taskdef classname="org.apache.ws.jaxme.generator.XJCTask" classpathref="pm.runtime.path" name="xjc"/>
    </target>

    <target name="PM.generate" depends="PM.compile,PM.taskdef,PM.init.db">
        <xjc target="${build.pm.test.src}">
            <schema dir="src/test/pm" includes="*.xsd"/>
            <sgFactoryChain className="org.apache.ws.jaxme.pm.generator.jdbc.JaxMeJdbcSG"/>
            <schemaReader className="org.apache.ws.jaxme.generator.sg.impl.JaxMeSchemaReader"/>
            <produces dir="${build.pm.test.src}" includes="org/apache/ws/jaxme/test/pm/session/*"/>
            <property name="jdbc.driver" value="${jdbc.pm.driver}"/>
            <property name="jdbc.url" value="${jdbc.pm.url}"/>
            <property name="jdbc.user" value="${jdbc.pm.user}"/>
            <property name="jdbc.password" value="${jdbc.pm.password}"/>
        </xjc>
    </target>

    <target name="PM.generate.compile" depends="PM.generate">
        <javac debug="${debug}"
            source="1.3" target="1.3"
            optimize="${optimize}" destdir="${build.pm.test.classes}">
            <classpath>
                <path refid="pm.class.path"/>
                <pathelement location="${dist}/jaxmepm-${version}.jar"/>
            </classpath>
            <src path="${build.pm.test.src}"/>
            <src path="${src.pm}"/>
            <include name="org/apache/ws/jaxme/test/pm/**/*"/>
            <include name="org/apache/ws/jaxme/pm/junit/**/*"/>
            <exclude name="org/apache/ws/jaxme/pm/ino/URLEncoder14.java" unless="have14"/>   
        </javac>
        <copy todir="${build.pm.test.classes}">
            <fileset dir="${build.pm.test.src}" includes="**/*.xml,**/*.properties"/>
        </copy>
    </target>

    <target name="test" depends="JM.test,PM.generate.compile">
        <path id="pm.junit.path">
            <path refid="pm.class.path"/>
            <pathelement location="${dist}/jaxmepm-${version}.jar"/>
            <pathelement location="${build.pm.test.classes}"/>
        </path>
        <runtests reportsdir="${build.pm.reports}" classpathref="pm.junit.path">
            <tests>
                <fileset dir="${src.pm}" includes="org/apache/ws/jaxme/pm/junit/**/*Test.java"/>
            </tests>
        </runtests>
    </target>
</project>
