<?xml version="1.0" encoding="UTF-8"?>
<!--======================================================================-->
<!--                                                                      -->
<!-- JBoss, the OpenSource J2EE webOS                                     -->
<!--                                                                      -->
<!-- Distributable under LGPL license.                                    -->
<!-- See terms of license at http://www.gnu.org.                          -->
<!--                                                                      -->
<!--======================================================================-->
<project default="main" name="JBoss/mod_cluster Demo" xmlns:server="http://jboss.org/ns/test/ant/server">

  <property environment="env"></property>
  
  <!-- TODO: consolidate common properties with build-test.xml -->
  <property name="module.output" location="${basedir}/target"/>
  <property name="module.src" location="${basedir}/src"/>

  <property name="demo.src" location="${module.src}/demo"/>
  <property name="demo.src.java" location="${demo.src}/java"/>
  <property name="demo.src.resources" location="${demo.src}/resources"/>
  <property name="demo.output" location="${module.output}/demo"/>
  <property name="demo.output.classes" location="${demo.output}/classes"/>
  <property name="demo.output.client" location="${demo.output}/client"/>
  <property name="demo.output.server" location="${demo.output}/server"/>
  <property name="demo.client.jar" value="mod-cluster-demo.jar"></property>
  <property name="demo.server.war" value="load-demo.war"></property>
  <property name="demo.dependencies.lib" location="${module.output}/dependencies/lib"></property>
    
  <path id="demo">
    <fileset dir="${demo.dependencies.lib}" includes="*.jar"/>
  </path>
    
  <target name="main" depends="init, compile-demo">
    <jar destfile="${demo.output.client}/lib/${demo.client.jar}">
      <fileset dir="${demo.output.classes}" excludes="**/server/**"></fileset>
      <manifest>
        <attribute name="Main-Class" value="org.jboss.modcluster.demo.client.ModClusterDemo"/>
      </manifest>
    </jar>	
    <copy todir="${demo.output.client}">
    	<fileset dir="${demo.src.resources}"> 
        <include name="run-demo.sh"/>
        <include name="run-demo.bat"/>
      </fileset>
    </copy>  
    <copy todir="${demo.output.client}/lib">
    	<fileset dir="${demo.dependencies.lib}">
        <include name="jcommon.jar"/>
        <include name="jfreechart.jar"/>
      </fileset>
    </copy> 
    <war destfile="${demo.output.server}/${demo.server.war}" webxml="${demo.src.resources}/web.xml">
      <classes dir="${demo.output.classes}" excludes="**/client/**"></classes>
      <lib dir="${demo.dependencies.lib}">
        <include name="commons-httpclient.jar"/>
        <include name="commons-codec.jar"/>
      </lib>
  	</war> 

   <fixcrlf srcdir="${demo.output.client}"
     eol="lf" eof="remove"
     includes="**/*.sh"/>

   <fixcrlf srcdir="${demo.output.client}"
     eol="crlf" eof="remove"
     includes="**/*.bat, **/*.cmd"/>

   <chmod perm="+x">
     <fileset dir="${demo.output.client}">
       <include name="**/*.sh"/>
     </fileset>
   </chmod>
  </target>

  <target name="init">
    <mkdir dir="${demo.output}"/>
    <mkdir dir="${demo.output.classes}"></mkdir>
    <mkdir dir="${demo.output.client}"/>
    <mkdir dir="${demo.output.client}/lib"/>
    <mkdir dir="${demo.output.server}"/>
  </target>
  
  <target name="compile-demo">
    <!-- Why doesn't this work without fork? -->
    <javac destdir="${demo.output.classes}" srcdir="${demo.src.java}" classpathref="demo" fork="true"></javac>
  </target>
  
  <target name="run-demo" depends="main">
    <java jar="${demo.output.client}/${demo.client.jar}" classpathref="demo" fork="true"></java>
  </target>
</project>