<?xml version="1.0" encoding="UTF-8"?>
<!--
  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.
-->

<project name="JCA" default="build" basedir=".">

    <property file="build.properties"/>

    <path id="classpath">
        <fileset dir="${jboss.home}/server/${jboss.server}/lib" includes="*.jar"/>
    </path>


    <!-- Builds JCA application -->
    <target name="build">
        <mkdir dir="bin"/>
        <javac srcdir="src" destdir="bin" classpathref="classpath"/>

        <antcall target="build.${server.name}"/>

        <jar destfile="jca.war">
            <zipfileset dir="bin" prefix="WEB-INF/classes" includes="**/web/*.class"/>
            <zipfileset dir="web" excludes="WEB-INF/*-web.xml"/>
            <zipfileset dir="web" includes="WEB-INF/${server.name}-web.xml"/>
        </jar>
    </target>

    <!-- Packs JBoss version of the resource adapter module -->
    <target name="build.jboss">
        <jar destfile="jca.rar">
            <zipfileset dir="bin" includes="**/connector/**/*.class"/>
            <zipfileset dir="meta/jboss" prefix="META-INF" includes="ra.xml"/>
        </jar>
    </target>

    <!-- Packs Geronimo version of the resource adapter module -->
    <target name="build.geronimo">
        <jar destfile="bin/jca.jar">
            <zipfileset dir="bin" includes="**/connector/**/*.class"/>
        </jar>
        <jar destfile="jca.rar">
            <zipfileset dir="bin" includes="jca.jar"/>
            <zipfileset dir="meta/geronimo" prefix="META-INF" includes="ra.xml"/>
        </jar>
    </target>


    <!--
        Deploys (or redeploys) the application on the currently selected
        server
    -->
    <target name="deploy">
        <antcall target="deploy.${server.name}"/>
    </target>

    <!-- 
        Deploys (or redeploys) the application on JBoss. If the server is
        started the application will be installed and started on the fly.
        The JBoss version of the application must be previously built 
        and located in the current folder.
    -->
    <target name="deploy.jboss">
        <copy todir="${jboss.home}/server/${jboss.server}/deploy"
              file="meta/jboss/jca-ds.xml"/>
        <copy todir="${jboss.home}/server/${jboss.server}/deploy" file="jca.rar"/>
        <copy todir="${jboss.home}/server/${jboss.server}/deploy" file="jca.war"/>
    </target>

    <!-- 
        Deploys (or redeploys) the application on Geronimo. The server 
        should be started.
        The Geronimo version of the application must be previously built
        and located in the current folder.
    -->
    <target name="deploy.geronimo">
        <java jar="${geronimo.home}/bin/deployer.jar" fork="true">
            <arg value="--user"/>
            <arg value="${geronimo.user}"/>
            <arg value="--password"/>
            <arg value="${geronimo.password}"/>
            <arg value="undeploy"/>
            <arg value="org/apache/geronimo/demo/jca.war"/>
        </java>

        <java jar="${geronimo.home}/bin/deployer.jar" fork="true">
            <arg value="--user"/>
            <arg value="${geronimo.user}"/>
            <arg value="--password"/>
            <arg value="${geronimo.password}"/>
            <arg value="undeploy"/>
            <arg value="org/apache/geronimo/demo/jca.rar"/>
        </java>

        <java jar="${geronimo.home}/bin/deployer.jar" fork="true">
            <arg value="--user"/>
            <arg value="${geronimo.user}"/>
            <arg value="--password"/>
            <arg value="${geronimo.password}"/>
            <arg value="deploy"/>
            <arg value="meta/geronimo/jca-plan.xml"/>
            <arg value="jca.rar"/>
        </java>

        <java jar="${geronimo.home}/bin/deployer.jar" fork="true">
            <arg value="--user"/>
            <arg value="${geronimo.user}"/>
            <arg value="--password"/>
            <arg value="${geronimo.password}"/>
            <arg value="deploy"/>
            <arg value="jca.war"/>
        </java>
    </target>

</project>
