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

  <!-- Configure properties specific to Fuse 6.1 -->
  <target name="properties-fuse-6.1">
    <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.fuse.config.dir" location="${s-ramp.appserver.dir}/etc/" />
  </target>

  <!-- Install S-RAMP -->
  <target name="install" depends="properties-fuse-6.1">
    <echo message=" " />
    <echo message="########################################" />
    <echo message="# Installing S-RAMP into Fuse 6.1.     #" />
    <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>Configuring Fuse (mvn)</echo>
    <echo>-----------------------------------</echo>
    <property file="${s-ramp.fuse.config.dir}/org.ops4j.pax.url.mvn.cfg" />
    <propertyfile file="${s-ramp.fuse.config.dir}/org.ops4j.pax.url.mvn.cfg">
      <entry key="org.ops4j.pax.url.mvn.repositories" 
             value="${org.ops4j.pax.url.mvn.repositories}, http://repository.jboss.org/nexus/content/groups/developer/@snapshots" />
    </propertyfile>

    <echo>-----------------------------------</echo>
    <echo>Configuring S-RAMP</echo>
    <echo>-----------------------------------</echo>
    <property name="overlord-apps.dir" location="${s-ramp.fuse.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.fuse.config.dir}" overwrite="true" />
    <copy file="${s-ramp.updates.dir}/sramp-ui.properties" todir="${s-ramp.fuse.config.dir}" overwrite="true" />
    <copy file="${s-ramp.updates.dir}/sramp-modeshape.json" todir="${s-ramp.fuse.config.dir}" overwrite="true" />

    <!-- Set the SAML keystore and alias password in the s-ramp-ui config -->
    <propertyfile file="${s-ramp.fuse.config.dir}/sramp-ui.properties">
      <entry key="s-ramp-ui.atom-api.endpoint" value="http://localhost:8181/s-ramp-server" />
      <entry key="s-ramp-ui.atom-api.authentication.saml.sign-assertions" value="false" />
      <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.fuse.config.dir}/sramp.properties">
      <entry key="sramp.modeshape.config.url" value="${sys:karaf.home}/etc/sramp-modeshape.json" />
    </propertyfile>

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

</project>
