<project name="${plugin.name} Plugin" default="createNpm" basedir="..">
   <description>Builds the ${plugin.name} Plugin project. Precompiles Jsps
   Compiles Java Logs compile errors to ${plugin.name.small}Compile.err Makes
   Jar Makes Npm Inserts Manifest into Jar and Npm Creates Javadoc liked to
   Source Deploys to Tomcat</description>

   <tstamp />

   <property file=".\build scripts\env.txt" />
   <property name="plugin.version" value="${imanager.version}.${DSTAMP}" />   
<!-- Please uncomment the variables which you do not place in env.txt. 



   <property name="plugin.desc"
   value="Priority Sync policies and partition management plugin." />

   <property name="plugin.title" value="Priority Sync" />

   <property name="plugin.name" value="PS" />

   <property name="plugin.name.small" value="ps" />   

   <property name="debug" value="off" />

   <property name="optimize" value="on" />

   <property name="deprecation" value="off" />

   <property name="verbose" value="5" />

   <property name="compress" value="on" />
   -->

   <property name="package.admin.dir"
   value="com/novell/admin/${plugin.name.small}" />

   <property name="webapp.name" value="nps" />
	
   <property name="resources.src.dir" value="src/${package.admin.dir}" />
	
   <property name="resources.dest.dir" value = "${package.admin.dir}" />

   <property name="plugin.name.caps" value="${plugin.name}" />

   <property name="plugin.npm.name" value="${plugin.name.caps}" />

   <property name="plugin.jar" value="${plugin.name.caps}" />

   

   <property name="class.dir" value="classes" />

   <property name="product.dir" value="product" />

   <property name="staging.dir" value="npm2" />

   <property name="precompiled.dir"
   value="${staging.dir}\compiledjsps\nps\portal\modules\${plugin.name}\skins\default\devices\default" />

   <property name="webapp.lib.dir"
   value="${NPS_TOMCAT}/webapps/nps/WEB-INF/lib" />

   <property name="common.lib.dir" value="../external/jclient" />

   <property name="jar.name"
   value="${staging.dir}/currentwebapp/WEB-INF/lib/${plugin.jar}.jar" />

   <property name="npm.name" value="${plugin.npm.name}.npm" />

   <property name="tomcat.dir" value="${NPS_TOMCAT}" />

   <property name="jasper.home" value="${tomcat.dir}/bin" />

   <property name="deploy.dir" value="${tomcat.dir}/webapps/${webapp.name}" />

   <property name="jsp.dir"
   value="${deploy.dir}/portal/modules/${plugin.name}/skins/default/devices/default" />

   <path id="local.class.path">
      <pathelement location="${tomcat.dir}/common/lib/ant.jar" />

      <pathelement location="${tomcat.dir}/common/lib/servlet.jar" />

      <pathelement location="${tomcat.dir}/common/lib/jasper-compiler.jar" />

      <pathelement location="${tomcat.dir}/common/lib/jasper-runtime.jar" />

      <pathelement location="${tomcat.dir}/bin/commons-logging-api.jar" />

      <pathelement location="${tomcat.dir}/common/lib/mail.jar" />

      <pathelement path="{class.dir}" />

      <pathelement location="${webapp.lib.dir}/${webapp.name}.jar" />

      <pathelement location="${jar.name}" />

      <pathelement location="${tomcat.dir}/common/lib/servlet.jar" />

      <pathelement location="${tomcat.dir}/common/lib/jasper-compiler.jar" />

      <pathelement location="${tomcat.dir}/common/lib/jasper-runtime.jar" />

      <pathelement location="${tomcat.dir}/common/lib/ant.jar" />

      <pathelement location="${java.home}/../lib/tools.jar" />

      <pathelement location="${webapp.lib.dir}/AdminNamespace.jar" />

      <pathelement location="${webapp.lib.dir}/cos.jar" />

      <pathelement location="${webapp.lib.dir}/eMFrame.jar" />

      <pathelement location="${webapp.lib.dir}/iManagerBase.jar" />

      <pathelement location="${webapp.lib.dir}/iManagerBaseExt.jar" />

      <pathelement location="${webapp.lib.dir}/iManTagLibrary.jar" />

      <pathelement location="${webapp.lib.dir}/imap.jar" />

      <pathelement location="${webapp.lib.dir}/jaxen-full.jar" />

      <pathelement location="${webapp.lib.dir}/jcert.jar" />

      <pathelement location="${webapp.lib.dir}/jcifs.jar" />

      <pathelement location="${webapp.lib.dir}/jclient.jar" />

      <pathelement location="${webapp.lib.dir}/jdom.jar" />

      <pathelement location="${webapp.lib.dir}/jnet.jar" />

      <pathelement location="${webapp.lib.dir}/jsso.jar" />

      <pathelement location="${webapp.lib.dir}/jstl.jar" />

      <pathelement location="${webapp.lib.dir}/ldap.jar" />

      <pathelement location="${webapp.lib.dir}/ldapbp.jar" />

      <pathelement location="${webapp.lib.dir}/local_policy.jar" />

      <pathelement location="${webapp.lib.dir}/LogEvent.jar" />

      <pathelement location="${webapp.lib.dir}/NetComponents.jar" />

      <pathelement location="${webapp.lib.dir}/novbp.jar" />

      <pathelement location="${webapp.lib.dir}/nps.jar" />

      <pathelement location="${webapp.lib.dir}/observer.jar" />

      <pathelement location="${webapp.lib.dir}/pop3.jar" />

      <pathelement location="${webapp.lib.dir}/rbsCore.jar" />

      <pathelement location="${webapp.lib.dir}/saxpath.jar" />

      <pathelement location="${webapp.lib.dir}/smtp.jar" />

      <pathelement location="${webapp.lib.dir}/snmp2.jar" />

      <pathelement location="${webapp.lib.dir}/standard.jar" />

      <pathelement location="${webapp.lib.dir}/sunjce_provider.jar" />

      <pathelement location="${webapp.lib.dir}/US_export_policy.jar" />

      <pathelement location="${webapp.lib.dir}/WebServiceSDK.jar" />

      <pathelement location="${webapp.lib.dir}/xp.jar" />

      <pathelement location="${webapp.lib.dir}/xtier.jar" />
   </path>

   <patternset id="resource.files">
      <include name="${plugin.name.caps}_Resources*.properties" />
   </patternset>

   <patternset id="image.files.neutral">
      <include name="*.gif" />
   </patternset>

   <patternset id="manifest">
      <include name="*.MF" />
   </patternset>

   <patternset id="tld">
      <include name="*.tld" />
   </patternset>

