<?xml version="1.0"?>

<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You 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.
  
   $Header:$
-->
<project name="Beehive/SystemControls/JdbcControl" default="build" basedir=".">

    <import file="../../systemcontrols-imports.xml"/>
    <property environment="os"/>

    <!-- build locations -->
    <property name="module.name" value="jdbc-control"/>
    <property name="module.dir" location="${src.dir}/jdbc"/>
    <property name="sqlgrammar.file" value="${module.dir}/org/apache/beehive/controls/system/jdbc/parser/SqlGrammar.jj"/>
    <property name="sqlgrammar.gen.dir" value="${module.dir}/org/apache/beehive/controls/system/jdbc/parser"/>

    <!-- classpath -->
    <path id="module.classpath">
        <pathelement location="${classes.dir}/${module.name}"/>
        <path refid="controls.dependency.path"/>
        <path refid="xbean.dependency.path"/>
        <path refid="commons-logging.dependency.path"/>
        <path refid="velocity.dependency.path"/>
        <path refid="tools.dependency.path"/>
    </path>

    <!-- =================================================================== -->
    <!-- build - build the Jdbc Control                                      -->
    <!-- =================================================================== -->
    <target name="build" description="Compiles and builds the jdbc-control.">

        <echo>compile module: ${module.name}</echo>
        <property name="classpath" refid="module.classpath"/>
        <echo>module classpath: ${classpath}</echo>
        <echo>debug: ${compile.debug}</echo>

        <mkdir dir="${classes.dir}/${module.name}"/>
        <mkdir dir="${gen.src.dir}/${module.name}"/>

        <build-controls srcdir="${module.dir}" 
                        destdir="${classes.dir}/${module.name}"
                        tempdir="${gen.src.dir}/${module.name}"
                        classpathref="module.classpath"/>

        <!-- Copy property files into the build -->
        <copy todir="${classes.dir}/${module.name}" overwrite="true">
            <fileset dir="${module.dir}" includes="**/*.properties"/>
        </copy>

        <control-jar destfile="${build.lib.dir}/${jdbccontrol.jar.name}" basedir="${classes.dir}/${module.name}">
          <metainf dir="${beehive.home}">
              <include name="LICENSE.txt"/>
              <include name="NOTICE.txt"/>
          </metainf>
          <manifest>
            <attribute name="Extension-Name" value="Beehive JDBC Control"/>
            <attribute name="Specification-Title" value="Beehive JDBC Control"/>
            <attribute name="Specification-Vendor" value="Apache Software Foundation"/>
            <attribute name="Specification-Version" value="${beehive.version}"/>
            <attribute name="Implementation-Title" value="Beehive JDBC Control"/>
            <attribute name="Implementation-Vendor" value="Apache Software Foundation"/>
            <attribute name="Implementation-Version" value="${beehive.version}"/>
            <attribute name="Web-Service-Control-Version" value="${beehive.version}"/>
          </manifest>
        </control-jar>
    </target>


    <!-- =================================================================== -->
    <!-- sqlgrammer - builds the parser using javacc                         -->
    <!-- To run this target is is necessary to have JavaCC installed         -->
    <!-- locally and to set the JAVACC_HOME environment variable to          -->
    <!-- JavaCC's home directory.                                            -->
    <!-- =================================================================== -->
    <target name="sqlgrammar_javacc">
        <javacc
            target="${sqlgrammar.file}"
            outputdirectory="${sqlgrammar.gen.dir}"
            javacchome="${os.JAVACC_HOME}"
            />
    </target>


    <!-- =================================================================== -->
    <!-- clean - cleans the Jdbc Control                                     -->
    <!-- =================================================================== -->
    <target name="clean" description="Cleans the Jdbc Control build.">
        <delete dir="${classes.dir}/${module.name}"/>
        <delete dir="${gen.src.dir}/${module.name}"/>
        <delete file="${build.lib.dir}/${jdbccontrol.jar.name}"/>
    </target>

</project>
