<commit_before><?xml version="1.0" encoding="utf-8" ?>

<!-- bda-build-template version 1.6.1 -->

<project name="ncireportwriter-installer" default="upgrade" basedir="."
    xmlns:ivy="antlib:org.apache.ivy.ant"
    >

    <description>
        This build file is part of the bda-build-templates project. This is the master install file for the project.  It should be placed in project/software.  This script is copied into the distribution and  executed from the extracted distribution.  It is run by typing "ant" from the master project build.xml or from command line. This script has two flows install and upgrade.
        Install will do the following
            * Install binaries
            * Configure binaries
            * Install application
            * Configure application
            * Re-create database
            * Upgrade database
        Upgrade will do the following
            * Install application
            * Configure application
            * Upgrade database
        Databases
            * MySQL
            * PostgreSQL
            * Oracle
        This script requires java and ant to run. Every thing else it needs is included in the distribution.
    </description>

    <!-- Properties file related properties and tasks -->

    <property environment="env" />
    <property file="local.properties"/>
    <property file="project.properties"/>
    <property name="properties.file" value="${basedir}/install.properties"/>
    <echo message="Using properties file of ${properties.file}."/>
    <available file="${properties.file}" property="properties.file.exists" />
    <fail unless="properties.file.exists" message="The properties.file ${properties.file} does not exist, please make sure that you pass in an accurate file name with the 'ant -Dproperties.file=somepath/somefile', otherwise the build will fail."/>
    <replaceregexp file="${properties.file}" byline="true" match="^([\w\d.]+)=(.*[\w\d\/\{\}\\]+)[ \t]+\r*$" replace="\1=\2"/>
    <replaceregexp file="${properties.file}" byline="true" match="^([\w\d.]+)=[ \t]+(.*[\w\d\/\{\}\\]+)\r*$" replace="\1=\2"/>
    <property file="${properties.file}" />
    <property name="env.name" value="local"/>

    <property name="project.name" value="ncireportwriter"/>

    <!-- Generic properties -->
    <property name="log.dir" value="${basedir}/logs" />
    <property name="working.dir" value="${basedir}/working" />
    <property name="temp.dir" value="${working.dir}/temp" />

    <!-- Install Time properties -->
    <!-- Source and target directories -->
    <property name="bda-utils.dir" value="bda-utils" />
    <property name="evs-utils.dir" value="evs-utils" />
    <property name="tools.dir" value="${basedir}/${tools.dist.relative.dir}" />
    <property name="common.dir.src" value="${basedir}/${common.dist.relative.dir}" />
    <property name="common.dir.dest" value="${working.dir}/${common.dist.relative.dir}" />
    <property name="db.dir.src" location="${basedir}/${db.dist.relative.dir}" />
    <property name="db.dir.dest" location="${working.dir}/${db.dist.relative.dir}" />
    <property name="db-install.dir.dest" location="${working.dir}/${db-install.dist.relative.dir}" />
    <property name="db-upgrade.dir.dest" location="${working.dir}/${db-upgrade.dist.relative.dir}" />
    <property name="jboss-conf.dir.src" value="${basedir}/${jboss-conf.dist.relative.dir}" />
    <property name="jboss-conf.dir.dest" value="${working.dir}/${jboss-conf.dist.relative.dir}" />

    <!-- Jboss binding configurtion related properties -->

    <property name="jboss.binding.template.location" value="${bda-utils.dir}/resource/${jboss.template.relative.dir}/bindings.xml"/>
    <property name="jboss.service.template.location" value="${bda-utils.dir}/resource/${jboss.template.relative.dir}/jboss-service.xml"/>

    <!-- WAR -->
    <property name="ncireportwriter-webapp.dir.dist" value="${basedir}/${ncireportwriter-webapp.dist.relative.dir}" />
    <property name="ncireportwriter-webapp.ds.file" value="ncireportwriter-ds.xml" />
    <property name="ncireportwriter-webapp.war.file" value="ncireportwriter.war" />
    <property name="ncireportwriter-webapp.prop.file" value="ncireportwriter.properties" />

    <!-- Grid related properties -->
    <!-- Default to false, properties can override -->
    <property name="jboss.ssl.enable" value="false"/>

    <!-- Paths -->
    <path id="bda-utils.classpath">
        <fileset dir="${bda-utils.dir}">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <!-- EVS Paths -->
    <path id="evs-utils.classpath">
        <fileset dir="${evs-utils.dir}">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <!-- Task definitions -->

    <taskdef uri="antlib:org.apache.ant.antunit" resource="org/apache/ant/antunit/antlib.xml" classpathref="bda-utils.classpath"/>
    <taskdef name="for" classname="net.sf.antcontrib.logic.ForTask" classpathref="bda-utils.classpath"/>
    <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="bda-utils.classpath"/>
    <taskdef resource="liquibasetasks.properties" classpathref="bda-utils.classpath"/>
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="bda-utils.classpath"/>

    <!-- EVS Task definitions -->

    <taskdef name="StringEncrypter"
        classname="gov.nih.nci.security.util.AntStringEncrypter">
        <classpath refid="evs-utils.classpath"/>
    </taskdef>

    <!-- Conditionals -->
    <available file="${jboss.home}/server/${jboss.server.name}/conf/jboss-service.xml" property="jboss.exists"/>
    <!-- Includes-->
    <import file="${bda-utils.dir}/bda-build-utils-${bda.version}.xml" />

    <!-- Start logging -->
    <property name="install-logs.dir" location="${log.dir}"/>
    <mkdir dir="${install-logs.dir}"/>

    <tstamp>
        <format property="install.time" pattern="yyyy-MM-dd-HH-mm" />
    </tstamp>
    <record name="${install-logs.dir}/install-${install.time}.log" action="start"/>

    <!-- ****************************** Installer section ********************************** -->

    <target name="diag">
        <echoproperties/>
    </target>

    <target name="common:init:pre">
        <!-- Set application.base.path based on platform -->

        <condition property="application.base.path" value="${application.base.path.linux}">
            <or>
                <os family="unix" />
                <os family="mac" />
            </or>
        </condition>

        <condition property="application.base.path" value="${application.base.path.windows}">
            <os family="windows" />
        </condition>
        <echo message="application.base.path=${application.base.path}"/>
        <property name="jboss.home" value="${application.base.path}/${jboss.relative.path}"/>
        <jboss-version/>

        <!-- Set application.data.path based on platform -->

        <condition property="application.data.path" value="${application.data.path.linux}">
            <or>
                <os family="unix" />
                <os family="mac" />
            </or>
        </condition>
        <condition property="application.data.path" value="${application.data.path.windows}">
            <os family="windows" />
        </condition>
        <echo message="application.data.path=${application.data.path}"/>
    </target>

    <target name="install:jboss:init" depends="common:init:pre" unless="exclude.jboss">
        <!-- determine if port configurations or port lists are being called -->
        <if>
            <isset property="jboss.ncicb-standard.port-config"/>
            <then>
                <!-- Read some port properties from standard bindings file -->
                <echo message="Using JBoss NCICB Standard port configurations"/>
                <if>
                    <equals arg1="${jboss.major.version}" arg2="4"/>
                    <then>
                        <property name="jboss.server.binding.template.location" value="${basedir}/${jboss-bindings.file}"/>
                        <jboss-read-ports
                            jboss.server.bindingfile.location="${jboss.server.binding.template.location}"
                            />
                        <jboss-bindings-validate
                            jboss.server.bindingfile.location="${jboss.server.binding.template.location}"
                    />
                    </then>
                    <elseif>
                        <equals arg1="${jboss.major.version}" arg2="5"/>
                        <then>
                            <property name="jboss.server.binding.template.location" value="${basedir}/${jboss-bindings.file}"/>
                            <property name="jboss.server.bindingfile.location" value="${jboss.home}/server/${jboss.server.name}/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml"/>
                            <property name="temp.ejb.file" value="${temp.dir}/ejb3-connectors-jboss-beans.xml"/>
                            <copy tofile="${temp.ejb.file}" file="${bda-utils.dir}/resource/jboss-5.1.0.GA/ejb3-connectors-jboss-beans.xml"/>
                            <!--
                            <jboss51-bindings-nci
                                jboss.server.bindingfile.location="${jboss-bindings.file}"
                                />
                            -->
                            <jboss51-read-ports-nci
                                jboss.server.bindingfile.location="${jboss-bindings.file}"
                                jboss.server.ejbfile.location="${temp.ejb.file}"
                                />
                        </then>
                    </elseif>
                </if>
                <echo message="http -${jboss.server.port} "/>
                <echo message="http -${jboss.server.jndi.port} "/>
                <properties-exist
                    properties.list="jboss.server.jndi.port,jboss.server.port,jboss.server.ports.name"
                    />
            </then>
            <else>
                <!-- else ensure that all ports are set, since these will be removed from install-properties.template we will verify here.  They have to be removed so the validator works with or without the properties or we have to change the format of the file. -->
                <echo message="Using custom JBoss port configurations"/>
                <if>
                    <equals arg1="${jboss.major.version}" arg2="4"/>
                    <then>
                        <property name="jboss.server.binding.template.location" value="${bda-utils.dir}/resource/${jboss.binaries.relative.dir}/bindings.xml"/>
                    </then>
                    <else>
                        <property name="jboss.server.binding.template.location" value="${bda-utils.dir}/resource/${jboss.binaries.relative.dir}/bindings-jboss-beans.xml"/>

                    </else>
                </if>
                <properties-exist
                    properties.list="jboss.server.jndi.port,jboss.server.port,jboss.cobraorb.port,jboss.hajndi.port,jboss.hajrmi.port,jboss.jmx-rmi.port,jboss.messaging.port,jboss.pooledha.port,jboss.server.bind.port,jboss.server.rmi.port,jboss.service.rmiobject.port,jboss.snmp.port,jboss.snmp-trapd.port,jboss.web.service.port,jboss.unifiedinvoker.port,jboss.hajndi.auto.port,jboss.ssl.port,jboss.jms2.netty.port,jboss.jms2.netty-ssl.port,jboss.transaction.recovery.port,jboss.transaction.status.port,jboss.transaction.processid.port"
                    />
            </else>
        </if>
    </target>

    <target name="common:jboss:init" depends="common:init:pre" unless="exclude.jboss">
        <math result="jboss.ssl.port" operand1="${jboss.server.port}" operation="+" operand2="363" datatype="int"/>
        <property name="jboss.ssl.enable" value="false"/>
        <property name="jboss.home" value="${application.base.path}/${jboss.relative.path}"/>
        <jboss-version/>
        <property name="jboss.application.url" value="http://${jboss.server.hostname}:${jboss.server.port}/${project.name}"/>
        <available file="${jboss.home}/server/${jboss.server.name}/conf/jboss-service.xml" property="jboss.exists"/>
        <basename file="${jboss.ssl.keystore.location}" property="jboss.ssl.keystore.file"/>
        <dirname file="${jboss.ssl.keystore.location}" property="jboss.ssl.keystore.dir"/>
        <basename file="${jboss.grid.secure.cert.location}" property="jboss.grid.secure.cert.file"/>
        <dirname file="${jboss.grid.secure.cert.location}" property="jboss.grid.secure.dir"/>
        <basename file="${jboss.grid.secure.key.location}" property="jboss.grid.secure.key.file"/>
        <property name="jboss.socket.ports" value="${jboss.server.port},${jboss.server.rmi.port},${jboss.server.jndi.port},${jboss.service.rmiobject.port},${jboss.jms.port},${jboss.web.service.port}"/>
    </target>

    <target name="common:init" depends="common:init:pre">
        <property name="install.running" value="true"/>
        <!-- ncireportwriter-webapp can use either Oracle or MySQL or PostgreSQL as its database platform, this is controled by the database.type property.  Based on the value of this property sent several variables for use during install -->
        <echoproperties prefix="database"/>
        <switch value="${database.type}">
            <case value="oracle">
                <property name="database.dialect" value="org.hibernate.dialect.OracleDialect"/>
                <property name="database.driver.file" value="${bda-utils.dir}/ojdbc14-10.2.0.4.0.jar"/>
                <property name="database.driver" value="oracle.jdbc.driver.OracleDriver"/>
                <property name="database.schema" value="${database.name}"/>
            </case>
            <case value="mysql">
                <property name="database.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                <property name="database.driver.file" value="${bda-utils.dir}/mysql-connector-java-5.0.8.jar"/>
                <property name="database.driver" value="com.mysql.jdbc.Driver"/>
                <property name="database.schema" value="${database.name}"/>
            </case>
            <case value="postgresql">
                <property name="database.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
                <property name="database.driver.file" value="${bda-utils.dir}/postgresql-jdbc3-8.3-604.jar"/>
                <property name="database.driver" value="org.postgresql.Driver"/>
                <property name="database.schema" value="public"/>
            </case>
            <default>
                <fail message="Invalid database type ${database.type}"/>
            </default>
        </switch>

        <path id="jdbc.driver.classpath">
            <pathelement location="${database.driver.file}"/>
        </path>

        <property name="properties.template.file" value="${basedir}/properties.template" />
        <filterset id="embedded.filterset">
            <!-- Internal properties that may be used in a filtered copy -->
            <filter token="application.base.path" value="${application.base.path}"/>
            <filter token="application.url" value="${application.url}"/>
            <filter token="database.url" value="${database.url}"/>
            <filter token="database.user" value="${database.user}"/>
            <filter token="database.password" value="${database.password}"/>
            <filter token="database.system.url" value="${database.system.url}"/>
            <filter token="database.driver" value="${database.driver}"/>
            <filter token="database.dialect" value="${database.dialect}"/>
            <!-- added for liquibase -->
            <filter token="db-upgrade.run.dir" value="${db-upgrade.dir.dest}/${database.type}"/>
            <filter token="jboss.home" value="${jboss.home}"/>
            <filter token="hibernate.cfg.file.path" value="${hibernate.cfg.file.path}"/>
            <filter token="env.LOGNAME" value="${env.LOGNAME}"/>
            <filter token="env.JAVA_HOME" value="${env.JAVA_HOME}"/>
            <filter token="project.name" value="project.name"/>
            <filter token="" value=""/>
        </filterset>

        <!--OS Temp dir -->
        <condition property="os.temp.dir" value="/tmp/${project.name}">
            <or>
                <os family="unix" />
                <os family="mac" />
            </or>
        </condition>

        <condition property="os.temp.dir" value="c:/temp/${project.name}">
            <os family="windows" />
        </condition>

        <!--
            Copy files to ensure values containing variables are expanded, such properties are stored in embedded.filterset
            and then copy with filter files
          -->

        <copy todir="${common.dir.dest}" filtering="true">
            <fileset dir="${common.dir.src}">
                <include name="**/*"/>
            </fileset>
            <filterset refid="embedded.filterset"/>
            <filterset>
                <filtersfile file="${properties.file}"/>
                <filtersfile file="project.properties"/>
            </filterset>
        </copy>

    </target>

    <target name="install:common:clean" description="Removes all files from the local filesystem" depends="
        common:init,
        install:jboss:clean
        ">
    </target>

    <target name="install:jboss:clean" unless="exclude.jboss" depends="common:jboss:init, common:init">
        <sleep seconds="5" />
        <property name="backup.count" value="5"/>
        <if>
            <not>
                <equals arg1="${exclude.jboss.backup}" arg2="true"/>
            </not>
            <then>
                <!-- Jboss backup, do not compress until install is finished -->
                <property name="backup.jboss.base.dir" location="${application.base.path}/backup/jboss"/>

                <!-- So these directories won't be included in the backup, they are not needed to use jboss -->
                <delete dir="${jboss.home}/server/${jboss.server.name}/work"/>
                <delete dir="${jboss.home}/server/${jboss.server.name}/tmp"/>

                <backup-dir
                    src.dir="${jboss.home}"
                    backup.base.dir="${backup.jboss.base.dir}"
                    backup.count="${backup.count}"
                    />
            </then>
        </if>
        <delete dir="${jboss.home}"/>
    </target>

    <target name="install:database:prep" description="Copies db files with filtering" unless="exclude.database" depends="common:init">
        <property name="db.prop.list" value="database.url,database.user,database.password,database.name"/>
        <echo  message="Checking if database properties exist: ${db.prop.list}"/>
        <properties-exist properties.list="${db.prop.list}"/>
        <echoproperties prefix="database"/>
        <StringEncrypter string="${database.password}" property="encryptedPassword"/>
        <StringEncrypter string="${rw.admin.user.passwd}" property="encrypted.rw.admin.user.passwd"/>
        <StringEncrypter string="${rw.user.passwd}" property="encrypted.rw.user.passwd"/>
        <filterset id="embedded.filterset">
            <!-- Database connection information -->
            <filter token="database.name" value="${database.name}"/>
            <filter token="database.server" value="${database.server}"/>
            <filter token="database.port" value="${database.port}"/>
            <filter token="database.user" value="${database.user}"/>
            <filter token="database.url" value="${database.url}"/>
            <filter token="database.password" value="${encryptedPassword}"/>
            <!-- User login information -->
            <filter token="rw.admin.user.name" value="${rw.admin.user.name}"/>
            <filter token="rw.admin.user.passwd" value="${encrypted.rw.admin.user.passwd}"/>
            <filter token="rw.admin.user.email" value="${rw.admin.user.email}"/>
            <filter token="rw.user.name" value="${rw.user.name}"/>
            <filter token="rw.user.passwd" value="${encrypted.rw.user.passwd}"/>
            <filter token="rw.user.email" value="${rw.user.email}"/>
        </filterset>
        <copy todir="${db.dir.dest}" filtering="true">
            <fileset dir="${db.dir.src}">
                <include name="**/*"/>
            </fileset>
            <filterset refid="embedded.filterset"/>
            <filterset>
                <filtersfile file="${properties.file}"/>
                <filtersfile file="project.properties"/>
                <filter token="db-upgrade.run.dir" value="${working.dir}/db/db-upgrade/${database.type}"/>
            </filterset>
        </copy>
        <mkdir dir="${os.temp.dir}/${project.name}"/>
        <copy todir="${os.temp.dir}/${project.name}" filtering="true" flatten="true" overwrite="true">
            <fileset dir="${db.dir.dest}">
                <include name="**/db-upgrade.xml"/>
            </fileset>
        </copy>
    </target>

    <target name="install:database" description="Runs database creation scripts then calls uprade database." unless="exclude.database"
        depends="

        common:init,
        install:database:prep,
        install:database:validation:pre-install
        ">
        <!-- Drop all schema objects or re-create the db -->
        <database-clean/>
        <!-- Run baseline scripts stored in db.install.create.${database.type}.file.list variable -->
        <switch value="${database.type}">
            <case value="oracle">
                <database-install
                    db.install.create.file.list="${db.install.create.oracle.file.list}"
                    sql.delimiter="/"
                    sql.delimitertype="row"
                    />
            </case>
            <case value="postgresql">
                <database-install
                    db.install.create.file.list="${db.install.create.postgresql.file.list}"
                    sql.delimiter="/"
                    sql.delimitertype="row"
                    />
            </case>
            <case value="mysql">
                <database-install
                    db.install.create.file.list="${db.install.create.mysql.file.list}"
                    />
            </case>
        </switch>
        <database-upgrade
            database.changelog.file="${os.temp.dir}/${project.name}/db-upgrade.xml"
            />
        <database-tag/>

        <!-- Remove old reports from the download folder -->

        <delete quiet="true" includeemptydirs="true">
            <fileset dir="${application.data.path}/${report.download.directory}" includes="**/*.txt" />
            <fileset dir="${application.data.path}/${report.download.directory}" includes="**/*.xls" />
        </delete>

    </target>

    <target name="install:jboss:binaries" description="Install JBoss binaries" unless="exclude.jboss" depends="common:jboss:init, common:init">
        <jboss-install-binaries/>
        <jboss-nci-customizations/>
    </target>

    <target name="install:jboss:ncireportwriter-webapp:filesystem-data"  depends="common:jboss:init, common:init">
        <!-- This target is a place holder for creating a file-system data repository.  If you do not use one you can remove this target and all targets that refer to it. If you require a certain directory structure be sure to create it here.  If you need to copy in files, make sure to check them into svn, copy them into the distribution and then copy them to thier ultimate directory.  If your data needs to be refreshed with each install make sure to delete the base directory, then create the structure and copy in data.  Also you can use an archive file with relative pathing inside to build out the structure if you like, using an archive like zip may shrink the footprint in svn.
        <mkdir dir="${fs-data.base.dir}"/>
        <mkdir dir="${fs-data.base.dir}/scratch"/>
        <copy file="${ncireportwriter-webapp.dir.dist}/${ncireportwriter-webapp.war.file}" todir="${fs-data.base.dir}/scratch" overwrite="true" />
        -->
    </target>

    <target name="install:jboss:ncireportwriter-webapp" description="Deploy ncireportwriter-webapp and common libraries to jboss installation" unless="exclude.jboss"
        depends="common:jboss:init, common:init">
        <!-- added to ensure working.dirs are fresh for our install -->
        <delete dir="${jboss.home}/server/${jboss.server.name}/tmp"/>
        <delete dir="${jboss.home}/server/${jboss.server.name}/work"/>
        <move file="${jboss.home}/server/${jboss.server.name}/log/server.log" tofile="${jboss.home}/server/${jboss.server.name}/log/server/log.${install.time}" failonerror="false"/>
        <copy file="${ncireportwriter-webapp.dir.dist}/${ncireportwriter-webapp.war.file}"
             todir="${jboss.home}/server/${jboss.server.name}/deploy"
             overwrite="true">
        </copy>
        <!--  Many NCI applications require clm for csm, so you can point this to where you have the version you want to use -->
        <copy file="${ncireportwriter-webapp.dir.dist}/deploy/clm.jar"
            todir="${jboss.home}/server/${jboss.server.name}/lib"
            overwrite="true">
        </copy>
        <copy file="${ncireportwriter-webapp.dir.dist}/upt.war"
             todir="${jboss.home}/server/${jboss.server.name}/deploy"
             overwrite="true">
         </copy>
        <!-- Copy datbase driver -->
        <copy file="${database.driver.file}" todir="${jboss.home}/server/${jboss.server.name}/lib" overwrite="true" />
    </target>

    <target name="install:jboss:ncireportwriter-webapp:configure" description="Configure ncireportwriter-webapp application, copies over externalized properties or configurations that are not part of the jboss configuration"
        unless="exclude.jboss" depends="-install:jboss:remove:jsf, -install:jboss:configure:properties-service">

        <tstamp>
            <format property="BUILD_DATE" pattern="MMMM-d-yyyy hh:mm aa" locale="en,US"/>
        </tstamp>

        <!-- copy over any other files you may need to configure your application -->

        <copy file="${jboss-conf.dir.dest}/${ncireportwriter-webapp.ds.file}" todir="${jboss.home}/server/${jboss.server.name}/deploy" overwrite="true" />

        <filterset id="embedded.filterset">
            <filter token="mail.smtp.server" value="${mail.smtp.server}"/>
            <filter token="debug.on" value="${debug.on}"/>
            <filter token="lex.evs.api.url" value="${lex.evs.api.url}"/>
            <filter token="application.version" value="${application.version}"/>
            <filter token="ncireportwriter.build.info" value="Built: ${BUILD_DATE}"/>
            <filter token="lg.config.file" value="${lg.config.file}"/>
            <filter token="ncireportwriter.conf.path" value="${application.data.path}/${ncireportwriter.conf.path}"/>
            <filter token="application.base.path" value="${application.base.path}"/>
            <filter token="application.url" value="${application.url}"/>
            <filter token="jboss.home" value="${jboss.home}"/>
            <filter token="tomcat.home" value="${tomcat.home}"/>
            <filter token="env.LOGNAME" value="${env.LOGNAME}"/>
            <filter token="env.JAVA_HOME" value="${env.JAVA_HOME}"/>
            <filter token="project.name" value="${project.name}"/>
            <filter token="debug.on" value="${debug.on}"/>
            <filter token="report.download.directory" value="${application.data.path}/${report.download.directory}"/>
            <filter token="maximum.level" value="${maximum.level}"/>
            <filter token="maximum.return" value="${maximum.return}"/>
            <filter token="csm.lockout.time" value="${csm.lockout.time}"/>
            <filter token="csm.allowed.login.time" value="${csm.allowed.login.time}"/>
            <filter token="csm.allowed.attempts" value="${csm.allowed.attempts}"/>
            <filter token="contact.us.email" value="${contact.us.email}"/>
            <filter token="account.admin.user.email" value="${account.admin.user.email}"/>
        </filterset>

        <mkdir dir="${application.data.path}/${ncireportwriter.conf.path}" />
        <copy todir="${application.data.path}/${ncireportwriter.conf.path}" filtering="true" overwrite="true" flatten="true">
            <filterset refid="embedded.filterset"/>
            <resources>
                <file file="${ncireportwriter-webapp.dir.dist}/deploy/ncireportwriter.properties"/>
            </resources>
        </copy>
        <mkdir dir="${application.data.path}/${report.download.directory}" />

        <!-- copy JBoss-web.xml file -->
        <!--
        <copy file="${jboss-conf.dir.dest}/${jboss.web.xml.file}" todir="${jboss.home}/server/${jboss.server.name}/deploy" overwrite="true" />
        -->

    </target>

    <target name="install:jboss:configure:log4j" description="Configure custom entries in system wide log4j" unless="exclude.jboss" depends="common:jboss:init, common:init">
      <echo message="DYEE: Disable: Configuring Log4J"/>
    </target>
	
    <target name="install:jboss:configure:log4j:DYEE" description="Configure custom entries in system wide log4j" unless="exclude.jboss" depends="common:jboss:init, common:init">
        <echo message="Configuring Log4J"/>
        <property name="log4j.file.name" value="log4j.xml"/>
        <copy file="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}" tofile="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}.pre"/>
        <replaceregexp file="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}"
            byline="true"
            match="^(&lt;!DOCTYPE.*)"
            replace="&lt;!-- \1 --&gt;"
            />
        <!--<copy file="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}" tofile="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}.1"/>-->
        <xmltask source="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}"
            dest="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}">
            <remove path="/log4j:configuration/appender[@name='TestAppender']"/>
            <!--
            <insert path="/log4j:configuration">
                <![CDATA[
                <appender name="TestAppender" class="org.jboss.logging.appender.RollingFileAppender">
                    <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                    <param name="File" value="${jboss.server.log.dir}/testAppender.log"/>
                    <param name="Append" value="false"/>
                    <param name="MaxFileSize" value="${log4j.maxFileSize}"/>
                    <layout class="org.apache.log4j.PatternLayout">
                        <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
                    </layout>
                </appender>
                ]]>
            </insert>
            -->
            <remove path="/log4j:configuration/category[@<EMAIL>='<EMAIL>']"/>
            <!--
            <insert path="/log4j:configuration"><commit_msg>GF27980: Fixed configuring JBoss Log4j BDA script problem.<commit_after><?xml version="1.0" encoding="utf-8" ?>