<!--
    ************************************************************************
        createStageDirs:
            Create the proper directory structure in the staging area.
    ************************************************************************
    -->
   <target name="createStageDirs">
      <mkdir dir="${class.dir}" />

      <mkdir
      dir="${staging.dir}/currentwebapp/portal/modules/${plugin.name}/help" />

      <mkdir
      dir="${staging.dir}/currentwebapp/portal/modules/${plugin.name}/images" />

      <mkdir
      dir="${staging.dir}/currentwebapp/portal/modules/${plugin.name}/install" />

      <mkdir
      dir="${staging.dir}/currentwebapp/portal/modules/${plugin.name}/javascripts" />

      <mkdir
      dir="${staging.dir}/currentwebapp/portal/modules/${plugin.name}/plugins" />

      <mkdir
      dir="${staging.dir}/currentwebapp/portal/modules/${plugin.name}/skins/default/devices/default" />

      <mkdir dir="${staging.dir}/currentwebapp/WEB-INF/lib" />

      <mkdir dir="${precompiled.dir}" />
   </target>

<!--
    ************************************************************************
        createDeployDirs:
            Create the proper directory structure in the deployment area.
    ************************************************************************
    -->
   <target name="createDeployDirs">
      <mkdir dir="${deploy.dir}/portal/modules/${plugin.name}/help" />

      <mkdir dir="${deploy.dir}/portal/modules/${plugin.name}/images" />

      <mkdir dir="${deploy.dir}/portal/modules/${plugin.name}/install" />

      <mkdir dir="${deploy.dir}/portal/modules/${plugin.name}/javascripts" />

      <mkdir dir="${deploy.dir}/portal/modules/${plugin.name}/plugins" />

      <mkdir
      dir="${deploy.dir}/portal/modules/${plugin.name}/skins/default/devices/default" />
   </target>

<!--
    ************************************************************************
        stageStaticFiles:
            Copy non-buildable files from the source directory structure into
            the staging area.
    ************************************************************************
    -->
   <target name="stageStaticFiles" depends="createStageDirs">
