<project name="misc examples build" default="build-all">
    <property name="src.root" value="src/main/org/jboss/book/misc" />
    <property name="chapter.dir" value="${build.dir}/misc"/>
    
    <path id="chapter.path">
        <pathelement location="src/main" />
        <pathelement location="output/classes" />
        <pathelement path="${client.path}" />
    </path>
       
    <target name="prepare">
        <mkdir dir="${chapter.dir}"/>
    </target>
    
    <target name="build-all">
        <antcall target="misc-ex2-sar" />
    </target>
    
    <target name="config">
        
    </target>

    <target name="misc-ex2-sar" depends="prepare">
        <jar jarfile="${chapter.dir}/misc-ex2.sar">
            <metainf dir="${src.root}/ex2" includes="jboss-service.xml"/>
            <fileset dir="${build.classes.dir}">
                <include name="org/jboss/book/misc/ex2/*" />
            </fileset>
        </jar>
    </target>
    <!-- Examples -->
    
    <target name="run-example1">
        <!-- Create a copy of jboss.deploy.conf as jboss0 -->
        <echo message="Preparing jboss0 configuration fileset"/>
        <mkdir dir="${jboss.dist}/server/jboss0"/>
        <copy todir="${jboss.dist}/server/jboss0">
            <fileset dir="${jboss.dist}/server/${jboss.deploy.conf}">
                <exclude name="data/**"/>
                <exclude name="deploy/chap*"/>
                <exclude name="log/**"/>
                <exclude name="tmp/**"/>
            </fileset>
        </copy>

        <echo message="Copying misc-ex1-bindings.xml File"/>
        <copy todir="${jboss.dist}/server/"
              file="${src.resources}/misc-ex1-bindings.xml"/>

        <echo message="Update jboss-service.xml to use misc-ex1-bindings.xml"/>
 	<replace file="${jboss.dist}/server/jboss0/conf/jboss-service.xml">
            <replacetoken><![CDATA[<!-- @TESTSUITE_CLUSTER_CONFIG@ -->]]></replacetoken>
            <replacevalue><![CDATA[
   <mbean code="org.jboss.services.binding.ServiceBindingManager"
     name="jboss.system:service=ServiceBindingManager">
     <attribute name="ServerName">${jboss.server.name}</attribute>
     <attribute name="StoreURL">${jboss.server.base.dir}/misc-ex1-bindings.xml</attribute>
     <attribute name="StoreFactoryClassName">
       org.jboss.services.binding.XMLServicesStoreFactory
     </attribute>
   </mbean>
            ]]></replacevalue>
         </replace>

        <echo message="Preparing jboss1 configuration fileset"/>
        <mkdir dir="${jboss.dist}/server/jboss1"/>
        <copy todir="${jboss.dist}/server/jboss1">
            <fileset dir="${jboss.dist}/server/jboss0">
                <exclude name="data/**"/>
                <exclude name="log/**"/>
                <exclude name="tmp/**"/>
            </fileset>
        </copy>
    </target>
    
    <target name="run-example2" depends="misc-ex2-sar">
        <copy file="${chapter.dir}/misc-ex2.sar" todir="${jboss.deploy.dir}"
              overwrite="true" />
    </target>
    
    <target name="run-examplebind">
        <java classname="org.jboss.book.misc.jndibind.Lookup"
              classpathref="chapter.path" fork="true" />
    </target>
</project>
