<project name="blog5" default="build" basedir=".">
    <description>
        A simple build script.
    </description>
  <!-- set global properties for this build -->
  <!-- change glassfish.home to point to appropriate location -->
  <property name="glassfish.home" location="/home/ss141213/ROOT/WS/gf/publish/glassfish"/>
  <property name="build" location="build"/>

  <target name="init">
    <!-- Create the build directory structure -->
    <mkdir dir="${build}/entities/META-INF"/>
    <mkdir dir="${build}/ejb-interfaces"/>
    <mkdir dir="${build}/ejbs"/>
    <mkdir dir="${build}/web-app2/WEB-INF/classes"/>
    <mkdir dir="${build}/lib"/>
    <mkdir dir="${build}/appclient"/>
  </target>

  <target name="build-entities" depends="init" 
        description="compile the entity beans and prepare a PU jar file." >
    <javac classpath="${glassfish.home}/lib/javaee.jar" 
           srcdir="entities/src" 
           destdir="${build}/entities"/>
    <copy file="entities/persistence.xml" todir="${build}/entities/META-INF"/>
    <jar destfile="${build}/entities.jar" basedir="${build}/entities"/>
  </target>

  <target name="build-ejb-interfaces" depends="build-entities" 
        description="compile the ejb interface classes and prepare a jar file.">
    <javac classpath="${glassfish.home}/lib/javaee.jar" 
           srcdir="ejbs/src" 
           destdir="${build}/ejb-interfaces" 
           includes="example/ejb/interfaces/**">
      <classpath>
        <pathelement location="${glassfish.home}/lib/javaee.jar"/>
        <pathelement location="${build}/entities.jar"/>
      </classpath>
    </javac>
    <jar destfile="${build}/ejb-interfaces.jar" basedir="${build}/ejb-interfaces"/>
  </target>

  <target name="build-ejbs" depends="build-ejb-interfaces"
        description="compile the EJBs and prepare a jar file">
    <javac srcdir="ejbs/src"
           destdir="${build}/ejbs"
           includes="example/ejb/impl/**">
      <classpath>
        <pathelement location="${glassfish.home}/lib/javaee.jar"/>
        <pathelement location="${build}/entities.jar"/>
        <pathelement location="${build}/ejb-interfaces.jar"/>
      </classpath>
    </javac>
    <jar destfile="${build}/ejbs.jar" basedir="${build}/ejbs"/>
  </target>
  
  <target name="build-web-app" depends="build-ejb-interfaces" 
        description="compile the servlets and prepare a war file">
    <javac srcdir="web-app2/src" 
           destdir="${build}/web-app2/WEB-INF/classes">
      <classpath>
        <pathelement location="${glassfish.home}/lib/javaee.jar"/>
        <pathelement location="${build}/ejb-interfaces.jar"/>
        <pathelement location="${build}/entities.jar"/>
      </classpath>
    </javac>
    <copy file="web-app2/web.xml" todir="${build}/web-app2/WEB-INF"/>
    <copy todir="${build}/web-app2/">
      <fileset dir="web-app2">
        <include name="**/*.html"/>
      </fileset>
    </copy>
    <jar destfile="${build}/web-app2.war" basedir="${build}/web-app2"/>
  </target>
  
  <target name="build-appclient" depends="build-ejb-interfaces"
        description="compile the appclient classes and prepare a jar file">
    <javac srcdir="appclient/src"
           destdir="${build}/appclient">
      <classpath>
        <pathelement location="${glassfish.home}/lib/javaee.jar"/>
        <pathelement location="${build}/entities.jar"/>
        <pathelement location="${build}/ejb-interfaces.jar"/>
      </classpath>
    </javac>
    <jar destfile="${build}/appclient.jar" basedir="${build}/appclient"
         manifest="appclient/manifest.mf"/>
  </target>

  <target name="build" depends="build-ejbs, build-web-app, build-appclient" 
          description="build the application">
    <copy file="${build}/entities.jar" todir="${build}/lib"/>
    <copy file="${build}/ejb-interfaces.jar" todir="${build}/lib"/>
    <jar destfile="${build}/blog5.ear" basedir="${build}"
         includes="lib/*.jar ejbs.jar appclient.jar web-app2.war"/>
  </target>

  <target name="clean" description="clean up" >
    <delete dir="${build}"/>
  </target>

  <!-- The following three targets are Sun Java System App Server specific -->
  <target name="verify" depends="build" 
          description="verify compliance of the app against Java EE spec">
    <exec executable="${glassfish.home}/bin/verifier" 
          failonerror="true" 
          vmlauncher="false">
      <arg line="-p -d ${build} ${build}/blog5.ear"/>
    </exec>
  </target>

  <target name="deploy" depends="build"
          description="deploy to Sun Java System Application Server">
    <exec executable="${glassfish.home}/bin/asadmin" 
          failonerror="true" 
          vmlauncher="false">
      <arg line="deploy --user admin --passwordfile .adminpassword.txt --createtables ${build}/blog5.ear"/>
    </exec>
  </target>

  <target name="undeploy" 
          description="undeploy from Sun Java System Application Server">
    <exec executable="${glassfish.home}/bin/asadmin" 
          failonerror="true" 
          vmlauncher="false">
      <arg line="undeploy --user admin  --passwordfile .adminpassword.txt blog5"/>
    </exec>
  </target>

</project>