<!-- JSP files -->
      <copy
      todir="${staging.dir}/currentwebapp/portal/modules/${plugin.name}/skins/default/devices/default"
       preservelastmodified="yes">
         <fileset
         dir="npm/currentwebapp/portal/modules/${plugin.name}/skins/default/devices/default" />
      </copy>

<!-- resources: copy to ouput for inclusion in the .jar file. -->
      <copy
      todir="${staging.dir}/currentwebapp/WEB-INF/classes/${resources.dest.dir}"
      preservelastmodified="yes">
         <fileset dir="${resources.src.dir}">
            <patternset refid="resource.files" />
         </fileset>
      </copy>

<!-- help files -->
      <copy
      todir="${staging.dir}/currentwebapp/portal/modules/${plugin.name}/help"
      preservelastmodified="yes">
         <fileset dir="npm/currentwebapp/portal/modules/${plugin.name}/help" />
      </copy>

<!-- image files -->
      <copy
      todir="${staging.dir}/currentwebapp/portal/modules/${plugin.name}/images"
      preservelastmodified="yes">
         <fileset dir="npm/currentwebapp/portal/modules/${plugin.name}/images">
            <patternset refid="image.files.neutral" />
         </fileset>
      </copy>
      
<!-- eDirectory image files -->
      <copy
      todir="${staging.dir}/currentwebapp/portal/modules/dev/images/dir"
      preservelastmodified="yes" failonerror="false">
         <fileset dir="npm/currentwebapp/portal/modules/dev/images/dir">
            <patternset refid="image.files.neutral" />
         </fileset>
      </copy>

<!-- install .xml files -->
      <copy
      todir="${staging.dir}/currentwebapp/portal/modules/${plugin.name}/install"
       preservelastmodified="yes">
         <fileset
         dir="npm/currentwebapp/portal/modules/${plugin.name}/install" />
      </copy>

<!-- plugins .xml files -->
      <copy
      todir="${staging.dir}/currentwebapp/portal/modules/${plugin.name}/plugins"
       preservelastmodified="yes">
         <fileset
         dir="npm/currentwebapp/portal/modules/${plugin.name}/plugins" />
      </copy>

<!-- javascripts files -->
      <copy
      todir="${staging.dir}/currentwebapp/portal/modules/${plugin.name}/javascripts"
       preservelastmodified="yes">
         <fileset
         dir="npm/currentwebapp/portal/modules/${plugin.name}/javascripts" />
      </copy>
   </target>

<!--
    ************************************************************************
        deployStaticFiles:
            Copy non-buildable files from the source directory structure into
            the deployment area.
    ************************************************************************
    -->
   <target name="deployStaticFiles" depends="createDeployDirs">
<!-- JSP files -->
      <copy
      todir="${deploy.dir}/currentwebapp/portal/modules/${plugin.name}/skins/default/devices/default"
       preservelastmodified="yes">
         <fileset
         dir="npm/currentwebapp/portal/modules/${plugin.name}/skins/default/devices/default" />
      </copy>

<!-- TLD files -->
      <copy
      todir="${deploy.dir}/portal/modules/${plugin.name}/skins/default/devices/default/WEB-INF"
       preservelastmodified="yes">
         <fileset dir="${deploy.dir}/WEB-INF/">
            <patternset refid="tld" />
         </fileset>
      </copy>

<!-- resources: copy to ouput for inclusion in the .jar file. -->
      <copy
      todir="${deploy.dir}/currentwebapp/WEB-INF/classes/${resources.dest.dir}"
      preservelastmodified="yes">
         <fileset dir="${resources.src.dir}">
            <patternset refid="resource.files" />
         </fileset>
      </copy>

<!-- help files -->
      <copy
      todir="${deploy.dir}/currentwebapp/portal/modules/${plugin.name}/help"
      preservelastmodified="yes">
         <fileset dir="npm/currentwebapp/portal/modules/${plugin.name}/help" />
      </copy>

<!-- image files -->
      <copy
      todir="${deploy.dir}/currentwebapp/portal/modules/${plugin.name}/images"
      preservelastmodified="yes">
         <fileset dir="npm/currentwebapp/portal/modules/${plugin.name}/images">
            <patternset refid="image.files.neutral" />
         </fileset>
      </copy>

<!-- eDirectory image files -->
      <copy
      todir="${deploy.dir}/currentwebapp/portal/modules/dev/images/dir"
      preservelastmodified="yes" failonerror="false">
         <fileset dir="npm/currentwebapp/portal/modules/dev/images/dir">
            <patternset refid="image.files.neutral" />
         </fileset>
      </copy>

