<?xml version="1.0" encoding="UTF-8"?>
<project name="Install S-RAMP into Tomcat 7" default="install">

  <!-- Configure properties specific to Tomcat 7 -->
  <target name="properties-tomcat-7">
    <property name="s-ramp.updates.dir" location="${basedir}/updates" />

    <property name="s-ramp.overlord-commons.installer.jar" location="overlord-commons-installer.jar" />
    <property name="s-ramp.overlord-commons.installer.dir" location="${s-ramp.install.dir}/overlord-commons-installer" />

    <property name="s-ramp.tomcat.deploy.dir" location="${s-ramp.appserver.dir}/webapps/" />
    <property name="s-ramp.tomcat.config.dir" location="${s-ramp.appserver.dir}/conf/" />

    <property name="s-ramp.s-ramp-server.war.path" location="bin/s-ramp-server-tomcat7-${s-ramp.version}.war" />
    <property name="s-ramp.s-ramp-ui.war.path" location="bin/s-ramp-ui-war-tomcat7-${s-ramp.version}.war" />
  </target>

  <!-- Install S-RAMP -->
  <target name="install" depends="properties-tomcat-7">
    <echo message=" " />
    <echo message="########################################" />
    <echo message="# Installing S-RAMP into Tomcat 7.     #" />
    <echo message="########################################" />

    <echo>----------------------------------</echo>
    <echo>Installing Overlord Commons</echo>
    <echo>----------------------------------</echo>
    <unzip src="${s-ramp.overlord-commons.installer.jar}" 
           dest="${s-ramp.overlord-commons.installer.dir}" overwrite="false" />
    <ant antfile="${s-ramp.overlord-commons.installer.dir}/build.xml" target="install"
         dir="${s-ramp.overlord-commons.installer.dir}" 
         inheritall="true" inheritrefs="false">
      <property name="appserver.id" value="${appserver.id}" />
      <property name="overlord-commons.install.dir" location="${s-ramp.install.dir}" />
      <property name="overlord-commons.appserver.dir" location="${s-ramp.appserver.dir}" />
    </ant>

    <echo>-----------------------------------</echo>
    <echo>Deploying S-RAMP and S-RAMP UI</echo>
    <echo>-----------------------------------</echo>
    <copy file="${s-ramp.s-ramp-server.war.path}" 
          tofile="${s-ramp.tomcat.deploy.dir}/s-ramp-server.war" overwrite="true" />
    <copy file="${s-ramp.s-ramp-ui.war.path}" 
          tofile="${s-ramp.tomcat.deploy.dir}/s-ramp-ui.war" overwrite="true" />

    <echo>-----------------------------------</echo>
    <echo>Configuring S-RAMP</echo>
    <echo>-----------------------------------</echo>
    <property name="overlord-apps.dir" location="${s-ramp.tomcat.config.dir}/overlord-apps" />
    <mkdir dir="${overlord-apps.dir}" />
    <copy file="${s-ramp.updates.dir}/srampui-overlordapp.properties" todir="${overlord-apps.dir}" overwrite="true" />
    <copy file="${s-ramp.updates.dir}/sramp.properties" todir="${s-ramp.tomcat.config.dir}" overwrite="true" />
    <copy file="${s-ramp.updates.dir}/sramp-ui.properties" todir="${s-ramp.tomcat.config.dir}" overwrite="true" />
    <copy file="${s-ramp.updates.dir}/sramp-modeshape.json" todir="${s-ramp.tomcat.config.dir}" overwrite="true" />

    <!-- Set the SAML keystore and alias password in the s-ramp-ui config -->
    <propertyfile file="${s-ramp.tomcat.config.dir}/sramp-ui.properties">
      <entry key="s-ramp-ui.atom-api.authentication.saml.keystore" value="${sys:catalina.home}/conf/overlord-saml.keystore" />
      <entry key="s-ramp-ui.atom-api.authentication.saml.keystore-password" value="samlkeystore77" />
      <entry key="s-ramp-ui.atom-api.authentication.saml.key-password" value="overlord99" />
    </propertyfile>

    <!-- Set the location of the modeshape config file in sramp.properties -->
    <propertyfile file="${s-ramp.tomcat.config.dir}/sramp.properties">
      <entry key="sramp.modeshape.config.url" value="${sys:catalina.home}/conf/sramp-modeshape.json" />
    </propertyfile>

    <echo message=" " />
    <echo message="########" />
    <echo message="# DONE #" />
    <echo message="########" />
    <echo message=" " />
  </target>

</project>
