<?xml version="1.0" encoding="UTF-8" ?>
<!--
-  Copyright(c) 2004, SpikeSource Inc. All Rights Reserved.
-  Licensed under the Open Source License version 2.1
-  (See http://www.spikesource.com/license.html)
-->

<project name="phpPgAdminTest">

  <!--
  These two lines are necessary in order to inherit the environment and
  resolve the properties in the top-level project.properties properly
  -->
  <property environment="env"/>
  <property file="${spike.parent.dir}/project.properties"/>

  <property name="deploy.dir" value="${spike.httpd.docroot}/phpPgAdmin"/>

  <!-- General targets, required -->

  <target name="spike:versions-dependency"
    description="Return the SpikeSource stack version required by the application and tests.">
    <echo>SpikeSource Core Stack 1.4</echo>
  </target>

  <target name="spike:interface-version"
    description="Return the interface version implemented by this build script.">
    <echo>1.0</echo>
  </target>

  <target name="spike:clean">
    <!--
    The deploy and class file directories are recreated here.
    This is for deleting all the class files created during
    previous test runs....
    -->

    <delete dir="classes"/>
    <delete dir="${deploy.dir}"/>
  </target>


  <target name="spike:install">
    <mkdir dir="${deploy.dir}"/>
    <chmod dir="${deploy.dir}" type="dir" perm="777" />
    <chmod dir="${basedir}/data" type="dir" perm="777" />
    <chmod dir="${basedir}/data/TableSpace" type="dir" perm="777" />
    <copy todir="${deploy.dir}" preservelastmodified="true">
      <fileset dir="${basedir}/phpPgAdmin" includes="**/*.*" excludes=""/>
    </copy>
    <chmod type="file" perm="777">
      <fileset dir="${deploy.dir}">
        <include name="**/*.*"/>
      </fileset>
    </chmod>
    <echo>Replace spike_bin_dir in /conf/config.inc.php with '${spike.bin.dir}'</echo>
    <replace file="${deploy.dir}/conf/config.inc.php" token="spike_bin_dir" value="${spike.bin.dir}"/>
  </target>

  <target name="spike:compile">
    <echo>Do  nothing</echo>
  </target>

  <target name="spike:pre-test-configure">
    <!--command for bringing up any dependent components can be written here-->
    <exec executable="maven" dir="${spike.parent.dir}">
      <arg line="-b -E"/>
      <arg value="spike:startup-httpd"/>
      <arg value="spike:startup-postgresql"/>
    </exec>
    <exec dir="${deploy.dir}/sql" executable="${spike.bin.dir}/psql">
      <arg line="-f test.sql -d template1 -U '${spike.postgresql.adminuser}'"/>
    </exec>
    <exec dir="${deploy.dir}/sql" executable="${spike.bin.dir}/psql">
      <arg line="-f reports-pgsql.sql -d template1 -U '${spike.postgresql.adminuser}'"/>
    </exec>
  </target>

  <target name="spike:test"
    description="phpPgAdmin simpletests">
    <!--The simpletest testcases are executed here-->
    <echo>--------------------------------------------------------------</echo>
    <echo>Starting phpPgAdmin SimpleTest Tests</echo>
    <echo>--------------------------------------------------------------</echo>

    <exec dir="${basedir}/testcase" executable="${spike.bin.dir}/php"
      failonerror="false">
      <!-- The name of the testcase/testsuite(if the testcases are grouped) should be mentioned as the first
      argument . For eg testNewsletterApp.php is the sample test case that is to be executed. 
      The second and third arguments would be PHP_SIMPLETEST_HOME and the PHP_SIMPLETEST_REPORT_PATH (which is a must).	 
      -->
      <arg line="testphpPgAdminMain.php PHP_SIMPLETEST_HOME='${spike.simpletest.home}' PHP_SIMPLETEST_REPORT_PATH='${spike.report.dir}/index.html'"/>
    </exec>

  </target>

  <target name="spike:post-test-configure">
    <!-- command for shutting down the dependent components can be given here-->
    <exec executable="maven" dir="${spike.parent.dir}">
      <arg line="-b -E"/>
      <arg value="spike:shutdown-httpd"/>
      <arg value="spike:shutdown-postgresql"/>
    </exec>
    <delete dir="${deploy.dir}"/>
  </target>

  <target name="spike:test-report">
    <echo>"Do nothing"</echo>
  </target>

  <!--
  Goals required for code coverage
  -->
  <target name="spike:coverage-compile">
    <echo>Do  nothing</echo>
  </target>

  <target name="spike:coverage-install">
    <mkdir dir="${deploy.dir}"/>
    <chmod dir="${deploy.dir}" type="dir" perm="777" />
    <chmod dir="${basedir}/data" type="dir" perm="777" />
    <chmod dir="${basedir}/data/TableSpace" type="dir" perm="777" />
    <copy todir="${deploy.dir}" preservelastmodified="true">
      <fileset dir="${basedir}/phpPgAdmin" includes="**/*.*"
        excludes=""/>
    </copy>
    <chmod type="file" perm="777">
      <fileset dir="${deploy.dir}">
        <include name="**/*.*"/>
      </fileset>
    </chmod>

    <replace file="${deploy.dir}/conf/config.inc.php" token="spike_bin_dir" value="${spike.bin.dir}"/>
    <!-- instrument the source code -->
    <exec dir="${deploy.dir}" executable="${spike.bin.dir}/php"
      failonerror="true">
      <arg line="${spike.phpcoverage.home}/cli/instrument.php"/>
      <arg line="-b . -p ${spike.phpcoverage.home} ."/>
    </exec>
  </target>

  <target name="spike:pre-test-coverage-configure">
    <!--command for bringing up any dependent components can be written here-->
    <exec executable="maven" dir="${spike.parent.dir}">
      <arg line="-b -E"/>
      <arg value="spike:startup-httpd"/>
      <arg value="spike:startup-postgresql"/>
    </exec>
  </target>

  <target name="spike:test-coverage"
    description="phpPgAdmin Coverage using PHPCoverage">
    <!--The command for running simpletest testcases can be given here-->
    <echo>--------------------------------------------------------------</echo>
    <echo>Starting Coverage</echo>
    <echo>--------------------------------------------------------------</echo>

    <exec dir="${basedir}/testcase" executable="${spike.bin.dir}/php">
      <arg line="coveragephpPgAdminMain.php PHPCOVERAGE_REPORT_DIR='${spike.report.dir}'"/>
      <arg line="PHPCOVERAGE_APPBASE_PATH='${deploy.dir}'"/>
      <arg line="PHP_SIMPLETEST_HOME='${spike.simpletest.home}'"/>
    </exec>

  </target>

  <target name="spike:post-test-coverage-configure">
    <!-- command for shutting down the dependent components can be given here-->
    <exec executable="maven" dir="${spike.parent.dir}">
      <arg line="-b -E"/>
      <arg value="spike:shutdown-httpd"/>
      <arg value="spike:shutdown-postgresql"/>
    </exec>
    <delete dir="${deploy.dir}"/>
  </target>

  <target name="spike:coverage-report">
    <echo> "Do nothing"</echo>
  </target>

</project> 