<!-- install .xml files -->
      <copy
      todir="${deploy.dir}/currentwebapp/portal/modules/${plugin.name}/install"
      preservelastmodified="yes">
         <fileset
         dir="npm/currentwebapp/portal/modules/${plugin.name}/install" />
      </copy>

<!-- plugins .xml files -->
      <copy
      todir="${deploy.dir}/currentwebapp/portal/modules/${plugin.name}/plugins"
      preservelastmodified="yes">
         <fileset
         dir="npm/currentwebapp/portal/modules/${plugin.name}/plugins" />
      </copy>

<!-- javascripts files -->
      <copy
      todir="${deploy.dir}/currentwebapp/portal/modules/${plugin.name}/javascripts"
       preservelastmodified="yes">
         <fileset
         dir="npm/currentwebapp/portal/modules/${plugin.name}/javascripts" />
      </copy>
   </target>

<!--
    ************************************************************************
        deployJars:
            Copy ndsservicemanager.jar from the staging area to the deployment area.
    ************************************************************************
    -->
   <target name="deployJars" depends="createDeployDirs,createJar">
      <copy file="${jar.name}" todir="${deploy.dir}/WEB-INF/lib"
      preservelastmodified="yes" />
   </target>

<!--
    ************************************************************************
        clean:
            Remove all Cert Plugin files from the staging area.
    ************************************************************************
    -->
   <target name="clean">
      <delete dir="${class.dir}" />

      <delete dir="${staging.dir}" />

      <delete dir="${precompiled.dir}" />

      <delete file="${npm.name}" />
   </target>

<!--
    ************************************************************************
        cleanDeployDir:
            Remove all Cert Plugin files from the deployment area.
    ************************************************************************
    -->
   <target name="cleanDeployDir">
      <delete dir="${deploy.dir}/portal/modules/${plugin.name}" />

      <delete file="${deploy.dir}/WEB-INF/lib/${jar.name}" />
   </target>

<!--
    ************************************************************************
        compile:
            Compile the .java source files.
    ************************************************************************
    -->
   <target name="compile" depends="createStageDirs">
      <record name="${plugin.name.small}Compile.err" append="no"
      loglevel="debug" action="start" />

      <javac destdir="${class.dir}" optimize="${optimize}"
      deprecation="${deprecation}" debug="${debug}"
      classpathref="local.class.path" verbose="${verbose}">
         <src path="./src/" />
      </javac>

      <record name="${plugin.name.small}Compile.err" action="stop" />
   </target>

<!--
    ************************************************************************
        createJar:
            Bundle the web application's .class files into a .jar file.
    ************************************************************************
    -->
   <target name="createJar" depends="compile,stageStaticFiles">
     

      <jar jarfile="${jar.name}" compress="${compress}">
         <fileset dir="${class.dir}" />

         <fileset dir="./src/${package.admin.dir}">
            <patternset refid="resource.files" />
         </fileset>

         <manifest>
            <attribute name="Module-ID" value="${plugin.name.caps}" />

            <attribute name="Implementation-Title" value="${plugin.title}" />

            <attribute name="Implementation-Description"
            value="${plugin.desc}" />

            <attribute name="Implementation-Version"
            value="${plugin.version}" />
         </manifest>
      </jar>
   </target>

<!--
    ************************************************************************
        createNpm:
            Bundle the entire web application into a .npm file.
    ************************************************************************
    -->
   <target name="createNpm"
   depends="clean,cleanDeployDir,createJar,precompileJSP">
      

      <jar jarfile="${npm.name}" compress="${compress}">
         <fileset dir="${staging.dir}" />

         <manifest>
            <attribute name="Module-ID" value="${plugin.name.caps}" />

            <attribute name="Implementation-Title" value="${plugin.title}" />

            <attribute name="Implementation-Description"
            value="${plugin.desc}" />

            <attribute name="Implementation-Version"
            value="${plugin.version}" />
         </manifest>
      </jar>
      
      <copy todir="${tomcat.dir}/webapps/nps/packages" preservelastmodified="yes">
         <fileset dir=".">
           <include name="${npm.name}" />
         </fileset>
      </copy>
   </target>