<!-- bda-build-template version 1.6.1 -->

<project name="ncireportwriter-installer" default="upgrade" basedir="."
    xmlns:ivy="antlib:org.apache.ivy.ant"
    >

    <description>
        This build file is part of the bda-build-templates project. This is the master install file for the project.  It should be placed in project/software.  This script is copied into the distribution and  executed from the extracted distribution.  It is run by typing "ant" from the master project build.xml or from command line. This script has two flows install and upgrade.
        Install will do the following
            * Install binaries
            * Configure binaries
            * Install application
            * Configure application
            * Re-create database
            * Upgrade database
        Upgrade will do the following
            * Install application
            * Configure application
            * Upgrade database
        Databases
            * MySQL
            * PostgreSQL
            * Oracle
        This script requires java and ant to run. Every thing else it needs is included in the distribution.
    </description>

    <!-- Properties file related properties and tasks -->

    <property environment="env" />
    <property file="local.properties"/>
    <property file="project.properties"/>
    <property name="properties.file" value="${basedir}/install.properties"/>
    <echo message="Using properties file of ${properties.file}."/>
    <available file="${properties.file}" property="properties.file.exists" />
    <fail unless="properties.file.exists" message="The properties.file ${properties.file} does not exist, please make sure that you pass in an accurate file name with the 'ant -Dproperties.file=somepath/somefile', otherwise the build will fail."/>
    <replaceregexp file="${properties.file}" byline="true" match="^([\w\d.]+)=(.*[\w\d\/\{\}\\]+)[ \t]+\r*$" replace="\1=\2"/>
    <replaceregexp file="${properties.file}" byline="true" match="^([\w\d.]+)=[ \t]+(.*[\w\d\/\{\}\\]+)\r*$" replace="\1=\2"/>
    <property file="${properties.file}" />
    <property name="env.name" value="local"/>

    <property name="project.name" value="ncireportwriter"/>

    <!-- Generic properties -->
    <property name="log.dir" value="${basedir}/logs" />
    <property name="working.dir" value="${basedir}/working" />
    <property name="temp.dir" value="${working.dir}/temp" />

    <!-- Install Time properties -->
    <!-- Source and target directories -->
    <property name="bda-utils.dir" value="bda-utils" />
    <property name="evs-utils.dir" value="evs-utils" />
    <property name="tools.dir" value="${basedir}/${tools.dist.relative.dir}" />
    <property name="common.dir.src" value="${basedir}/${common.dist.relative.dir}" />
    <property name="common.dir.dest" value="${working.dir}/${common.dist.relative.dir}" />
    <property name="db.dir.src" location="${basedir}/${db.dist.relative.dir}" />
    <property name="db.dir.dest" location="${working.dir}/${db.dist.relative.dir}" />
    <property name="db-install.dir.dest" location="${working.dir}/${db-install.dist.relative.dir}" />
    <property name="db-upgrade.dir.dest" location="${working.dir}/${db-upgrade.dist.relative.dir}" />
    <property name="jboss-conf.dir.src" value="${basedir}/${jboss-conf.dist.relative.dir}" />
    <property name="jboss-conf.dir.dest" value="${working.dir}/${jboss-conf.dist.relative.dir}" />

    <!-- Jboss binding configurtion related properties -->

    <property name="jboss.binding.template.location" value="${bda-utils.dir}/resource/${jboss.template.relative.dir}/bindings.xml"/>
    <property name="jboss.service.template.location" value="${bda-utils.dir}/resource/${jboss.template.relative.dir}/jboss-service.xml"/>

    <!-- WAR -->
    <property name="ncireportwriter-webapp.dir.dist" value="${basedir}/${ncireportwriter-webapp.dist.relative.dir}" />
    <property name="ncireportwriter-webapp.ds.file" value="ncireportwriter-ds.xml" />
    <property name="ncireportwriter-webapp.war.file" value="ncireportwriter.war" />
    <property name="ncireportwriter-webapp.prop.file" value="ncireportwriter.properties" />

    <!-- Grid related properties -->
    <!-- Default to false, properties can override -->
    <property name="jboss.ssl.enable" value="false"/>

    <!-- Paths -->
    <path id="bda-utils.classpath">
        <fileset dir="${bda-utils.dir}">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <!-- EVS Paths -->
    <path id="evs-utils.classpath">
        <fileset dir="${evs-utils.dir}">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <!-- Task definitions -->

    <taskdef uri="antlib:org.apache.ant.antunit" resource="org/apache/ant/antunit/antlib.xml" classpathref="bda-utils.classpath"/>
    <taskdef name="for" classname="net.sf.antcontrib.logic.ForTask" classpathref="bda-utils.classpath"/>
    <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="bda-utils.classpath"/>
    <taskdef resource="liquibasetasks.properties" classpathref="bda-utils.classpath"/>
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="bda-utils.classpath"/>

    <!-- EVS Task definitions -->

    <taskdef name="StringEncrypter"
        classname="gov.nih.nci.security.util.AntStringEncrypter">
        <classpath refid="evs-utils.classpath"/>
    </taskdef>

    <!-- Conditionals -->
    <available file="${jboss.home}/server/${jboss.server.name}/conf/jboss-service.xml" property="jboss.exists"/>
    <!-- Includes-->
    <import file="${bda-utils.dir}/bda-build-utils-${bda.version}.xml" />

    <!-- Start logging -->
    <property name="install-logs.dir" location="${log.dir}"/>
    <mkdir dir="${install-logs.dir}"/>

    <tstamp>
        <format property="install.time" pattern="yyyy-MM-dd-HH-mm" />
    </tstamp>
    <record name="${install-logs.dir}/install-${install.time}.log" action="start"/>

    <!-- ****************************** Installer section ********************************** -->

    <target name="diag">
        <echoproperties/>
    </target>

    <target name="common:init:pre">
        <!-- Set application.base.path based on platform -->

        <condition property="application.base.path" value="${application.base.path.linux}">
            <or>
                <os family="unix" />
                <os family="mac" />
            </or>
        </condition>

        <condition property="application.base.path" value="${application.base.path.windows}">
            <os family="windows" />
        </condition>
        <echo message="application.base.path=${application.base.path}"/>
        <property name="jboss.home" value="${application.base.path}/${jboss.relative.path}"/>
        <jboss-version/>

        <!-- Set application.data.path based on platform -->

        <condition property="application.data.path" value="${application.data.path.linux}">
            <or>
                <os family="unix" />
                <os family="mac" />
            </or>
        </condition>
        <condition property="application.data.path" value="${application.data.path.windows}">
            <os family="windows" />
        </condition>
        <echo message="application.data.path=${application.data.path}"/>
    </target>

    <target name="install:jboss:init" depends="common:init:pre" unless="exclude.jboss">
        <!-- determine if port configurations or port lists are being called -->
        <if>
            <isset property="jboss.ncicb-standard.port-config"/>
            <then>
                <!-- Read some port properties from standard bindings file -->
                <echo message="Using JBoss NCICB Standard port configurations"/>
                <if>
                    <equals arg1="${jboss.major.version}" arg2="4"/>
                    <then>
                        <property name="jboss.server.binding.template.location" value="${basedir}/${jboss-bindings.file}"/>
                        <jboss-read-ports
                            jboss.server.bindingfile.location="${jboss.server.binding.template.location}"
                            />
                        <jboss-bindings-validate
                            jboss.server.bindingfile.location="${jboss.server.binding.template.location}"
                    />
                    </then>
                    <elseif>
                        <equals arg1="${jboss.major.version}" arg2="5"/>
                        <then>
                            <property name="jboss.server.binding.template.location" value="${basedir}/${jboss-bindings.file}"/>
                            <property name="jboss.server.bindingfile.location" value="${jboss.home}/server/${jboss.server.name}/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml"/>
                            <property name="temp.ejb.file" value="${temp.dir}/ejb3-connectors-jboss-beans.xml"/>
                            <copy tofile="${temp.ejb.file}" file="${bda-utils.dir}/resource/jboss-5.1.0.GA/ejb3-connectors-jboss-beans.xml"/>
                            <!--
                            <jboss51-bindings-nci
                                jboss.server.bindingfile.location="${jboss-bindings.file}"
                                />
                            -->
                            <jboss51-read-ports-nci
                                jboss.server.bindingfile.location="${jboss-bindings.file}"
                                jboss.server.ejbfile.location="${temp.ejb.file}"
                                />
                        </then>
                    </elseif>
                </if>
                <echo message="http -${jboss.server.port} "/>
                <echo message="http -${jboss.server.jndi.port} "/>
                <properties-exist
                    properties.list="jboss.server.jndi.port,jboss.server.port,jboss.server.ports.name"
                    />
            </then>
            <else>
                <!-- else ensure that all ports are set, since these will be removed from install-properties.template we will verify here.  They have to be removed so the validator works with or without the properties or we have to change the format of the file. -->
                <echo message="Using custom JBoss port configurations"/>
                <if>
                    <equals arg1="${jboss.major.version}" arg2="4"/>
                    <then>
                        <property name="jboss.server.binding.template.location" value="${bda-utils.dir}/resource/${jboss.binaries.relative.dir}/bindings.xml"/>
                    </then>
                    <else>
                        <property name="jboss.server.binding.template.location" value="${bda-utils.dir}/resource/${jboss.binaries.relative.dir}/bindings-jboss-beans.xml"/>

                    </else>
                </if>
                <properties-exist
                    properties.list="jboss.server.jndi.port,jboss.server.port,jboss.cobraorb.port,jboss.hajndi.port,jboss.hajrmi.port,jboss.jmx-rmi.port,jboss.messaging.port,jboss.pooledha.port,jboss.server.bind.port,jboss.server.rmi.port,jboss.service.rmiobject.port,jboss.snmp.port,jboss.snmp-trapd.port,jboss.web.service.port,jboss.unifiedinvoker.port,jboss.hajndi.auto.port,jboss.ssl.port,jboss.jms2.netty.port,jboss.jms2.netty-ssl.port,jboss.transaction.recovery.port,jboss.transaction.status.port,jboss.transaction.processid.port"
                    />
            </else>
        </if>
    </target>

    <target name="common:jboss:init" depends="common:init:pre" unless="exclude.jboss">
        <math result="jboss.ssl.port" operand1="${jboss.server.port}" operation="+" operand2="363" datatype="int"/>
        <property name="jboss.ssl.enable" value="false"/>
        <property name="jboss.home" value="${application.base.path}/${jboss.relative.path}"/>
        <jboss-version/>
        <property name="jboss.application.url" value="http://${jboss.server.hostname}:${jboss.server.port}/${project.name}"/>
        <available file="${jboss.home}/server/${jboss.server.name}/conf/jboss-service.xml" property="jboss.exists"/>
        <basename file="${jboss.ssl.keystore.location}" property="jboss.ssl.keystore.file"/>
        <dirname file="${jboss.ssl.keystore.location}" property="jboss.ssl.keystore.dir"/>
        <basename file="${jboss.grid.secure.cert.location}" property="jboss.grid.secure.cert.file"/>
        <dirname file="${jboss.grid.secure.cert.location}" property="jboss.grid.secure.dir"/>
        <basename file="${jboss.grid.secure.key.location}" property="jboss.grid.secure.key.file"/>
        <property name="jboss.socket.ports" value="${jboss.server.port},${jboss.server.rmi.port},${jboss.server.jndi.port},${jboss.service.rmiobject.port},${jboss.jms.port},${jboss.web.service.port}"/>
    </target>

    <target name="common:init" depends="common:init:pre">
        <property name="install.running" value="true"/>
        <!-- ncireportwriter-webapp can use either Oracle or MySQL or PostgreSQL as its database platform, this is controled by the database.type property.  Based on the value of this property sent several variables for use during install -->
        <echoproperties prefix="database"/>
        <switch value="${database.type}">
            <case value="oracle">
                <property name="database.dialect" value="org.hibernate.dialect.OracleDialect"/>
                <property name="database.driver.file" value="${bda-utils.dir}/ojdbc14-10.2.0.4.0.jar"/>
                <property name="database.driver" value="oracle.jdbc.driver.OracleDriver"/>
                <property name="database.schema" value="${database.name}"/>
            </case>
            <case value="mysql">
                <property name="database.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                <property name="database.driver.file" value="${bda-utils.dir}/mysql-connector-java-5.0.8.jar"/>
                <property name="database.driver" value="com.mysql.jdbc.Driver"/>
                <property name="database.schema" value="${database.name}"/>
            </case>
            <case value="postgresql">
                <property name="database.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
                <property name="database.driver.file" value="${bda-utils.dir}/postgresql-jdbc3-8.3-604.jar"/>
                <property name="database.driver" value="org.postgresql.Driver"/>
                <property name="database.schema" value="public"/>
            </case>
            <default>
                <fail message="Invalid database type ${database.type}"/>
            </default>
        </switch>

        <path id="jdbc.driver.classpath">
            <pathelement location="${database.driver.file}"/>
        </path>

        <property name="properties.template.file" value="${basedir}/properties.template" />
        <filterset id="embedded.filterset">
            <!-- Internal properties that may be used in a filtered copy -->
            <filter token="application.base.path" value="${application.base.path}"/>
            <filter token="application.url" value="${application.url}"/>
            <filter token="database.url" value="${database.url}"/>
            <filter token="database.user" value="${database.user}"/>
            <filter token="database.password" value="${database.password}"/>
            <filter token="database.system.url" value="${database.system.url}"/>
            <filter token="database.driver" value="${database.driver}"/>
            <filter token="database.dialect" value="${database.dialect}"/>
            <!-- added for liquibase -->
            <filter token="db-upgrade.run.dir" value="${db-upgrade.dir.dest}/${database.type}"/>
            <filter token="jboss.home" value="${jboss.home}"/>
            <filter token="hibernate.cfg.file.path" value="${hibernate.cfg.file.path}"/>
            <filter token="env.LOGNAME" value="${env.LOGNAME}"/>
            <filter token="env.JAVA_HOME" value="${env.JAVA_HOME}"/>
            <filter token="project.name" value="project.name"/>
            <filter token="" value=""/>
        </filterset>

        <!--OS Temp dir -->
        <condition property="os.temp.dir" value="/tmp/${project.name}">
            <or>
                <os family="unix" />
                <os family="mac" />
            </or>
        </condition>

        <condition property="os.temp.dir" value="c:/temp/${project.name}">
            <os family="windows" />
        </condition>

        <!--
            Copy files to ensure values containing variables are expanded, such properties are stored in embedded.filterset
            and then copy with filter files
          -->

        <copy todir="${common.dir.dest}" filtering="true">
            <fileset dir="${common.dir.src}">
                <include name="**/*"/>
            </fileset>
            <filterset refid="embedded.filterset"/>
            <filterset>
                <filtersfile file="${properties.file}"/>
                <filtersfile file="project.properties"/>
            </filterset>
        </copy>

    </target>

    <target name="install:common:clean" description="Removes all files from the local filesystem" depends="
        common:init,
        install:jboss:clean
        ">
    </target>

    <target name="install:jboss:clean" unless="exclude.jboss" depends="common:jboss:init, common:init">
        <sleep seconds="5" />
        <property name="backup.count" value="5"/>
        <if>
            <not>
                <equals arg1="${exclude.jboss.backup}" arg2="true"/>
            </not>
            <then>
                <!-- Jboss backup, do not compress until install is finished -->
                <property name="backup.jboss.base.dir" location="${application.base.path}/backup/jboss"/>

                <!-- So these directories won't be included in the backup, they are not needed to use jboss -->
                <delete dir="${jboss.home}/server/${jboss.server.name}/work"/>
                <delete dir="${jboss.home}/server/${jboss.server.name}/tmp"/>

                <backup-dir
                    src.dir="${jboss.home}"
                    backup.base.dir="${backup.jboss.base.dir}"
                    backup.count="${backup.count}"
                    />
            </then>
        </if>
        <delete dir="${jboss.home}"/>
    </target>

    <target name="install:database:prep" description="Copies db files with filtering" unless="exclude.database" depends="common:init">
        <property name="db.prop.list" value="database.url,database.user,database.password,database.name"/>
        <echo  message="Checking if database properties exist: ${db.prop.list}"/>
        <properties-exist properties.list="${db.prop.list}"/>
        <echoproperties prefix="database"/>
        <StringEncrypter string="${database.password}" property="encryptedPassword"/>
        <StringEncrypter string="${rw.admin.user.passwd}" property="encrypted.rw.admin.user.passwd"/>
        <StringEncrypter string="${rw.user.passwd}" property="encrypted.rw.user.passwd"/>
        <filterset id="embedded.filterset">
            <!-- Database connection information -->
            <filter token="database.name" value="${database.name}"/>
            <filter token="database.server" value="${database.server}"/>
            <filter token="database.port" value="${database.port}"/>
            <filter token="database.user" value="${database.user}"/>
            <filter token="database.url" value="${database.url}"/>
            <filter token="database.password" value="${encryptedPassword}"/>
            <!-- User login information -->
            <filter token="rw.admin.user.name" value="${rw.admin.user.name}"/>
            <filter token="rw.admin.user.passwd" value="${encrypted.rw.admin.user.passwd}"/>
            <filter token="rw.admin.user.email" value="${rw.admin.user.email}"/>
            <filter token="rw.user.name" value="${rw.user.name}"/>
            <filter token="rw.user.passwd" value="${encrypted.rw.user.passwd}"/>
            <filter token="rw.user.email" value="${rw.user.email}"/>
        </filterset>
        <copy todir="${db.dir.dest}" filtering="true">
            <fileset dir="${db.dir.src}">
                <include name="**/*"/>
            </fileset>
            <filterset refid="embedded.filterset"/>
            <filterset>
                <filtersfile file="${properties.file}"/>
                <filtersfile file="project.properties"/>
                <filter token="db-upgrade.run.dir" value="${working.dir}/db/db-upgrade/${database.type}"/>
            </filterset>
        </copy>
        <mkdir dir="${os.temp.dir}/${project.name}"/>
        <copy todir="${os.temp.dir}/${project.name}" filtering="true" flatten="true" overwrite="true">
            <fileset dir="${db.dir.dest}">
                <include name="**/db-upgrade.xml"/>
            </fileset>
        </copy>
    </target>

    <target name="install:database" description="Runs database creation scripts then calls uprade database." unless="exclude.database"
        depends="

        common:init,
        install:database:prep,
        install:database:validation:pre-install
        ">
        <!-- Drop all schema objects or re-create the db -->
        <database-clean/>
        <!-- Run baseline scripts stored in db.install.create.${database.type}.file.list variable -->
        <switch value="${database.type}">
            <case value="oracle">
                <database-install
                    db.install.create.file.list="${db.install.create.oracle.file.list}"
                    sql.delimiter="/"
                    sql.delimitertype="row"
                    />
            </case>
            <case value="postgresql">
                <database-install
                    db.install.create.file.list="${db.install.create.postgresql.file.list}"
                    sql.delimiter="/"
                    sql.delimitertype="row"
                    />
            </case>
            <case value="mysql">
                <database-install
                    db.install.create.file.list="${db.install.create.mysql.file.list}"
                    />
            </case>
        </switch>
        <database-upgrade
            database.changelog.file="${os.temp.dir}/${project.name}/db-upgrade.xml"
            />
        <database-tag/>

        <!-- Remove old reports from the download folder -->

        <delete quiet="true" includeemptydirs="true">
            <fileset dir="${application.data.path}/${report.download.directory}" includes="**/*.txt" />
            <fileset dir="${application.data.path}/${report.download.directory}" includes="**/*.xls" />
        </delete>

    </target>

    <target name="install:jboss:binaries" description="Install JBoss binaries" unless="exclude.jboss" depends="common:jboss:init, common:init">
        <jboss-install-binaries/>
        <jboss-nci-customizations/>
    </target>

    <target name="install:jboss:ncireportwriter-webapp:filesystem-data"  depends="common:jboss:init, common:init">
        <!-- This target is a place holder for creating a file-system data repository.  If you do not use one you can remove this target and all targets that refer to it. If you require a certain directory structure be sure to create it here.  If you need to copy in files, make sure to check them into svn, copy them into the distribution and then copy them to thier ultimate directory.  If your data needs to be refreshed with each install make sure to delete the base directory, then create the structure and copy in data.  Also you can use an archive file with relative pathing inside to build out the structure if you like, using an archive like zip may shrink the footprint in svn.
        <mkdir dir="${fs-data.base.dir}"/>
        <mkdir dir="${fs-data.base.dir}/scratch"/>
        <copy file="${ncireportwriter-webapp.dir.dist}/${ncireportwriter-webapp.war.file}" todir="${fs-data.base.dir}/scratch" overwrite="true" />
        -->
    </target>

    <target name="install:jboss:ncireportwriter-webapp" description="Deploy ncireportwriter-webapp and common libraries to jboss installation" unless="exclude.jboss"
        depends="common:jboss:init, common:init">
        <!-- added to ensure working.dirs are fresh for our install -->
        <delete dir="${jboss.home}/server/${jboss.server.name}/tmp"/>
        <delete dir="${jboss.home}/server/${jboss.server.name}/work"/>
        <move file="${jboss.home}/server/${jboss.server.name}/log/server.log" tofile="${jboss.home}/server/${jboss.server.name}/log/server/log.${install.time}" failonerror="false"/>
        <copy file="${ncireportwriter-webapp.dir.dist}/${ncireportwriter-webapp.war.file}"
             todir="${jboss.home}/server/${jboss.server.name}/deploy"
             overwrite="true">
        </copy>
        <!--  Many NCI applications require clm for csm, so you can point this to where you have the version you want to use -->
        <copy file="${ncireportwriter-webapp.dir.dist}/deploy/clm.jar"
            todir="${jboss.home}/server/${jboss.server.name}/lib"
            overwrite="true">
        </copy>
        <copy file="${ncireportwriter-webapp.dir.dist}/upt.war"
             todir="${jboss.home}/server/${jboss.server.name}/deploy"
             overwrite="true">
         </copy>
        <!-- Copy datbase driver -->
        <copy file="${database.driver.file}" todir="${jboss.home}/server/${jboss.server.name}/lib" overwrite="true" />
    </target>

    <target name="install:jboss:ncireportwriter-webapp:configure" description="Configure ncireportwriter-webapp application, copies over externalized properties or configurations that are not part of the jboss configuration"
        unless="exclude.jboss" depends="-install:jboss:remove:jsf, -install:jboss:configure:properties-service">

        <tstamp>
            <format property="BUILD_DATE" pattern="MMMM-d-yyyy hh:mm aa" locale="en,US"/>
        </tstamp>

        <!-- copy over any other files you may need to configure your application -->

        <copy file="${jboss-conf.dir.dest}/${ncireportwriter-webapp.ds.file}" todir="${jboss.home}/server/${jboss.server.name}/deploy" overwrite="true" />

        <filterset id="embedded.filterset">
            <filter token="mail.smtp.server" value="${mail.smtp.server}"/>
            <filter token="debug.on" value="${debug.on}"/>
            <filter token="lex.evs.api.url" value="${lex.evs.api.url}"/>
            <filter token="application.version" value="${application.version}"/>
            <filter token="ncireportwriter.build.info" value="Built: ${BUILD_DATE}"/>
            <filter token="lg.config.file" value="${lg.config.file}"/>
            <filter token="ncireportwriter.conf.path" value="${application.data.path}/${ncireportwriter.conf.path}"/>
            <filter token="application.base.path" value="${application.base.path}"/>
            <filter token="application.url" value="${application.url}"/>
            <filter token="jboss.home" value="${jboss.home}"/>
            <filter token="tomcat.home" value="${tomcat.home}"/>
            <filter token="env.LOGNAME" value="${env.LOGNAME}"/>
            <filter token="env.JAVA_HOME" value="${env.JAVA_HOME}"/>
            <filter token="project.name" value="${project.name}"/>
            <filter token="debug.on" value="${debug.on}"/>
            <filter token="report.download.directory" value="${application.data.path}/${report.download.directory}"/>
            <filter token="maximum.level" value="${maximum.level}"/>
            <filter token="maximum.return" value="${maximum.return}"/>
            <filter token="csm.lockout.time" value="${csm.lockout.time}"/>
            <filter token="csm.allowed.login.time" value="${csm.allowed.login.time}"/>
            <filter token="csm.allowed.attempts" value="${csm.allowed.attempts}"/>
            <filter token="contact.us.email" value="${contact.us.email}"/>
            <filter token="account.admin.user.email" value="${account.admin.user.email}"/>
        </filterset>

        <mkdir dir="${application.data.path}/${ncireportwriter.conf.path}" />
        <copy todir="${application.data.path}/${ncireportwriter.conf.path}" filtering="true" overwrite="true" flatten="true">
            <filterset refid="embedded.filterset"/>
            <resources>
                <file file="${ncireportwriter-webapp.dir.dist}/deploy/ncireportwriter.properties"/>
            </resources>
        </copy>
        <mkdir dir="${application.data.path}/${report.download.directory}" />

        <!-- copy JBoss-web.xml file -->
        <!--
        <copy file="${jboss-conf.dir.dest}/${jboss.web.xml.file}" todir="${jboss.home}/server/${jboss.server.name}/deploy" overwrite="true" />
        -->

    </target>

    <target name="install:jboss:configure:log4j" description="Configure custom entries in system wide log4j" unless="exclude.jboss" depends="common:jboss:init, common:init">
        <echo message="Configuring Log4J"/>
        <property name="log4j.file.name" value="jboss-log4j.xml"/>
        <copy file="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}" tofile="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}.pre"/>
        <replaceregexp file="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}"
            byline="true"
            match="^(&lt;!DOCTYPE.*)"
            replace="&lt;!-- \1 --&gt;"
            />
        <!--<copy file="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}" tofile="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}.1"/>-->
        <xmltask source="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}"
            dest="${jboss.home}/server/${jboss.server.name}/conf/${log4j.file.name}">
            <remove path="/log4j:configuration/appender[@name='TestAppender']"/>
            <!--
            <insert path="/log4j:configuration">
                <![CDATA[
                <appender name="TestAppender" class="org.jboss.logging.appender.RollingFileAppender">
                    <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                    <param name="File" value="${jboss.server.log.dir}/testAppender.log"/>
                    <param name="Append" value="false"/>
                    <param name="MaxFileSize" value="${log4j.maxFileSize}"/>
                    <layout class="org.apache.log4j.PatternLayout">
                        <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
                    </layout>
                </appender>
                ]]>
            </insert>
            -->
            <remove path="/log4j:configuration/category[@<EMAIL>='<EMAIL>']"/>
            <!--
            <insert path="/log4j:configuration">
{'fraction_non_alphanumeric': 0.17067590429388543, 'fraction_numerical': 0.002626278901152018, 'mean_word_length': 2.4330438630455222, 'pattern_counts': {'":': 0, '<': 850, '<?xml version=': 2, '>': 848, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 42}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1849526', 'n_tokens_mistral': 18112, 'n_tokens_neox': 17206, 'n_words': 3058}