<project name="ejava" default="all" basedir=".">
   <property name="earfile" value="simpleApp"/>
   <property file="ant.properties"/>
   <property name="src" value="${basedir}"/>
   <property name="classes" value="${basedir}"/>
   <property name="libfile" value="util"/>

   <target name="all" depends="compile">
      <ant antfile="helloWorldEJB/build.xml" target="all" inheritAll="false"/>
      <ant antfile="helloEJB/build.xml" target="all" inheritAll="false"/>
      <ant antfile="helloNameEJB/build.xml" target="all" inheritAll="false"/>
      <ant antfile="simpleWEB/build.xml" target="all" inheritAll="false"/>
      <touch file="META-INF/REDEPLOY"/>
   </target>

   <target name="compile">
      <javac srcdir="${src}" destdir="${classes}" debug="on"
             includes="**/*.java"
             excludes="*EJB/**/*.java, *WEB/**/*.java">
         <classpath path="${j2ee.classes}"/>
         <classpath path="${classes}"/>
      </javac>
   </target>

   <target name="init" depends="">
      <mkdir dir="${app}"/>
   </target>

   <target name="lib" depends="init, compile">
      <jar file="${lib}/${libfile}.jar">
	   <fileset dir="${classes}" 
	            includes="**/*.class,**/*.properties"
		    excludes="*, *EJB/, *WEB/" />
      </jar>
   </target>
   
   <target name="deploy" depends="init, compile, lib">
      <ant antfile="helloWorldEJB/build.xml" 
           target="deploy" 
	   inheritAll="false"/>
      <ant antfile="helloEJB/build.xml" 
           target="deploy" 
	   inheritAll="false"/>
      <ant antfile="helloNameEJB/build.xml" 
           target="deploy" 
	   inheritAll="false"/>
      <ant antfile="simpleWEB/build.xml" 
           target="deploy" 
	   inheritAll="false"/>
      <copy file="META-INF/application.xml" 
            todir="${app}/META-INF"/>
      <replace file="${app}/META-INF/application.xml"
               token="EJB&lt;/ejb&gt;"
	       value="EJB.jar&lt;/ejb&gt;"/>
      <replace file="${app}/META-INF/application.xml"
               token="WEB&lt;/web-uri&gt;"
	       value="WEB.war&lt;/web-uri&gt;"/>
      <ear file="${ear}/${earfile}.ear"
           appxml="${app}/META-INF/application.xml">
	   <fileset dir="${app}" includes="*.jar, *.war"/>
      </ear>
   </target>

   <target name="cleansrc">
      <delete>
         <fileset dir="${basedir}" 
	          defaultexcludes="false"
	          includes="**/*.*~,**/*.bak"/>
      </delete>
   </target>

   <target name="clean" depends="cleansrc">
      <ant antfile="helloWorldEJB/build.xml" 
           target="clean" inheritAll="false"/>
      <ant antfile="helloEJB/build.xml" 
           target="clean" inheritAll="false"/>
      <ant antfile="helloNameEJB/build.xml" 
           target="clean" inheritAll="false"/>
      <ant antfile="simpleWEB/build.xml" 
           target="clean" inheritAll="false"/>
      <delete>
         <fileset dir="${classes}" includes="**/*.class"/>
         <fileset dir="${lib}" includes="${libfile}.jar"/>
         <fileset dir="${ear}" includes="${earfile}.jar"/>
      </delete>
   </target>
</project>