<!--
    ************************************************************************
        precompileJSP:
            Copy the jsp files to plugin deploy directory,precompile the jsp
            files to java,compile java files to bytecode,copy the class files
            to npm build directory. Copying is required as precompilation can
            be done only on deployed jsp files.

            jsp.dir-${deploy.dir}/portal/modules/${plugin.name}/skins/default
            /devices/default

            deploy.dir-${tomcat.dir}/webapps/${webapp.name}

            precompiled.dir-npm\compiledjsps\nps\portal\modules\${plugin.name}
            \skins\default\devices\default

            templates\browser-source directory of jsp files in workarea

            createStageDirs-makes all npm subdirectories in the workarea
    ************************************************************************
    -->
   <target name="precompileJSP"
   depends="createStageDirs,deployJars,deployStaticFiles">
      <copy todir="${jsp.dir}" preservelastmodified="yes">
         <fileset
         dir="npm/currentwebapp/portal/modules/${plugin.name}/skins/default/devices/default">

            <include name="*.jsp" />
         </fileset>
      </copy>

      <record name="${plugin.name.small}Compile.err" append="yes"
      loglevel="debug" action="start" />

      <jspc classpathref="local.class.path" srcdir="${jsp.dir}"
      verbose="${verbose}" destdir="${jsp.dir}" uribase="${jsp.dir}"
      uriroot="${jsp.dir}" package="org.apache.jsp">
         <include name="*.jsp" />
      </jspc>

      <depend srcdir="${jsp.dir}" destdir="${jsp.dir}"
      cache="build/dependencies" />

      <javac srcdir="${jsp.dir}" classpathref="local.class.path"
      debug="${debug}" deprecation="${deprecation}" verbose="${verbose}">
         <include name="*.java" />
      </javac>

      <record name="${plugin.name.small}Compile.err" action="stop" />

      <copy todir="${basedir}\${precompiled.dir}" preservelastmodified="yes">
         <fileset dir="${jsp.dir}">
            <include name="*.class" />
         </fileset>
      </copy>
   </target>

<!--

    ************************************************************************

        doc:

            Copy appropriate files to the deployment area.

    ************************************************************************

    -->
   <target name="doc" depends="compile">
      <javadoc destdir="docs/api" author="true" version="true" use="true"
      sourcepath="src" linksource="true" classpathref="local.class.path"
      breakiterator="yes" packagenames="*" />
   </target>

<!--
    ************************************************************************
        deploy:
            Copy appropriate files to the deployment area.
    ************************************************************************
    -->
   <target name="deploy" depends="all,deployStaticFiles,deployJars">
   </target>

<!--
    ************************************************************************
        all:
            Start from scratch and rebuild everything.
    ************************************************************************
    -->
   <target name="all" depends="createNpm,doc" />

<!--
    ************************************************************************
        help:
            Give the user information on available build targets.
    ************************************************************************
    -->
   <target name="help">
      <echo
      message="${line.separator} Help screen for building ${plugin.name} Plugin for iManager ${line.separator} ${line.separator} All compilation targets rely on the variable NPS_TOMCAT being ${line.separator} set to the location of TOMCAT_HOME,for example: c:/imgrsdk/tomcat ${line.separator} in 'build scripts\env.txt'.${line.separator} ${line.separator} Can be invoked from 'build scripts' directory only.${line.separator} ${line.separator} Usage: %ANT_HOME%\bin\ant.bat -f build.xml [target]${line.separator} ${line.separator} all = Build everything without deploying.${line.separator} clean = Remove all plugin files from the staging area.${line.separator} cleanDeployDir = Remove all plugin files from the deployment area.${line.separator} compile = Compile all java sources.${line.separator} createDeployDirs = Create the directory structure in the deployment area. ${line.separator} createJar = Create ${plugin.name}.jar from the compiled .class files.${line.separator} createNpm = Create ${plugin.name}.npm from the contents of the staging area. ${line.separator} createStageDirs = Create the directory structure in the staging area. ${line.separator} deploy = Build everything and deploy all plugin files.${line.separator} deployJars = Copy ${plugin.name}.jar to the deployment area. ${line.separator} deployStaticFiles = Copy all static files to the deployment area.${line.separator} doc = Generate javadoc for all java sources.${line.separator} precompileJSP= Precompiles jsp files to java and then compiles them to class.${line.separator} stageStaticFiles = Copy all static files to the staging area.${line.separator} ${line.separator} The default target is 'all'.${line.separator} " />
   </target>
</project>

