<?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.
-->
<!-- ====================================================================== -->
<!--                                                                        -->
<!--   Ant build script for JEE version of OpenBooks for                    -->
<!--   WebSphere Application Server with OpenJPA 2.0/JPA 2.0 functionality  -->
<!--                                                                        -->
<!--   NOTE: The main build script (build.xml) must be run with ws_ant      -->
<!--   located in the was.home/bin directory.  Otherwise, WebSphere         -->
<!--   provided ant tools will not be included on the classpath and build   -->
<!--   errors will result.                                                  -->
<!-- ====================================================================== -->

<project name="OpenBooks.JEE.WAS">

	<!-- WebSphere Application Server task definitions -->
  	<taskdef name="wsUninstallApp" classname="com.ibm.websphere.ant.tasks.UninstallApplication"/>
  	<taskdef name="wsInstallApp" classname="com.ibm.websphere.ant.tasks.InstallApplication"/>
  	<taskdef name="wsUninstallApp" classname="com.ibm.websphere.ant.tasks.UninstallApplication"/>
   <taskdef name="wsStartApplication" classname="com.ibm.websphere.ant.tasks.StartApplication"/>
   <taskdef name="wsadmin" classname="com.ibm.websphere.ant.tasks.WsAdmin"/>

	<!-- Location of WebSphere Application Server home/install dir -->
	<property name="was.home" value="/opt/IBM/WebSphere/AppServer"/>

	<!-- WebSphere Server name (IP name or address) -->
	<property name="was.server" value=""/>

	<!-- WebSphere Admin port -->
	<property name="was.port" value=""/>

		<!-- WebSphere admin connection type.  SOAP, RMI, JMS, or NONE. -->
	<property name="was.conntype" value=""/>

	<!-- WebSphere User name (required if security is enabled) -->
	<property name="was.user" value=""/>

	<!-- WebSphere Password (required if security enabled) -->
	<property name="was.password" value=""/>

	<target name="pre-package">
	   <echo message="In WAS pre-package"/>
		<copy file="${rsrc.dir}/META-INF/persistence.jee.was.xml" tofile="${classes.dir}/META-INF/persistence.xml"/>
	</target>

	<target name="install"
		description="Deploy OpenBooks as a WAR application in WebSphere Application Server">
		<condition property="default.deploy">
		   <length string="${was.server}" length="0"/>
		</condition>
		<antcall target="was.deploy"/>
		<antcall target="was.deploy.secure"/>
   </target>

   <target name="uninstall"
      description="Uninstall OpenBooks from the Application Server">
		<condition property="default.uninstall">
		   <length string="${was.server}" length="0"/>
		</condition>
		<antcall target="was.uninstall"/>
		<antcall target="was.secure.uninstall"/>
   </target>

   <!-- Default app uninstall -->
   <target name="was.uninstall" if="default.uninstall">
   	<echo>
         ---------------------------------------
         Uninstalling OpenBooks demo application
         WAS Home: ${was.home}
   	</echo>
   	<wsUninstallApp wasHome="${was.home}"
   	              application="OpenBooks"/>
   </target>

   <!-- App uninstall when security is enabled -->
   <target name="was.secure.uninstall" unless="default.uninstall">
   	<echo>
         ---------------------------------------
         Uninstalling OpenBooks demo application
   	</echo>
   	<wsUninstallApp wasHome="${was.home}"
   	              application="OpenBooks"
   	              conntype="${was.conntype}"
   	              host="${was.server}"
   	              port="${was.port}"
   	              user="${was.user}"
   	              password="${was.password}"/>

   </target>

   <!-- Default simple deployment if WAS security is disabled -->
   <target name="was.deploy" if="default.deploy">
   	<echo>
         --------------------------------------------
         Creating Derby JDBC provider and data source
         WAS Home: ${was.home}
   	</echo>
	   <wsadmin wasHome="${was.home}"
	            script="scripts/was/ds_config.py"
	            lang="jython"/>

   	<echo>
         -------------------------------------
         Deploying OpenBooks demo application
   	</echo>
   	<wsInstallApp wasHome="${was.home}"
   	              ear="${target.dir}/openbooks.war"
   	              options="-usedefaultbindings -contextroot OpenBooks -appname OpenBooks"/>

   	<echo>
         -------------------------------------
         Starting OpenBooks demo application
   	</echo>
    	<wsStartApplication wasHome="${was.home}"
  	              application="OpenBooks"/>

   </target>

   <!-- Target for installation and deployment of the application when a      -->
   <!-- server IP name or address is provided.  This type of deployment       -->
   <!-- requires server IP name was.home, was.server, was.conntype,           -->
   <!-- was.port, was.user, and was.password to be provided.                  -->

   <target name="was.deploy.secure" unless="default.deploy">
   	<echo>
         -------------------------------------------
         Creating Derby JDBC Provider and DataSource
         WAS Home: ${was.home}
         WAS Server: ${was.server}
         ConnType: ${was.conntype}
         Port: ${was.port}
         User: ${was.user}
         Password: Not shown
   	</echo>
	   <wsadmin wasHome="${was.home}"
	            script="scripts/was/ds_config.py"
	            lang="jython"
               conntype="${was.conntype}"
   	         host="${was.server}"
   	         port="${was.port}"
   	         user="${was.user}"
   	         password="${was.password}"/>

   	<echo>
         -------------------------------------
         Deploying OpenBooks demo application
   	</echo>

   	<wsInstallApp wasHome="${was.home}"
   	              ear="${target.dir}/openbooks.war"
   	              conntype="${was.conntype}"
   	              host="${was.server}"
   	              port="${was.port}"
   	              user="${was.user}"
   	              password="${was.password}"
   	              options="-usedefaultbindings -contextroot OpenBooks -appname OpenBooks"/>
   	<echo>
         -------------------------------------
         Starting OpenBooks demo application
         Start OpenBooks via http://server:port/OpenBooks
   	</echo>
      <wsStartApplication wasHome="${was.home}"
   	              application="OpenBooks"
   	              conntype="${was.conntype}"
   	              host="${was.server}"
   	              port="${was.port}"
   	              user="${was.user}"
   	              password="${was.password}"/>
   </target>
</project>
