<?xml version="1.0" encoding="UTF-8"?>

<project name="jBPM.install">

  <property file="build.properties" />

  <property name="install.home" value="./" />

  <property name="jboss.server.conf.dir" value="${jboss.home}/server/${jboss.server.configuration}/conf" />
  <property name="jboss.server.lib.dir" value="${jboss.home}/server/${jboss.server.configuration}/lib" />
  <property name="jboss.bind.address" value="localhost" />

  <property name="eclipse.workspace.dir" value="${install.home}/workspace"/>

  <property name="h2.download.url" value="http://repo1.maven.org/maven2/com/h2database/h2/1.3.161/h2-1.3.161.jar"/>
  <property name="mysql.download.url" value="https://repository.jboss.org/nexus/service/local/repositories/central/content/mysql/mysql-connector-java/5.1.18/mysql-connector-java-5.1.18.jar" />
  <property name="postgresql.download.url" value="https://repository.jboss.org/nexus/service/local/repositories/deprecated/content/postgresql/postgresql/8.4-701.jdbc3/postgresql-8.4-701.jdbc3.jar" />
  <property name="slf4j.download.url" value="http://repo1.maven.org/maven2/org/slf4j/slf4j-jdk14/1.5.11/slf4j-jdk14-1.5.11.jar"/>
  <property name="birt.download.url.as7" value="http://www.eclipse.org/downloads/download.php?file=/birt/downloads/drops/R-R1-3_7_0-201106151818/birt-runtime-3_7_0.zip&amp;url=http://mirrors.ibiblio.org/pub/mirrors/eclipse/birt/downloads/drops/R-R1-3_7_0-201106151818/birt-runtime-3_7_0.zip&amp;mirror_id=187"/>
  <property name="birt.download.url.as5" value="http://www.eclipse.org/downloads/download.php?file=/birt/downloads/drops/R-R1-2_3_2_2-200906011507/birt-runtime-2_3_2_2.zip&amp;url=http://download.eclipse.org/birt/downloads/drops/R-R1-2_3_2_2-200906011507/birt-runtime-2_3_2_2.zip&amp;mirror_id=1"/>
  <property name="birt.version.as7" value="3_7_0"/>
  <property name="birt.version.as5" value="2_3_2_2"/>
	
  <!-- ############ DOWNLOAD ############ -->

  <!-- Download H2 -->
  <target name="download.h2.check">
    <echo message="Checking h2 download ..." />
    <condition property="h2.not.available">
      <not>
        <available file="${install.home}/db/driver/h2.jar" />
      </not>
    </condition>
  </target>

  <target name="download.h2" depends="download.h2.check" if="h2.not.available">
    <echo message="Getting h2 ..." />
    <mkdir dir="${install.home}/db/driver"/>
    <get src="${h2.download.url}" dest="${install.home}/db/driver/h2.jar"  />
  </target>

  <!-- Download JDBC driver jar (MySQL is default)-->
  <property name="db.driver.jar.name" value="mysql-connector-java.jar" />
  <property name="db.driver.jar" value="${install.home}db/driver/${db.driver.jar.name}" />

  <target name="download.db.driver.check">
    <echo message="Checking if db driver jar has been downloaded ..." />
    <condition property="db.driver.not.available">
      <not>
        <available file="${db.driver.jar}" />
      </not>
    </condition>
  </target>

  <target name="download.mysql.driver" depends="download.db.driver.check" if="db.driver.not.available">
    <echo message="Getting mysql driver jar ..." />
    <mkdir dir="${install.home}/db/driver"/>
    <get src="${mysql.download.url}" dest="${db.driver.jar}" />
  </target>

  <!-- db driver module in jBoss AS 7 installation -->
  <property name="db.driver.module.prefix">com/mysql</property> 
  <property name="db.driver.module.dir">${jboss.home}/modules/${db.driver.module.prefix}/main/</property> 

  <target name="install.db.files" depends="check.jboss.version,download.mysql.driver" if="jboss.version.is.7">
    <mkdir dir="${db.driver.module.dir}" />
    <copy file="${db.driver.jar}" tofile="${db.driver.module.dir}/${db.driver.jar.name}" />
    <copy file="db/driver_jar_module.xml" tofile="${db.driver.module.dir}/module.xml" />
    <!--
    <copy file="${db.driver.jar}" tofile="${jboss.home}/standalone/deployments" />
    -->
    <property name="db.driver.installed" value="true" />
  </target>

  <target name="remove.db.files" depends="check.jboss.version" if="jboss.version.is.7">
    <delete dir="${jboss.home}/modules/${db.driver.module.prefix}" />
  </target>

  <!-- Download BIRT engine for AS5 -->
  <target name="check.birt.as5">
    <condition property="birt.download">
      <equals arg1="${jBPM.birt.download}" arg2="true" />
    </condition>
  </target>
  <target name="download.birt.check.as5" depends="check.birt.as5" if="birt.download">
    <echo message="Checking birt reporting engine download for as5 ..." />
    <condition property="birt.not.available">
      <not>
        <available file="${install.home}/lib/birt-runtime-${birt.version.as5}.zip" />
      </not>
    </condition>
  </target> 
  <target name="download.birt.as5" depends="download.birt.check.as5" if="birt.not.available">
    <echo message="Getting birt reporting engine for AS5 ..." />
    <mkdir dir="${install.home}/lib"/>
    <get src="${birt.download.url.as5}" dest="${install.home}/lib/birt-runtime-${birt.version.as5}.zip" />
  </target>

  <!-- Download BIRT engine for AS7 -->
  <target name="check.birt.as7">
    <condition property="birt.download">
      <equals arg1="${jBPM.birt.download}" arg2="true" />
    </condition>
  </target>
  <target name="download.birt.check.as7" depends="check.birt.as7" if="birt.download">
    <echo message="Checking birt reporting engine download for as7 ..." />
    <condition property="birt.not.available">
      <not>
        <available file="${install.home}/lib/birt-runtime-${birt.version.as7}.zip" />
      </not>
    </condition>
  </target>
  <target name="download.birt.as7" depends="download.birt.check.as7" if="birt.not.available">
    <echo message="Getting birt reporting engine for AS7 ..." />
    <mkdir dir="${install.home}/lib"/>
    <get src="${birt.download.url.as7}" dest="${install.home}/lib/birt-runtime-${birt.version.as7}.zip" />
  </target>  

  <!-- Download JBoss AS -->
  <target name="check.jboss.version">
    <condition property="jboss.version.is.5">
      <equals arg1="${jboss.server.version}" arg2="${jboss.server.version.5}" />
    </condition>
    <condition property="jboss.version.is.7">
      <equals arg1="${jboss.server.version}" arg2="${jboss.server.version.7}" />
    </condition>
  </target>
  <target name="download.jboss.check">
    <echo message="Checking JBoss AS download ..." />
    <condition property="jboss.not.available">
      <not>
        <available file="${install.home}/lib/jboss-as-${jboss.server.version}.zip" />
      </not>
    </condition>
  </target>
  <target name="download.jboss" depends="download.jboss.check" if="jboss.not.available">
    <echo message="Getting JBoss AS ..." />
    <mkdir dir="${install.home}/lib"/>
    <get src="${jboss.download.url}" dest="${install.home}/lib/jboss-as-${jboss.server.version}.zip"  />
  </target>

  <!-- Download Eclipse -->
  <condition property="download.type" value="win32">
    <os family="windows" />
  </condition>	
  <condition property="download.type" value="macosx-cocoa">
    <and>
      <os family="mac" />
      <os family="unix" />
    </and>
  </condition>
  <condition property="download.type" value="linux-gtk">
    <and>
      <not>
        <os family="mac" />
      </not>
      <os family="unix" />
      <not>
        <or>
          <os arch="x86_64" />
          <os arch="amd64" />
        </or>
      </not>
    </and>
  </condition>
  <condition property="download.type" value="linux-gtk-x86_64">
    <and>
      <not>
        <os family="mac" />
      </not>
      <os family="unix" />
      <or>
        <os arch="x86_64" />
        <os arch="amd64" />
      </or>
    </and>
  </condition>		
  <condition property="download.extension" value="zip">
    <os family="windows" />
  </condition>		
  <condition property="download.extension" value="tar.gz">
    <or>
      <os family="mac" />
      <os family="unix" />
    </or>
  </condition>	
  <condition property="expandTypeZip" value="true">
    <equals arg1="${download.extension}" arg2="zip" />
  </condition>   
  <condition property="expandTypeTarGz" value="true">
    <equals arg1="${download.extension}" arg2="tar.gz" />
  </condition>   
  <target name="download.eclipse.check">
    <echo message="Checking Eclipse download ..." />
    <condition property="eclipse.not.available">
      <not>
        <available file="${install.home}/lib/eclipse-java-helios-SR2-${download.type}.${download.extension}" />
      </not>
    </condition>
  </target>
  <target name="download.eclipse" depends="download.eclipse.check" if="eclipse.not.available">
    <echo message="Getting Eclipse ..." />
    <mkdir dir="${install.home}/lib"/>
    <get src="http://download.eclipse.org/technology/epp/downloads/release/helios/SR2/eclipse-java-helios-SR2-${download.type}.${download.extension}"
         dest="${install.home}/lib/eclipse-java-helios-SR2-${download.type}.${download.extension}"  />
  </target>
  <target name="download.eclipse.gef.check">
    <echo message="Checking Eclipse GEF download ..." />
    <condition property="eclipse.gef.not.available">
      <not>
        <available file="${install.home}/lib/GEF-SDK-3.6.2.zip" />
      </not>
    </condition>
  </target>
  <target name="download.eclipse.gef" depends="download.eclipse.gef.check" if="eclipse.gef.not.available">
    <echo message="Getting Eclipse GEF ..." />
    <mkdir dir="${install.home}/lib"/>
    <get src="http://download.eclipse.org/tools/gef/downloads/drops/3.6.2/R201102251600/GEF-SDK-3.6.2.zip"
         dest="${install.home}/lib/GEF-SDK-3.6.2.zip"  />
  </target>

  <!-- Download jBPM binaries -->
  <target name="download.jBPM.bin.check">
    <echo message="Checking jBPM binaries download ..." />
    <condition property="jBPM.bin.not.available">
      <not>
        <available file="${install.home}/lib/jbpm-${jBPM.version}-bin.zip" />
      </not>
    </condition>
  </target>
  <target name="download.jBPM.bin" depends="download.jBPM.bin.check" if="jBPM.bin.not.available">
    <echo message="Getting jBPM binaries ..." />
    <mkdir dir="${install.home}/lib"/>
    <get src="${jBPM.url}/jbpm-${jBPM.version}-bin.zip" dest="${install.home}/lib/jbpm-${jBPM.version}-bin.zip"  />
  </target>

  <!-- Download Drools Guvnor -->
  <target name="download.drools.guvnor.check">
    <echo message="Checking Drools Guvnor download ..." />
    <condition property="drools.guvnor.not.available">
      <not>
        <available file="${install.home}/lib/guvnor-distribution-wars-${drools.guvnor.version}.war" />
      </not>
    </condition>
  </target>  
  <target name="download.drools.guvnor" depends="download.drools.guvnor.check" if="drools.guvnor.not.available">
    <echo message="Getting Drools Guvnor ..." />
    <mkdir dir="${install.home}/lib"/>
    <get src="${drools.guvnor.url}" dest="${install.home}/lib/guvnor-distribution-wars-${drools.guvnor.version}.war"/>
  </target>

  <!-- Download Designer -->
  <target name="download.designer.check">
    <echo message="Checking Designer download ..." />
    <condition property="designer.not.available">
      <not>
        <available file="${install.home}/lib/designer-${designer.version}.war" />
      </not>
    </condition>
  </target>  
  <target name="download.designer" depends="download.designer.check" if="designer.not.available">
    <echo message="Getting Designer ..." />
    <mkdir dir="${install.home}/lib"/>
    <get src="${designer.url}/designer-${designer.version}.war" dest="${install.home}/lib/designer-${designer.version}.war" />
  </target>

  <!-- Download jBPM and Drools Eclipse plugins -->
  <target name="download.droolsjbpm.eclipse.check">
    <echo message="Checking jBPM and Drools Eclipse download ..." />
    <condition property="droolsjbpm.eclipse.not.available">
      <not>
        <available file="${install.home}/lib/org.drools.updatesite-${droolsjbpm.eclipse.version}-assembly.zip" />
      </not>
    </condition>
  </target>
  <target name="download.droolsjbpm.eclipse" depends="download.droolsjbpm.eclipse.check" if="droolsjbpm.eclipse.not.available">
    <echo message="Getting jBPM and Drools Eclipse ..." />
    <mkdir dir="${install.home}/lib"/>
    <get src="${droolsjbpm.eclipse.url}" dest="${install.home}/lib/org.drools.updatesite-${droolsjbpm.eclipse.version}-assembly.zip"  />
  </target>
  
  <!-- Download jBPM gwt-console -->
  <target name="download.jBPM.gwt-console.check">
    <echo message="Checking jBPM gwt-console download ..." />
    <condition property="jBPM.gwt-console.not.available">
      <not>
        <available file="${install.home}/lib/jbpm-${jBPM.version}-gwt-console.zip" />
      </not>
    </condition>
  </target>
  <target name="download.jBPM.gwt-console" depends="download.jBPM.gwt-console.check" if="jBPM.gwt-console.not.available">
    <echo message="Getting jBPM gwt-console ..." />
    <mkdir dir="${install.home}/lib"/>
    <get src="${jBPM.url}/jbpm-${jBPM.version}-gwt-console.zip" dest="${install.home}/lib/jbpm-${jBPM.version}-gwt-console.zip"  />
  </target>

  <!-- ############ INSTALL ############ -->

  <!-- Install JBoss AS -->
  <target name="install.jboss" depends="download.jboss">
    <unzip src="${install.home}/lib/jboss-as-${jboss.server.version}.zip" dest="${install.home}" />
    <chmod perm="a+x" file="${jboss.home}/bin/run.sh" />
    <chmod perm="a+x" file="${jboss.home}/bin/shutdown.sh" />
    <chmod perm="a+x" file="${jboss.home}/bin/standalone.sh" />
  	<chmod perm="a+x" file="${jboss.home}/bin/jboss-admin.sh" />
  </target>

  <!-- Install guvnor -->
  <target name="install.guvnor.into.jboss" depends="download.drools.guvnor,check.jboss.version">
    <copy file="${install.home}/lib/guvnor-distribution-wars-${drools.guvnor.version}.war"
          tofile="${jboss.server.deploy.dir}/drools-guvnor.war"
          overwrite="true" />
  </target>  	

  <!-- Install designer -->
  <target name="install.designer.into.jboss" depends="download.designer,check.jboss.version">
    <copy file="${install.home}/lib/designer-${designer.version}.war"
          tofile="${jboss.server.deploy.dir}/designer.war"
          overwrite="true" />
  	<antcall target="created.designer.deployment.as7" />
  </target>
	
  <target name="created.designer.deployment.as7" depends="check.jboss.version" if="jboss.version.is.7">
  	<touch file="${jboss.server.deploy.dir}/designer.war.dodeploy"/>
  </target>
  			
  <!-- Install gwt-console -->
  <target name="install.jBPM-gwt-console.into.jboss" depends="download.h2,download.jBPM.gwt-console">
    <antcall target="install.jBPM-gwt-console.into.jboss5" />
    <antcall target="install.jBPM-gwt-console.into.jboss7" />
  </target>
  <target name="install.jBPM-gwt-console.into.jboss7" depends="check.jboss.version" if="jboss.version.is.7">
    <!-- reporting -->
    <antcall target="download.birt.as7" />
    <!-- gwt-console -->
    <mkdir dir="${install.home}/target"/>
    <unzip src="${install.home}/lib/jbpm-${jBPM.version}-gwt-console.zip" dest="${install.home}/target" />
    <mkdir dir="${install.home}/target/jbpm-gwt-console-server-war"/>
    <unzip src="${install.home}/target/jbpm-gwt-console-server-${jBPM.version}.war"
           dest="${install.home}/target/jbpm-gwt-console-server-war"/>
    <copy file="${install.home}/db/persistence.xml"
          tofile="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/classes/META-INF/persistence.xml"
          overwrite="true" />
    <copy file="${install.home}/db/ProcessInstanceInfo.hbm.xml"
          tofile="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/classes/META-INF/ProcessInstanceInfo.hbm.xml"
          overwrite="true" />
    <copy file="${install.home}/auth/users.properties"
          tofile="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/classes/users.properties"
          overwrite="true" />
    <copy file="${install.home}/auth/roles.properties"
          tofile="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/classes/roles.properties"
          overwrite="true" />
    <copy file="${install.home}/jbpm-tm.jar"
          tofile="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/jbpm-tm.jar"
          overwrite="true" />
    <copy todir="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" overwrite="true">
      <fileset dir="${install.home}/db/driver"/>
    </copy>
    <!-- Fix for conflicting javassist jar -->
    <delete file="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/javassist-3.6.0.GA.jar"/>
    <!-- Other configuration like work item handlers -->
    <copy todir="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/classes" overwrite="true">
      <fileset dir="${install.home}/conf"/>
    </copy>
    <!-- reporting -->
    <antcall target="install.reporting.into.jboss7" />
    <zip basedir="${install.home}/target/jbpm-gwt-console-server-war"
         destfile="${install.home}/target/jbpm-gwt-console-server-${jBPM.version}.war"/>
    <copy file="${install.home}/target/jbpm-gwt-console-server-${jBPM.version}.war"
          tofile="${jboss.server.deploy.dir}/jbpm-gwt-console-server.war"
          overwrite="true" />
    <copy file="${install.home}/target/jbpm-gwt-console-${jBPM.version}.war"
          tofile="${jboss.server.deploy.dir}/jbpm-gwt-console.war"
          overwrite="true" />
    <delete dir="${install.home}/target"/>
    <copy file="${install.home}/standalone.xml"
          tofile="${jboss.home}/standalone/configuration/standalone.xml"
          overwrite="true" />
  </target>
  <target name="install.jBPM-gwt-console.into.jboss5" depends="check.jboss.version" unless="jboss.version.is.7">
    <!-- reporting -->
    <antcall target="download.birt.as5" />
    <!-- gwt-console -->
    <mkdir dir="${install.home}/target"/>
    <unzip src="${install.home}/lib/jbpm-${jBPM.version}-gwt-console.zip" dest="${install.home}/target" />
    <mkdir dir="${install.home}/target/jbpm-gwt-console-server-war"/>
    <unzip src="${install.home}/target/jbpm-gwt-console-server-${jBPM.version}.war"
           dest="${install.home}/target/jbpm-gwt-console-server-war"/>
    <copy file="${install.home}/db/persistence.xml"
          tofile="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/classes/META-INF/persistence.xml"
          overwrite="true" />
    <copy file="${install.home}/db/ProcessInstanceInfo.hbm.xml"
          tofile="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/classes/META-INF/ProcessInstanceInfo.hbm.xml"
          overwrite="true" />
    <!-- Fix for conflicting javassist jar -->
    <delete file="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/xml-apis-1.3.04.jar"/>
    <delete file="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/hibernate-annotations-3.4.0.GA.jar"/>
    <delete file="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/hibernate-commons-annotations-3.1.0.GA.jar"/>
    <delete file="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/hibernate-core-3.3.2.GA.jar"/>
    <delete file="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/hibernate-entitymanager-3.4.0.GA.jar"/>
    <delete file="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/hibernate-tools-3.2.3.GA.jar"/>
  	<delete file="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/ejb3-persistence-1.0.2.GA.jar"/>
  	<delete file="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/javassist-3.4.GA.jar"/>
  	<delete file="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/javassist-3.14.0-GA.jar"/>
    <!-- Other configuration like work item handlers -->
    <copy todir="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/classes" overwrite="true">
      <fileset dir="${install.home}/conf"/>
    </copy>
    <!-- reporting -->
    <antcall target="install.reporting.into.jboss5" />
    <zip basedir="${install.home}/target/jbpm-gwt-console-server-war"
         destfile="${install.home}/target/jbpm-gwt-console-server-${jBPM.version}.war"/>
    <copy file="${install.home}/target/jbpm-gwt-console-server-${jBPM.version}.war"
          tofile="${jboss.server.deploy.dir}/jbpm-gwt-console-server.war"
          overwrite="true" />
    <copy file="${install.home}/target/jbpm-gwt-console-${jBPM.version}.war"
          tofile="${jboss.server.deploy.dir}/jbpm-gwt-console.war"
          overwrite="true" />
    <delete dir="${install.home}/target"/>
    <!-- db configuration -->
    <copy file="${install.home}/db/jBPM-ds.xml"
          tofile="${jboss.server.deploy.dir}/jBPM-ds.xml"
          overwrite="true" />
    <copy todir="${jboss.server.lib.dir}" overwrite="true">
      <fileset dir="${install.home}/db/driver"/>
    </copy>
    <!-- authentication configuration -->
    <copy file="${install.home}/auth/users.properties"
          tofile="${jboss.server.conf.dir}/users.properties"
          overwrite="true" />
    <copy file="${install.home}/auth/roles.properties"
          tofile="${jboss.server.conf.dir}/roles.properties"
          overwrite="true" />
  </target>

  <!-- Install reporting AS7  -->
  <target name="install.reporting.into.jboss7" depends="check.birt.as7" if="birt.download" >
    <mkdir dir="${install.home}/birt"/>
    <unzip src="${install.home}/lib/birt-runtime-${birt.version.as7}.zip"
           dest="${install.home}/birt"/>
   <copy todir="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib">
      <fileset dir="${install.home}/birt/birt-runtime-${birt.version.as7}/ReportEngine/lib">
         <include name="**/*.jar"/>
      </fileset>
   </copy>
   <mkdir dir="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/output"/>
   <mkdir dir="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/reports"/>
   <copy file="${install.home}/report/${birt.version.as7}/overall_activity.rptdesign"
          tofile="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/reports/overall_activity.rptdesign"
          overwrite="true"/>
   <delete dir="${install.home}/birt"/>
  </target>

  <!-- Install reporting AS5  -->
  <target name="install.reporting.into.jboss5" depends="check.birt.as5" if="birt.download" >
    <mkdir dir="${install.home}/target"/>
    <unzip src="${install.home}/lib/birt-runtime-${birt.version.as5}.zip"
           dest="${install.home}/target"/>
    <mkdir dir="${jboss.server.data.dir}/birt"/>
    <mkdir dir="${jboss.server.data.dir}/birt/ReportEngine"/>
    <copy todir="${jboss.server.data.dir}/birt/ReportEngine" overwrite="true">
      <fileset dir="${install.home}/target/birt-runtime-2_3_2/ReportEngine"/>
    </copy>
    <copy file="${install.home}/report/${birt.version.as5}/overall_activity.rptdesign"
          tofile="${jboss.server.data.dir}/birt/overall_activity.rptdesign"
          overwrite="true"/>
    <copy file="${install.home}/report/${birt.version.as5}/process_summary.rptdesign"
          tofile="${jboss.server.data.dir}/birt/process_summary.rptdesign"
          overwrite="true"/>
    <copy todir="${jboss.server.data.dir}/birt/ReportEngine/plugins/org.eclipse.birt.report.data.oda.jdbc_2.3.2.r232_v20090212/drivers" overwrite="true">
      <fileset dir="${install.home}/db/driver"/>
    </copy>
    <!-- Replace the reporting jars -->
    <delete file="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/report-core-1.4.0-SNAPSHOT.jar"/>
    <delete file="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/report-shared-1.4.0-SNAPSHOT.jar"/>   
    <get src="https://repository.jboss.org/nexus/content/repositories/releases/org/jboss/bpm/report-core/1.3.0/report-core-1.3.0.jar" 
         dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="https://repository.jboss.org/nexus/content/repositories/releases/org/jboss/bpm/report-shared/1.3.0/report-shared-1.3.0.jar" 
         dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/eclipse/birt/engineapi/2.3.2/engineapi-2.3.2.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/eclipse/birt/dteapi/2.3.2/dteapi-2.3.2.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/eclipse/birt/chartengineapi/2.3.2/chartengineapi-2.3.2.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/eclipse/birt/coreapi/2.3.2/coreapi-2.3.2.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/eclipse/birt/dataadapterapi/2.3.2/dataadapterapi-2.3.2.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/eclipse/birt/modelapi/2.3.2/modelapi-2.3.2.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/eclipse/birt/scriptapi/2.3.2/scriptapi-2.3.2.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/eclipse/emf/ecore/2.4.2/ecore-2.4.2.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/eclipse/emf/ecore-xmi/2.4.1/ecore-xmi-2.4.1.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/eclipse/emf/common/2.4.0/common-2.4.0.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/w3c/flute/1.2/flute-1.2.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/w3c/sac/1.3/sac-1.3.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repo1.maven.org/maven2/commons-cli/commons-cli/1.0/commons-cli-1.0.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repo1.maven.org/maven2/commons-discovery/commons-discovery/0.2/commons-discovery-0.2.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repo1.maven.org/maven2/com/lowagie/itext/1.3/itext-1.3.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/com/ibm/icu/icu4j/3.8.1/icu4j-3.8.1.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
    <get src="http://repo1.maven.org/maven2/rhino/js/1.6R2/js-1.6R2.jar" dest="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" />
  </target>
  
  <!-- Install Eclipse -->
  <target name="install.eclipse" depends="download.eclipse,download.eclipse.gef">   
    <antcall target="unzipEclipse" />	
    <antcall target="untarEclipse" />
    <unzip dest="${install.home}" overwrite="true" 
           src="${install.home}/lib/GEF-SDK-3.6.2.zip" />				         
  </target>
  
  <target name="unzipEclipse" if="expandTypeZip">
    <unzip dest="${install.home}" overwrite="true" 
           src="${install.home}/lib/eclipse-java-helios-SR2-${download.type}.zip" />  
  </target>

  <target name="untarEclipse" if="expandTypeTarGz">
    <gunzip src="${install.home}/lib/eclipse-java-helios-SR2-${download.type}.tar.gz"/>
    <untar dest="${install.home}" src="${install.home}/lib/eclipse-java-helios-SR2-${download.type}.tar" />
    <chmod perm="a+x" file="${install.home}/eclipse/eclipse" os="Linux"/>
    <chmod perm="a+x" file="${install.home}/eclipse/Eclipse.app/Contents/MacOS/eclipse" os="Mac OS X"/>
  </target>

  <!-- Install Eclipse plugins -->
  <target name="install.jBPM.runtime" depends="download.jBPM.bin">
    <!-- create runtime -->
    <mkdir dir="${install.home}/runtime"/>
    <unzip src="${install.home}/lib/jbpm-${jBPM.version}-bin.zip" dest="${install.home}/runtime" />
  </target>

  <!-- Install Eclipse plugins -->
  <target name="install.droolsjbpm-eclipse.into.eclipse" depends="download.droolsjbpm.eclipse">
    <!-- install plugins -->
    <mkdir dir="${eclipse.home}/droolsjbpm-update-site"/>
    <unzip src="${install.home}/lib/org.drools.updatesite-${droolsjbpm.eclipse.version}-assembly.zip" dest="${eclipse.home}/droolsjbpm-update-site" />
    <copy todir="${eclipse.home}/features" overwrite="true">
      <fileset dir="${eclipse.home}/droolsjbpm-update-site/features"/>
    </copy>
    <copy todir="${eclipse.home}/plugins" overwrite="true">
      <fileset dir="${eclipse.home}/droolsjbpm-update-site/plugins"/>
    </copy>
    <delete dir="${eclipse.home}/droolsjbpm-update-site"/>
  </target>

  <!-- Install Demo -->
  <target name="install.demo" depends="install.jboss,install.guvnor.into.jboss,install.designer.into.jboss,install.jBPM-gwt-console.into.jboss,install.eclipse,install.jBPM.runtime,install.droolsjbpm-eclipse.into.eclipse" />

  <!-- Install Demo (Eclipse) -->
  <target name="install.demo.eclipse" depends="install.eclipse,install.jBPM.runtime,install.droolsjbpm-eclipse.into.eclipse" />

  <!-- Install Demo (No Eclipse) -->
  <target name="install.demo.noeclipse" depends="install.jboss,install.guvnor.into.jboss,install.designer.into.jboss,install.jBPM-gwt-console.into.jboss,install.jBPM.runtime" />

  <!-- Install Demo (DB == No Eclipse) -->
  <target name="install.demo.db" depends="install.demo.noeclipse" />
  
  <!-- ############ START/STOP ############ -->

  <!-- Start H2 server -->
  <target name="start.h2" depends="download.h2">
    <java classname="org.h2.tools.Server" fork="true" spawn="true">
      <arg value="-tcp" />
      <classpath location="${install.home}/db/driver/h2.jar" />
    </java>
  </target>

  <!-- Stop H2 server -->
  <target name="stop.h2" depends="download.h2">
    <java classname="org.h2.tools.Server" fork="true">
      <classpath location="${install.home}/db/driver/h2.jar" />
      <arg value="-tcpShutdown" />
      <arg value="tcp://localhost:9092" />
    </java>
  </target>

  <!-- Start JBoss AS -->
  <target name="start.jboss">
    <antcall target="start.jboss5" />
    <antcall target="start.jboss7" />
  </target>
  <target name="start.jboss7" depends="check.jboss.version" if="jboss.version.is.7">
    <property name="jboss.full.path.win" location="${jboss.home}/bin/standalone.bat" />
    <exec executable="${jboss.full.path.win}" spawn="yes"
          osfamily="windows">
      <env key="JAVA_OPTS" value="-XX:MaxPermSize=256m -Xms256m -Xmx512m" />
      <arg value="-b" />
      <arg value="${jboss.bind.address}" />
      <arg value="-Djbpm.console.directory=${install.home}/sample/evaluation/src/main/resources" />
      <arg value="-Dreporting.needcontext=true" />
    </exec>
    <property name="jboss.full.path.linux" location="${jboss.home}/bin/standalone.sh" />
    <exec executable="${jboss.full.path.linux}" spawn="yes" osfamily="unix">
      <env key="JAVA_OPTS" value="-XX:MaxPermSize=256m -Xms256m -Xmx512m" />
      <arg value="-b" />
      <arg value="${jboss.bind.address}" />
      <arg value="-Djbpm.console.directory=${install.home}/sample/evaluation/src/main/resources" />
      <arg value="-Dreporting.needcontext=true" />
    </exec>
    <waitfor maxwait="5" maxwaitunit="minute" checkevery="10"
             checkeveryunit="second" timeoutproperty="jboss.timeout">
      <socket server="${jboss.bind.address}" port="8080" />
    </waitfor>
    <fail if="jboss.timeout" message="JBoss AS7 did not start within 5 minutes"/>
  </target>
  <target name="start.jboss5" depends="check.jboss.version" unless="jboss.version.is.7">
    <property name="jboss.full.path.win" location="${jboss.home}/bin/run.bat" />
    <exec executable="${jboss.full.path.win}" spawn="yes"
          osfamily="windows">
      <env key="JAVA_OPTS" value="-XX:MaxPermSize=256m -Xms256m -Xmx512m" />
      <arg value="-b" />
      <arg value="${jboss.bind.address}" />
      <arg value="-Djbpm.console.directory=${install.home}/sample/evaluation/src/main/resources" />
    </exec>
    <property name="jboss.full.path.linux" location="${jboss.home}/bin/run.sh" />
    <exec executable="${jboss.full.path.linux}" spawn="yes" osfamily="unix">
      <env key="JAVA_OPTS" value="-XX:MaxPermSize=256m -Xms256m -Xmx512m" />
      <arg value="-b" />
      <arg value="${jboss.bind.address}" />
      <arg value="-Djbpm.console.directory=${install.home}/sample/evaluation/src/main/resources" />
    </exec>
    <waitfor maxwait="10" maxwaitunit="minute" checkevery="30"
             checkeveryunit="second" timeoutproperty="jboss.timeout">
      <socket server="${jboss.bind.address}" port="8080" />
    </waitfor>
    <fail if="jboss.timeout" message="JBoss AS5 did not start within 10 minutes"/>
  </target>

  <!-- Stop JBoss AS -->
  <target name="stop.jboss">
    <antcall target="stop.jboss5" />
    <antcall target="stop.jboss7" />
  </target>
  <target name="stop.jboss7" depends="check.jboss.version" if="jboss.version.is.7">
    <exec executable="${jboss.home}/bin/jboss-admin.bat"
          osfamily="windows">
      <arg value="--connect" />
      <arg value="command=:shutdown" />
    </exec>
    <exec executable="${jboss.home}/bin/jboss-admin.sh" osfamily="unix">
      <arg value="--connect" />
      <arg value="command=:shutdown" />
    </exec>
  </target>
  <target name="stop.jboss5" depends="check.jboss.version" unless="jboss.version.is.7">
    <exec executable="${jboss.home}/bin/shutdown.bat"
          osfamily="windows">
      <arg value="-s" />
      <arg value="jnp://${jboss.bind.address}:1099" />
      <arg value="-S" />
    </exec>
    <exec executable="${jboss.home}/bin/shutdown.sh" osfamily="unix">
      <arg value="-s" />
      <arg value="jnp://${jboss.bind.address}:1099" />
      <arg value="-S" />
    </exec>
  </target>

  <!-- Start Eclipse -->
  <target name="start.eclipse">
    <exec executable="${eclipse.home}/eclipse.exe"
          spawn="yes"
          osfamily="windows">
      <arg value="-data" />
      <arg value="${eclipse.workspace.dir}" />
      <arg value="-plugincustomization" />
      <arg value="./eclipse.preferences.ini" />
      <arg value="-perspective" />
      <arg value="org.jbpm.eclipse.JBPMPerspective" />
    </exec>
    <exec executable="${eclipse.home}/eclipse" spawn="yes" os="Linux">
      <arg value="-data" />
      <arg value="${eclipse.workspace.dir}" />
      <arg value="-plugincustomization" />
      <arg value="./eclipse.preferences.ini" />
      <arg value="-perspective" />
      <arg value="org.jbpm.eclipse.JBPMPerspective" />
    </exec>
  	<chmod perm="a+x" file="./generate.mac.eclipse.preferences.sh" />
    <exec executable="./generate.mac.eclipse.preferences.sh" osfamily="mac"/>
    <exec executable="${eclipse.home}/Eclipse.app/Contents/MacOS/eclipse" spawn="yes" osfamily="mac">
      <arg value="-data" />
      <arg value="../../../../${eclipse.workspace.dir}" />
      <arg value="-plugincustomization" />
      <arg value="../../../../mac.eclipse.preferences.ini" />
      <arg value="-perspective" />
      <arg value="org.jbpm.eclipse.JBPMPerspective" />
    </exec>
  </target>

  <!-- Start Human Task Service -->
  <path id="classpath.human.task">
    <fileset dir="${install.home}/runtime" includes="**/*.jar"/>
    <fileset dir="${install.home}/db/driver" includes="**/*.jar"/>
  </path>
 
  <target name="start.human.task">
    <mkdir dir="${install.home}/task-service/target"/>
    <javac srcdir="${install.home}/task-service/src" destdir="${install.home}/task-service/target" classpathref="classpath.human.task">
      <compilerarg value="-Xlint:unchecked"/>
    </javac>
    <copy todir="${install.home}/task-service/target">
      <fileset dir="${install.home}/task-service/resources"/>
    </copy>
    <java classname="org.jbpm.DemoTaskService" fork="true">  
      <classpath>
        <pathelement path="${install.home}/task-service/target"/>
        <path refid="classpath.human.task" />
      </classpath>
    </java>
  </target>

  <!-- Start Demo -->
  <target name="start.demo" depends="start.h2,start.jboss,start.eclipse,start.human.task" />
  
  <!-- Start Demo (Eclipse) -->
  <target name="start.demo.eclipse" depends="start.h2,start.eclipse,start.human.task" />

  <!-- Start Demo (No Eclipse)--> 
  <target name="start.demo.noeclipse" depends="start.h2,start.jboss,start.human.task" />	
  
  <!-- Start Demo (Database)--> 
  <target name="start.demo.db" depends="install.db.files,start.jboss,start.human.task" />	
  
  <!-- Stop Demo -->
  <target name="stop.demo" depends="stop.h2,stop.jboss" />

  <!-- Stop Demo (Database) -->
  <target name="stop.demo.db" depends="stop.jboss,remove.db.files" />

  <!-- ############ CLEAN ############ -->
	
  <!-- Clean jboss -->
  <target name="clean.jboss">
    <delete dir="${jboss.home}"/>
    <delete dir="${install.home}/repository"/>
    <delete file="${install.home}/repository.xml"/>
  </target>

  <!-- Clean eclipse -->
  <target name="clean.eclipse">
    <delete dir="${install.home}/eclipse"/>
    <delete dir="${install.home}/runtime"/>
    <delete dir="${eclipse.workspace.dir}"/>
  </target>

  <!-- Clean Demo -->
  <target name="clean.demo" depends="clean.jboss,clean.eclipse" />
  <!-- Clean Demo (No Eclipse) -->
  <target name="clean.demo.noeclipse" depends="clean.jboss" />
	
</project>
