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

<project name="jBPM.install">

  <property file="build.properties" />

  <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="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://download.eclipse.org/birt/downloads/drops/R-R1-3_7_0-201106151818/birt-runtime-3_7_0.zip&amp;mirror_id=1"/>
  <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"/>
	
  <property name="jpa.version" value="JPA2"/>
  <property name="hibernate.tools.4.download.url" value="https://repository.jboss.org/nexus/content/groups/public/org/hibernate/hibernate-tools/4.0.0-CR1/hibernate-tools-4.0.0-CR1.jar"/>
  <property name="hibernate.tools.3.download.url" value="https://repository.jboss.org/nexus/content/groups/public/org/hibernate/hibernate-tools/3.2.4.GA/hibernate-tools-3.2.4.GA.jar"/>
  <property name="hibernate4.download.url" value="https://repository.jboss.org/nexus/content/groups/public/org/hibernate"/>
  <property name="freemarker.download.url" value="https://repository.jboss.org/nexus/content/repositories/central/org/freemarker/freemarker/2.3.19/freemarker-2.3.19.jar"/>
  <property name="jboss.logging.download.url" value="https://repository.jboss.org/nexus/content/groups/public/org/jboss/logging/jboss-logging/3.1.2.GA/jboss-logging-3.1.2.GA.jar"/>
	
  <path id="generate.ddl.JPA1.class.path">
    <fileset dir="${install.home}/runtime">
      <include name="**/*.jar"/>
      <exclude name="jbpm-test-*.jar"/>
    </fileset>
    <fileset dir="${install.home}/db/driver">
      <include name="**/*.jar"/>
    </fileset>
    <fileset dir="${install.home}/lib/ddl-dependencies">
      <include name="hibernate-tools3.jar"/>
      <include name="freemarker-*.jar"/>
    </fileset>
  </path>
    
  <path id="generate.ddl.JPA2.class.path">
    <fileset dir="${install.home}/runtime">
      <include name="*.jar"/>
      <exclude name="jbpm-test-*.jar"/>
    </fileset>
    <fileset dir="${install.home}/db/driver">
      <include name="**/*.jar"/>
    </fileset>
    <fileset dir="${install.home}/lib/ddl-dependencies">
      <include name="*.jar"/>
      <exclude name="hibernate-tools3.jar"/>
    </fileset>
    <fileset dir="${install.home}/runtime/lib/">
      <include name="drools*.jar"/>
      <include name="knowledge*.jar"/>
      <include name="protobuf*.jar"/>
      <include name="slf4j*.jar"/>
      <include name="log4j*.jar"/>
      <include name="commons-logging*.jar"/>
      <include name="commons-collections*.jar"/>
      <include name="dom4j-1.6.1.jar"/>
      <include name="antlr-2.7.7.jar"/>
      <include name="hibernate-jpa-2.0-api*.jar"/>
      <include name="jta-1.1.jar"/>
      <include name="javassist-*.jar"/>
    </fileset>
  </path>
    
  <path id="runtime.class.path">
    <fileset dir="${install.home}/runtime/">
      <include name="*.jar"/>
      <exclude name="jbpm-test-*.jar"/>
    </fileset>
    <fileset dir="${install.home}/runtime/lib/">
      <include name="drools*.jar"/>
    </fileset>
  </path>	
	
  <!-- ############ DOWNLOAD ############ -->

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

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

  <target name="install.db.files" depends="check.jboss.version,download.db.driver" if="db.driver.module.prefix" unless="jboss.version.is.5">
    <mkdir dir="${db.driver.module.dir}" />
    <copy file="${db.driver.jar}" tofile="${db.driver.module.dir}/${db.driver.jar.name}" />
    <copy file="db/${db.name}_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" />
  	<mkdir dir="${install.home}/lib/birt"/>
    <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}/lib/birt" />
    <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}/lib/birt" />
    <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}/lib/birt" />
    <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}/lib/birt" />
    <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}/lib/birt" />
    <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}/lib/birt" />
    <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}/lib/birt" />
    <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}/lib/birt" />
    <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}/lib/birt" />
    <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}/lib/birt" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/w3c/flute/1.2/flute-1.2.jar" dest="${install.home}/lib/birt" />
    <get src="http://repository.jboss.org/nexus/content/groups/public/org/w3c/sac/1.3/sac-1.3.jar" dest="${install.home}/lib/birt" />
    <get src="http://repo1.maven.org/maven2/commons-cli/commons-cli/1.0/commons-cli-1.0.jar" dest="${install.home}/lib/birt" />
    <get src="http://repo1.maven.org/maven2/commons-discovery/commons-discovery/0.2/commons-discovery-0.2.jar" dest="${install.home}/lib/birt" />
    <get src="http://repo1.maven.org/maven2/com/lowagie/itext/1.3/itext-1.3.jar" dest="${install.home}/lib/birt" />
    <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}/lib/birt" />
    <get src="http://repo1.maven.org/maven2/rhino/js/1.6R2/js-1.6R2.jar" dest="${install.home}/lib/birt" />
  </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://archive.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/jbpm-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}/jbpm-designer-${designer.version}.war" dest="${install.home}/lib/jbpm-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 ...${deployment.version}" />
    <condition property="jBPM.gwt-console.not.available">
      <and>
    	<not>
          <available file="${install.home}/lib/jbpm-gwt-console-server-${jBPM.version}-${deployment.version}.war" />
        </not>
      </and>
    </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.console.server.url}" dest="${install.home}/lib/jbpm-gwt-console-server-${jBPM.version}-${deployment.version}.war"  />
  	<get src="${jBPM.console.url}" dest="${install.home}/lib/jbpm-gwt-console-${jBPM.version}.war"  />
  </target>

  <!-- Download form builder -->
  <target name="download.form.builder.check">
  	<echo message="Checking Form Builder download ..." />
  	<condition property="form.builder.not.available">
  	  <not>
  		<available file="${install.home}/lib/jbpm-${jBPM.version}-form-builder.war" />
  	  </not>
    </condition>
  </target>
  <target name="download.form.builder" depends="download.form.builder.check" if="form.builder.not.available">
  	<echo message="Getting Form Builder ..." />
  	<mkdir dir="${install.home}/lib"/>
  	<get src="${form.builder.url}" dest="${install.home}/lib/jbpm-${jBPM.version}-form-builder.war" />
  </target>
	
  <!-- Download jBPM human task server war -->
  <target name="download.jBPM.ht-war.check">
    <echo message="Checking jBPM human task war download ..." />
    <condition property="jBPM.ht-war.not.available">
      <not>
        <available file="${install.home}/lib/jbpm-human-task-war-${jBPM.version}-${deployment.version}.war" />
      </not>
    </condition>
  </target>
  <target name="download.jBPM-ht.war" depends="download.jBPM.ht-war.check" if="jBPM.ht-war.not.available">
    <echo message="Getting jBPM human task war ..." />
    <mkdir dir="${install.home}/lib"/>
    <get src="${ht.server.url}" dest="${install.home}/lib/jbpm-human-task-war-${jBPM.version}-${deployment.version}.war"  />
  </target>
	
  <target name="download.transport.lib.check" if="jboss.version.is.5">
    <echo message="Checking Transport lib download ..." />
    <condition property="transport.lib.not.available">
	<and>
	  <not>
        <available file="${jboss.server.lib.dir}/hornetq-core-2.2.10.Final.jar" />
      </not>
	  <not>
        <available file="${jboss.server.lib.dir}/netty-3.2.0.Final.jar" />
      </not>
	</and>
    </condition>
  </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-cli.sh" />
  </target>
	
  <!-- transport libs (hornetq and netty) must be placed on server/lib for AS 5 to ensure proper deployment as netty registers itself using beans.xml
   and that cannot be done twice thus these libs are not included in wars 
  -->	
  <target name="install.transport.lib" depends="download.transport.lib.check" if="transport.lib.not.available">
  	<get src="https://repository.jboss.org/nexus/content/groups/public/org/hornetq/hornetq-core/2.2.10.Final/hornetq-core-2.2.10.Final.jar" dest="${jboss.server.lib.dir}"  />
  	<get src="https://repository.jboss.org/nexus/content/groups/public/org/jboss/netty/netty/3.2.0.Final/netty-3.2.0.Final.jar" dest="${jboss.server.lib.dir}"  />
  </target>	

  <!-- Install guvnor -->
  <target name="install.guvnor.into.jboss" depends="download.drools.guvnor,check.jboss.version" if="jboss.version.is.7">
    <mkdir dir="${install.home}/target"/>
    <unzip src="${install.home}/lib/guvnor-distribution-wars-${drools.guvnor.version}.war" dest="${install.home}/target" />
    <copy file="${install.home}/conf/guvnor.preferences.properties"
          tofile="${install.home}/target/WEB-INF/classes/preferences.properties"
          overwrite="true" />
    <zip basedir="${install.home}/target"
         destfile="${install.home}/target/guvnor-distribution-wars-${drools.guvnor.version}.war"/>
    <copy file="${install.home}/target/guvnor-distribution-wars-${drools.guvnor.version}.war"
          tofile="${jboss.server.deploy.dir}/drools-guvnor.war"
          overwrite="true" />
    <delete dir="${install.home}/target"/>
  </target>  	

  <!-- Install designer -->
  <target name="install.designer.into.jboss" depends="download.designer,check.jboss.version">
    <copy file="${install.home}/lib/jbpm-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.db.driver,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">
    <!-- download reporting -->
    <antcall target="download.birt.as7" />
    <!-- gwt-console -->
    <mkdir dir="${install.home}/target"/>
    <mkdir dir="${install.home}/target/jbpm-gwt-console-server-war"/>
    <unzip src="${install.home}/lib/jbpm-gwt-console-server-${jBPM.version}-${deployment.version}.war"
           dest="${install.home}/target/jbpm-gwt-console-server-war"/>
    <copy todir="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib" overwrite="true">
      <fileset dir="${install.home}/db/driver"/>
    </copy>
    <!-- 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>
  	<!-- copy user defined persistence configuration if exists -->
  	<copy tofile="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/classes/META-INF/persistence.xml" overwrite="true" 
  		file="${install.home}/db/jbpm-persistence.xml" failonerror="false"/>
  	<copy tofile="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/classes/META-INF/ProcessInstanceInfoMapping.xml" overwrite="true" 
  		file="${install.home}/db/ProcessInstanceInfoMapping.xml" failonerror="false"/>

    <!-- install reporting -->
    <antcall target="install.reporting.into.jboss7" />
  	<!-- install dependencies -->
  	<antcall target="install.dependencies" />
    <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}/lib/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" />
    <!-- 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>
  <target name="install.jBPM-gwt-console.into.jboss5" depends="check.jboss.version,install.transport.lib" unless="jboss.version.is.7">
    <!-- download reporting -->
    <antcall target="download.birt.as5" />
    <!-- gwt-console -->
    <mkdir dir="${install.home}/target"/>
    <mkdir dir="${install.home}/target/jbpm-gwt-console-server-war"/>
    <unzip src="${install.home}/lib/jbpm-gwt-console-server-${jBPM.version}-${deployment.version}.war"
           dest="${install.home}/target/jbpm-gwt-console-server-war"/>
    <!-- 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>
  	<!-- copy user defined persistence configuration if exists -->
    <copy tofile="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/classes/META-INF/persistence.xml" overwrite="true" 
    	file="${install.home}/db/jbpm-persistence.xml" failonerror="false"/>
    <copy tofile="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/classes/META-INF/ProcessInstanceInfoMapping.xml" overwrite="true"
    	file="${install.home}/db/ProcessInstanceInfo.hbm.xml" failonerror="false"/>

    <!-- install reporting -->
    <antcall target="install.reporting.into.jboss5" />
  	<!-- install dependencies -->
  	<antcall target="install.dependencies" />
    <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}/lib/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 form builder -->
  <target name="install.form.builder.into.jboss" depends="download.form.builder" if="jboss.version.is.7">
    <mkdir dir="${install.home}/target"/>
    <mkdir dir="${install.home}/target/jbpm-form-builder-war"/>
    <unzip src="${install.home}/lib/jbpm-${jBPM.version}-form-builder.war" dest="${install.home}/target/jbpm-form-builder-war" />
    <copy file="${install.home}/auth/users.properties"
          tofile="${install.home}/target/jbpm-form-builder-war/WEB-INF/classes/users.properties" 
          overwrite="true" />
    <copy file="${install.home}/auth/roles.properties"
          tofile="${install.home}/target/jbpm-form-builder-war/WEB-INF/classes/roles.properties" 
          overwrite="true" />
    <zip basedir="${install.home}/target/jbpm-form-builder-war"
         destfile="${install.home}/target/jbpm-${jBPM.version}-form-builder.war" />
    <copy file="${install.home}/target/jbpm-${jBPM.version}-form-builder.war" 
          tofile="${jboss.server.deploy.dir}/jbpm-form-builder.war" 
          overwrite="true" />
    <delete dir="${install.home}/target" />
  </target>
	
	
  <!-- Install jbpm human task war -->
  <target name="install.jBPM-ht.into.jboss" depends="download.db.driver,download.jBPM-ht.war,install.transport.lib">
    <antcall target="install.ht.war.into.jboss5" />
    <antcall target="install.ht.war.into.jboss7" />
  </target>	

  <!-- Install jbpm human task war -->
  <target name="install.ht.war.into.jboss7" if="jboss.version.is.7">
    <mkdir dir="${install.home}/target"/>
    <mkdir dir="${install.home}/target/jbpm-human-task-war"/>
    <unzip src="${install.home}/lib/jbpm-human-task-war-${jBPM.version}-${deployment.version}.war" dest="${install.home}/target/jbpm-human-task-war" />
  	<copy file="${install.home}/task-service/resources/war/web.xml" 
  	          tofile="${install.home}/target/jbpm-human-task-war/WEB-INF/web.xml" 
  	          overwrite="true" />
    <!-- copy user defined persistence configuration if exists -->
    <copy tofile="${install.home}/target/jbpm-human-task-war/WEB-INF/classes/META-INF/persistence.xml" overwrite="true" 
    	file="${install.home}/db/task-persistence.xml" failonerror="false"/>
    <copy tofile="${install.home}/target/jbpm-human-task-war/WEB-INF/classes/META-INF/ProcessInstanceInfoMapping.xml" overwrite="true"
    	file="${install.home}/db/Taskorm.xml" failonerror="false"/>
    <zip basedir="${install.home}/target/jbpm-human-task-war"
         destfile="${install.home}/target/jbpm-${jBPM.version}-human-task-war.war" />
    <copy file="${install.home}/target/jbpm-${jBPM.version}-human-task-war.war" 
          tofile="${jboss.server.deploy.dir}/jbpm-human-task-war.war" 
          overwrite="true" />
    <delete dir="${install.home}/target" />
  </target>
	
  <!-- Install jbpm human task war -->
  <target name="install.ht.war.into.jboss5"  unless="jboss.version.is.7">
    <mkdir dir="${install.home}/target"/>
    <mkdir dir="${install.home}/target/jbpm-human-task-war"/>
    <unzip src="${install.home}/lib/jbpm-human-task-war-${jBPM.version}-${deployment.version}.war" dest="${install.home}/target/jbpm-human-task-war" />
  	<copy file="${install.home}/task-service/resources/war/web.xml" 
  	              tofile="${install.home}/target/jbpm-human-task-war/WEB-INF/web.xml" 
  	              overwrite="true" />
    <!-- copy user defined persistence configuration if exists -->
    <copy tofile="${install.home}/target/jbpm-human-task-war/WEB-INF/classes/META-INF/persistence.xml" overwrite="true"
    	file="${install.home}/db/task-persistence.xml" failonerror="false"/>
    <copy tofile="${install.home}/target/jbpm-human-task-war/WEB-INF/classes/META-INF/ProcessInstanceInfoMapping.xml" overwrite="true"
    	file="${install.home}/db/Taskorm.xml" failonerror="false"/>
  	
    <zip basedir="${install.home}/target/jbpm-human-task-war"
         destfile="${install.home}/target/jbpm-${jBPM.version}-human-task-war.war" />
    <copy file="${install.home}/target/jbpm-${jBPM.version}-human-task-war.war" 
          tofile="${jboss.server.deploy.dir}/jbpm-human-task-war.war" 
          overwrite="true" />
    <delete dir="${install.home}/target" />
  </target>
	
  <!-- Install dependencies -->
  <target name="install.dependencies">	
  	<copy todir="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib">
  		<fileset dir="${install.home}/dependencies">
  		  <include name="**/*.jar"/>
  		</fileset>
    </copy>
  </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"/>
      	 <exclude name="org.apache.commons.codec*.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>
      <fileset dir="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib/" includes="report-core-*.jar,report-shared-*.jar" />
    </delete>
    <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" />
  	<copy todir="${install.home}/target/jbpm-gwt-console-server-war/WEB-INF/lib">
  		<fileset dir="${install.home}/lib/birt"/>
  	</copy>
  </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.db.files,install.guvnor.into.jboss,install.designer.into.jboss,install.jBPM-gwt-console.into.jboss,install.jBPM-ht.into.jboss,install.form.builder.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.db.files,install.guvnor.into.jboss,install.designer.into.jboss,install.jBPM-gwt-console.into.jboss,install.jBPM-ht.into.jboss,install.form.builder.into.jboss,install.jBPM.runtime" />
  
  <!-- ############ START/STOP ############ -->
  <target name="start.h2.check">
    <echo message="Checking if h2 db should be started ..." />
    <condition property="start.h2.db">
      <equals arg1="${db.name}" arg2="h2"/>
    </condition>
  </target>	

  <!-- Start H2 server -->
  <target name="start.h2" depends="download.db.driver,start.h2.check" if="start.h2.db">
    <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.db.driver,start.h2.check" if="start.h2.db">
    <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" />
      <arg value="-Djboss.server.config.dir=${jboss.server.conf.dir}" />
    </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" />
      <arg value="-Djboss.server.config.dir=${jboss.server.conf.dir}" />
    </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-cli.bat"
          osfamily="windows">
      <arg value="--connect" />
      <arg value="command=:shutdown" />
    </exec>
    <exec executable="${jboss.home}/bin/jboss-cli.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 Demo (Eclipse) -->
  <target name="start.demo.eclipse" depends="start.h2,start.eclipse" />

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


  <!-- ############ CLEAN ############ -->
	
  <!-- Clean jboss -->
  <target name="clean.jboss" depends="check.clean.repository">
    <delete dir="${jboss.home}"/>
  	<antcall target="clean.jboss.repository" />    
  </target>
	
  <target name="clean.db" >
    <delete file="${user.home}/jbpm.h2.db" failonerror="false"/>
  	<delete file="${user.home}/jbpm.trace.db" failonerror="false"/>
  </target>

  <target name="clean.jboss.repository" if="clean.repository">
  	<delete dir="${install.home}/repository"/>
  	<delete file="${install.home}/repository.xml"/>
  </target>
	
  <target name="check.clean.repository">
    <condition property="clean.repository">
	  <equals arg1="${jboss.clean.repository}" arg2="true" />
	</condition>
  </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.generated.ddl,clean.db" />
  <!-- Clean Demo (No Eclipse) -->
  <target name="clean.demo.noeclipse" depends="clean.jboss,clean.generated.ddl,clean.db" />
	
  <!-- ############### generate DDL out of persitence.xml ############### -->
	<target name="download.ddl.check">
	    <echo message="Checking if ddl generation dependencies jars has been downloaded ..." />
	    <condition property="ddl.dependencies.not.available">
	      <not>
	        <available file="${install.home}/lib/ddl-dependencies" />
	      </not>
	    </condition>
	  </target>	
	
  <target name="download.ddl.dependencies" depends="download.ddl.check" if="ddl.dependencies.not.available">
    <echo message="Getting hibernate4 libs ..." />
    <mkdir dir="${install.home}/lib/ddl-dependencies"/>
    <get src="${hibernate4.download.url}/hibernate-core/4.1.0.Final/hibernate-core-4.1.0.Final.jar" dest="${install.home}/lib/ddl-dependencies" />
  	<get src="${hibernate4.download.url}/hibernate-entitymanager/4.1.0.Final/hibernate-entitymanager-4.1.0.Final.jar" dest="${install.home}/lib/ddl-dependencies" />
    <get src="${hibernate4.download.url}/common/hibernate-commons-annotations/4.0.1.Final/hibernate-commons-annotations-4.0.1.Final.jar" dest="${install.home}/lib/ddl-dependencies" />
  	<get src="${jboss.logging.download.url}" dest="${install.home}/lib/ddl-dependencies" />
  	
  	<echo message="Getting freemarker ..." />
  	<get src="${freemarker.download.url}" dest="${install.home}/lib/ddl-dependencies" />
  	
  	<echo message="Getting hibernate tools 4 ..." />
  	<get src="${hibernate.tools.4.download.url}" dest="${install.home}/lib/ddl-dependencies/hibernate-tools4.jar" />
  	
  	<echo message="Getting hibernate tools 3 ..." />
  	<get src="${hibernate.tools.3.download.url}" dest="${install.home}/lib/ddl-dependencies/hibernate-tools3.jar" />
  </target>
	
	<!-- Clean generated ddl -->
	<target name="clean.generated.ddl" >
		<delete dir="db/export-jbpm"/>
		<delete dir="db/export-ht"/>
	</target>
	
	<target name="jbpm.schemaexport" depends="install.jBPM.runtime,download.ddl.dependencies">
	  <delete dir="db/export-jbpm"/>
	  <!-- task definition; project.class.path contains all necessary libs -->
	  <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
	      classpathref="generate.ddl.${jpa.version}.class.path" />
	  <mkdir dir="db/export-jbpm"/>
	  <mkdir dir="db/export-jbpm/META-INF"/>
	  <copy tofile="db/export-jbpm/META-INF/persistence.xml" file="db/jbpm-persistence-${jpa.version}.xml"/>
	  <copy todir="db/export-jbpm/META-INF">
    	  <fileset dir="db/">
    	  	<include name="ProcessInstanceInfo.hbm.xml"/>
    	  	<include name="ProcessInstanceInfoMapping.xml"/>
    	  </fileset>
	  </copy>	
	  <hibernatetool destdir="db/export-jbpm">
	    <jpaconfiguration persistenceunit="org.jbpm.persistence.jpa.ddl" />
	    <classpath>
    	    <pathelement path="${runtime.class.path}"/>
	    	<dirset dir="db/export-jbpm/">
	        </dirset>
	    </classpath>
	    <hbm2ddl outputfilename="jbpmschemaexport.sql" format="true"
	        export="false" drop="true" />
	  </hibernatetool>
	  <delete dir="db/export-jbpm/META-INF"/>
	</target>

   <target name="ht.schemaexport" depends="install.jBPM.runtime,download.ddl.dependencies">
      <delete dir="db/export-ht"/>
      <!-- task definition; project.class.path contains all necessary libs -->
      <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
          classpathref="generate.ddl.${jpa.version}.class.path" />
      <mkdir dir="db/export-ht"/>
      <mkdir dir="db/export-ht/META-INF"/>
   	  <copy tofile="db/export-ht/META-INF/persistence.xml" file="db/task-persistence-${jpa.version}.xml"/>
      <copy todir="db/export-ht/META-INF">
        <fileset dir="db/">
      	  <include name="Taskorm-${jpa.version}.xml"/>
        </fileset>
      </copy>   
      <hibernatetool destdir="db/export-ht">
        <jpaconfiguration persistenceunit="org.jbpm.task.ddl" />
        <classpath>
            <pathelement path="${runtime.class.path}"/>
            <dirset dir="db/export-ht/">
            </dirset>
        </classpath>
        <hbm2ddl outputfilename="htschemaexport.sql" format="true"
            export="false" drop="true" />
      </hibernatetool>
      <delete dir="db/export-ht/META-INF"/>
    </target>
</project>
