<?xml version="1.0" encoding="UTF-8"?>
<project name="CCTNSApplication" default="CCTNS" basedir=".">
<property name="directory" value="C:\CCTNSApplication"/>
<property name="ant_log_directory" value="C:\cctns_offline_installation_log"/>	
<record name="${ant_log_directory}\simple.log"/>
<echo message="Installing CCTNS Application (Complete-Server)" /> 

<target name="CCTNS" depends="dircheck,reCreateAppRootDirectory,createAppRootDirectory,copyApplication,MySqlUserDetails,DBScript,deleteTempFile,ApplicationDBUserDetails,createAppShortCut,pauseAfterDone" >
	<echo message="CCTNS Installed " /> 
</target>
  <target name="reCreateAppRootDirectory" depends="dircheck" if="dir.exists">
    <echo>${directory} exists</echo>
    <delete dir="${directory}"/>
   <mkdir dir="C:\CCTNSApplication" />
  </target>
    <target name="createAppRootDirectory" depends="dircheck" unless="dir.exists">
    <echo>${directory} Not Available "</echo>
    <mkdir dir="${directory}" /> 
  </target>
  <target name="dircheck">
    <condition property="dir.exists">
      <available file="${directory}" type="dir"/>
    </condition>
  </target>
<!-- <target name="MakedirForCCTNSApplication" description="CCTNS Application Directory"> 
<echo message="Creating CCTNS Application Directory"></echo>
	<mkdir dir="C:/CCTNSApplication" /> 
</target> -->

<target name="copyApplication"  description="Copying  CCTNS Application"  depends="dircheck"> 
<echo message="Copying CCTNS Application"></echo> 
 <copy todir="${directory}"> 
 <fileset dir="./Application"/> 
</copy>
</target> 

<target name="MySqlUserDetails" description="MySqlUserDetails" >
	<echo message="MySql User Details to Access the DB"> </echo>
  	  <java jar="${directory}\MySQlAccess\MySQLAccessConfig.jar" fork="true"/>
  <property file="${directory}/database.properties"/>
  <property name="db.username" value="${db.user}"/>
  <property name="db.password" value="${db.pass}"/>
  <property name="db.name" value="${db.mySqlDBname}"/>
<!--
  <property name="mysql" value="C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql"/>
  <property name="mysqladmin" value="C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqladmin"/>
 -->
  <property name="mysql" value="${mysqlbin}\mysql"/>
  <property name="mysqladmin" value="${mysqladminbin}\mysqladmin"/> 
  <property name="restore.dir" value="${directory}\DbScript\script"/>
  <property name="db.url" value="${db.urlMysql}"/> 	
  <echo message="MySQL Path=${mysqlbin}" />
  </target>
  

  <target name="deleteTempFile" depends="DBScript" if="dir.exists">
    
    <delete file="${directory}/database.properties"/>
		<echo>deleteTempFile done</echo>
 
  </target>
  
<target name="DeleteDB" description="Deleting DB" depends="MySqlUserDetails">
<echo message="Deleteing current DB" />
    <exec executable="${mysqladmin}">
      <arg value="--user=${db.username}"/>
      <arg value="--password=${db.password}"/>
      <arg value="--force"/>
      <arg value="drop"/>
      <arg value="${db.name}"/>
    </exec>
</target>
<target name="CreateDB" description="Creating DB" depends="DeleteDB" >
    <echo message="Creating DB " /> 
    <exec executable="${mysqladmin}">
      <arg value="--user=${db.username}"/>
      <arg value="--password=${db.password}"/>
      <arg value="--force"/>
      <arg value="create"/>
	  <!--
      <arg value="${db.name}"/>
	  -->
    </exec>
</target>

<target name="DBScript" description="Running DB Script" depends="MySqlUserDetails">
    <echo message="Executing DB script " />
    <exec executable="${mysql}" input="${restore.dir}.sql">
      <arg value="--user=${db.username}"/>
      <arg value="--password=${db.password}"/>
      <arg value="--force"/>
	  <!--
      <arg value="${db.name}"/>
	  -->
    </exec>
</target>
<property name="browser" location="C:/CCTNSApplication"/>

<target name="ApplicationDBUserDetails" description="ApplicationDBUserDetails" depends="DBScript"  >

	<echo message="MySql User Details to Access the Application"> </echo>
	<java jar="${directory}\ConfigureCASOfflineServerComplete.jar" fork="true"    />
</target>
<!--target name="ApplicationDBUserDetails" description="ApplicationDBUserDetails" depends="DBScript"  >
	<echo message="MySql User Details to Access the Application"> </echo>
  	  <java jar="C:\CCTNSApplication\ConfigureCASOffline.jar" fork="true"/>
   </target -->
<!--target name="SyncPSConfiguration" description="Sync PS Configuration" depends="ApplicationDBUserDetails"  >
	<echo message="MySql User Details to Access the Application"> </echo>
  	  <java jar="C:\CCTNSApplication\SyncPoliceStationConfiguration.jar" fork="true"/>
   </target -->
<target name="createAppShortCut" depends="ApplicationDBUserDetails" description="Created Short Cut">
    <echo message="CCTNS Short CUT Created" /> 	
    <exec executable="cscript">
        <arg value="${directory}\ShotCCTNS.vbs"/>
     </exec>
</target>
<target name="pauseAfterDone" description="Pause After done" depends="createAppShortCut" >
    <echo message="Done, please look at the output above, if any error please follow the procedure again." /> 	
    <input>Press return(enter) key to continue...</input>
        
    </target>
</project>