text:
<!--L
   Copyright Ekagra Software Technologies Ltd.
   Copyright SAIC, SAIC-Frederick

   Distributed under the OSI-approved BSD 3-Clause License.
   See http://ncip.github.com/common-security-module/LICENSE.txt for details.
L-->

<project name="build-utils" xmlns:antunit="antlib:org.apache.ant.antunit">
 	<!-- Properties -->
	<property name="software.dir" location="${basedir}"/>
	<property name="temp.dir" location="${software.dir}/target/temp"/>
	<property name="build-utils.dir" location="${software.dir}/build-utils"/>
	<property name="build-utils.resource.dir" location="${build-utils.dir}/resource"/>
 	<property name="antunit.jar" value="antunit-1.0.jar"/>
	<property name="template.dbintegrate.file" location="${build-utils.resource.dir}/template-db-integrate.xml"/>

	<!-- Supported versions -->
	<property name="jboss.version.min" value="4.0.4"/>
	<property name="jboss.version.max" value="5.1.999"/>
	<property name="tomcat.version.min" value="5.0.0"/>
	<property name="tomcat.version.max" value="6.999.999"/>
	<!-- conditionals -->
	<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>

	<mkdir dir="${os.temp.dir}"/>
	<!-- PATHS -->
	<path id="macrodef.classpath">
		<fileset dir="${build-utils.dir}">
			<include name="**/*.jar" />
		</fileset>
	</path>

	<!-- Taskdefs -->
	<typedef resource="net/ggtools/grand/antlib.xml" classpathref="macrodef.classpath" />
	<taskdef name="dbconfig" classname="com.dbconfig.anttask.DbConfig" classpathref="macrodef.classpath" />
	<taskdef name="svn" classpathref="macrodef.classpath" classname="org.tigris.subversion.svnant.SvnTask" />
	<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="macrodef.classpath"/>
	<taskdef uri="antlib:org.apache.ant.antunit" resource="org/apache/ant/antunit/antlib.xml" classpathref="macrodef.classpath"/>
	<taskdef name="for" classname="net.sf.antcontrib.logic.ForTask" classpathref="macrodef.classpath"/>
	<taskdef name="propertyvalidator" classname="gov.nih.nci.bda.PropertyValidator" classpathref="macrodef.classpath"/>
	<taskdef resource="liquibasetasks.properties" classpathref="macrodef.classpath"/>
	<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="macrodef.classpath"/>
	<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpathref="macrodef.classpath"/>
	<taskdef name="uptconfigurator" classname="gov.nih.nci.bda.UptConfigurator" classpathref="macrodef.classpath"/>

	<xmlcatalog id="build.xml.catalog">
		<dtd
			publicId="-//JBoss//DTD Application Client 3.2//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-client_3_2.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD Application Client 4.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-client_4_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD Application Client 5.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-client_5_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD J2EE Application 1.3//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-app_3_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD J2EE Application 1.3V2//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-app_3_2.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD J2EE Application 1.4//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-app_4_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JAWS 2.4//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jaws_2_4.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JAWS 3.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jaws_3_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JAWS//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jaws.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSS 2.4//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss_2_4.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSS 3.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss_3_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSS 3.2//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss_3_2.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSS 4.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss_4_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSS 5.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss_5_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jbosscmp-jdbc_3_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jbosscmp-jdbc_3_2.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jbosscmp-jdbc_4_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSS//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSS JCA Config 1.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-ds_1_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSS JCA Config 1.5//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-ds_1_5.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSS Security Config 3.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/security_config.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSS XMBEAN 1.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss_xmbean_1_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSS XMBEAN 1.1//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss_xmbean_1_1.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD JBOSS XMBEAN 1.2//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss_xmbean_1_2.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD MBean Service 3.2//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-service_3_2.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD MBean Service 4.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-service_4_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD Web Application 2.2//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-web.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD Web Application 2.3//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-web_3_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD Web Application 2.3V2//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-web_3_2.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD Web Application 2.4//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-web_4_0.dtd"
			/>
		<dtd
			publicId="-//JBoss//DTD Web Application 5.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/jboss-web_5_0.dtd"
			/>
		<dtd
			publicId="-//Sun Microsystems, Inc.//DTD Connector 1.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/connector_1_0.dtd"
			/>
		<dtd
			publicId="-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/ejb-jar.dtd"
			/>
		<dtd
			publicId="-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/ejb-jar_2_0.dtd"
			/>
		<dtd
			publicId="-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/application_1_2.dtd"
			/>
		<dtd
			publicId="-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/application_1_3.dtd"
			/>
		<dtd
			publicId="-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/application-client_1_3.dtd"
			/>
		<dtd
			publicId="-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/web-app_2_2.dtd"
			/>
		<dtd
			publicId="-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/web-app_2_3.dtd"
			/>
		<dtd
			publicId="-//W3C//DTD/XMLSCHEMA 200102//EN"
			location="${build-utils.resource.dir}/jboss-5.1.0.GA/dtd/XMLSchema.dtd"
			/>

		<!--
		<dtd
			publicId=""
			location="${build-utils.resource.dir}/jboss-4.0.5.GA-jems-ejb3/dtd/"
			/>
			/>
		-->
		<dtd
			publicId="-//Hibernate/Hibernate Configuration DTD 3.0//EN"
			location="${build-utils.resource.dir}/other-dtds/hibernate-configuration-3.0.dtd"
			/>

		<dtd
			publicId="-//Hibernate/Hibernate Mapping DTD 3.0//EN"
			location="${build-utils.resource.dir}/other-dtds/hibernate-mapping-3.0.dtd"
			/>

	</xmlcatalog>

 	<tstamp>
 		<format property="run.date" pattern="yyMMddHHmm"/>
 	</tstamp>

	<!-- init tasks -->
	<mkdir dir="${temp.dir}"/>

	<!-- run-junit-tests macro runs the unit test cases
	usage: <run-junit-tests test.src.dir="${test.src.dir}" xml.output.dir="${target.dir}/junit" instrumented.classes="${instrumented.classes.dir}" classpath="${caarray-client.test.classes.dir};${test.data.files.dir};${test.classes.dir};${commons-lang.jar};${commons-io.jar};${caarray-client.test.files.dir};${caarray-client.classes.dir};${caarray-client.resources.dir};${junit.jar};${nci-commons-core.jar}" />
	-->
	<macrodef name="run-junit-tests">
		<attribute name="test.src.dir" />
		<attribute name="xml.output.dir" />
		<attribute name="classpath" default="" />
		<attribute name="instrumented.classes" default="" />
		<attribute name="maxmemory" default="256m"/>

		<sequential>
			<mkdir dir="@{xml.output.dir}" />
			<junit printsummary="on" failureproperty="junit.failure" fork="true" forkmode="once" maxmemory="@{maxmemory}">
				<sysproperty key="net.sourceforge.cobertura.datafile" file="${cobertura.file}" />
				<sysproperty key="server.hostname" value="${jboss.server.hostname}" />
				<sysproperty key="server.port" value="${jboss.server.port}" />
				<sysproperty key="server.jndi.port" value="${jboss.server.jndi.port}" />
				<sysproperty key="selenium.server.port" value="${selenium.server.port}" />

				<classpath>
					<pathelement path="@{instrumented.classes}" />
					<pathelement path="@{classpath}" />
					<path refid="cobertura.classpath" />
				</classpath>
				<formatter type="xml" />
				<batchtest todir="@{xml.output.dir}">
					<fileset dir="@{test.src.dir}">
						<include name="**/*Test.java" />
						<exclude name="**/Abstract*Test.java" />
					</fileset>
				</batchtest>
			</junit>
		</sequential>
	</macrodef>

	<!-- run-sql-script macro executes the sql scripts for a database
	usage: <run-sql-script database.url="${database.url}" database.user="${database.user}" database.password="${database.password}" sql.file="${sql.dir}/create_table.sql" />
	-->
	<macrodef name="run-sql-script" description="By default this will use the database.url, to use drop database & user use the database.system.url property">
		<attribute name="sql.file" />
		<attribute name="sql.delimiter" default=";" />
		<attribute name="sql.delimitertype" default="normal" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="onerror" default="abort" />
		<attribute name="database.driver" default="${database.driver}"/>
		<attribute name="database.driver.file" default="${database.driver.file}"/>
		<sequential>
			<sql driver="@{database.driver}" url="@{database.url}" userid="@{database.user}" password="@{database.password}" src="@{sql.file}" onerror="@{onerror}" autocommit="true" delimiter="@{sql.delimiter}" delimitertype="@{sql.delimitertype}" keepformat="true">
				<classpath>
					<pathelement location="@{database.driver.file}" />
				</classpath>
			</sql>
		</sequential>
	</macrodef>

	<!-- remote-ssh macro is a remote SSH procedure. It will use SSH connection defaults as defined in the environment property file to initiate SSH connections and execure remote unix commands. remoteSshCommand is a mandatory attribute to this macrodef.
	usage: <remote-ssh remotesshcommand="mv ${jboss.temp.dir}/caarray.ear ${jboss.home}/deploy/" />
	-->
	<macrodef name="remote-ssh" description="This is a remote SSH procedure. It will use SSH connection defaults as defined in the environment property file to initiate SSH connections and execure remote unix commands. remoteSshCommand is a mandatory attribute to this macrodef.">
		<attribute name="remoteSshCommand" />
		<attribute name="remoteSshPort" default="22" />
		<attribute name="remoteSshHost" default="${ssh.server.hostname}" />
		<attribute name="remoteSshUser" default="${ssh.server.username}" />
		<attribute name="remoteSshKeyfile" default="${ssh.key.file}" />
		<attribute name="remoteSshSleep" default="5" />
		<attribute name="remoteSshPassPhrase" default="${ssh.key.passphrase}"/>
		<sequential>
			<sshexec port="@{remoteSshPort}" host="@{remoteSshHost}" username="@{remoteSshUser}" keyfile="@{remoteSshKeyfile}" trust="true" passphrase="@{remoteSshPassPhrase}" verbose="true" command="@{remoteSshCommand}" />
			<sleep seconds="@{remoteSshSleep}" />
			<echo message="Performed @{remoteSshCommand} command on @{remoteSshHost}:@{remoteSshPort} using SSH..." />
		</sequential>
	</macrodef>

	<!-- remote-scp macro copies files in a secure manner using SCP.
	remoteScpToDir and remoteScpFileToCopy are required attributes to this macrodef
	usage: <remote-scp remoteScpFileToCopy="${caarray.ear}"
	remoteScpToDir="${ssh.server.username}@${ssh.server.hostname}:${jboss.temp.dir}" />
	-->
	<macrodef name="remote-scp" description="This task copies files in a secure manner using SCP.
	remoteScpToDir and remoteScpFileToCopy are required attributes to this macrodef.">
		<attribute name="remoteScpFileToCopy" />
		<attribute name="remoteScpToDir" />
		<attribute name="remoteScpKeyFile" default="${ssh.key.file}" />
		<attribute name="remoteScpPassphrase" default="${ssh.key.passphrase}" />
		<attribute name="remoteScpTrust" default="true" />
		<attribute name="remoteScpVerbose" default="true" />
		<attribute name="remoteScpSleep" default="5"  />
		<sequential>
			<scp file="@{remoteScpFileToCopy}" keyfile="@{remoteScpKeyFile}" passphrase="@{remoteScpPassphrase}" trust="@{remoteScpTrust}" verbose="@{remoteScpVerbose}" todir="@{remoteScpToDir}" />
			<sleep seconds="@{remoteScpSleep}" />
			<echo message="Copied @{remoteScpFileToCopy} to @{remoteScpToDir} using SCP..." />
		</sequential>
	</macrodef>

	<!--
	jboss-stop-jboss macro will stop the jboss instance
	usage: 	<jboss-start-jboss jboss.home="${jboss.home}"/>
		jboss.home is the location where Jboss is installed
		jboss.server.hostname is the host name where the application server is installed
		jboss.server.jndi.port is the JNDI port on which the server listens
	-->
	<macrodef name="jboss-stop-jboss">
		<attribute name="jboss.home" default="${jboss.home}" />
		<attribute name="jboss.server.hostname" default="${jboss.server.hostname}" />
		<attribute name="jboss.server.jndi.port" default="${jboss.server.jndi.port}" />
		<attribute name="jboss.server.name" default="${jboss.server.name}" />
		<attribute name="jboss.web.user" default="${jboss.web.user}" />
		<attribute name="jboss.web.password" default="${jboss.web.password}" />
		<attribute name="sleep.time" default="5"/>
		<sequential>
			<if>
				<socket server="@{jboss.server.hostname}" port="@{jboss.server.jndi.port}" />
				<then>
					<available file="@{jboss.home}/server/@{jboss.server.name}/bin" property="jboss.bin.exists"/>
					<if>
						<isset property="jboss.bin.exists"/>
						<then>
							<echo message="Shutting down jboss with stop_jboss"/>
							<exec executable="@{jboss.home}/server/@{jboss.server.name}/bin/stop_jboss" osfamily="unix"/>
						</then>
						<else>
							<echo message="Shutting down jboss with no user/password."/>
							<java classname="org.jboss.Shutdown" fork="true" spawn="false">
								<arg line="-s @{jboss.server.hostname}:@{jboss.server.jndi.port} -S" />
								<classpath>
									<pathelement location="@{jboss.home}/bin/shutdown.jar" />
								</classpath>
							</java>
						</else>
					</if>
				</then>
				<else>
					<echo message="JBoss is not running on @{jboss.server.jndi.port}"/>
				</else>
			</if>

			<sleep seconds="@{sleep.time}" />
			<if>
				<socket server="@{jboss.server.hostname}" port="@{jboss.server.jndi.port}" />
				<then>
					<echo message="Shutting down jboss with shutdown.jar with user and password"/>
					<java classname="org.jboss.Shutdown" fork="true" spawn="false">
						<arg line="-s @{jboss.server.hostname}:@{jboss.server.jndi.port} -u @{jboss.web.user} -p @{jboss.web.password} -S" />
						<classpath>
							<pathelement location="@{jboss.home}/bin/shutdown.jar" />
						</classpath>
					</java>
				</then>
			</if>
			<sleep seconds="@{sleep.time}" />
			<if>
				<socket server="@{jboss.server.hostname}" port="@{jboss.server.jndi.port}" />
				<then>
					<echo message="Shutting down jboss with default user/password."/>
					<java classname="org.jboss.Shutdown" fork="true" spawn="false">
						<arg line="-s @{jboss.server.hostname}:@{jboss.server.jndi.port} -u admin -p admin -S" />
						<classpath>
							<pathelement location="@{jboss.home}/bin/shutdown.jar" />
						</classpath>
					</java>
				</then>
			</if>
			<sleep seconds="@{sleep.time}" />
			<if>
				<socket server="@{jboss.server.hostname}" port="@{jboss.server.jndi.port}" />
				<then>
					<fail message="Failed to shutdown jboss server at @{jboss.server.hostname}:@{jboss.server.jndi.port}"/>
				</then>
				<else>
					<echo message="We believe we have shutdown JBoss."/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<!--
	jboss-check-if-jboss-is-running macro checks if the jboss server is up and listening
	usage: 	<jboss-check-if-jboss-is-running jboss.server.port="${jboss.server.port}" jboss.server.hostname="${jboss.server.hostname}" jboss.server.jndi.port="${jboss.server.jndi.port}"/>
		jboss.server.port is the http port number of which the web container listens
		jboss.server.hostname is the host name where the application server is installed
	-->
	<macrodef name="jboss-check-if-jboss-is-running" description="Checks if a local JBoss instance is running">
		<attribute name="jboss.server.port" default="${jboss.server.port}" />
		<attribute name="jboss.server.hostname" default="${jboss.server.hostname}" />
		<sequential>
			<condition property="jboss.running">
				<socket port="@{jboss.server.port}" server="@{jboss.server.hostname}" />
			</condition>
		</sequential>
	</macrodef>

	<!--
	jboss-start-jboss macro will start the jboss instance
	usage: 	<jboss-start-jboss jboss.home="${jboss.home}"/>
		jboss.home is the location where Jboss is installed
	-->
	<macrodef name="jboss-start-jboss" description="Starts a local JBoss instance">
		<attribute name="jboss.home" default="${jboss.home}" />
		<attribute name="jboss.server.name" default="${jboss.server.name}" />
		<attribute name="jboss.major.version" default="${jboss.major.version}"/>
		<sequential>
			<if>
				<and>
					<available file="@{jboss.home}/server/@{jboss.server.name}/bin/start_jboss"/>
					<or>
						<os family="unix"/>
						<os family="mac"/>
					</or>

				</and>
				<then>
					<echo message="Starting JBoss instance at @{jboss.home}/server/@{jboss.server.name}/bin with start_jboss" />
					<exec executable="@{jboss.home}/server/@{jboss.server.name}/bin/start_jboss" osfamily="unix" />
				</then>
				<elseif>
					<and>
						<available file="@{jboss.home}/bin/start_jboss"/>
						<or>
							<os family="unix"/>
							<os family="mac"/>
						</or>
					</and>
					<then>
						<echo message="Starting JBoss instance at @{jboss.home} with start_jboss" />
						<exec executable="@{jboss.home}/bin/start_jboss" osfamily="unix"/>
					</then>
				</elseif>
				<else>
					<echo message="Starting JBoss instance at @{jboss.home}/bin/run.sh" />
					<var name="bind.address.arg" value=""/>
					<if>
						<equals arg1="@{jboss.major.version}" arg2="5"/>
						<then>
							<property name="bind.address.arg" value="-b 0.0.0.0"/>
						</then>
					</if>
					<exec executable="nohup" osfamily="unix" dir="@{jboss.home}/bin" spawn="true">
						<env key="NOPAUSE" value="true" />
						<env key="JBOSS_HOME" value=""/>
						<arg line="./run.sh -c @{jboss.server.name} ${bind.address.arg}" />
					</exec>

					<exec osfamily="windows" executable="${build-utils.resource.dir}/psexec.exe" dir="@{jboss.home}/bin" spawn="true" >
						<env key="NOPAUSE" value="true" />
						<env key="JBOSS_HOME" value=""/>
						<arg line="-d -i -w @{jboss.home}/bin @{jboss.home}/bin/run.bat -c @{jboss.server.name} ${bind.address.arg}" />
					</exec>
					<sleep seconds="15" />
				</else>
			</if>
		</sequential>
	</macrodef>

	<!--
	jboss-update-shutdown macro updates the shutdown.jar with the host and jndi port information
	usage: 	<jboss-update-runconf jboss.home="${jboss.home}" jboss.server.hostname="${jboss.server.hostname}" jboss.server.jndi.port="${jboss.server.jndi.port}"/>
		jboss.home is the location where Jboss is installed
		jboss.server.hostname is the host name where the application server is installed
		jboss.server.jndi.port is the JNDI port on which the server listens
	-->
	<macrodef name="jboss-update-shutdown" description="Update the shutdown.jar ">
		<attribute name="jboss.home" default="${jboss.home}" />
		<attribute name="jboss.server.hostname" default="${jboss.server.hostname}" />
		<attribute name="jboss.server.jndi.port" default="${jboss.server.jndi.port}" />
		<sequential>
			<delete dir="${temp.dir}/shutdown"/>
			<unzip src="@{jboss.home}/bin/shutdown.jar" dest="${temp.dir}/shutdown" />
			<replaceregexp file="${temp.dir}/shutdown/jndi.properties" byline="true"
				match="^(java.naming.provider.url)=(.*)"
				replace="\1=jnp://@{jboss.server.hostname}:@{jboss.server.jndi.port}"/>

			<jar jarfile="${temp.dir}/shutdown/shutdown.jar" compress="false" manifest="${temp.dir}/shutdown/META-INF/MANIFEST.MF">
				<fileset dir="${temp.dir}/shutdown">
					<include name="*/**" />
				</fileset>
			</jar>
			<copy file="${temp.dir}/shutdown/shutdown.jar" todir="@{jboss.home}/bin" overwrite="true"/>
		</sequential>
	</macrodef>

	<!--
	jboss-update-runconf macro updates the configuration of run.conf and sets the desired JAVA_OPTS
	usage: 	<jboss-update-runconf jboss.home="${jboss.home}" jboss.java.opts="${jboss.java.opts}"/>
		jboss.home is the location where Jboss is installed
		jboss.java.opts are the desired java options for the application server
	-->
	<macrodef name="jboss-update-runconf">
		<attribute name="jboss.home" default="${jboss.home}" />
		<attribute name="jboss.java.opts" default="${jboss.java.opts}" />
		<sequential>
			<replaceregexp file="${jboss.home}/bin/run.conf" byline="true"
				match="^(\s+JAVA_OPTS)=(.*)"
				replace="\1='@{jboss.java.opts}'"/>
		</sequential>
	</macrodef>

	<!--
	validate-pre-install macro is a wrapper for all the pre-install validations and would vaildate for the environment, properties and directory structure of the host before application installation
	usage: 	<validate-pre-install />
		database.driver is the jdbc driver to connect to database
		database.system.url is the installed host of the database
		database.system.user is the system user for the database
		database.system.password is the system password for the database
		database.name is the name of the database
		database.url is the url of the database where it is hosted
		database.user is the user of the database
		database.password is the password of the user for the database
		validate-ports-preinstall is the list of comma seperated port numbers
		ant.check.version is the version of ant. By default the ant version should be greater than 1.7.0
		java.check.version.major is the major version of java. By default the major version should be greater than 1.5
		java.check.version.minor is the minor version of java. By default the minor version should be greater than 1.5.0_10
		The property.template.file is the template file to compare with
		The envpropertyfile is the properties file to be compared to
	-->
	<!-- System Diagnostics  -->
	<macrodef name="validate-pre-install" description="Diagnose the host system before the installation">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.system.url" default="${database.system.url}" />
		<attribute name="database.system.user" default="${database.system.user}" />
		<attribute name="database.system.password" default="${database.system.password}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.version" default="5.5.0" />
		<attribute name="database.name" default="${database.name}" />
 		<attribute name="validation.pre.port.list" default="${validation.pre.port.list}" />
		<attribute name="ant.check.version" default="1.8.0" />
		<attribute name="java.check.version.major" default="1.7" />
		<attribute name="java.check.version.minor" default="1.7.0" />
		<attribute name="property.template.file" default="${properties.template.file}"/>
		<attribute name="envpropertyfile" default="${properties.file}"/>
		<attribute name="jboss.ssl.enable" default="${jboss.ssl.enable}"/>
		<attribute name="jboss.ssl.keystore.file" default="${jboss.ssl.keystore.file}"/>
		<attribute name="jboss.ssl.keystore.dir" default="${jboss.ssl.keystore.dir}"/>
		<attribute name="jboss.ssl.keystore.pass" default="${jboss.ssl.keystore.pass}"/>
		<attribute name="jboss.ssl.keystore.alias" default="${jboss.ssl.keystore.alias}"/>
		<attribute name="jboss.ssl.fullyqualified.hostname" default="${jboss.ssl.fullyqualified.hostname}"/>
		<attribute name="tomcat.ssl.enable" default="${tomcat.ssl.enable}"/>
		<attribute name="tomcat.ssl.keystore.file" default="${tomcat.ssl.keystore.file}"/>
		<attribute name="tomcat.ssl.keystore.dir" default="${tomcat.ssl.keystore.dir}"/>
		<attribute name="tomcat.ssl.keystore.pass" default="${tomcat.ssl.keystore.pass}"/>
		<attribute name="tomcat.ssl.keystore.alias" default="${tomcat.ssl.keystore.alias}"/>
		<attribute name="tomcat.ssl.fullyqualified.hostname" default="${tomcat.ssl.fullyqualified.hostname}"/>
		<attribute name="jboss.binaries.relative.dir" default="${jboss.binaries.relative.dir}"/>
		<attribute name="tomcat.binaries.relative.dir" default="${tomcat.binaries.relative.dir}"/>
		<attribute name="database.type" default="${database.type}"/>
		<attribute name="database.re-create" default="${database.re-create}" />
		<attribute name="database.drop-schema" default="${database.drop-schema}" />
		<sequential>
			<validate-environment
				ant.check.version="@{ant.check.version}"
				java.check.version.major="@{java.check.version.major}"
				java.check.version.minor="@{java.check.version.minor}"
				/>
			<validate-database
				database.driver="@{database.driver}"
				database.system.url="@{database.system.url}"
				database.system.user="@{database.system.user}"
				database.system.password="@{database.system.password}"
				database.url="@{database.url}"
				database.user="@{database.user}"
				database.password="@{database.password}"
				database.version="@{database.version}"
				database.name="@{database.name}"
				database.type="@{database.type}"
				database.drop-schema="@{database.drop-schema}"
				database.re-create="@{database.re-create}"
				/>
			<validate-properties/>
			<compare-properties
				property.template.file="@{property.template.file}"
				envpropertyfile="@{envpropertyfile}"
				/>
			<check-absolute-directory
				directory.property="application.base.path"
				/>

			<!-- Not required with dac
			<check-direct-child-directory
				parent.dir.property="application.base.path"
				child.dir.property="jboss.home"
				/>
			<check-not-child-directory
				parent.dir.property="application.base.path"
				child.dir.property="basedir"
				/>
			-->
			<check-valid-directory-name
				directory.property="application.base.path"
				/>
			<check-database-exists
				database.driver="@{database.driver}"
				database.url="@{database.url}"
				database.user="@{database.user}"
				database.password="@{database.password}"
				database.name="@{database.name}"
				database.type="@{database.type}"
				/>
			<validate-appserver-versions
				jboss.binaries.relative.dir="@{jboss.binaries.relative.dir}"
				tomcat.binaries.relative.dir="@{tomcat.binaries.relative.dir}"
				/>
			<validate-env-name
				/>
			<if>
				<isset property="jboss.home"/>
				<then>
					<check-application-exists
						application.dir.property="jboss.home"
						/>
					<verify-keystore
						appserver.ssl.enable="@{jboss.ssl.enable}"
						appserver.ssl.keystore.file="@{jboss.ssl.keystore.file}"
						appserver.ssl.keystore.pass="@{jboss.ssl.keystore.pass}"
						appserver.ssl.keystore.alias="@{jboss.ssl.keystore.alias}"
						appserver.ssl.fullyqualified.hostname="@{jboss.ssl.fullyqualified.hostname}"
						appserver.ssl.keystore.dir="@{jboss.ssl.keystore.dir}"
						/>
					<validate-jboss-home
						/>
				</then>
			</if>
			<if>
				<isset property="tomcat.home"/>
				<then>
					<verify-keystore
						appserver.ssl.enable="@{tomcat.ssl.enable}"
						appserver.ssl.keystore.file="@{tomcat.ssl.keystore.file}"
						appserver.ssl.keystore.pass="@{tomcat.ssl.keystore.pass}"
						appserver.ssl.keystore.alias="@{tomcat.ssl.keystore.alias}"
						appserver.ssl.fullyqualified.hostname="@{tomcat.ssl.fullyqualified.hostname}"
						appserver.ssl.keystore.dir="@{tomcat.ssl.keystore.dir}"
						/>
				</then>
			</if>
		</sequential>
	</macrodef>

	<!--
	validate-environment macro validates host environment i.e the version of the installed ant, jdk.
	usage: 	<validate-environment ant.check.version="1.8.0" java.check.version.major="1.7" java.check.version.minor="1.7.0"/>
		ant.check.version is the version of ant. By default the ant version should be greater than 1.8.0
		java.check.version.major is the major version of java. By default the major version should be greater than 1.5
		java.check.version.minor is the minor version of java. By default the minor version should be greater than 1.5.0_10
	-->
	<macrodef name="validate-environment" description="Diagnose the host system before the installation">
		<attribute name="ant.check.version" default="1.8.0" />
		<attribute name="java.check.version.major" default="1.7" />
		<attribute name="java.check.version.minor" default="1.7.0" />
		<sequential>
			<!-- Echo the properties for diagnostic purposes -->
			<echoproperties > <propertyset negate="yes" > <propertyref regex="passw" /> </propertyset> </echoproperties>
			<!-- Validate Ant version is 1.7.x -->
			<echo message="Validating Ant version..." />
			<condition property="ant.version.success">
				<antversion atleast="@{ant.check.version}" />
			</condition>
			<antunit:assertPropertyEquals name="ant.version.success" value="true" />
			<echo message="Ant Version: PASSED" />

 			<echo message="Validating Java version..."/>
 			<condition property="java.major.version.good">
				<equals arg1="${ant.java.version}" arg2="@{java.check.version.major}" />
 			</condition>
			<antunit:assertTrue message="${line.separator}${line.separator}    Your Java SDK version must be @{java.check.version.major}. The version you have installed is ${java.version}. Please install the correct version of the Java SDK and update your System PATH to point to directory where you installed it. ${line.separator}">
 				<isset property="java.major.version.good"/>
 			</antunit:assertTrue>
			<if>
				<equals arg1="${java.version}" arg2="@{java.check.version.minor}" />
				<then>
					<echo message="Java version check: PASSED" />
				</then>
				<else>
					<echo message="Java version check: WARNING, version is not 1.5.0_10" />
				</else>
			</if>
 			<echo message="Java version check: PASSED" />

			<!-- Checks if user running build is root, if so it fails -->
			<if>
				<equals arg1="${user.name}" arg2="root"/>
				<then>
					<fail message="Cannot run build as root."/>
				</then>
				<else>
					<echo message="Not running as root."/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<!--
	validate-properties macro validates the property values in the property file. The checks include if an REPLACE are left and fails the build,compares database system user and databases users are the same,Checks that hostnames are reachable.
	usage: 	<validate-properties />
		properties.file property should be set before calling this macro
	-->
	<macrodef name="validate-properties" description="Diagnose the host system before the installation">
		<sequential>
			<!-- Validate properties, checks if an REPLACE are left and fails the build -->
			<if>
				<isset property="properties.file"/>
				<then>
					<echo message="Validating properties file  ${properties.file}..."/>
					<loadfile
						property="fail.properties"
						srcFile="${properties.file}">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern="REPLACE"/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>
					<if>
						<isset property="fail.properties"/>
						<then>
							<echo message="Property file validation: FAILED 'replace' found in file"/>
							<echo message="${fail.properties}"/>
							<fail message="Some properties still have 'REPLACE' in them. These properties require valid values. Please update ${properties.file} and run the installer again. " />
						</then>
					</if>
				</then>
				<else>
					<echo message="Warning: properties.file property is not set"/>
				</else>
			</if>
			<if>
				<isset property="properties.file"/>
				<then>
					<loadfile
						property="warn.properties"
						srcFile="${properties.file}">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern="replace"/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>
					<if>
						<isset property="warn.properties"/>
						<then>
							<echo message="Some properties still have 'replace' in them, this may cause issues."/>
							<echo message="${warn.properties}"/>
						</then>
					</if>
				</then>
				<else>
					<echo message="Properties file validation: PASSED"/>
				</else>
			</if>

			<!-- Validate database properties, compares database.system.user to other *databases.*.user  -->
			<if>
				<and>
					<isset property="properties.file"/>
					<isset property="database.system.user"/>
				</and>
				<then>
					<loadfile
						property="all.match.property"
						srcFile="${properties.file}">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern=".*database.*user=${database.system.user}\r*\n"/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>
					<if>
						<isset property="all.match.property"/>
						<then>
							<for list="${all.match.property}" delimiter="${line.separator}" param="matches.line">
								<sequential>
									<echo message="Evaluating line in properties file = @{matches.line}"/>
									<var name="match.tmp" value="@{matches.line}"/>
									<var name="is.system.user" unset="true"/>
									<propertyregex property="is.system.user"
										input="${match.tmp}"
										regexp="database.system.user.*"
										select="true"
										/>
									<if>
										<isset property="is.system.user"/>
										<else>
											<fail message="${line.separator}    The above line in the properties file uses the same user as the database.system.user. This will cause problems creating the database. Please change the mentioned property value to something other than ${database.system.user} and run the install again."/>
										</else>
									</if>
								</sequential>
							</for>
						</then>
						<else>
							<echo message="No other users match database.system.user = ${database.system.user}"/>
						</else>
					</if>
				</then>
			</if>
			<!-- Checks that hostnames are reachable, does not fail build, just prints message -->
			<if>
				<isset property="properties.file"/>
				<then>
					<propertyselector property="hostname.property.list"
						delimiter=","
						match="^(.*hostname)$"
						select="\1"
						casesensitive="true" />

					<if>
						<isset property="hostname.property.list"/>
						<then>
							<for list="${hostname.property.list}"  param="hostname.property" >
								<sequential>
		 							<propertycopy name="hostname.value" from="@{hostname.property}" override="true"/>
									<echo message="Attempting to connnect to ${hostname.value}...."/>
									<var name="hostname.has.value" value="false"/>
									<propertyregex property="hostname.has.value"
										input="@{hostname.value}"
										regexp="\S+"
										select="true"
										/>
									<if>
										<equals arg1="${hostname.has.value}" arg2="true"/>
										<then>
											<if>
												<isreachable host="${hostname.value}" timeout="5"/>
												<then>
													<echo message="${hostname.value} reached. (@{hostname.property})"/>
												</then>
												<else>
													<echo message="Could not reach host from property @{hostname.property} with value of ${hostname.value}"/>
												</else>
											</if>
										</then>
									</if>
								</sequential>
							</for>
						</then>
					</if>
				</then>
			</if>
		</sequential>
	</macrodef>

	<!--
	validate-ports-preinstall macro validates whether the host listens on provided list of comma seperated ports
	usage: 	<validate-ports-preinstall validate-ports-preinstall="${validate-ports-preinstall}" hostname="${jboss.server.hostname}" />
		validate-ports-preinstall is the list of comma seperated port numbers
		hostname is the host name of the machine e.x.localhost
	-->
	<macrodef name="validate-ports-preinstall" description="Diagnose the host system before the installation">
		<attribute name="validation.pre.port.list" default="${validation.pre.port.list}" />
		<attribute name="hostname" default="${jboss.server.hostname}" />
		<sequential>
			<!-- Validate ports are not listening -->
			<if>
				<and>
					<isset property="validation.pre.port.list"/>
					<not>
						<isset property="jboss.ncicb-standard.port-config"/>
					</not>
					<not>
						<isset property="exclude.jboss"/>
					</not>
				</and>
				<then>
 					<echo message="Validationg Ports Are not in use..."/>
 					<for list="@{validation.pre.port.list}" param="validate.port">
						<sequential>
				 			<echo message="Checking if @{validate.port} is running."/>
							<if>
				 				<socket server="@{hostname}" port="@{validate.port}" />
								<then>
									<fail message="${line.separator}${line.separator}    Port is listening at @{hostname}:@{validate.port}.${line.separator}Verify the JBoss server is not running at @{hostname}:@{validate.port}. If it is not, there may be a different process or application using this port (@{validate.port}).  You can either change the port this application uses by updating your *-install.properties file or change your other application to resolve this issue and continue installing."/>
 								</then>
								<else>
									<echo message="Ports check: PASSED" />
								</else>
							</if>
						</sequential>
					</for>
				</then>
			</if>
		</sequential>
	</macrodef>

	<!--
	check-direct-child-directory macro checks the child directory is the child of the parent directory
	usage: 	<check-direct-child-directory parent.dir.property="application.base.path" child.dir.property="jboss.home" />
		parent.dir.property is the property for the parent directory
		child.dir.property is the property for the child directory
	-->
	<macrodef name="check-direct-child-directory" description="Diagnose the host system before the installation">
		<attribute name="parent.dir.property" />
		<attribute name="child.dir.property" />
		<sequential>
			<!-- Application.base.path compare to Jboss.home -->
			<propertycopy name="child.dir" from="@{child.dir.property}" override="true"/>
			<propertycopy name="parent.dir" from="@{parent.dir.property}" override="true" />
			<var name="child.good" unset="true"/>
			<propertyregex property="child.good"
				input="${child.dir}"
				regexp="${parent.dir}[\\/][\d\w\.\-\_]+"
				select="true"
				/>
			<if>
				<isset property="child.good"/>
				<then>
					<echo message="@{child.dir.property}=${child.dir} is direct child of @{parent.dir.property}=${parent.dir}."/>
				</then>
				<else>
					<echo message="@{child.dir.property}=${child.dir} is not a direct child of @{parent.dir.property}=${parent.dir}."/>
					<fail message="@{child.dir.property} needs to be direct child of @{parent.dir.property}, please update the properties file and retry the build."/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<!--
	check-not-child-directory macro checks the parent and child directories do not have the same name
	usage: 	<check-not-child-directory parent.dir.property="application.base.path" child.dir.property="basedir" />
		parent.dir.property is the property for the parent directory
		child.dir.property is the property for the child directory
	-->
	<macrodef name="check-not-child-directory" description="Diagnose the host system before the installation">
		<attribute name="parent.dir.property" />
		<attribute name="child.dir.property" />
		<sequential>
			<!-- Application.base.path compare basedir -->
			<propertycopy name="not.child.dir" from="@{child.dir.property}" override="true"/>
			<propertycopy name="not.parent.dir" from="@{parent.dir.property}" override="true"/>
			<var name="child.bad" unset="true"/>
			<propertyregex property="child.bad"
				input="${not.child.dir}"
				regexp="${not.parent.dir}"
				select="true"
				/>
			<if>
				<isset property="child.bad"/>
				<then>
					<echo message="@{child.dir.property}=${not.child.dir} is child of @{parent.dir.property}=${not.parent.dir}."/>
					<fail message="@{child.dir.property} cannt be be direct child of @{parent.dir.property}, please update the properties file and retry the build."/>
				</then>
				<else>
					<echo message="@{child.dir.property}=${not.child.dir} is not child of @{parent.dir.property}=${not.parent.dir}."/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<!--
	check-valid-directory-name macro checks for the possible combinations of the directories and should be called before deleting any directories
	usage: <check-valid-directory-name directory.property="jboss.home" />
		directory.property is the property for the directory to be checked
	-->
	<macrodef name="check-valid-directory-name" description="Diagnose the host system before the installation">
		<attribute name="directory.property" />
		<sequential>
			<!-- Application.base.path check for bad directory -->
			<propertycopy name="directory.value" from="@{directory.property}" override="true"/>
			<var name="has.spaces" unset="true"/>
			<propertyregex property="has.spaces"
				regexp="\s+"
				input="${directory.value}"
				select="\1"
				/>
			<if>
				<isset property="has.spaces"/>
				<then>
					<fail message="@{directory.property} is using directory that space in the name, this is not supported by our current build process.  Please chose another diretory name without a space in it."/>
				</then>
			</if>

			<!-- Application.base.path check for bad directory -->
			<var name="directory.bad" unset="true"/>
			<propertyregex property="directory.bad"
				regexp="^(\w:[\/\\])$"
				input="${directory.value}"
				select="\1"
				/>
			<propertyregex property="directory.bad"
				regexp="^(\w:[\\\/]win.*)"
				input="${directory.value}"
				select="\1"
				/>
			<propertyregex property="directory.bad"
				regexp="^(\w:[\\\/]WIN.*)"
				input="${directory.value}"
				select="\1"
				/>
			<propertyregex property="directory.bad"
				regexp="^(\/)$"
				input="${directory.value}"
				select="\1"
				/>
			<propertyregex property="directory.bad"
				regexp="^(\/usr)$"
				input="${directory.value}"
				select="\1"
				/>
			<!-- Relax this one for local installs
			<propertyregex property="directory.bad"
				regexp="^(\/usr\/local)$"
				input="${directory.value}"
				select="\1"
				/>
			-->
			<propertyregex property="directory.bad"
				regexp="^(\/opt)$"
				input="${directory.value}"
				select="\1"
				/>
			<if>
				<isset property="directory.bad"/>
				<then>
					<fail message="@{directory.property} is set to or includes '${directory.bad}, this is not allowed.  As part of the install proces the first thing we do is delete this directory.  Deleting the directory you specified may cause system issues, please chose another directory."/>
				</then>
			</if>
		</sequential>
	</macrodef>

	<!--
	check-application-exists macro checks if the application exists. The property where the applications is installed should be priovided as input
	usage: <check-application-exists application.dir.property="jboss.home" />
		application.dir.property is the property for the installation directory of the application
	-->
	<macrodef name="check-application-exists" description="Diagnose the host system before the installation">
		<attribute name="application.dir.property" />
		<sequential>
			<!-- If jboss.home exists prompt to conntinue -->
			<propertycopy name="application.dir" from="@{application.dir.property}" override="true"/>
			<available property="application.dir.exists" file="${application.dir}"/>
			<if>
				<and>
					<isset property="application.dir.exists"/>
					<not>
						<isset property="force.reinstall"/>
					</not>
				</and>
				<then>
					<input message="The @{application.dir.property} (${application.dir}) already exists.  Please be sure you have a recent backup of this directory.  This process will alter files in this path and any customizations you have could be lost.  Do you want to proceed?"
						validargs="y,n"
						addproperty="accept.application.dir.update" />
					<if>
						<equals arg1="${accept.application.dir.update}" arg2="n"/>
						<then>
							<fail message="User tereminated the build."/>
						</then>
					</if>
				</then>
				<else>
					<echo message="@{application.dir.property} ${application.dir} does not exist or the force.reinstall property is set."/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<!--
	check-database-exists macro checks if the database exists. The root user name and password should be provided
	usage: <check-database-exists database.driver="${database.driver}" database.system.url="${database.system.url}" database.system.user="${database.system.user}" database.system.password="${database.system.password} database.name="${database.name}" />
		database.driver is the jdbc driver to connect to database
		database.url is the installed host of the database
		database.user is the user for the database
		database.password is the password for the database
		database.name is the name of the database
	-->
	<macrodef name="check-database-exists" description="Checks if the database exists">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.name" default="${database.name}" />
		<attribute name="database.type" default="${database.type}" />
		<sequential>
			<switch value="@{database.type}">
				<case value="mysql">
					<dbconfig property="database.exists"
						driver="@{database.driver}" url="@{database.url}"  user="@{database.user}" password="@{database.password}">
						<validate />
					</dbconfig>
					<echo message="Does @{database.name} exist = ${database.exists} "/>
					<if>
						<and>
							<equals arg1="${database.exists}" arg2="true"/>
							<not>
								<isset property="force.reinstall"/>
							</not>
						</and>
						<then>
							<input message="The database @{database.name} already exists.  Please be sure you have a recent backup of this database.  This process will alter the database if you need to return your database to the current state you need a good backup.  Please ensure you have a good backup before proceeding.  Do you want to proceed?"
								validargs="y,n"
								addproperty="accept.database.update" />
							<if>
								<equals arg1="${accept.database.update}" arg2="n"/>
								<then>
									<fail message="User tereminated the build."/>
								</then>
								<else>
									<var name="force.reinstall" value="true"/>
								</else>
							</if>
						</then>
						<else>
							<echo message="Database @{database.name} does not exist or the force.reinstall property is set."/>
							<var name="force.reinstall" value="true"/>
						</else>
					</if>
				</case>
				<default>
					<echo message="Database is @{database.type}, warning prompt not displayed."/>
					<var name="force.reinstall" value="true"/>
				</default>
			</switch>
		</sequential>
	</macrodef>

	<!--
	validate-post-install macro Diagnose the host system after the installation
	usage: <validate-post-install validation.post.http.list="${validation.post.http.list}" validation.post.socket.list="${validation.post.socket.list}" jboss.home="${jboss.home}" jboss.server.name="${jboss.server.name}"/>
		validation.post.http.list is the list of all comma seperated ports numbers
		validation.post.socket.list is the list of all comma seperated sockets
		jboss.home is the location where Jboss is installed
		jboss.server.name is the name of the deployed Jboss server
	-->
	<macrodef name="validate-post-install" description="Diagnose the host system after the installation">
 		<attribute name="validation.post.http.list" default="${validation.post.http.list}" />
 		<attribute name="validation.post.socket.list" default="${validation.post.socket.list}" />
		<attribute name="jboss.home" default="${jboss.home}" />
		<attribute name="jboss.server.name" default="${jboss.server.name}" />
		<attribute name="application.url" default="${application.url}" />
		<attribute name="application.base.path" default="${application.base.path}"/>
		<attribute name="propertyfile.backup.location" default="@{application.base.path}/change-logs" />
		<sequential>

			<!-- Echo the properties for diagnostic purposes -->
			<echoproperties > <propertyset negate="yes" > <propertyref regex="passw" /> </propertyset> </echoproperties>

			<!-- Give JBOSS another couple of seconds to come up -->
			<waitfor maxwait="90" maxwaitunit="second" checkevery="5" checkeveryunit="second">
				<http url="${application.url}"/>
			</waitfor>

			<if>
				<and>
					<isset property="validation.post.port.list"/>
					<not>
						<isset property="jboss.ncicb-standard.port-config"/>
					</not>
				</and>
				<then>
					<validate-ports-postinstall
						validation.post.http.list="@{validation.post.http.list}"
						validation.post.socket.list="@{validation.post.socket.list}"
						/>
				</then>
			</if>
			<validate-jboss-logs-postinstall
				jboss.home="@{jboss.home}"
				jboss.server.name="@{jboss.server.name}"
			/>

			<!-- Send test message if smtp proeprties are set
			<if>
				<and>
					<isset property="mail.smtp.host"/>
					<isset property="mail.smtp.port"/>
					<isset property="validation.email.from"/>
					<isset property="validation.email.to"/>
				</and>
			<then>
				<if>
						<socket port="${mail.smtp.port}" server="${mail.smtp.host}" />
					<then>
						<echo message="Able to connect to smpt host on port."/>
					</then>
					<else>
						<echo message="Failed to connnect to ${mail.smtp.host}:${mail.smtp.port}"/>
					</else>
				</if>
				<echo message="Sending Test message- look for errors below"/>
				<mail mailhost="${mail.smtp.host}" mailport="${mail.smtp.port}" subject="Test Message" failonerror="false">
					<from address="${validation.email.from}"/>
					<to address="${validation.email.to}"/>
				<message>Attempting install of ${project.name} ${env.USER}@${env.HOSTNAME} at ${run.date}.</message>
				</mail>
			</then>
			</if>
			-->
			<echo message="******* INSTALLATION COMPLETED SUCESSFULLY *******"/>
			<echo message="${line.separator}To view your application goto ${application.url}."/>
			<tstamp>
				<format property="run.date" pattern="yyMMddHHmm"/>
			</tstamp>
			<basename file="${properties.file}" property="properties.file.name"/>
			<var name="backup.properties.file" value="${properties.file.name}-${run.date}"/>
			<mkdir dir="@{propertyfile.backup.location}"/>
			<copy tofile="@{propertyfile.backup.location}/${backup.properties.file}" file="${properties.file}"/>

		</sequential>
	</macrodef>

	<!--
	validate-ports-postinstall macro checks if the application listens on the specified port numbers and is part of postinstall checks
	usage: <validate-ports-postinstall validation.post.http.list="${validation.post.http.list}" validation.post.socket.list="${validation.post.socket.list}" hostname="${jboss.server.hostname}" />
		validation.post.http.list is the list of all comma seperated ports numbers
		validation.post.socket.list is the list of all comma seperated sockets
		hostname is the deployed host ex. localhost
	-->
	<macrodef name="validate-ports-postinstall" description="Diagnose the host system after the installation">
		<attribute name="validation.post.http.list" default="${validation.post.http.list}" />
		<attribute name="validation.post.socket.list" default="${validation.post.socket.list}" />
		<attribute name="hostname" default="${jboss.server.hostname}" />
		<sequential>
			<!-- For each http port call validate:post:http -->
			<for list="${validation.post.http.list}" param="validate.port">
				<sequential>
					<echo message="Checking if @{validate.port} is running."/>
					<if>
						<http url="http://@{hostname}:@{validate.port}" />
						<then>
							<echo message="Port is @{validate.port} RUNNNING as expected."/>
						</then>
						<else>
							<echo message="Port is not responding or giving an HTTP error code @{hostname}:@{validate.port}. You may experience problems using the application."/>
						</else>
					</if>
				</sequential>
			</for>

			<!-- For each socket port call validate:post:socket -->
			<if>
			<isset property="validation.post.socket.list"/>
				<then>
					<for list="${validation.post.socket.list}" param="validate.port" >
						<sequential>
							<echo message="Checking if @{validate.port} is running."/>
							<if>
								<socket server="@{hostname}" port="@{validate.port}" />
								<then>
									<echo message="Port is @{validate.port} RUNNNING as expected."/>
								</then>
								<else>
									<echo message="Unable to reach @{hostname}:@{validate.port}. You may experience problems using the application."/>
								</else>
							</if>
						</sequential>
					</for>
				</then>
			</if>
		</sequential>
	</macrodef>

	<!--
	validate-jboss-logs-postinstall macro is part of postinstall checks and parses the the jboss server.log and boot.log for any warning and errors after the installation.
	usage: <validate-jboss-logs-postinstall jboss.home="${jboss.home}" jboss.server.name="${jboss.server.name}" />
		jboss.home is the location where Jboss is installed
		jboss.server.name is the name of the deployed Jboss server
	-->
	<macrodef name="validate-jboss-logs-postinstall" description="Diagnose the host system after the installation">
		<attribute name="jboss.home" default="${jboss.home}" />
		<attribute name="jboss.server.name" default="${jboss.server.name}" />
		<sequential>
			<!-- Process jboss server.log for errors and warnings and display on screen -->
			<var name="server.log" value="@{jboss.home}/server/@{jboss.server.name}/log/server.log"/>
			<var name="boot.log" value="@{jboss.home}/server/@{jboss.server.name}/log/boot.log"/>
			<available property="server.log.exists" file="${server.log}"/>
			<available property="boot.log.exists" file="${boot.log}"/>
			<if>
				<isset property="server.log.exists"/>
				<then>
					<loadfile
						property="log.server.errors"
						srcFile="${server.log}">
						<filterchain>
							<filterreader classname="org.apache.tools.ant.filters.TailFilter">
								<param name="lines" value="10000"/>
							</filterreader>
							<linecontainsregexp>
								<regexp pattern="^\w+.* ERROR "/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>
					<if>
						<isset property="log.server.errors"/>
						<then>
							<echo message="The following are ERRORS from the ${server.log}."/>
							<echo message="${log.server.errors}"/>
						</then>
					</if>

					<loadfile
						property="log.server.warnings"
						srcFile="${server.log}">
						<filterchain>
							<filterreader classname="org.apache.tools.ant.filters.TailFilter">
								<param name="lines" value="10000"/>
							</filterreader>
							<linecontainsregexp>
								<regexp pattern="^\w+.* WARN "/>
							</linecontainsregexp>

						</filterchain>
					</loadfile>
					<if>
						<isset property="log.server.warnings"/>
						<then>
							<echo message="${line.separator}The following are WARNINGS from the ${server.log}."/>
							<echo message="${log.server.warnings}"/>
						</then>
					</if>
				</then>
			</if>

			<!-- Process jboss boot.log for errors and warnings and display on screen -->
			<if>
				<isset property="boot.log.exists"/>
				<then>
					<loadfile
						property="log.boot.errors"
						srcFile="${boot.log}">
						<filterchain>
							<filterreader classname="org.apache.tools.ant.filters.TailFilter">
								<param name="lines" value="10000"/>
							</filterreader>
							<linecontainsregexp>
								<regexp pattern="^\w+.* ERROR "/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>
					<if>
						<isset property="log.boot.errors"/>
						<then>
							<echo message="The following are ERRORS from the ${boot.log}."/>
							<echo message="${log.boot.errors}"/>
						</then>
					</if>

					<loadfile
						property="log.boot.warnings"
						srcFile="${boot.log}">
						<filterchain>
							<filterreader classname="org.apache.tools.ant.filters.TailFilter">
								<param name="lines" value="10000"/>
							</filterreader>
							<linecontainsregexp>
								<regexp pattern="^\w+.* WARN "/>
							</linecontainsregexp>

						</filterchain>
					</loadfile>
					<if>
						<isset property="log.boot.warnings"/>
						<then>
							<echo message="${line.separator}The following are WARNINGS from the ${boot.log}."/>
							<echo message="${log.boot.warnings}"/>
						</then>
					</if>
				</then>
			</if>
		</sequential>
	</macrodef>

	<!--
	database-create macro create the mysql database and user and grant priledges to the user
	usage: <database-create database.driver="${database.driver}" database.system.url="${database.system.url}" database.system.user="${database.system.user}" database.system.password="${database.system.password} database.name="${database.name}" database.url="${database.url}" database.password="${database.password}"/>
		database.driver is the jdbc driver to connect to database
		database.system.url is the installed host of the database
		database.system.user is the system user for the database
		database.system.password is the system password for the database
		database.name is the name of the database
		database.url is the url of the database where it is hosted
		database.user is the user of the database
		database.password is the password of the user for the database
	-->
	<macrodef name="database-create">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.driver.file" default="${database.driver.file}" />
		<attribute name="database.system.url" default="${database.system.url}" />
		<attribute name="database.system.user" default="${database.system.user}" />
		<attribute name="database.system.password" default="${database.system.password}" />
		<attribute name="database.version" default="5.5.0" />
		<attribute name="database.name" default="${database.name}" />
		<attribute name="database.server" default="${database.server}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.type" default="${database.type}" />
		<sequential>
			<echo message="Entering database-create"/>
			<if>
				<isset property="force.reinstall"/>
				<then>
					<echo message="Creating @{database.type} database named @{database.name}."/>
					<switch value="@{database.type}">
						<case value="mysql">
							<echo message="Database @{database.name} does not exist or the force.reinstall property is set."/>
							<var name="create.sql.dir" value="${build-utils.resource.dir}/target" />
							<delete dir="${create.sql.dir}"/>
							<sql
								driver="@{database.driver}"
								url="@{database.system.url}"
								userid="@{database.system.user}"
								password="@{database.system.password}"
								expandproperties="true"
								onerror="continue"
								>
								<classpath>
									<pathelement location="@{database.driver.file}" />
								</classpath>
								<transaction>
									REVOKE ALL ON @{database.name}.* FROM '@{database.user}'@'@{database.server}';
									REVOKE ALL ON @{database.name}.* FROM '@{database.user}'@'%';
								</transaction>
							</sql>
							<sql
								driver="@{database.driver}"
								url="@{database.system.url}"
								userid="@{database.system.user}"
								password="@{database.system.password}"
								expandproperties="true"
								onerror="continue"
								>
								<classpath>
									<pathelement location="@{database.driver.file}" />
								</classpath>
								<transaction>
									DROP DATABASE IF EXISTS @{database.name};
									CREATE DATABASE @{database.name} DEFAULT CHARACTER SET latin1;
									GRANT ALL ON @{database.name}.* TO '@{database.user}'@'@{database.server}' IDENTIFIED BY '@{database.password}';
									GRANT ALL ON @{database.name}.* TO '@{database.user}'@'%' IDENTIFIED BY '@{database.password}';
									GRANT ALL ON @{database.name}.* TO '@{database.user}'@'%';
								</transaction>
							</sql>
						</case>
						<case value="postgresql">
							<sql
								driver="@{database.driver}"
								url="@{database.system.url}"
								userid="@{database.system.user}"
								password="@{database.system.password}"
								expandproperties="true"
								onerror="continue"
								autocommit="true"
								>
								<classpath>
									<pathelement location="@{database.driver.file}" />
								</classpath>
									drop database if exists @{database.name};
									drop user if exists @{database.user};
									create database @{database.name};
									create user @{database.user} with password '@{database.password}';
									grant all on database @{database.name} to @{database.user};
							</sql>
						</case>
					</switch>
				</then>
			</if>
		</sequential>
	</macrodef>

	<!--
	validate-database macro validates the creadentials of the provided system user and the installed version of the database
	usage: <validate-database database.driver="${database.driver}" database.system.url="${database.system.url}" database.system.user="${database.system.user}" database.system.password="${database.system.password}" database.version="${database.version}"/>
		database.driver is the jdbc driver to connect to database
		database.system.url is the installed host of the database
		database.system.user is the system user for the database
		database.system.password is the system password for the database
		database.version is the version of the installed database
	-->
	<macrodef name="validate-database">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.system.url" default="${database.system.url}" />
		<attribute name="database.system.user" default="${database.system.user}" />
		<attribute name="database.system.password" default="${database.system.password}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.version" default="5.5.0" />
		<attribute name="database.name" default="${database.name}" />
		<attribute name="database.type" default="${database.type}" />
		<attribute name="database.re-create" default="${database.re-create}" />
		<attribute name="database.drop-schema" default="${database.drop-schema}" />
		<sequential>
			<!-- Only validates connection for oracle -->
			<if>
				<and>
					<not>
						<isset property="ignore.check.database"/>
					</not>
					<not>
						<isset property="exclude.check.database"/>
					</not>
					<not>
						<isset property="exclude.database"/>
					</not>
				</and>
				<then>
					<echo message="Validating database connection..." />
					<switch value="@{database.type}">
						<case value="mysql">
							<echoproperties  prefix="database"> <propertyset negate="yes" > <propertyref regex="passw" /> </propertyset> </echoproperties>
							<if>
								<equals arg1="@{database.re-create}" arg2="true"/>
								<then>
									<dbconfig property="db.connection.success"
										driver="@{database.driver}" url="@{database.system.url}"  user="@{database.system.user}" password="@{database.system.password}">
										<validate />
										<checkversion atleast="@{database.version}" />
									</dbconfig>
									<antunit:assertPropertyEquals message="Database connection failed for @{database.url}. Verify that your database.user and database.password property values are valid in the *-install.properties file.  Your database version must be least @{database.version}" name="db.connection.success" value="true" />
									<echo message="Database Connection: PASSED" />
								</then>
								<else>
									<dbconfig property="db.connection.success"
										driver="@{database.driver}" url="@{database.url}"  user="@{database.user}" password="@{database.password}">
										<validate />
										<checkversion atleast="@{database.version}" />
									</dbconfig>
									<antunit:assertPropertyEquals message="Database connection failed for @{database.url}. Verify that your database.user and database.password property values are valid in the *-install.properties file.  Your database version must be least @{database.version}" name="db.connection.success" value="true" />
									<echo message="Database Connection: PASSED" />
								</else>
							</if>
						</case>
						<case value="postgresql">
							<if>
								<equals arg1="@{database.re-create}" arg2="true"/>
								<then>
									<dbconfig property="db.connection.success"
										driver="@{database.driver}" url="@{database.system.url}"  user="@{database.system.user}" password="@{database.system.password}">
										<validate />
									</dbconfig>
									<antunit:assertPropertyEquals message="Database connection failed for @{database.url}. Verify that your database.user and database.password property values are valid in the *-install.properties file.  Your database version must be least @{database.version}" name="db.connection.success" value="true" />
									<echo message="Database Connection: PASSED" />
								</then>
								<else>
									<dbconfig property="db.connection.success"
										driver="@{database.driver}" url="@{database.url}"  user="@{database.user}" password="@{database.password}">
										<validate />
									</dbconfig>
									<antunit:assertPropertyEquals message="Database connection failed for @{database.url}. Verify that your database.user and database.password property values are valid in the *-install.properties file.  Your database version must be least @{database.version}" name="db.connection.success" value="true" />
									<echo message="Database Connection: PASSED" />
								</else>
							</if>
						</case>
						<case value="oracle">
							<dbconfig property="oracle.connection.success"
								driver="@{database.driver}"
								url="@{database.url}"
								user="@{database.user}"
								password="@{database.password}">
									<validate />
							</dbconfig>
							<antunit:assertPropertyEquals
								message="Database connection failed for @{database.system.url}. Validate your database related properties in the *-install.properties file."
								name="oracle.connection.success"
							       	value="true" />
							<echo message="Database Connection: PASSED" />
						</case>
					</switch>
				</then>
				<else>
					<echo message="Skipped database checkes"/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<!--
	tomcat-stop macro stops the tomcat instance and can be used in both linux and windows platforms
	usage: <tomcat-stop tomcat.home="${tomcat.home}"/>
		The tomcat.home must be set and passed when calling this macro
	-->
	<macrodef name="tomcat-stop" description="Stops a local tomcat instance">
		<attribute name="tomcat.home" />
		<sequential>
			<echo message="Stopping Tomcat instance at @{tomcat.home}" />
			<exec executable="sh" osfamily="unix" dir="@{tomcat.home}/bin" spawn="true">
				<env key="NOPAUSE" value="true" />
				<env key="CATALINA_BASE" value=""/>
				<env key="CATALINA_HOME" value=""/>
				<env key="CATALINA_TMPDIR" value=""/>
				<arg line="shutdown.sh" />
			</exec>
			<exec osfamily="windows" executable="cmd" dir="@{tomcat.home}/bin" spawn="true" >
				<env key="NOPAUSE" value="true" />
				<env key="CATALINA_BASE" value=""/>
				<env key="CATALINA_HOME" value=""/>
				<env key="CATALINA_TMPDIR" value=""/>
				<arg line="/c shutdown.bat" />
			</exec>
			<sleep seconds="5" />
		</sequential>
	</macrodef>

	<!--
	tomcat-stop macro starts the tomcat instance and can be used in both linux and windows platforms
	usage: <tomcat-start tomcat.home="${tomcat.home}"/>
		The tomcat.home must be set and passed when calling this macro
	-->
	<macrodef name="tomcat-start" description="Starts a local tomcat instance">
		<attribute name="tomcat.home" />
		<sequential>
			<echo message="Starting Tomcat instance at @{tomcat.home}" />
			<exec executable="sh" osfamily="unix" dir="@{tomcat.home}/bin" spawn="true">
				<env key="NOPAUSE" value="true" />
				<env key="CATALINA_BASE" value=""/>
				<env key="CATALINA_HOME" value=""/>
				<env key="CATALINA_TMPDIR" value=""/>
				<arg line="startup.sh" />
			</exec>
			<echo message="executing ${build-utils.resource.dir}/psexec.exe"/>
			<exec osfamily="windows" executable="${build-utils.resource.dir}/psexec.exe" dir="@{tomcat.home}/bin" spawn="true" >
				<env key="NOPAUSE" value="true" />
				<env key="CATALINA_BASE" value=""/>
				<env key="CATALINA_HOME" value=""/>
				<env key="CATALINA_TMPDIR" value=""/>
				<arg line="-d -i -w @{tomcat.home}/bin @{tomcat.home}/bin/startup.bat" />
			</exec>
			<sleep seconds="5" />
		</sequential>
	</macrodef>

	<!--
	properties-exist macro checks if the value of the property is set in the list of properties seperated by ','
	usage: <properties-exist properties.list="${properties.list}"/>
		The properties.list must be set and passed when calling this macro
	-->
	<macrodef name="properties-exist" description="Check if the value of the property is set">
		<attribute name="properties.list" />
		<sequential>
			<for list="@{properties.list}" param="prop.list.item" delimiter=",">
				<sequential>
					<propertyregex property="prop.list.item.trimmed"
						input="@{prop.list.item}"
						regexp="\s*(\S+)\s*"
						select="\1"
						override="true"
						/>
					<echo level="debug" message="Verifying ${prop.list.item.trimmed} is set"/>
					<if>
						<not>
							<isset property="${prop.list.item.trimmed}"/>
						</not>
						<then>
							<fail message="Property ${prop.list.item.trimmed} is not set, it needs to be set, please set it to continue"/>
						</then>
					</if>
				</sequential>
			</for>
		</sequential>
	</macrodef>

	<!--
	compare-properties macro checks that there are same number of key for a given property files
	usage: <compare-properties property.template.file="${property.template.file} envpropertyfile="${envpropertyfile} "/>
		The property.template.file is the template file to compare with
		The envpropertyfile is the properties file to be compared to
	-->
	<macrodef name="compare-properties" description="validate the properties from the given files">
		<attribute name="property.template.file" default="${property.template.file}"/>
		<attribute name="envpropertyfile" default="${properties.file}"/>
		<sequential>
			<echo message="Checking @{envpropertyfile} against template file @{property.template.file}"/>
			<if>
				<available file="@{property.template.file}"/>
				<then>
					<propertyvalidator keyFile="@{property.template.file}"
						compareFile="@{envpropertyfile}"
						readInMemory="true"
						match="atleast"
						/>
				</then>
				<else>
					<echo message="Template file @{property.template.file} not avaliable"/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<!--
	svn-co macro checks out from a subversion repository based on properties passed to macro, clean the destination directory, then check out the tag specified into the destination directory.
	The macro assumes that all code required to build the application will be located under the software folder off the project root.  You will not be able to use this macro if you do not adhere to this structure.
	usage: <svn-co svn.project.base.url="${svn.project.base.url}" svn.project.name="${svn.project.name}" svn.tag="${svn.tag}" svn.co.base.dir="${svn.co.base.dir}"/>
		The svn.project.base.url is the URL of Subverion reposition to check out from
		The svn.project.name is the name of the project in the repositiory
		The svn.tag is the tag of the build ex. trunk
		The svn.co.base.dir is the local directory to the checkout
	-->

	<macrodef name="svn-co" description="based on properties passed to macro, clean the destination directory, then check out the tag specified into the destination directory.">
		<attribute name="svn.checkout.url" />
		<attribute name="svn.checkout.dir"/>
		<attribute name="svn.checkout.user" default="anonymous"/>
		<attribute name="svn.checkout.pass" default=""/>
		<attribute name="delete" default="true"/>
		<sequential>
			<if>
				<equals arg1="@{delete}" arg2="true" />
				<then>
					<echo message="Scorching temporary checkout directory @{svn.checkout.dir}."/>
					<delete dir="@{svn.checkout.dir}" failonerror="false"/>
					<mkdir dir="@{svn.checkout.dir}"/>
				</then>
			</if>
			<echo message="Checking out @{svn.checkout.url} to @{svn.checkout.dir}."/>
			<svn username="@{svn.checkout.user}" password="@{svn.checkout.pass}" javahl="false" svnkit="true">
				<!-- <checkout url="@{svn.checkout.url}" revision="HEAD" destPath="@{svn.checkout.dir}" />-->
				<checkout url="@{svn.checkout.url}"  destPath="@{svn.checkout.dir}" />
			</svn>
		</sequential>
	</macrodef>

	<macrodef name="svn-add" description="">
		<attribute name="svn.add.dir"/>
		<sequential>
			<echo message="Adding @{svn.add.dir} to svn."/>
			<svn failonerror="false" javahl="false" svnkit="true">
				<add dir="@{svn.add.dir}" force="true"/>
			</svn>
		</sequential>
	</macrodef>
	<macrodef name="svn-update" description="">
		<attribute name="svn.update.dir"/>
		<sequential>
			<echo message="Adding @{svn.update.dir} to svn."/>
			<svn failonerror="false" javahl="false" svnkit="true">
				<update dir="@{svn.update.dir}"/>
			</svn>
		</sequential>
	</macrodef>

	<macrodef name="svn-commit" description="">
		<attribute name="svn.commit.dir"/>
		<attribute name="svn.commit.user" default="anonymous"/>
		<attribute name="svn.commit.pass" default=""/>
		<attribute name="svn.commit.message" default="Added by build process"/>
		<sequential>
			<echo message="Commiting @{svn.commit.dir} to svn."/>
			<svn username="@{svn.commit.user}" password="@{svn.commit.pass}" javahl="false" svnkit="true">
				<commit dir="@{svn.commit.dir}" message="@{svn.commit.message}"/>
			</svn>
		</sequential>
	</macrodef>

	<macrodef name="report-grand" description="generates grand graphs of build.xml files">
		<attribute name="build.file.location" default="build.xml"/>
		<attribute name="output.file.dir" default="."/>
		<attribute name="output.file.name" default="build.xml"/>
		<attribute name="file.type" default="pdf"/>
		<sequential>
			<var name="grand.output.file" value="${temp.dir}/grand.dot" />
			<grand output="${grand.output.file}" buildfile="@{build.file.location}"/>
			<exec executable="dot" >
				<arg line="-T@{file.type} -Gsize=11.69,8.27 -o @{output.file.dir}/@{output.file.name}.@{file.type} ${grand.output.file}"/>
			</exec>
		</sequential>
	</macrodef>

	<!--
	jboss-bindings macro configures the binding.xml and the jboss-service.xml which is used by jboss Binding Manager.
	usage: <jboss-bindings jboss.home="${jboss.home}" jboss.server.name="${jboss.server.name}" jboss.server.ports.name="${jboss.server.ports.name}" jboss.server.bindingfile.location="${jboss.server.bindingfile.location}"/>
		The jboss.home is the location where Jboss is installed
		The jboss.server.name is the name of the deployed Jboss server
		The jboss.server.ports.name is the name of the configuration to be used from binding.xml
		jboss.server.bindingfile.location is the location of the binding.xml
	-->
	<macrodef name="jboss-bindings" description="configures the binding.xml and the jboss-service.xml">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.server.ports.name" default="${jboss.server.ports.name}"/>
		<attribute name="jboss.server.bindingfile.location" default="${jboss.server.bindingfile.location}"/>
		<attribute name="jboss.server.binding.template.location" default="${jboss.server.binding.template.location}"/>
		<attribute name="jboss.server.jndi.port" default="${jboss.server.jndi.port}"/>
		<attribute name="jboss.server.port" default="${jboss.server.port}"/>
		<attribute name="jboss.cobraorb.port" default="${jboss.cobraorb.port}"/>
		<attribute name="jboss.ejbinvoker.port" default="${jboss.ejbinvoker.port}"/>
		<attribute name="jboss.hajndi.port" default="${jboss.hajndi.port}"/>
		<attribute name="jboss.hajrmi.port" default="${jboss.hajrmi.port}"/>
		<attribute name="jboss.jms.port" default="${jboss.jms.port}"/>
		<attribute name="jboss.jmx-rmi.port" default="${jboss.jmx-rmi.port}"/>
		<attribute name="jboss.messaging.port" default="${jboss.messaging.port}"/>
		<attribute name="jboss.pooledha.port" default="${jboss.pooledha.port}"/>
		<attribute name="jboss.remoting.port" default="${jboss.remoting.port}"/>
		<attribute name="jboss.server.bind.port" default="${jboss.server.bind.port}"/>
		<attribute name="jboss.server.rmi.port" default="${jboss.server.rmi.port}"/>
		<attribute name="jboss.service.rmiobject.port" default="${jboss.service.rmiobject.port}"/>
		<attribute name="jboss.snmp.port" default="${jboss.snmp.port}"/>
		<attribute name="jboss.snmp-trapd.port" default="${jboss.snmp-trapd.port}"/>
		<attribute name="jboss.web.service.port" default="${jboss.web.service.port}"/>
		<!-- new with 5.1.0-->
		<attribute name="jboss.unifiedinvoker.port" default="${jboss.unifiedinvoker.port}"/>
		<attribute name="jboss.hajndi.auto.port" default="${jboss.hajndi.auto.port}"/>
		<attribute name="jboss.ssl.port" default="${jboss.ssl.port}"/>
		<attribute name="jboss.jms2.netty.port" default="${jboss.jms2.netty.port}"/>
		<attribute name="jboss.jms2.netty-ssl.port" default="${jboss.jms2.netty-ssl.port}"/>
		<attribute name="jboss.transaction.recovery.port" default="${jboss.transaction.recovery.port}"/>
		<attribute name="jboss.transaction.status.port" default="${jboss.transaction.status.port}"/>
		<attribute name="jboss.transaction.processid.port" default="${jboss.transaction.processid.port}"/>
		<!-- grid secure fixes -->
		<attribute name="jboss.http-connector.remove" default="${jboss.http-connector.remove}"/>
		<attribute name="grid.secure.port" default="${grid.secure.port}"/>
		<!-- for 5.1 port config -->
		<attribute name="jboss.ncicb-standard.port-config" default="${jboss.ncicb-standard.port-config}"/>
		<sequential>
			<var name="jboss.is.40" unset="true"/>
			<propertyregex property="jboss.is.40"
				input="@{jboss.home}"
				regexp=".*jboss-4.*"
				select="true"
				/>
			<var name="jboss.is.51" unset="true"/>
			<propertyregex property="jboss.is.51"
				input="@{jboss.home}"
				regexp=".*jboss-5.1.*"
				select="true"
				/>
			<if>
				<isset property="jboss.is.40"/>
				<then>
					<jboss-bindings-40
						jboss.home="@{jboss.home}"
						jboss.server.name="@{jboss.server.name}"
						jboss.server.ports.name="@{jboss.server.ports.name}"
						jboss.server.bindingfile.location="@{jboss.server.bindingfile.location}"
						jboss.server.binding.template.location="@{jboss.server.binding.template.location}"
						jboss.server.jndi.port="@{jboss.server.jndi.port}"
						jboss.server.port="@{jboss.server.port}"
						jboss.cobraorb.port="@{jboss.cobraorb.port}"
						jboss.ejbinvoker.port="@{jboss.ejbinvoker.port}"
						jboss.hajndi.port="@{jboss.hajndi.port}"
						jboss.hajrmi.port="@{jboss.hajrmi.port}"
						jboss.jms.port="@{jboss.jms.port}"
						jboss.jmx-rmi.port="@{jboss.jmx-rmi.port}"
						jboss.messaging.port="@{jboss.messaging.port}"
						jboss.pooledha.port="@{jboss.pooledha.port}"
						jboss.remoting.port="@{jboss.remoting.port}"
						jboss.server.bind.port="@{jboss.server.bind.port}"
						jboss.server.rmi.port="@{jboss.server.rmi.port}"
						jboss.service.rmiobject.port="@{jboss.service.rmiobject.port}"
						jboss.snmp.port="@{jboss.snmp.port}"
						jboss.snmp-trapd.port="@{jboss.snmp-trapd.port}"
						jboss.web.service.port="@{jboss.web.service.port}"
						grid.secure.port="@{grid.secure.port}"
						jboss.http-connector.remove="@{jboss.http-connector.remove}"
						jboss.ssl.port="@{jboss.ssl.port}"
						/>
				</then>
			</if>
			<if>
				<isset property="jboss.is.51"/>
				<then>
					<jboss-bindings-51
						jboss.home="@{jboss.home}"
						jboss.server.name="@{jboss.server.name}"
						jboss.server.ports.name="@{jboss.server.ports.name}"
						jboss.server.bindingfile.location="@{jboss.server.bindingfile.location}"
						jboss.server.binding.template.location="@{jboss.server.binding.template.location}"
						jboss.server.jndi.port="@{jboss.server.jndi.port}"
						jboss.server.port="@{jboss.server.port}"
						jboss.cobraorb.port="@{jboss.cobraorb.port}"
						jboss.ejbinvoker.port="@{jboss.ejbinvoker.port}"
						jboss.hajndi.port="@{jboss.hajndi.port}"
						jboss.hajrmi.port="@{jboss.hajrmi.port}"
						jboss.jms.port="@{jboss.jms.port}"
						jboss.jmx-rmi.port="@{jboss.jmx-rmi.port}"
						jboss.messaging.port="@{jboss.messaging.port}"
						jboss.pooledha.port="@{jboss.pooledha.port}"
						jboss.remoting.port="@{jboss.remoting.port}"
						jboss.server.bind.port="@{jboss.server.bind.port}"
						jboss.server.rmi.port="@{jboss.server.rmi.port}"
						jboss.service.rmiobject.port="@{jboss.service.rmiobject.port}"
						jboss.snmp.port="@{jboss.snmp.port}"
						jboss.snmp-trapd.port="@{jboss.snmp-trapd.port}"
						jboss.web.service.port="@{jboss.web.service.port}"
						jboss.unifiedinvoker.port="@{jboss.unifiedinvoker.port}"
						jboss.hajndi.auto.port="@{jboss.hajndi.auto.port}"
						jboss.ssl.port="@{jboss.ssl.port}"
						jboss.jms2.netty.port="@{jboss.jms2.netty.port}"
						jboss.jms2.netty-ssl.port="@{jboss.jms2.netty-ssl.port}"
						jboss.transaction.recovery.port="@{jboss.transaction.recovery.port}"
						jboss.transaction.status.port="@{jboss.transaction.status.port}"
						jboss.transaction.processid.port="@{jboss.transaction.processid.port}"
						jboss.ncicb-standard.port-config="@{jboss.ncicb-standard.port-config}"
						/>
				</then>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="jboss-bindings-51" description="configures the binding.xml and the jboss-service.xml">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.server.ports.name" default="${jboss.server.ports.name}"/>
		<attribute name="jboss.server.bindingfile.location" default="@{jboss.home}/server/@{jboss.server.name}/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml"/>
		<!--<attribute name="jboss.server.bindingfile.location" default="${jboss.server.bindingfile.location}"/>-->
		<attribute name="jboss.server.binding.template.location" default="${jboss.server.binding.template.location}"/>
		<attribute name="jboss.server.jndi.port" default="${jboss.server.jndi.port}"/>
		<attribute name="jboss.server.port" default="${jboss.server.port}"/>
		<attribute name="jboss.cobraorb.port" default="${jboss.cobraorb.port}"/>
		<attribute name="jboss.ejbinvoker.port" default="${jboss.ejbinvoker.port}"/>
		<attribute name="jboss.hajndi.port" default="${jboss.hajndi.port}"/>
		<attribute name="jboss.hajrmi.port" default="${jboss.hajrmi.port}"/>
		<attribute name="jboss.jms.port" default="${jboss.jms.port}"/>
		<attribute name="jboss.jmx-rmi.port" default="${jboss.jmx-rmi.port}"/>
		<attribute name="jboss.messaging.port" default="${jboss.messaging.port}"/>
		<attribute name="jboss.pooledha.port" default="${jboss.pooledha.port}"/>
		<attribute name="jboss.remoting.port" default="${jboss.remoting.port}"/>
		<attribute name="jboss.server.bind.port" default="${jboss.server.bind.port}"/>
		<attribute name="jboss.server.rmi.port" default="${jboss.server.rmi.port}"/>
		<attribute name="jboss.service.rmiobject.port" default="${jboss.service.rmiobject.port}"/>
		<attribute name="jboss.snmp.port" default="${jboss.snmp.port}"/>
		<attribute name="jboss.snmp-trapd.port" default="${jboss.snmp-trapd.port}"/>
		<attribute name="jboss.web.service.port" default="${jboss.web.service.port}"/>
		<!-- new with 5.1.0-->
		<attribute name="jboss.unifiedinvoker.port" default="${jboss.unifiedinvoker.port}"/>
		<attribute name="jboss.hajndi.auto.port" default="${jboss.hajndi.auto.port}"/>
		<attribute name="jboss.ssl.port" default="${jboss.ssl.port}"/>
		<attribute name="jboss.jms2.netty.port" default="${jboss.jms2.netty.port}"/>
		<attribute name="jboss.jms2.netty-ssl.port" default="${jboss.jms2.netty-ssl.port}"/>
		<attribute name="jboss.transaction.recovery.port" default="${jboss.transaction.recovery.port}"/>
		<attribute name="jboss.transaction.status.port" default="${jboss.transaction.status.port}"/>
		<attribute name="jboss.transaction.processid.port" default="${jboss.transaction.processid.port}"/>
		<attribute name="search.jboss.ejbinvoker.port" default="3873"/>
		<attribute name="jboss.ncicb-standard.port-config" default="${jboss.ncicb-standard.port-config}"/>
		<sequential>
			<if>
				<not>
					<equals arg1="@{jboss.ncicb-standard.port-config}" arg2="true"/>
				</not>
				<then>
					<echo message="Bindings file location @{jboss.server.bindingfile.location}"/>
					<echo message="jboss.server.ports.name-@{jboss.server.ports.name}"/>
					<copy tofile="@{jboss.server.bindingfile.location}" file="@{jboss.server.binding.template.location}" overwrite="true">
						<filterset>
							<filter token="jboss.server.ports.name" value="@{jboss.server.ports.name}"/>
							<filter token="jboss.server.bindingfile.location" value="@{jboss.server.bindingfile.location}"/>
							<filter token="jboss.server.jndi.port" value="@{jboss.server.jndi.port}"/>
							<filter token="jboss.server.port" value="@{jboss.server.port}"/>
							<filter token="jboss.cobraorb.port" value="@{jboss.cobraorb.port}"/>
							<filter token="jboss.ejbinvoker.port" value="@{jboss.ejbinvoker.port}"/>
							<filter token="jboss.hajndi.port" value="@{jboss.hajndi.port}"/>
							<filter token="jboss.hajrmi.port" value="@{jboss.hajrmi.port}"/>
							<filter token="jboss.jms.port" value="@{jboss.jms.port}"/>
							<filter token="jboss.jmx-rmi.port" value="@{jboss.jmx-rmi.port}"/>
							<filter token="jboss.messaging.port" value="@{jboss.messaging.port}"/>
							<filter token="jboss.pooledha.port" value="@{jboss.pooledha.port}"/>
							<filter token="jboss.remoting.port" value="@{jboss.remoting.port}"/>
							<filter token="jboss.server.bind.port" value="@{jboss.server.bind.port}"/>
							<filter token="jboss.server.rmi.port" value="@{jboss.server.rmi.port}"/>
							<filter token="jboss.service.rmiobject.port" value="@{jboss.service.rmiobject.port}"/>
							<filter token="jboss.snmp.port" value="@{jboss.snmp.port}"/>
							<filter token="jboss.snmp-trapd.port" value="@{jboss.snmp-trapd.port}"/>
							<filter token="jboss.web.service.port" value="@{jboss.web.service.port}"/>
							<filter token="jboss.unifiedinvoker.port" value="@{jboss.unifiedinvoker.port}"/>
							<filter token="jboss.hajndi.auto.port" value="@{jboss.hajndi.auto.port}"/>
							<filter token="jboss.ssl.port" value="@{jboss.ssl.port}"/>
							<filter token="jboss.jms2.netty.port" value="@{jboss.jms2.netty.port}"/>
							<filter token="jboss.jms2.netty-ssl.port" value="@{jboss.jms2.netty-ssl.port}"/>
							<filter token="jboss.transaction.recovery.port" value="@{jboss.transaction.recovery.port}"/>
							<filter token="jboss.transaction.status.port" value="@{jboss.transaction.status.port}"/>
							<filter token="jboss.transaction.processid.port" value="@{jboss.transaction.processid.port}"/>
						</filterset>
					</copy>
					<!--
					<jboss-bindings-validate
						jboss.server.ports.name="@{jboss.server.ports.name}"
						jboss.server.bindingfile.location="@{jboss.server.bindingfile.location}"
						/>
					-->
					<!-- change ejb port -->
					<replaceregexp file="@{jboss.home}/server/@{jboss.server.name}/deploy/ejb3-connectors-jboss-beans.xml" byline="true"
						match="(.*)>@{search.jboss.ejbinvoker.port}<(.*)"
						replace="\1>@{jboss.ejbinvoker.port}<\2"
						/>
				</then>
				<else>
					<jboss51-bindings-nci
						jboss.home="@{jboss.home}"
						jboss.server.name="@{jboss.server.name}"
						jboss.server.ports.name="@{jboss.server.ports.name}"
						jboss.ncicb-standard.port-config="@{jboss.ncicb-standard.port-config}"
						jboss.server.bindingfile.location="@{jboss.server.bindingfile.location}"

						/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="jboss-bindings-40" description="configures the binding.xml and the jboss-service.xml">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.server.ports.name" default="${jboss.server.ports.name}"/>
		<attribute name="jboss.server.bindingfile.location" default="${jboss.server.bindingfile.location}"/>
		<attribute name="jboss.server.binding.template.location" default="${jboss.server.binding.template.location}"/>
		<attribute name="jboss.server.jndi.port" default="${jboss.server.jndi.port}"/>
		<attribute name="jboss.server.port" default="${jboss.server.port}"/>
		<attribute name="jboss.cobraorb.port" default="${jboss.cobraorb.port}"/>
		<attribute name="jboss.ejbinvoker.port" default="${jboss.ejbinvoker.port}"/>
		<attribute name="jboss.hajndi.port" default="${jboss.hajndi.port}"/>
		<attribute name="jboss.hajrmi.port" default="${jboss.hajrmi.port}"/>
		<attribute name="jboss.jms.port" default="${jboss.jms.port}"/>
		<attribute name="jboss.jmx-rmi.port" default="${jboss.jmx-rmi.port}"/>
		<attribute name="jboss.messaging.port" default="${jboss.messaging.port}"/>
		<attribute name="jboss.pooledha.port" default="${jboss.pooledha.port}"/>
		<attribute name="jboss.remoting.port" default="${jboss.remoting.port}"/>
		<attribute name="jboss.server.bind.port" default="${jboss.server.bind.port}"/>
		<attribute name="jboss.server.rmi.port" default="${jboss.server.rmi.port}"/>
		<attribute name="jboss.service.rmiobject.port" default="${jboss.service.rmiobject.port}"/>
		<attribute name="jboss.snmp.port" default="${jboss.snmp.port}"/>
		<attribute name="jboss.snmp-trapd.port" default="${jboss.snmp-trapd.port}"/>
		<attribute name="jboss.web.service.port" default="${jboss.web.service.port}"/>
		<!-- grid secure fixes -->
		<attribute name="jboss.http-connector.remove" default="${jboss.http-connector.remove}"/>
		<attribute name="grid.secure.port" default="${grid.secure.port}"/>
		<attribute name="jboss.ssl.port" default="${jboss.ssl.port}"/>

		<sequential>
			<echo message="Bindings file location @{jboss.server.bindingfile.location}"/>
			<copy tofile="@{jboss.server.bindingfile.location}" file="@{jboss.server.binding.template.location}" overwrite="true">
				<filterset>
					<filter token="jboss.server.ports.name" value="@{jboss.server.ports.name}"/>
					<filter token="jboss.server.bindingfile.location" value="@{jboss.server.bindingfile.location}"/>
					<filter token="jboss.server.jndi.port" value="@{jboss.server.jndi.port}"/>
					<filter token="jboss.server.port" value="@{jboss.server.port}"/>
					<filter token="jboss.cobraorb.port" value="@{jboss.cobraorb.port}"/>
					<filter token="jboss.ejbinvoker.port" value="@{jboss.ejbinvoker.port}"/>
					<filter token="jboss.hajndi.port" value="@{jboss.hajndi.port}"/>
					<filter token="jboss.hajrmi.port" value="@{jboss.hajrmi.port}"/>
					<filter token="jboss.jms.port" value="@{jboss.jms.port}"/>
					<filter token="jboss.jmx-rmi.port" value="@{jboss.jmx-rmi.port}"/>
					<filter token="jboss.messaging.port" value="@{jboss.messaging.port}"/>
					<filter token="jboss.pooledha.port" value="@{jboss.pooledha.port}"/>
					<filter token="jboss.remoting.port" value="@{jboss.remoting.port}"/>
					<filter token="jboss.server.bind.port" value="@{jboss.server.bind.port}"/>
					<filter token="jboss.server.rmi.port" value="@{jboss.server.rmi.port}"/>
					<filter token="jboss.service.rmiobject.port" value="@{jboss.service.rmiobject.port}"/>
					<filter token="jboss.snmp.port" value="@{jboss.snmp.port}"/>
					<filter token="jboss.snmp-trapd.port" value="@{jboss.snmp-trapd.port}"/>
					<filter token="jboss.web.service.port" value="@{jboss.web.service.port}"/>
				</filterset>
			</copy>
			<if>
				<equals arg1="@{jboss.http-connector.remove}" arg2="true"/>
				<then>
					<echo message="Changing redirect port in bindings file to @{grid.secure.port}"/>
					<replaceregexp file="@{jboss.server.bindingfile.location}"
						byline="true"
						match="\$port \+ 363"
						replace="@{grid.secure.port}"
						/>
				</then>
				<else>
					<!-- Right now only  removing http port for grid ssl.
					<echo message="Changing redirect port in bindings file to @{grid.secure.port}"/>
					<replaceregexp file="@{jboss.server.bindingfile.location}"
						byline="true"
						match="\$port\s\++\s\+363"
						replace="@{jboss.ssl.port}"
						/>
					-->
				</else>
			</if>
			<jboss-bindings-validate
				jboss.server.ports.name="@{jboss.server.ports.name}"
				jboss.server.bindingfile.location="@{jboss.server.bindingfile.location}"
				/>
			<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-service.xml" dest="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-service.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove path="/server/mbean[@code='org.jboss.services.binding.ServiceBindingManager']"/>
			</xmltask>
			<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-service.xml" dest="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-service.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="/server/mbean[@code='org.jboss.util.property.jmx.SystemPropertyClassValue']"
					position="after">
					<![CDATA[
					<mbean code="org.jboss.services.binding.ServiceBindingManager"
						name="jboss.system:service=ServiceBindingManager">
						<attribute name="ServerName">@{jboss.server.ports.name}</attribute>
						<attribute name="StoreURL">file:@{jboss.server.bindingfile.location}</attribute>
						<attribute name="StoreFactoryClassName">
							org.jboss.services.binding.XMLServicesStoreFactory
						</attribute>
					</mbean>
					]]>
				</insert>
			</xmltask>
		</sequential>
	</macrodef>

	<!--
	jboss-read-dbconfig macro reads the database information from the application ds.xml and makes connection to the database to check is the application and the database is installed
		usage: <jboss-read-dbconfig jboss.home="${jboss.home} jboss.server.name="${svn.project.name} jboss.ds-xml.file="name if the ds file"/>
			The jboss.home is the location where Jboss is installed
			The jboss.server.name is the name of the deployed Jboss server
			The jboss.ds-xml.file is the name of the ds.xml file
	-->
	<macrodef name="jboss-read-dbconfig" description="check if the application is installed">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.ds-xml.file"/>
		<attribute name="database.url.property.name" default="database.url" />
		<attribute name="database.name.property.name" default="database.name" />
		<attribute name="database.user.property.name" default="database.user" />
		<attribute name="database.password.property.name" default="database.password" />
		<attribute name="database.server.property.name" default="database.server" />
		<attribute name="database.port.property.name" default="database.port" />
		<attribute name="database.type.property.name" default="database.type" />
		<attribute name="database.schema.property.name" default="database.schema" />
		<sequential>
			<var name="db.properties.list" value="@{database.url.property.name},@{database.name.property.name},@{database.user.property.name},@{database.password.property.name},@{database.server.property.name},@{database.port.property.name},@{database.type.property.name}"/>
			<properties-missing
				properties.list="${db.properties.list}"
				properties.missing.property.name="db.properties.missing"
				/>
			<available file="@{jboss.home}/server/@{jboss.server.name}/deploy/@{jboss.ds-xml.file}" property="ds.exists"/>
			<if>
				<isset property="db.properties.missing"/>
				<then>
					<if>
						<not>
							<isset property="ds.exists" />
						</not>
						<then>
							<fail message="Some or all required database properties are not set and @{jboss.home}/server/@{jboss.server.name}/deploy/@{jboss.ds-xml.file} is not found.   Ensure arguments passed to this macro are correct or set required database properties in your property file."/>
						</then>
						<else>
							<echo message="Reading database properties: ${db.properties.list}"/>
							<!-- Blank props to be able to run this macro multiple times -->
							<var name="read.database.url" unset="true"/>
							<var name="read.database.user" unset="true"/>
							<var name="read.database.password" unset="true"/>
							<var name="read.database.driver" unset="true"/>
							<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/@{jboss.ds-xml.file}" >
								<xmlcatalog refid="build.xml.catalog"/>
								<copy path="//datasources/local-tx-datasource/connection-url/text()" property="read.database.url" />
								<copy path="//datasources/local-tx-datasource/user-name/text()" property="read.database.user" />
								<copy path="//datasources/local-tx-datasource/password/text()" property="read.database.password" />
								<copy path="//datasources/local-tx-datasource/driver-class/text()" property="read.database.driver" />
							</xmltask>

							<dbconfig property="db.appuser.works"
										driver="${read.database.driver}"
								url="${read.database.url}"
								user="${read.database.user}"
								password="${read.database.password}">
								<validate />
							</dbconfig>
							<propertyregex property="read.database.name"
								input="${read.database.url}"
								regexp=".*[\/](.*)\?*"
								select="\1"
								/>
							<propertyregex property="read.database.server"
								input="${read.database.url}"
								regexp=".*\/\/(.*):.*"
								select="\1"
								/>
							<propertyregex property="read.database.port"
								input="${read.database.url}"
								regexp=".*:(.*)\/.*"
								select="\1"
								/>
							<var name="read.database.type" unset="true"/>
							<propertyregex property="read.database.type"
								input="${read.database.driver}"
								regexp="mysql"
								select="mysql"
								/>
							<propertyregex property="read.database.type"
								input="${read.database.driver}"
								regexp="oracle"
								select="oracle"
								/>
							<propertyregex property="read.database.type"
								input="${read.database.driver}"
								regexp="postgresql"
								select="postgresql"
								/>

							<property name="@{database.url.property.name}" value="${read.database.url}" />
							<property name="@{database.user.property.name}" value="${read.database.user}" />
							<property name="@{database.password.property.name}" value="${read.database.password}" />
							<property name="@{database.name.property.name}" value="${read.database.name}" />
							<property name="@{database.server.property.name}" value="${read.database.server}" />
							<property name="@{database.port.property.name}" value="${read.database.port}" />
							<property name="@{database.type.property.name}" value="${read.database.type}" />

							<propertycopy name="db.type" from="@{database.type.property.name}" override="true"/>
							<switch value="${db.type}">
								<case value="oracle">
									<var name="@{database.schema.property.name}" value="${database.user}"/>
								</case>
								<case value="mysql">
									<var name="@{database.schema.property.name}" value="${database.name}"/>
								</case>
								<case value="postgresql">
									<var name="@{database.schema.property.name}" value="public"/>
								</case>
							</switch>
							<if>
								<isset property="db.appuser.works"/>
								<then>
									<echo level="debug" message="Read application database configuration from ${jboss.home}/server/${jboss.server.name}/deploy/@{jboss.ds-xml.file}"/>
									<echo level="debug"  message="Value after read of *-ds.xml: TYPE - ${read.database.type} URL- ${database.url}  USER- ${database.user} PASS- ##### NAME- ${database.name} SERVER- ${database.server} PORT- ${database.port}"/>
								</then>
								<else>
									<fail  message="Failed to connect to database TYPE - ${read.database.type} URL- ${database.url}  USER- ${database.user} PASS- ${database.password} NAME- ${database.name} SERVER- ${database.server} PORT- ${database.port}"/>
								</else>
							</if>
						</else>
					</if>
				</then>
			</if>
			<properties-print
				properties.list="${db.properties.list}"
				/>
			<var name="read.properties.list" value="${read.properties.list},${db.properties.list}"/>
		</sequential>
	</macrodef>

	<!--
	svn-getinfo macro gets the latest revision number in the repository for the give path and will set the lsd.revision property
		usage: <svn-getinfo />
		my.path is the checked out location of the project
	-->
	<macrodef name="svn-getinfo">
		<attribute name="my.path" default="${basedir}"/>
		<sequential>
			<svn javahl="false" svnkit="true">
				<status path="@{my.path}" revisionProperty="svn.revision" urlProperty="svn.url"/>
			</svn>
			<var name="lsd.revision" value="${svn.revision}" />
			<echo> in macrodef - @{my.path} </echo>
		</sequential>
	</macrodef>

	<!--
	generate-uml macro will generate the UML diagram from the checked in code. It will first create a javadoc HTML report and uses Graphviz to generate the UML graph
	Pre-Requisites: Graphviz should be present in the Path,
		usage: <generate-uml />
		uml.dir is the directory where the UML diagram are generated.
		src.java.dir is the source of class files.
		uml.source.path is the classpath for the files
	-->
	<macrodef name="generate-uml">
		<attribute name="uml.dir" />
		<attribute name="src.java.dir" />
		<attribute name="uml.source.path" />
		<attribute name="UMLGraph.jar" default="umlgraph-4.8.jar" />
		<sequential>
			<mkdir dir="@{uml.dir}"/>
			<javadoc sourcepath="@{src.java.dir}" destdir="@{uml.dir}" classpathref="@{uml.source.path}" access="private">
				<doclet name="gr.spinellis.umlgraph.doclet.UmlGraphDoc" path="${build-utils.dir}\@{UMLGraph.jar}">
					<param name="-attributes" />
					<param name="-enumerations" />
					<param name="-enumconstants" />
					<param name="-operations" />
					<param name="-qualify" />
					<param name="-types" />
					<param name="-visibility" />
				</doclet>
			</javadoc>
			<apply executable="dot" dest="@{uml.dir}" parallel="false">
				<arg value="-Tpng"/>
				<arg value="-o"/>
				<targetfile/>
				<srcfile/>
				<fileset dir="@{uml.dir}" includes="*.dot"/>
				<mapper type="glob" from="*.dot" to="*.png"/>
			</apply>
		</sequential>
	</macrodef>

	<!--
	generate-erd macro will generate an ERD from the Database
		usage: <generate-erd />
		report.dir is the directory where the ERD is generated.
	-->
	<macrodef name="generate-erd">
		<attribute name="report.dir" default="${target.dir}/reports/schema-spy" />
		<attribute name="database.driver.jar" default="mysql-connector-java-5.1.13.jar" />
		<attribute name="schemaspy.jar" default="schemaspy_3.1.1.jar" />
		<attribute name="database.server" default="${database.server}" />
		<attribute name="database.port" default="${database.port}" />
		<attribute name="database.name" default="${database.name}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.type" default="${database.type}" />
		<sequential>
			<java jar="${build-utils.dir}/@{schemaspy.jar}"
			output="@{report.dir}/schemaspy-out.log"
			error="@{report.dir}/schemaspy-error.log"
			fork="true">
				<arg line="-t @{database.type}"/>
				<arg line="-host @{database.server}"/>
				<arg line="-port @{database.port}"/>
				<arg line="-db @{database.name}"/>
				<arg line="-u @{database.user}"/>
				<arg line="-p @{database.password}"/>
				<arg line="-cp ${build-utils.dir}/@{database.driver.jar}"/>
				<arg line="-o @{report.dir}"/>
			</java>
		</sequential>
	</macrodef>

	<!--
	fusebox-metrics macro will generate graphical representation of the static analysis for the project
		usage: <fusebox-matrix fusebox.config.file="${build-utils.resource.dir}/fusemetrics_config.xml" fusebox.template.file="${build-utils.resource.dir}/dashboard.tmpl" fusebox.output.dir="${basedir}/target/output" fusebox.persist.dir="${basedir}/target/persist" fusebox.search.dir="${basedir}/reports"/>
		fusebox.config.file is the location of the config file.
		fusebox.project.name is the name of the project and the macro configures it into the config file.
		fusebox.search.dir is the location of the resulted XML files from the static analysis.
		fusebox.output.file is the location of the output directory.
		fusebox.persist.dir is the locations of the persisted directory and the data is appended after each build
		fusebox.template.file is the name of the file that renders data from the persistent file
	-->
	<macrodef name="fusebox-metrics" description="generates the fusebox metrics">
		<attribute name="fusebox.config.file" default="${build-utils.resource.dir}/fusemetrics_config.xml" />
		<attribute name="fusebox.project.name" default="Project" />
		<attribute name="fusebox.search.dir" default="reports" />
		<attribute name="fusebox.output.dir" default="output" />
		<attribute name="fusebox.persist.dir" default="persist" />
		<attribute name="fusebox.template.file" default="${build-utils.resource.dir}/dashboard.tmpl" />

		<sequential>
			<if>
				<equals arg1="@{fusebox.config.file}" arg2="fusemetrics_config.xml"/>
				<then>
					<property name= "fusebox.arg.value" value="fusemetrics_config.xml" />
				</then>
				<else>
					<property name= "fusebox.arg.value" value="@{fusebox.config.file}" />
				</else>
			</if>
			<if>
				<equals arg1="@{fusebox.config.file}" arg2="fusemetrics_config.xml"/>
				<then>
					<property name= "fusebox.arg.value" value="fusemetrics_config.xml" />
				</then>
				<else>
					<property name= "fusebox.arg.value" value="@{fusebox.config.file}" />
				</else>
			</if>

			<mkdir dir="@{fusebox.output.dir}"/>
			<mkdir dir="@{fusebox.persist.dir}"/>

			<xmltask preservetype="true" source="@{fusebox.config.file}" dest="@{fusebox.config.file}">
				<xmlcatalog refid="build.xml.catalog"/>
				<replace path="//config/@project" withtext="@{fusebox.project.name}" />
				<replace path="//config/@search" withtext="@{fusebox.search.dir}" />
				<replace path="//config/@output" withtext="@{fusebox.output.dir}" />
				<replace path="//config/@persist" withtext="@{fusebox.persist.dir}" />
				<replace path="//config/@template" withtext="@{fusebox.template.file}" />
				<replace path="//config/@html" withtext="@{fusebox.output.dir}/dashboard.html" />
			</xmltask>

			<java classname="com.stelligent.fusemetrics.FuseMetrics" >
			<arg value="-c"/>
			<arg value="${fusebox.arg.value}"/>
			<arg value="-d"/>
			 <classpath>
				   <pathelement location="${build-utils.dir}/fusemetrics-1.0.jar"/>
				   <pathelement location="${build-utils.dir}/xom-1.1.jar"/>
				   <pathelement location="${build-utils.dir}/xercesImpl-2.6.2.jar"/>
				   <pathelement location="${build-utils.dir}/jfreechart-swt-1.0.9.jar"/>
				   <pathelement location="${build-utils.dir}/jfreechart-1.0.9.jar"/>
				   <pathelement location="${build-utils.dir}/swtgraphics2d-1.0.9.jar"/>
				   <pathelement location="${build-utils.dir}/jcommon-1.0.12.jar"/>
				   <pathelement location="${build-utils.dir}/itext-2.0.6.jar"/>
				   <pathelement location="${build-utils.dir}/groovy-all-1.6.jar"/>
			 </classpath>
			</java>
		</sequential>
	</macrodef>

	<!--
	diffrevision macro will generate a file will names of the java files that were checked in from the last revision number till the HEAD or the current revision number
		usage: <diffrevision envpropertyfile="project.properties" differential.file.name="diff_list.txt" />
		old.revision.number is the old revision number when the static analysis is done
		differential.file.name is the name of the file to which the differential list is written.
	-->
	<macrodef name="diffrevision">
		<attribute name="old.revision.number" />
		<attribute name="differential.file.name" default="diff_list.txt" />
		<sequential>
			<svn javahl="false" svnkit="true">
				<status path="${basedir}"  revisionProperty="build.svn.revision" urlProperty="svn.source.url"/>
			</svn>

			<svn javahl="false" svnkit="true">
				<diff oldUrl="${svn.source.url}" oldTargetRevision="@{old.revision.number}" newTargetRevision="${build.svn.revision}" outFile="${basedir}/patch.txt"/>
			</svn>
			<loadfile
				property="diff.file.list"
				srcFile="${basedir}/patch.txt">
				<filterchain>
					<linecontainsregexp>
						<regexp pattern="Index: .*\.java"/>
					</linecontainsregexp>
				</filterchain>
			</loadfile>
			<if>
				<isset property="diff.file.list"/>
				<then>
					<echo file="@{differential.file.name}" append="false" message="${diff.file.list}${line.separator}"/>
				</then>
			</if>
			<replaceregexp file="@{differential.file.name}" byline="true" match="^Index: (.*)" replace="\1"/>
			<delete file="${basedir}/patch.txt"/>

		</sequential>
	</macrodef>

	<macrodef name="util-dot-on-dir">

		<attribute name="dot-file.dir" />
		<attribute name="report.type" default="pdf" />
		<sequential>
			<exec osfamily="unix" executable="ls" outputproperty="file.list" dir="@{dot-file.dir}">
				<arg value="-1"/>
			</exec>
			<exec osfamily="windows" executable="dir" outputproperty="file.list" dir="@{dot-file.dir}">
				<arg line="/c dir /b"/>
			</exec>

			<for list="${file.list}" delimiter="${line.separator}" param="file.name">
				<sequential>
					<if>
						<contains string="@{file.name}" substring="dot"/>
						<then>
							<var name="base.file.name" unset="true"/>
							<propertyregex property="base.file.name"
								input="@{file.name}"
								regexp="(.*)\.dot"
								select="\1"
								override="true"
								/>
							<echo message="Running graphviz on ${base.file.name}"/>
							<exec executable="dot" dir="@{dot-file.dir}">
								<arg value="-T@{report.type}"/>
								<arg value="-Gsize=11.69,8.27"/>
								<!--
								<arg value="-Grotate=90"/>
								-->
								<arg value="-o"/>
								<arg value="${base.file.name}.@{report.type}"/>
								<arg value="@{file.name}"/>
							</exec>
						</then>
					</if>
				</sequential>
			</for>
		</sequential>
	</macrodef>
	<macrodef name="database-clean">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.driver.file" default="${database.driver.file}" />
		<attribute name="database.system.url" default="${database.system.url}" />
		<attribute name="database.system.user" default="${database.system.user}" />
		<attribute name="database.system.password" default="${database.system.password}" />
		<attribute name="database.version" default="5.5.0" />
		<attribute name="database.name" default="${database.name}" />
		<attribute name="database.server" default="${database.server}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.schema" default="${database.schema}" />
		<attribute name="database.re-create" default="${database.re-create}" />
		<attribute name="database.drop-schema" default="${database.drop-schema}" />
		<attribute name="database.type" default="${database.type}" />
		<sequential>
			<if>
				<and>
					<equals arg1="@{database.re-create}" arg2="true"/>
					<equals arg1="@{database.drop-schema}" arg2="true"/>
				</and>
				<then>
					<fail message="You cannot set both database.re-create and database.drop-schema at the same time.  database.re-create is used in local installs.  database.drop-schema is used in remote installs.  Either one can be set for external (Cancer Center) installs."/>
				</then>
			</if>
			<if>
				<not>
					<or>
						<equals arg1="@{database.re-create}" arg2="true"/>
						<equals arg1="@{database.drop-schema}" arg2="true"/>
					</or>
				</not>
				<then>
					<fail message="Either database.re-create or database.drop-schema must be set to call the database install target.  Please set one in the properties file and build again, or if you don't want databases targets to run you can set exclude.database in the properties file."/>
				</then>
			</if>
			<if>
				<equals arg1="@{database.re-create}" arg2="true"/>
				<then>
					<switch value="@{database.type}">
						<case value="postgresql">
							<database-create
								database.driver="@{database.driver}"
								database.driver.file="@{database.driver.file}"
								database.system.url="@{database.system.url}"
								database.system.user="@{database.system.user}"
								database.system.password="@{database.system.password}"
								database.version="@{database.version}"
								database.name="@{database.name}"
								database.server="@{database.server}"
								database.url="@{database.url}"
								database.user="@{database.user}"
								database.password="@{database.password}"
								/>
						</case>
						<case value="mysql">
							<database-create
								database.driver="@{database.driver}"
								database.driver.file="@{database.driver.file}"
								database.system.url="@{database.system.url}"
								database.system.user="@{database.system.user}"
								database.system.password="@{database.system.password}"
								database.version="@{database.version}"
								database.name="@{database.name}"
								database.server="@{database.server}"
								database.url="@{database.url}"
								database.user="@{database.user}"
								database.password="@{database.password}"
								/>
						</case>
						<default>
							<echo message="Re-creation (drop and re-create) of @{database.type} databases is not supported, nothing done."/>
						</default>
					</switch>
				</then>
				<else>
					<echo message="Database.recreate flag not set, database not re-created."/>
				</else>
			</if>
			<if>
				<equals arg1="@{database.drop-schema}" arg2="true"/>
				<then>
					<echo message="Dropping database objects"/>
					<dropAllDatabaseObjects
						driver="@{database.driver}"
						url="@{database.url}"
						username="@{database.user}"
						password="@{database.password}"
						promptOnNonLocalDatabase="@{prompt.user.if.not.local.database}"
						classpathref="build-utils.classpath"
						defaultSchemaName="@{database.schema}"
						/>
					<!-- Sequences don't seem to drop in first run second run cleans them up -->
					<dropAllDatabaseObjects
						driver="@{database.driver}"
						url="@{database.url}"
						username="@{database.user}"
						password="@{database.password}"
						promptOnNonLocalDatabase="@{prompt.user.if.not.local.database}"
						classpathref="build-utils.classpath"
						defaultSchemaName="@{database.schema}"
						/>
					<sleep seconds="5"/>
				</then>
				<else>
					<echo message="Database.drop-schema flag not set, database schema not dropped."/>
				</else>
			</if>

		</sequential>
	</macrodef>
	<macrodef name="database-install">
		<attribute name="database.type" default="${database.type}" />
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.driver.file" default="${database.driver.file}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="sql.delimiter" default=";" />
		<attribute name="sql.delimitertype" default="normal" />
		<attribute name="onerror" default="abort" />
		<attribute name="db-install.dir" default="${db-install.dir.dest}" />
		<attribute name="db.install.create.file.list" />
		<sequential>
			<for list="@{db.install.create.file.list}" param="db.install.file">
				<sequential>
					<run-sql-script database.url="@{database.url}"
						database.user="@{database.user}"
						database.password="@{database.password}"
						database.driver="@{database.driver}"
						database.driver.file="@{database.driver.file}"
						sql.delimiter="@{sql.delimiter}"
						sql.delimitertype="@{sql.delimitertype}"
						sql.file="@{db-install.dir}/@{database.type}/@{db.install.file}"
						onerror="@{onerror}"/>
				</sequential>
			</for>
		</sequential>
	</macrodef>
	<macrodef name="database-upgrade">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.driver.file" default="${database.driver.file}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.schema" default="${database.schema}" />
		<attribute name="database.changelog.file" default="${os.temp.dir}/${project.name}/db-upgrade.xml" />
		<sequential>

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

			<updateDatabase
				driver="@{database.driver}"
				url="@{database.url}"
				username="@{database.user}"
				password="@{database.password}"
				classpathref="jdbc.driver.classpath"
				defaultSchemaName="@{database.schema}"
				changeLogFile="@{database.changelog.file}"
				databaseChangeLogTableName="databasechangelog"
				databaseChangeLogLockTableName="CSM_DB_UPG_CHANGE_LOCK_LOG"
				/>
			<database-upgrade-fix
				database.driver="@{database.driver}"
				database.url="@{database.url}"
				database.user="@{database.user}"
				database.password="@{database.password}"
				database.driver.file="@{database.driver.file}"
				database.changelog.file="@{database.changelog.file}"
				databaseChangeLogTableName="databasechangelog"
				database.schema="@{database.schema}"
				/>

		</sequential>
	</macrodef>
	<macrodef name="database-genchangelog">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.schema" default="${database.schema}" />
		<attribute name="database.changelog.file" default="generated-change-log.xml" />
		<sequential>
			<generateChangeLog
				driver="@{database.driver}"
				url="@{database.url}"
				username="@{database.user}"
				password="@{database.password}"
				classpathref="jdbc.driver.classpath"
				defaultSchemaName="@{database.schema}"
				outputFile="@{database.changelog.file}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="database-tag">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.schema" default="${database.schema}" />
		<sequential>
			<if>
				<isset property="database.release.version"/>
				<then>
					<tagDatabase
						driver="@{database.driver}"
						url="@{database.url}"
						username="@{database.user}"
						password="@{database.password}"
						classpathref="jdbc.driver.classpath"
						defaultSchemaName="@{database.schema}"
						tag="${database.release.version}"
						>
					</tagDatabase>
				</then>
				<else>
					<fail message="Variable database.release.version must be set to call upgrade:database:tag target."/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="database-rollback">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.schema" default="${database.schema}" />
		<attribute name="database.changelog.file" default="${db-upgrade.dir.dest}/db-upgrade.xml" />
		<sequential>
			<if>
				<isset property="database.rollback.version"/>
				<then>
					<echo message="Rolling datbase back to version ${database.rollback.version}."/>
					<rollbackDatabase
						driver="@{database.driver}"
						url="@{database.url}"
						username="@{database.user}"
						password="@{database.password}"
						classpathref="jdbc.driver.classpath"
						defaultSchemaName="@{database.schema}"
						changeLogFile="@{database.changelog.file}"
						rollbackTag="${database.rollback.version}"
						>
					</rollbackDatabase>
				</then>
				<else>
					<fail message="Variable database.rollback.version must be set to call upgrade:database:rollback target."/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="database-diff">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="compare1.database.url" default="${compare1.database.url}" />
		<attribute name="compare1.database.user" default="${compare1.database.user}" />
		<attribute name="compare1.database.password" default="${compare1.database.password}" />
		<attribute name="compare1.database.schema" default="${compare1.database.schema}" />
		<attribute name="compare2.database.url" default="${compare2.database.url}" />
		<attribute name="compare2.database.user" default="${compare2.database.user}" />
		<attribute name="compare2.database.password" default="${compare2.database.password}" />
		<attribute name="compare2.database.schema" default="${compare2.database.schema}" />
		<attribute name="output.file.txt" default="generated-diff-log.txt"/>
		<attribute name="output.file.xml" default="generated-diff-log.xml"/>
		<sequential>
			<echo message="Generating diff report @{compare1.database.url} to @{compare2.database.url}."/>
			<diffDatabase
				driver="@{database.driver}"
				outputFile="@{output.file.txt}"
				classpathref="jdbc.driver.classpath"

				baseUrl="@{compare1.database.url}"
				baseUsername="@{compare1.database.user}"
				basePassword="@{compare1.database.password}"
				baseDefaultSchemaName="@{compare1.database.schema}"

				url="@{compare2.database.url}"
				username="@{compare2.database.user}"
				password="@{compare2.database.password}"
				defaultSchemaName="@{compare2.database.schema}"

				/>
			<diffDatabaseToChangeLog
				driver="@{database.driver}"
				outputFile="@{output.file.xml}"
				classpathref="jdbc.driver.classpath"

				baseUrl="@{compare1.database.url}"
				baseUsername="@{compare1.database.user}"
				basePassword="@{compare1.database.password}"
				baseDefaultSchemaName="@{compare1.database.schema}"

				url="@{compare2.database.url}"
				username="@{compare2.database.user}"
				password="@{compare2.database.password}"
				defaultSchemaName="@{compare2.database.schema}"

				/>
		</sequential>
	</macrodef>
	<macrodef name="database-doc">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.schema" default="${database.schema}" />
		<attribute name="output.dir" default="${temp.dir}/dbDoc" />
		<attribute name="database.changelog.file" default="${db-upgrade.dir.dest}/db-upgrade.xml" />
		<sequential>
			<mkdir dir="@{output.dir}"/>
			<dbDoc
				driver="@{database.driver}"
				url="@{database.url}"
				username="@{database.user}"
				password="@{database.password}"
				classpathref="jdbc.driver.classpath"
				defaultSchemaName="@{database.schema}"
				outputDirectory="@{output.dir}"
				changeLogFile="@{database.changelog.file}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="ivy-module-add2repo">
		<attribute name="ivy-repo.base.url" default="http://forge.nci.nih.gov/svnroot/commonlibrary/trunk/ivy-repo"/>
		<attribute name="ivy-repo.base.dir"/>
		<attribute name="ivy.add.org" />
		<attribute name="ivy.add.module" />
		<attribute name="ivy.add.version" />
		<attribute name="ivy.add.module.src.dir" />
		<attribute name="ivy.add.module.src.file.list" />
		<attribute name="ivy.add.xml.src.location" />

		<sequential>
			<var name="ivy.org.dir" value="@{ivy-repo.base.dir}/@{ivy.add.org}"/>
			<var name="ivy.module.dir" value="@{ivy-repo.base.dir}/@{ivy.add.org}/@{ivy.add.module}"/>
			<var name="ivy.version.dir" value="@{ivy-repo.base.dir}/@{ivy.add.org}/@{ivy.add.module}/@{ivy.add.version}"/>
			<available file="${ivy.org.dir}" property="org.dir.exists" />
			<available file="${ivy.module.dir}" property="module.dir.exists" />

			<check-svnuser/>
			<!-- Conditionally checkout or update -->
			<if>
				<available file="@{ivy-repo.base.dir}"/>
				<then>
					<echo message="Found @{ivy-repo.base.dir}, doing svn update."/>
					<svn-update
						svn.update.dir="@{ivy-repo.base.dir}"
						/>
				</then>
				<else>
					<svn-co
						svn.checkout.url="@{ivy-repo.base.url}"
						svn.checkout.dir="@{ivy-repo.base.dir}"
						delete="false"
						/>
				</else>
			</if>
			<!-- Copy artifacts to directory -->
			<copy todir="${ivy.version.dir}" file="@{ivy.add.xml.src.location}"/>

			<for list="@{ivy.add.module.src.file.list}" param="ivy.add.module.src.file" delimiter=",">
				<sequential>
					<copy todir="${ivy.version.dir}" file="@{ivy.add.module.src.dir}/@{ivy.add.module.src.file}"/>
				</sequential>
			</for>
			<!-- Add and commit to svn, only the directory level that does not exist -->
			<if>
				<not>
					<isset property="org.dir.exists"/>
				</not>
				<then>
					<echo message="Adding org @{ivy.add.org}."/>
					<svn-add
						svn.add.dir="${ivy.org.dir}"
						/>
					<svn-commit
						svn.commit.dir="${ivy.org.dir}"
						svn.commit.user="${svn.user.name}"
						svn.commit.pass="${svn.user.pass}"
						svn.commit.message="Files added by build process as part of ivy deploy process"
						/>
				</then>
				<elseif>
					<not>
						<isset property="module.dir.exists"/>
					</not>
					<then>
						<echo message="Adding module @{ivy.add.org}/@{ivy.add.module}."/>
						<svn-add
							svn.add.dir="${ivy.module.dir}"
							/>
						<svn-commit
							svn.commit.dir="${ivy.module.dir}"
							svn.commit.user="${svn.user.name}"
							svn.commit.pass="${svn.user.pass}"
							svn.commit.message="Files added by build process as part of ivy deploy process"
							/>
					</then>
				</elseif>
				<else>
					<echo message="Adding version @{ivy.add.org}/@{ivy.add.module}/@{ivy.add.version}."/>
					<svn-add
						svn.add.dir="${ivy.version.dir}"
						/>
					<svn-commit
						svn.commit.dir="${ivy.version.dir}"
						svn.commit.user="${svn.user.name}"
						svn.commit.pass="${svn.user.pass}"
						svn.commit.message="Files added by build process as part of ivy deploy process"
						/>
				</else>
			</if>
		</sequential>

	</macrodef>

	<macrodef name="check-svnuser">
		<sequential>
			<property name="prop.list" value="svn.user.name,svn.user.pass"/>
			<for list="${prop.list}" param="prop.list.item" delimiter=",">
				<sequential>
					<echo message="Checking for existence of @{prop.list.item}"/>
					<if>
						<not>
							<isset property="@{prop.list.item}"/>
						</not>
						<then>
							<fail message="svn.user.name svn.user.pass must be set to add files to ivy so add them to a properties file (like local.properties) or pass them in on the command line."/>
						</then>
					</if>
				</sequential>
			</for>
		</sequential>
	</macrodef>
	<macrodef name="jboss-configure-grid">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.conf.dir" default="@{jboss.home}/server/@{jboss.server.name}/conf"/>
		<attribute name="jboss.webapp.dir" default="@{jboss.home}/server/@{jboss.server.name}/deploy"/>
		<attribute name="jboss.server-xml.file" default="@{jboss.home}/server/@{jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="jboss.server-xml.service.name" default="jboss.web"/>
		<attribute name="jboss.port.http" default="${jboss.server.port}"/>
		<attribute name="jboss.port.ssl" default="${jboss.ssl.port}"/>
		<attribute name="jboss.hostname" default="${jboss.server.hostname}"/>
		<attribute name="jboss.external.http.host" default="${jboss.external.http.host}"/>
		<attribute name="jboss.external.http.port" default="${jboss.external.http.port}"/>
		<attribute name="search.host" default="localhost"/>
		<attribute name="search.port" default="8080"/>
		<attribute name="jboss.external.grid.secure.host" default="${jboss.external.grid.secure.host}"/>
		<attribute name="jboss.external.grid.secure.port" default="${jboss.external.grid.secure.port}"/>
		<attribute name="jboss.grid.secure.enable" default="${jboss.grid.secure.enable}"/>
		<attribute name="jboss.grid.secure.dir" default="${jboss.grid.secure.dir}"/>
		<attribute name="jboss.grid.secure.port" default="${jboss.grid.secure.port}"/>
		<attribute name="jboss.grid.secure.key.file" default="${jboss.grid.secure.key.file}"/>
		<attribute name="jboss.grid.secure.cert.file" default="${jboss.grid.secure.cert.file}"/>
		<!-- Grid specific attributes -->
		<attribute name="grid.application.name" default="${grid.application.name}"/>
		<attribute name="grid.application.relative.dir" default="${grid.dir.dest}"/>
		<attribute name="grid.index.url" default="${grid.index.url}"/>
		<attribute name="grid.poc.science.affiliation" default="${grid.poc.science.affiliation}"/>
		<attribute name="grid.poc.science.name.last" default="${grid.poc.science.name.last}"/>
		<attribute name="grid.poc.science.name.first" default="${grid.poc.science.name.first}" />
		<attribute name="grid.poc.science.phone" default="${grid.poc.science.phone}"/>
		<attribute name="grid.poc.science.role" default="${grid.poc.science.role}" />
		<attribute name="grid.poc.science.email" default="${grid.poc.science.email}" />
		<attribute name="grid.poc.tech.researchCenter.displayname" default="${grid.poc.tech.researchCenter.displayname}"/>
		<attribute name="grid.poc.tech.researchCenter.shortname" default="${grid.poc.tech.researchCenter.shortname}"/>
		<attribute name="grid.poc.tech.addr.country" default="${grid.poc.tech.addr.country}"/>
		<attribute name="grid.poc.tech.addr.locality" default="${grid.poc.tech.addr.locality}"/>
		<attribute name="grid.poc.tech.addr.postalCode" default="${grid.poc.tech.addr.postalCode}"/>
		<attribute name="grid.poc.tech.addr.stateProvince" default="${grid.poc.tech.addr.stateProvince}"/>
		<attribute name="grid.poc.tech.addr.street1" default="${grid.poc.tech.addr.street1}"/>
		<attribute name="grid.poc.tech.addr.street2" default="${grid.poc.tech.addr.street2}"/>
		<attribute name="grid.poc.tech.affiliation" default="${grid.poc.tech.affiliation}"/>
		<attribute name="grid.poc.tech.name.last" default="${grid.poc.tech.name.last}"/>
		<attribute name="grid.poc.tech.name.first" default="${grid.poc.tech.name.first}"/>
		<attribute name="grid.poc.tech.phone" default="${grid.poc.tech.phone}"/>
		<attribute name="grid.poc.tech.email" default="${grid.poc.tech.email}"/>
		<attribute name="grid.poc.tech.role" default="${grid.poc.tech.role}"/>
		<attribute name="grid.secdesc.file" default="@{jboss.webapp.dir}/@{grid.application.relative.dir}/WEB-INF/etc/globus_wsrf_core/global_security_descriptor.xml"/>
		<!-- appserver-install-sync-gts -->
		<attribute name="sync-gts.build.dir" default="${sync-gts.build.dir}"/>
		<attribute name="cagrid-target.dir" default="${cagrid-target.dir}"/>
		<attribute name="grid.target" default="${grid.target}"/>
		<attribute name="cagrid-console.dir" default="${basedir}/caGrid-console"/>
		<attribute name="cagrid-console.target" default="deployJBoss"/>
		<attribute name="wscore.src.url" default="${wscore.src.url}"/>
		<sequential>
			<grid-appserver-configure
				appserver.home="@{jboss.home}"
				appserver.server.name="@{jboss.server.name}"
				appserver.conf.dir="@{jboss.conf.dir}"
				appserver.webapp.dir="@{jboss.webapp.dir}"
				appserver.server-xml.file="@{jboss.server-xml.file}"
				appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
				appserver.port.http="@{jboss.port.http}"
				appserver.port.ssl="@{jboss.port.ssl}"
				appserver.hostname="@{jboss.hostname}"
				appserver.external.http.host="@{jboss.external.http.host}"
				appserver.external.http.port="@{jboss.external.http.port}"
				search.host="@{search.host}"
				search.port="@{search.port}"
				grid.external.secure.host="@{jboss.external.grid.secure.host}"
				grid.external.secure.port="@{jboss.external.grid.secure.port}"
				grid.secure.enable="@{jboss.grid.secure.enable}"
				grid.secure.dir="@{jboss.grid.secure.dir}"
				grid.secure.port="@{jboss.grid.secure.port}"
				grid.secure.key.file="@{jboss.grid.secure.key.file}"
				grid.secure.cert.file="@{jboss.grid.secure.cert.file}"

				grid.application.name="@{grid.application.name}"
				grid.application.relative.dir="@{grid.application.relative.dir}"
				grid.index.url="@{grid.index.url}"
				grid.poc.science.affiliation="@{grid.poc.science.affiliation}"
				grid.poc.science.name.last="@{grid.poc.science.name.last}"
				grid.poc.science.name.first="@{grid.poc.science.name.first}"
				grid.poc.science.phone="@{grid.poc.science.phone}"
				grid.poc.science.role="@{grid.poc.science.role}"
				grid.poc.science.email="@{grid.poc.science.email}"
				grid.poc.tech.researchCenter.displayname="@{grid.poc.tech.researchCenter.displayname}"
				grid.poc.tech.researchCenter.shortname="@{grid.poc.tech.researchCenter.shortname}"
				grid.poc.tech.addr.country="@{grid.poc.tech.addr.country}"
				grid.poc.tech.addr.locality="@{grid.poc.tech.addr.locality}"
				grid.poc.tech.addr.postalCode="@{grid.poc.tech.addr.postalCode}"
				grid.poc.tech.addr.stateProvince="@{grid.poc.tech.addr.stateProvince}"
				grid.poc.tech.addr.street1="@{grid.poc.tech.addr.street1}"
				grid.poc.tech.addr.street2="@{grid.poc.tech.addr.street2}"
				grid.poc.tech.affiliation="@{grid.poc.tech.affiliation}"
				grid.poc.tech.name.last="@{grid.poc.tech.name.last}"
				grid.poc.tech.name.first="@{grid.poc.tech.name.first}"
				grid.poc.tech.phone="@{grid.poc.tech.phone}"
				grid.poc.tech.email="@{grid.poc.tech.email}"
				grid.poc.tech.role="@{grid.poc.tech.role}"
				grid.secdesc.file="@{grid.secdesc.file}"
				sync-gts.build.dir="@{sync-gts.build.dir}"
				cagrid-target.dir="@{cagrid-target.dir}"
				grid.target="@{grid.target}"
				cagrid-console.dir="@{cagrid-console.dir}"
				cagrid-console.target="@{cagrid-console.target}"
				wscore.src.url="@{wscore.src.url}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="tomcat-configure-grid">
		<attribute name="tomcat.home" default="${tomcat.home}"/>
		<attribute name="tomcat.server.name" default=""/>
		<attribute name="tomcat.conf.dir" default="@{tomcat.home}/conf"/>
		<attribute name="tomcat.webapp.dir" default="@{tomcat.home}/webapps"/>
		<attribute name="tomcat.server-xml.file" default="@{tomcat.home}/conf/server.xml"/>
		<attribute name="tomcat.server-xml.service.name" default="Catalina"/>
		<attribute name="tomcat.port.http" default="${tomcat.port.http}"/>
		<attribute name="tomcat.port.ssl" default="${tomcat.port.ssl}"/>
		<attribute name="tomcat.hostname" default="${tomcat.hostname}"/>
		<attribute name="tomcat.external.http.host" default="${tomcat.external.http.host}"/>
		<attribute name="tomcat.external.http.port" default="${tomcat.external.http.port}"/>
		<attribute name="search.host" default="localhost"/>
		<attribute name="search.port" default="8080"/>
		<attribute name="tomcat.external.grid.secure.host" default="${tomcat.external.grid.secure.host}"/>
		<attribute name="tomcat.external.grid.secure.port" default="${tomcat.external.grid.secure.port}"/>
		<attribute name="tomcat.grid.secure.enable" default="${tomcat.grid.secure.enable}"/>
		<attribute name="tomcat.grid.secure.dir" default="${tomcat.grid.secure.dir}"/>
		<attribute name="tomcat.grid.secure.port" default="${tomcat.grid.secure.port}"/>
		<attribute name="tomcat.grid.secure.key.file" default="${tomcat.grid.secure.key.file}"/>
		<attribute name="tomcat.grid.secure.cert.file" default="${tomcat.grid.secure.cert.file}"/>
		<!-- Grid specific attributes -->
		<attribute name="grid.application.name" default="${grid.application.name}"/>
		<attribute name="grid.application.relative.dir" default="${grid.dir.dest}"/>
		<attribute name="grid.index.url" default="${grid.index.url}"/>
		<attribute name="grid.poc.science.affiliation" default="${grid.poc.science.affiliation}"/>
		<attribute name="grid.poc.science.name.last" default="${grid.poc.science.name.last}"/>
		<attribute name="grid.poc.science.name.first" default="${grid.poc.science.name.first}" />
		<attribute name="grid.poc.science.phone" default="${grid.poc.science.phone}"/>
		<attribute name="grid.poc.science.role" default="${grid.poc.science.role}" />
		<attribute name="grid.poc.science.email" default="${grid.poc.science.email}" />
		<attribute name="grid.poc.tech.researchCenter.displayname" default="${grid.poc.tech.researchCenter.displayname}"/>
		<attribute name="grid.poc.tech.researchCenter.shortname" default="${grid.poc.tech.researchCenter.shortname}"/>
		<attribute name="grid.poc.tech.addr.country" default="${grid.poc.tech.addr.country}"/>
		<attribute name="grid.poc.tech.addr.locality" default="${grid.poc.tech.addr.locality}"/>
		<attribute name="grid.poc.tech.addr.postalCode" default="${grid.poc.tech.addr.postalCode}"/>
		<attribute name="grid.poc.tech.addr.stateProvince" default="${grid.poc.tech.addr.stateProvince}"/>
		<attribute name="grid.poc.tech.addr.street1" default="${grid.poc.tech.addr.street1}"/>
		<attribute name="grid.poc.tech.addr.street2" default="${grid.poc.tech.addr.street2}"/>
		<attribute name="grid.poc.tech.affiliation" default="${grid.poc.tech.affiliation}"/>
		<attribute name="grid.poc.tech.name.last" default="${grid.poc.tech.name.last}"/>
		<attribute name="grid.poc.tech.name.first" default="${grid.poc.tech.name.first}"/>
		<attribute name="grid.poc.tech.phone" default="${grid.poc.tech.phone}"/>
		<attribute name="grid.poc.tech.email" default="${grid.poc.tech.email}"/>
		<attribute name="grid.poc.tech.role" default="${grid.poc.tech.role}"/>
		<attribute name="grid.secdesc.file" default="@{tomcat.webapp.dir}/@{grid.application.relative.dir}/WEB-INF/etc/globus_wsrf_core/global_security_descriptor.xml"/>
		<!-- appserver-install-sync-gts -->
		<attribute name="sync-gts.build.dir" default="${sync-gts.build.dir}"/>
		<attribute name="cagrid-target.dir" default="${cagrid-target.dir}"/>
		<attribute name="grid.target" default="${grid.target}"/>
		<attribute name="cagrid-console.dir" default="${basedir}/caGrid-console"/>
		<attribute name="cagrid-console.target" default="deployTomcat"/>
		<attribute name="wscore.src.url" default="${wscore.src.url}"/>
		<sequential>
			<grid-appserver-configure
				appserver.home="@{tomcat.home}"
				appserver.server.name="@{tomcat.server.name}"
				appserver.conf.dir="@{tomcat.conf.dir}"
				appserver.webapp.dir="@{tomcat.webapp.dir}"
				appserver.server-xml.file="@{tomcat.server-xml.file}"
				appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
				appserver.port.http="@{tomcat.port.http}"
				appserver.port.ssl="@{tomcat.port.ssl}"
				appserver.hostname="@{tomcat.hostname}"
				appserver.external.http.host="@{tomcat.external.http.host}"
				appserver.external.http.port="@{tomcat.external.http.port}"
				search.host="@{search.host}"
				search.port="@{search.port}"
				grid.external.secure.host="@{tomcat.external.grid.secure.host}"
				grid.external.secure.port="@{tomcat.external.grid.secure.port}"
				grid.secure.enable="@{tomcat.grid.secure.enable}"
				grid.secure.dir="@{tomcat.grid.secure.dir}"
				grid.secure.port="@{tomcat.grid.secure.port}"
				grid.secure.key.file="@{tomcat.grid.secure.key.file}"
				grid.secure.cert.file="@{tomcat.grid.secure.cert.file}"

				grid.application.name="@{grid.application.name}"
				grid.application.relative.dir="@{grid.application.relative.dir}"
				grid.index.url="@{grid.index.url}"
				grid.poc.science.affiliation="@{grid.poc.science.affiliation}"
				grid.poc.science.name.last="@{grid.poc.science.name.last}"
				grid.poc.science.name.first="@{grid.poc.science.name.first}"
				grid.poc.science.phone="@{grid.poc.science.phone}"
				grid.poc.science.role="@{grid.poc.science.role}"
				grid.poc.science.email="@{grid.poc.science.email}"
				grid.poc.tech.researchCenter.displayname="@{grid.poc.tech.researchCenter.displayname}"
				grid.poc.tech.researchCenter.shortname="@{grid.poc.tech.researchCenter.shortname}"
				grid.poc.tech.addr.country="@{grid.poc.tech.addr.country}"
				grid.poc.tech.addr.locality="@{grid.poc.tech.addr.locality}"
				grid.poc.tech.addr.postalCode="@{grid.poc.tech.addr.postalCode}"
				grid.poc.tech.addr.stateProvince="@{grid.poc.tech.addr.stateProvince}"
				grid.poc.tech.addr.street1="@{grid.poc.tech.addr.street1}"
				grid.poc.tech.addr.street2="@{grid.poc.tech.addr.street2}"
				grid.poc.tech.affiliation="@{grid.poc.tech.affiliation}"
				grid.poc.tech.name.last="@{grid.poc.tech.name.last}"
				grid.poc.tech.name.first="@{grid.poc.tech.name.first}"
				grid.poc.tech.phone="@{grid.poc.tech.phone}"
				grid.poc.tech.email="@{grid.poc.tech.email}"
				grid.poc.tech.role="@{grid.poc.tech.role}"
				grid.secdesc.file="@{grid.secdesc.file}"
				sync-gts.build.dir="@{sync-gts.build.dir}"
				cagrid-target.dir="@{cagrid-target.dir}"
				grid.target="@{grid.target}"
				cagrid-console.dir="@{cagrid-console.dir}"
				cagrid-console.target="@{cagrid-console.target}"
				wscore.src.url="@{wscore.src.url}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="check-absolute-directory" description="Diagnose the host system before the installation">
		<attribute name="directory.property" />
		<sequential>
			<!-- Application.base.path check for bad directory -->
			<propertycopy name="directory.value" from="@{directory.property}" override="true"/>
			<var name="is.absolute.dir" unset="true"/>
			<propertyregex property="is.absolute.dir"
				regexp="^(\w:\/)"
				input="${directory.value}"
				select="\1"
				/>
			<propertyregex property="is.absolute.dir"
				regexp="^(\/)"
				input="${directory.value}"
				select="\1"
				/>
			<if>
				<isset property="is.absolute.dir"/>
				<then>
					<echo message="@{directory.property} is an absolute path."/>
				</then>
				<else>
					<fail message="@{directory.property} needs to be an absolute path, please correct this and build again."/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="obfuscate-properties-file" description="Diagnose the host system before the installation">
		<attribute name="properties.file"/>
		<attribute name="comment.property.list" default=""/>
		<attribute name="uncomment.property.list" default=""/>
		<attribute name="required.property.list" default=""/>
		<attribute name="optional.property.list" default=""/>
		<attribute name="delete.property.list" default=""/>
		<sequential>
			<for list="@{comment.property.list}" param="property.name" delimiter=",">
				<sequential>
					<replaceregexp file="@{properties.file}"
						match="^(@{property.name})=(.*)"
						replace="#\1=\2"
						flags="g" byline="true"/>
				</sequential>
			</for>
			<for list="@{uncomment.property.list}" param="property.name" delimiter=",">
				<sequential>
					<replaceregexp file="@{properties.file}"
						match="^#(@{property.name})=(.*)"
						replace="\1=\2"
						flags="g" byline="true"/>
				</sequential>
			</for>
			<for list="@{required.property.list}" param="property.name" delimiter=",">
				<sequential>
					<replaceregexp file="@{properties.file}"
						match="^(@{property.name})=.*"
						replace="\1=REPLACE_VALUE"
						flags="g" byline="true"/>
				</sequential>
			</for>
			<for list="@{optional.property.list}" param="property.name" delimiter=",">
				<sequential>
					<replaceregexp file="@{properties.file}"
						match="^(@{property.name})=.*"
						replace="\1=replace_value"
						flags="g" byline="true"/>
				</sequential>
			</for>
			<for list="@{delete.property.list}" param="property.name" delimiter=",">
				<sequential>
					<replaceregexp file="@{properties.file}"
						match="^@{property.name}=.*"
						replace=""
						flags="g" byline="true"/>
				</sequential>
			</for>
		</sequential>
	</macrodef>
	<macrodef name="secure-jboss41-console" description="Diagnose the host system before the installation">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.web.user" default="${jboss.web.user}"/>
		<attribute name="jboss.web.password" default="${jboss.web.password}"/>
		<sequential>
			<var name="jmx-console.web-xml.file" value="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/web.xml"/>
			<echo message="Updating ${jmx-console.web-xml.file}"/>
			<xmltask preservetype="true" source="${jmx-console.web-xml.file}"
				dest="${jmx-console.web-xml.file}">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove path="/web-app/security-constraint"/>
				<remove path="/web-app/login-config"/>
				<remove path="/web-app/security-role"/>
			</xmltask>
			<xmltask preservetype="true" source="${jmx-console.web-xml.file}"
				dest="${jmx-console.web-xml.file}"
				failWithoutMatch="true" >
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="/web-app">
					<![CDATA[
					<security-constraint>
						<web-resource-collection>
							<web-resource-name>HtmlAdaptor</web-resource-name>
							<description>An example security config that only allows users with the
								role JBossAdmin to access the HTML JMX console web application
							</description>
							<url-pattern>/*</url-pattern>
							<http-method>GET</http-method>
							<http-method>POST</http-method>
						</web-resource-collection>
						<auth-constraint>
							<role-name>JBossAdmin</role-name>
						</auth-constraint>
					</security-constraint>

					]]>
				</insert>
				<insert path="/web-app">
					<![CDATA[
					<login-config>
						<auth-method>BASIC</auth-method>
						<realm-name>JBoss JMX Console</realm-name>
					</login-config>
					]]>
				</insert>
				<insert path="/web-app">
					<![CDATA[
					<security-role>
						<role-name>JBossAdmin</role-name>
					</security-role>
					]]>
				</insert>
			</xmltask>

			<var name="jmx-console.jboss-web-xml.file" value="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/jboss-web.xml"/>
			<echo message="Updating ${jmx-console.jboss-web-xml.file}"/>
			<xmltask preservetype="true" source="${jmx-console.jboss-web-xml.file}"
				dest="${jmx-console.jboss-web-xml.file}">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove path="/jboss-web/security-domain"/>
			</xmltask>
			<xmltask preservetype="true" source="${jmx-console.jboss-web-xml.file}"
				dest="${jmx-console.jboss-web-xml.file}"
				failWithoutMatch="true" >
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="/jboss-web">
					<![CDATA[
					<security-domain>java:/jaas/jmx-console</security-domain>
					]]>
				</insert>
			</xmltask>

			<var name="jmx-console.user.file" value="@{jboss.home}/server/@{jboss.server.name}/conf/props/jmx-console-users.properties"/>
			<if>
				<isset property="jboss.web.user"/>
				<then>
					<var name="jmx-console.user.file" value="@{jboss.home}/server/@{jboss.server.name}/conf/props/jmx-console-users.properties"/>
					<echo message="Updating ${jmx-console.user.file}"/>
					<var name="jmx-console.user.matched" unset="true"/>
					<loadfile
						property="jmx-console.user.matched"
						srcFile="${jmx-console.user.file}">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern="@{jboss.web.user}="/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>

					<if>
						<isset property="jmx-console.user.matched"/>
						<then>
							<echo message="@{jboss.web.user} found in ${jmx-console.user.file} updating record."/>
							<replaceregexp file="${jmx-console.user.file}"
								match="^(@{jboss.web.user})=.*"
								replace="@{jboss.web.user}=@{jboss.web.password}"
								flags="g" byline="true"/>
						</then>
						<else>
							<echo message="@{jboss.web.user} not found in ${jmx-console.user.file} inserting record."/>
							<echo file="${jmx-console.user.file}" append="true" message="@{jboss.web.user}=@{jboss.web.password}"/>
						</else>
							</if>
					<var name="jmx-console.role.file" value="@{jboss.home}/server/@{jboss.server.name}/conf/props/jmx-console-roles.properties"/>
					<echo message="Updating ${jmx-console.role.file}"/>
					<var name="jmx-console.role.matched" unset="true"/>
					<loadfile
						property="jmx-console.role.matched"
						srcFile="${jmx-console.role.file}">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern="@{jboss.web.user}="/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>

					<if>
						<isset property="jmx-console.role.matched"/>
						<then>
							<echo message="@{jboss.web.user} found in ${jmx-console.role.file} updating record."/>
							<replaceregexp file="${jmx-console.role.file}"
								match="^(@{jboss.web.user})=.*"
								replace="@{jboss.web.user}=JBossAdmin,HttpInvoker"
								flags="g" byline="true"/>
						</then>
						<else>
							<echo message="@{jboss.web.user} not found in ${jmx-console.role.file} inserting record."/>
							<echo file="${jmx-console.role.file}" append="true" message="@{jboss.web.user}=JBossAdmin,HttpInvoker"/>
						</else>
					</if>
				</then>
				<else>
					<echo message="User not added to ${jmx-console.user.file}"/>
				</else>
			</if>

			<var name="web-console.web-xml.file" value="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/web.xml"/>
			<echo message="Updating ${web-console.web-xml.file}"/>
			<xmltask preservetype="true" source="${web-console.web-xml.file}"
				dest="${web-console.web-xml.file}">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove path="/web-app/security-constraint"/>
				<remove path="/web-app/login-config"/>
				<remove path="/web-app/security-role"/>
			</xmltask>
			<xmltask preservetype="true" source="${web-console.web-xml.file}"
				dest="${web-console.web-xml.file}"
				failWithoutMatch="true" >
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="/web-app">
					<![CDATA[
					<security-constraint>
						<web-resource-collection>
							<web-resource-name>HtmlAdaptor</web-resource-name>
							<description>An example security config that only allows users with the
								role JBossAdmin to access the HTML JMX console web application
							</description>
							<url-pattern>/*</url-pattern>
							<http-method>GET</http-method>
							<http-method>POST</http-method>
						</web-resource-collection>
						<auth-constraint>
							<role-name>JBossAdmin</role-name>
						</auth-constraint>
					</security-constraint>

					]]>
				</insert>
				<insert path="/web-app">
					<![CDATA[
					<login-config>
						<auth-method>BASIC</auth-method>
						<realm-name>JBoss Web Console</realm-name>
					</login-config>
					]]>
				</insert>
				<insert path="/web-app">
					<![CDATA[
					<security-role>
						<role-name>JBossAdmin</role-name>
					</security-role>
					]]>
				</insert>
			</xmltask>

			<var name="web-console.jboss-web-xml.file" value="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/jboss-web.xml"/>
			<echo message="Updating ${web-console.jboss-web-xml.file}"/>

			<xmltask preservetype="true" source="${web-console.jboss-web-xml.file}"
				dest="${web-console.jboss-web-xml.file}">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove path="/jboss-web/security-domain"/>
			</xmltask>
			<xmltask preservetype="true" source="${web-console.jboss-web-xml.file}"
				dest="${web-console.jboss-web-xml.file}"
				failWithoutMatch="true" >
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="/jboss-web">
					<![CDATA[
					<security-domain>java:/jaas/web-console</security-domain>
					]]>
				</insert>
			</xmltask>

			<var name="web-console.classes.dir" value="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/classes"/>
			<var name="jboss.props.dir" value="@{jboss.home}/server/@{jboss.server.name}/conf/props"/>
			<copy todir="${jboss.props.dir}">
				<fileset dir="${web-console.classes.dir}">
					<include name="web-console-*.properties"/>
				</fileset>
			</copy>

			<var name="web-console.user.file" value="@{jboss.home}/server/@{jboss.server.name}/conf/props/web-console-users.properties"/>
			<if>
				<isset property="jboss.web.user"/>
				<then>
					<var name="web-console.user.file" value="@{jboss.home}/server/@{jboss.server.name}/conf/props/web-console-users.properties"/>
					<echo message="Updating ${web-console.user.file}"/>
					<var name="web-console.user.matched" unset="true"/>
					<loadfile
						property="web-console.user.matched"
						srcFile="${web-console.user.file}">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern="@{jboss.web.user}="/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>

					<if>
						<isset property="web-console.user.matched"/>
						<then>
							<echo message="@{jboss.web.user} found in ${web-console.user.file} updating record."/>
							<replaceregexp file="${web-console.user.file}"
								match="^(@{jboss.web.user})=.*"
								replace="@{jboss.web.user}=@{jboss.web.password}"
								flags="g" byline="true"/>
						</then>
						<else>
							<echo message="@{jboss.web.user} not found in ${web-console.user.file} inserting record."/>
							<echo file="${web-console.user.file}" append="true" message="@{jboss.web.user}=@{jboss.web.password}"/>
						</else>
					</if>
					<var name="web-console.role.file" value="@{jboss.home}/server/@{jboss.server.name}/conf/props/web-console-roles.properties"/>
					<echo message="Updating ${web-console.role.file}"/>
					<var name="web-console.role.matched" unset="true"/>
					<loadfile
						property="web-console.role.matched"
						srcFile="${web-console.role.file}">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern="@{jboss.web.user}="/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>

					<if>
						<isset property="web-console.role.matched"/>
						<then>
							<echo message="@{jboss.web.user} found in ${web-console.role.file} updating record."/>
							<replaceregexp file="${web-console.role.file}"
								match="^(@{jboss.web.user})=.*"
								replace="@{jboss.web.user}=JBossAdmin"
								flags="g" byline="true"/>
						</then>
						<else>
							<echo message="@{jboss.web.user} not found in ${web-console.role.file} inserting record."/>
							<echo file="${web-console.role.file}" append="true" message="@{jboss.web.user}=JBossAdmin,HttpInvoker"/>
						</else>
					</if>

				</then>
				<else>
					<echo message="User not added to ${jmx-console.user.file}"/>
				</else>
			</if>

			<!--
			<var name="web-console.password.file" value="@{jboss.home}/server/@{jboss.server.name}/conf/props/web-console-users.properties"/>
			<echo message="Updating ${web-console.password.file}"/>

			<replaceregexp file="${web-console.password.file}"
				match="^(admin)=.*"
				replace="@{jboss.web.user}=@{jboss.web.password}"
				flags="g" byline="true"/>

			<var name="login-config.xml" value="@{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml"/>
			<echo message="Updating ${login-config.xml}"/>

			<replaceregexp file="${login-config.xml}"
				match="web-console-"
				replace="props\/web-console-"
				flags="g" byline="true"/>
			-->
		</sequential>
	</macrodef>
	<macrodef name="gui-installer-prep">
		<attribute name="build-utils.dir" default="${build-download.dir}" />
		<attribute name="gui-installer.dir" default="${gui-installer.dir}" />
		<attribute name="target.dir" default="${target.dir}"/>
		<attribute name="download.dir" default="${download.dir}" />
		<attribute name="dist.dir" default="${dist.dir}"/>
		<attribute name="izpack.binary.name" default="izpack-4.3" />
		<attribute name="izpack.binary.file" default="izpack-4.3.zip" />
		<attribute name="izpack.binary.uri" default="https://ncisvn.nci.nih.gov/svn/commonlibrary/trunk/techstack-2008/os-independent" />
		<attribute name="izpack-custom.svn.url" default="https://ncisvn.nci.nih.gov/svn/automation/trunk/software/bda-installer/src-custom-4.3"/>
		<attribute name="izpack-custom.svn.dir" default="${target.dir}/izpack-custom"/>
		<attribute name="product.name" default="caArray-installer" />
		<attribute name="product.version" default="2.1.0" />
		<attribute name="ant.binary.file" default="apache-ant-1.8.0-bin.zip"/>
		<attribute name="ant.binary.url" default="http://archive.apache.org/dist/ant/binaries/apache-ant-1.8.0-bin.zip"/>
		<attribute name="ant.binary.dir" default="${target.dir}/apache-ant-1.8.0"/>
		<sequential>
			<tstamp>
				<format property="JAR_STAMP" pattern="MMddyyyyhhmmss" unit="millisecond" />
			</tstamp>

			<!-- Cleanup target area -->
			<delete dir="@{target.dir}/@{izpack.binary.name}" />

			<get src="@{izpack.binary.uri}/@{izpack.binary.file}" dest="@{download.dir}/@{izpack.binary.file}" usetimestamp="true"/>
			<unzip dest="@{target.dir}" src="@{download.dir}/@{izpack.binary.file}" />

			<!-- Check out izpack custom code and copy into extracted izpack dist -->
			<osfamily property="os.family"/>
			<switch value="${os.family}">
				<case value="windows">
					<echo message="Retreiving izpack custom code from svn task."/>
					<svn-co
						svn.checkout.url="@{izpack-custom.svn.url}"
						svn.checkout.dir="@{izpack-custom.svn.dir}"
						/>
				</case>
				<case value="unix">
					<echo message="Retreiving izpack custom code from svn command line."/>
					<mkdir dir="@{izpack-custom.svn.dir}"/>
					<exec osfamily="unix" executable="svn" spawn="true">
						<arg line="co @{izpack-custom.svn.url} @{izpack-custom.svn.dir}" />
					</exec>
				</case>
				<default>
					<fail message="Unexpected OS type ${os.family}"/>
				</default>
			</switch>
			<sleep seconds="10"/>

			<copy todir="@{target.dir}/@{izpack.binary.name}/src/lib" overwrite="true">
				<fileset dir="@{izpack-custom.svn.dir}" />
			</copy>

			<!-- customize izpack  -->
			<xmltask preservetype="true" failWithoutMatch="true" source="@{target.dir}/@{izpack.binary.name}/src/build.xml"
				dest="@{target.dir}/@{izpack.binary.name}/src/build.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="//target[@name='build.listeners']" file="@{izpack-custom.svn.dir}/resources/ProgressBarInstallerListener.xml"/>
			</xmltask>
			<copy file="@{izpack-custom.svn.dir}/resources/eng.xml" todir="@{target.dir}/@{izpack.binary.name}/bin/langpacks/installer" overwrite="true" />

			<!-- Copy over library files -->
			<mkdir dir="@{target.dir}/@{izpack.binary.name}/lib"/>
			<copy todir="@{target.dir}/@{izpack.binary.name}/lib">
				<fileset dir="@{build-utils.dir}">
					<include name="ant-1.8.0.jar"/>
					<include name="ant-launcher-1.8.0.jar"/>
					<include name="ant-nodeps-1.8.0.jar"/>
				</fileset>
			</copy>

			<!-- Compile the izpack with custom code -->
			<ant inheritall="false" antfile="@{target.dir}/@{izpack.binary.name}/src/build.xml" />

			<if>
				<os family="unix" />
				<then>
					<chmod dir="@{target.dir}/@{izpack.binary.name}/bin" perm="ugo+rx" includes="compile" />
				</then>
			</if>
			<get src="@{ant.binary.url}" dest="@{download.dir}/@{ant.binary.file}" usetimestamp="true"/>
			<unzip dest="@{target.dir}" src="@{download.dir}/@{ant.binary.file}" />
		</sequential>
	</macrodef>
	<macrodef name="jboss-read-ldapconfig" description="check if the application is installed">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="ldap.url.property.name" default="ldap.url" />
		<attribute name="ldap.basedn.property.name" default="ldap.basedn" />
		<attribute name="ldap.searchprefix.property.name" default="ldap.searchprefix" />
		<attribute name="authentication.type.property.name" default="authentication.type" />
		<sequential>
			<var name="ldap.properties.list" value="@{ldap.url.property.name},@{ldap.basedn.property.name},@{ldap.searchprefix.property.name},@{authentication.type.property.name}"/>
			<properties-missing
				properties.list="${ldap.properties.list}"
				properties.missing.property.name="ldap.properties.missing"
				/>
			<available file="@{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml" property="login-config.exists"/>
			<if>
				<isset property="ldap.properties.missing"/>
				<then>
					<if>
						<not>
							<isset property="login-config.exists" />
						</not>
						<then>
							<echo message="LDAP properties not set and can't open login-config.xml to see if JBoss is setup to use LDAP for authentication."/>
						</then>
						<else>
							<echo message="Reading LDAP properties ${ldap.properties.list}"/>
							<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml" >
								<xmlcatalog refid="build.xml.catalog"/>
								<copy path="//module-option[@name='ldapHost']/text()" property="read.ldap.url" />
								<copy path="//module-option[@name='ldapSearchableBase']/text()" property="read.ldap.basedn" />
								<copy path="//module-option[@name='ldapUserIdLabel']/text()" property="read.ldap.searchprefix" />
							</xmltask>
							<if>
								<isset property="read.ldap.url"/>
								<then>
									<property name="@{ldap.url.property.name}" value="${read.ldap.url}" />
									<property name="@{ldap.basedn.property.name}" value="${read.ldap.basedn}" />
									<property name="@{ldap.searchprefix.property.name}" value="${read.ldap.searchprefix}" />
									<property name="@{authentication.type.property.name}" value="ldap"/>
								</then>
								<else>
									<property name="@{ldap.url.property.name}" value=""/>
									<property name="@{ldap.basedn.property.name}" value=""/>
									<property name="@{ldap.searchprefix.property.name}" value=""/>
									<property name="@{authentication.type.property.name}" value="db"/>
								</else>
							</if>
						</else>
					</if>
				</then>
				<else>
					<var name="authentication.type" value="db"/>
				</else>
			</if>
			<properties-print
				properties.list="${ldap.properties.list}"
				/>
			<var name="read.properties.list" value="${read.properties.list},${ldap.properties.list}"/>
		</sequential>
	</macrodef>

	<macrodef name="report-dir-diff">
		<attribute name="dir1"/>
		<attribute name="dir2"/>
		<attribute name="reportFile"/>
		<sequential>
			<if>
				<or>
					<os family="unix"/>
					<os family="mac"/>
				</or>
				<then>

			<groovy>
				<arg line="@{dir1} @{dir2} @{reportFile}"/>
				dir1 = new File(args[0]).getAbsoluteFile()
				if(!dir1.exists())
				{
				println "${dir1} does not exist, please check that you are refering to the correct directory."
				System.exit(1)
				}
				dir2 = new File(args[1]).getAbsoluteFile()
				if(!dir2.exists())
				{
				println "${dir2} does not exist, please check that you are refering to the correct directory."
				System.exit(1)
				}
				reportFile = new File(args[2]).getAbsoluteFile()
				Integer dir1Length = dir1.toString().length()
				Integer dir2Length = dir2.toString().length()

				println "Command line args are "
				println "\t dir1 -\t\t" + dir1
				println "\t dir2 -\t\t" + dir2
				println "\t reportFile -\t" + reportFile

				reportText = ""

				println "## Comparing files in " + dir1 + " to files in " + dir2
				dir1.eachFileRecurse
				{ file1 ->
				if (file1.isFile())
				{
				// println file1.toString() + " is a file"
				file1Name = file1.getName()
				file1Path = file1.getParent()
				file2Str = dir2.toString() + "/" + file1.toString().substring(dir1Length)
				file2 = new File(file2Str)
				// println file2.toString() + " debug"
				if (!file2.isFile() && !file2.isDirectory())
				{
				println file2.toString() + " is a new file."
				reportText += "## " + file2.toString() + " is a new file.\n"
				}
				if (file2.isFile())
				{
				// println file2.toString() + " is a file"
				diffCmd = "diff --ignore-all-space --ignore-blank-lines " + file1 + " " + file2
				String diffText = diffCmd.execute().text
				if (diffText.length() > 0)
				{
				println file2.toString() + " differences found"
				reportText += "## Differences found between " + file1 + " " + file2 + "\n"
				diffText.eachLine {reportText += it + "\n"}
				}
				}
				}
				}
				println "## Looking for new files in " + dir2 + " ..."
				dir2.eachFileRecurse
				{ file2 ->
				if (file2.isFile())
				{
				file1Str = dir1.toString() + "/" + file2.toString().substring(dir2Length)
				file1 = new File(file1Str)
				//println file2.toString() + " debug"
				if (!file1.isFile() && !file1.isDirectory())
				{
				println file2.toString() + " is missing in new installation."
				reportText += "## " + file2.toString() + " is a new file.\n"
				}
				}
				}

				reportFile.write(reportText)
			</groovy>
				</then>
				<else>
					<echo message="Not a Unix system, report not generated"/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="backup-roll">
		<attribute name="backupDir"/>
		<attribute name="backupCount"/>
		<sequential>
			<groovy>
				<arg line="@{backupDir} @{backupCount}"/>

				String backupDir = args[0]
				Integer backupCount = new Integer(0).valueOf(args[1])

				println "Command Line Arguments:"
				println "\tbackupDir -\t" + backupDir
				println "\tbackupCount -\t" + backupCount

				ant = new AntBuilder()
				i = 1..backupCount.minus(1)

				File rmdir= new File(backupDir + "/backup" + backupCount)

				if (rmdir.exists()) {ant.delete(dir:rmdir)}

				i.reverse().each
				{
				File mv_src_dir= new File(backupDir + "/backup" + it)
				File mv_dest_dir= new File(backupDir + "/backup" + (it+1))
				if (mv_src_dir.exists())
				{
				println "move ${mv_src_dir} ${mv_dest_dir}"
				ant.move(file: mv_src_dir, tofile: mv_dest_dir);
				}
				}
			</groovy>
		</sequential>
	</macrodef>

	<macrodef name="backup-dir">
		<attribute name="src.dir"/>
		<attribute name="backup.base.dir"/>
		<attribute name="backup.count" default="5" />
		<sequential>
			<backup-roll
				backupDir="@{backup.base.dir}"
				backupCount="@{backup.count}"
				/>
			<delete dir="@{backup.base.dir}/backup"/>
			<mkdir dir="@{backup.base.dir}/backup"/>
			<mkdir dir="@{src.dir}"/>
			<move file="@{src.dir}" todir="@{backup.base.dir}/backup"/>
			<delete dir="@{src.dir}" quiet="false" />
		</sequential>
	</macrodef>
	<macrodef name="jboss-install-binaries">
		<attribute name="application.base.path" default="${application.base.path}"/>
		<attribute name="jboss.binaries.file" default="${tools.dir}/${jboss.binaries.file}" />
		<attribute name="jbosscp.binaries.file" default="${tools.dir}/${jbosscp.binaries.file}" />
		<attribute name="jems.install.option" default="ejb3" />
		<attribute name="jboss.home" default="${jboss.home}" />
		<attribute name="jboss.server.name" default="${jboss.server.name}" />
		<sequential>
			<var name="jboss.is.zip" unset="true"/>
			<propertyregex property="jboss.is.zip"
				input="@{jboss.binaries.file}"
				regexp=".*.zip"
				select="true"
				/>
			<var name="jboss.is.jar" unset="true"/>
			<propertyregex property="jboss.is.jar"
				input="@{jboss.binaries.file}"
				regexp=".*.jar"
				select="true"
				/>
			<var name="jboss.is.405" unset="true"/>
			<propertyregex property="jboss.is.405"
				input="@{jboss.binaries.file}"
				regexp=".*jboss-4.0.5.*"
				select="true"
				/>
			<var name="jboss.base.dir" unset="true"/>
			<dirname file="@{jboss.home}" property="jboss.base.dir"/>
			<if>
				<isset property="jboss.is.zip"/>
				<then>
					<unzip dest="${jboss.base.dir}" src="@{jboss.binaries.file}" />
				</then>
			</if>
			<if>
				<isset property="jboss.is.jar"/>
				<then>
					<java jar="@{jboss.binaries.file}" fork="true">
						<arg line="-installGroup @{jems.install.option} installpath=@{jboss.home}"/>
					</java>
				</then>
			</if>
			<!-- make sure default server is renamed if applicable -->
			<if>
				<not>
					<equals arg1="@{jboss.server.name}" arg2="default"/>
				</not>
				<then>
					<move todir="@{jboss.home}/server/@{jboss.server.name}">
						<fileset dir="@{jboss.home}/server/default"/>
					</move>
				</then>
			</if>

			<available file="@{jbosscp.binaries.file}" property="jbosscp.exists"/>
			<if>
				<and>
					<or>
						<isset property="jboss.is.405"/>
						<isset property="jboss.is.jar"/>
					</or>
					<isset property="jbosscp.exists"/>
				</and>
				<then>
					<echo message="Patching jboss with @{jbosscp.binaries.file}."/>
					<unzip dest="@{jboss.home}" src="@{jbosscp.binaries.file}" />
					<!-- Copy of patched configuration files -->
					<copy file="@{jboss.home}/config-patches/jboss-service.xml.patched" tofile="@{jboss.home}/server/@{jboss.server.name}/deploy/jbossweb-tomcat55.sar/META-INF/jboss-service.xml" overwrite="true"/>
					<copy file="@{jboss.home}/config-patches/jmx-invoker-service.xml.patched" tofile="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-invoker-service.xml" overwrite="true"/>
					<copy file="@{jboss.home}/config-patches/EntityEjb.jsp.patched" tofile="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/EntityEjb.jsp" overwrite="true"/>
					<copy file="@{jboss.home}/config-patches/MdbEjb.jsp.patched" tofile="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/MdbEjb.jsp" overwrite="true"/>
					<copy file="@{jboss.home}/config-patches/StatefulEjb.jsp.patched" tofile="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/StatefulEjb.jsp" overwrite="true"/>
					<copy file="@{jboss.home}/config-patches/StatelessEjb.jsp.patched" tofile="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/StatelessEjb.jsp" overwrite="true"/>
				</then>
			</if>
			<chmod dir="@{jboss.home}/bin" perm="ugo+rx" includes="**/*.sh" osfamily="unix"/>
			<if>
				<equals arg1="@{jboss.major.version}" arg2="5"/>
				<then>
					<chmod dir="@{jboss.home}/bin" perm="ugo+rx" includes="*_jboss"/>
				</then>
			</if>

		</sequential>
	</macrodef>
	<macrodef name="jboss-login-config">
		<attribute name="authentication.type" default="${authentication.type}"/>
		<attribute name="application.context.name" default="${application.context.name}"/>
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="login-config.ldap.file"/>
		<attribute name="login-config.db.file"/>
		<sequential>
			<if>
				<equals arg1="@{authentication.type}" arg2="ldap"/>
				<then>
					<var name="login-config.block.file" value="@{login-config.ldap.file}"/>
				</then>
				<else>
					<if>
						<equals arg1="@{authentication.type}" arg2="db"/>
						<then>
							<var name="login-config.block.file" value="@{login-config.db.file}"/>
						</then>
						<else>
							<fail message="@{authentication.type} is not a valid authentiation type, please change to db or ldap and re-run the build."/>
						</else>
					</if>
				</else>
			</if>
			<echo message="Inserting ${login-config.block.file} into @{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml"/>
			<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml"
				dest="@{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove path="//policy/application-policy[@name='@{application.context.name}']"/>
			</xmltask>
			<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml"
				dest="@{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="//policy" file="${login-config.block.file}"/>
			</xmltask>
		</sequential>
	</macrodef>
	<macrodef name="jboss-log4j-config">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="log4j.template.file"/>
		<sequential>
			<validate-log4j
				log4j.template.file="@{log4j.template.file}"
				/>

			<copy file="@{jboss.home}/server/@{jboss.server.name}/conf/log4j.xml" tofile="@{jboss.home}/server/@{jboss.server.name}/conf/log4j.xml.bak" overwrite="true"/>
			<copy file="@{log4j.template.file}" tofile="@{jboss.home}/server/@{jboss.server.name}/conf/log4j.xml" overwrite="true">
				<filterset>
					<filtersfile file="${properties.file}"/>
					<filtersfile file="project.properties"/>
				</filterset>
			</copy>
		</sequential>
	</macrodef>
	<macrodef name="validate-log4j">
		<attribute name="log4j.file" default="${jboss.home}/server/${jboss.server.name}/conf/log4j.xml"/>
		<sequential>
			<echo message="Validating log4j configuration at @{log4j.file}"/>
			<groovy>
				<arg line="@{log4j.file}"/>
				import java.util.regex.Matcher
				import java.util.regex.Pattern

				sizeMap = [
				KB: 1024,
				MB: (1024*1024),
				GB: (1024*1024*1024),
				]

				Integer thresholdFileNum = 15
				Integer thresholdFileSize = (1 * sizeMap["GB"])
				Integer exitCode = 2
				String errorMsg = '''
				There was an violation with your log4j configuraiton, see the rules below.
				All appenders except "console" should be a rolling type appender
				All appenders must have a MaxFileSize and be less than 1TB
				All appenders must have a MaxBackupIndex and be less than 15
				'''

				log4jFile = new File(args[0]).getAbsoluteFile()
				log4j = new XmlParser(false,false).parse(log4jFile)

				// Test Appenders
				println log4j.appender."@name"
				log4j.appender."@name".each{name ->
				if (name != "CONSOLE" && name != "FILE")
				{
				appenderClass = log4j.appender.find{it.'@name'==name}."@class"
				println "Appender Name-\t${name}"
				println "Appender Class-\t${appenderClass}"
				if (appenderClass.indexOf("Roll") < 1)
				{
				println "WARNING - Appender should be a rolling appender."
				//println errorMsg
				//System.exit(exitCode)
				}
				// Test Thresholds
				String fileSize=""
				if (log4j.appender.find{it.'@name'==name}.param.find{it.'@name'=='MaxFileSize'})
				{
				fileSize = log4j.appender.find{it.'@name'==name}.param.find{it.'@name'=='MaxFileSize'}."@value"
				}
				else
				{
				println "WARNING - Max Size is not set."
				//println errorMsg
				//System.exit(exitCode)
				}
				Integer numFiles
				if ( log4j.appender.find{it.'@name'==name}.param.find{it.'@name'=='MaxBackupIndex'})
				{
				numFiles =  log4j.appender.find{it.'@name'==name}.param.find{it.'@name'=='MaxBackupIndex'}."@value".toInteger()
				}
				else
				{
				println "WARNING - Max Files is not set."
				//println errorMsg
				//System.exit(exitCode)
				}

				println "Appender MaxSize-\t${fileSize}"
				println "Appender MaxFiles-\t${numFiles}"

				numMatcher =  java.util.regex.Pattern.compile(/(\d+)(\D*)/).matcher(fileSize)
				numMatches = numMatcher.matches()
				Integer numUnits = numMatcher.group(1).toInteger()
				String unit = numMatcher.group(2)

				Integer maxSize = numUnits
				if (unit.length() > 0 )
				{
				maxSize = numUnits * sizeMap[unit]
				}
				if (maxSize > thresholdFileSize)
				{
				println "WARNING - MaxFileSize exceeds threshold of ${thresholdFileSize}"
				//println errorMsg
				//System.exit(exitCode)
				}

				if (numFiles > thresholdFileNum)
				{
				println "WARNING - MaxFileNum exceeds threshold of ${thresholdFileNum}"
				//println errorMsg
				//System.exit(exitCode)
				}
				println "Appender Processed Sucessfully.\n"
				}
				}
			</groovy>
		</sequential>
	</macrodef>
	<macrodef name="deploy-local">
		<attribute name="build.dir" default="${build.dir}"/>
		<attribute name="install.dir" default="${dist.exploded.dir}" />
		<attribute name="properties.file" default="${properties.file}" />
		<attribute name="target.name" />
		<attribute name="enable.install.debug" default="${enable.install.debug}"/>
		<attribute name="enable.install.timing" default="${enable.install.timing}"/>
		<attribute name="override.properties" default="${override.properties}" />
		<attribute name="override.properties.delimiter" default="${override.properties.delimiter}" />
		<sequential>
			<var name="install.debug" unset="true"/>
			<if>
				<equals arg1="@{enable.install.debug}" arg2="true"/>
				<then>
					<echo message="Turning on ANT debug for install"/>
					<property name="install.debug" value="-v"/>
				</then>
				<else>
					<property name="install.debug" value=""/>
				</else>
			</if>
			<var name="install.timing" unset="true"/>
			<if>
				<equals arg1="@{enable.install.timing}" arg2="true"/>
				<then>
					<echo message="Turning on ANT target/task execution time reporting for install"/>
					<property name="install.timing" value="-listener   net.java.antutility.BuildMetricsListener"/>
				</then>
				<else>
					<property name="install.timing" value=""/>
				</else>
			</if>
			<!-- Copies over all files so linux and windows properties are present -->
			<copy todir="@{install.dir}">
				<fileset dir="@{build.dir}">
					<include name="*.properties" />
				</fileset>
			</copy>
			<override-properties-prep
				override.properties="@{override.properties}"
				override.properties.delimiter="@{override.properties.delimiter}"
				override.properties.string.property.name="override.properties.string"
				/>
			<exec osfamily="unix" executable="ant" dir="@{install.dir}" failonerror="true">
				<!-- use alternate properties file since default has replace values -->
				<!-- force reinstall of database and jboss without prompting -->
				<arg line="${install.debug} ${install.timing} -Dproperties.file=@{properties.file} -Dforce.reinstall=true ${override.properties.string} @{target.name}" />
			</exec>
			<exec osfamily="windows" executable="ant.bat" dir="@{install.dir}" failonerror="true">
				<!-- use alternate properties file since default has replace values -->
				<!-- force reinstall of database and jboss without prompting -->
				<arg line="${install.debug} ${install.timing} -Dproperties.file=@{properties.file} -Dforce.reinstall=true ${override.properties.string} @{target.name}" />
			</exec>
			<!-- ant returns exit code zero on failure to psexec, issue still lives on
			<exec osfamily="windows" executable="${build-utils.resource.dir}/psexec.exe" dir="@{install.dir}" failonerror="true">
				<arg line="ant.bat -Dproperties.file=@{properties.file} -Dforce.reinstall=true @{target.name}"/>
			</exec>
			-->
		</sequential>
	</macrodef>
	<macrodef name="deploy-files" description="Macro for deploying and extracting distrution to server">
		<attribute name="ssh.user" default="${ssh.server.username}" />
		<attribute name="ssh.host" default="${ssh.server.hostname}" />
		<attribute name="remote.directory.property.name" default="ssh.dir.temp" />
		<attribute name="properties.file" default="${properties.file}" />
		<attribute name="dist.dir" default="${dist.dir}" />
		<attribute name="dist.file" />
		<attribute name="ssh.port" default="22"/>
		<attribute name="ssh.key.file" default="${ssh.key.file}"/>
		<attribute name="ssh.key.passphrase" default="${ssh.key.passphrase}"/>
		<sequential>
			<!-- Validate remote directory is valid -->
			<propertycopy name="remote.dir" from="@{remote.directory.property.name}" override="true" />
			<check-valid-directory-name directory.property="remote.dir" />
			<!-- Delete/re-create remote directory -->
			<remote-ssh
				remoteSshHost="@{ssh.host}"
				remoteSshUser="@{ssh.user}"
				remoteSshKeyfile="@{ssh.key.file}"
				remoteSshPassPhrase="@{ssh.key.passphrase}"
				remotesshcommand="rm -rf ${remote.dir};mkdir -p ${remote.dir}" />
			<!-- work around for issue where basedir is required but is not currently used -->
			<remote-ssh
				remoteSshHost="@{ssh.host}"
				remoteSshUser="@{ssh.user}"
				remoteSshKeyfile="@{ssh.key.file}"
				remoteSshPassPhrase="@{ssh.key.passphrase}"
				remotesshcommand="mkdir -p ${remote.dir}/lib" />

			<!-- copy distribution and prop file to remote system -->
			<remote-scp
				remoteScpFileToCopy="@{dist.dir}/@{dist.file}" remoteScpToDir="@{ssh.user}@@@{ssh.host}:${remote.dir}"
				remoteScpKeyFile="@{ssh.key.file}"
				remoteScpPassphrase="@{ssh.key.passphrase}"
				/>

			<!-- Extract zip file -->
			<remote-ssh
				remoteSshHost="@{ssh.host}"
				remoteSshUser="@{ssh.user}"
				remoteSshKeyfile="@{ssh.key.file}"
				remoteSshPassPhrase="@{ssh.key.passphrase}"
				remotesshcommand="cd ${remote.dir}; unzip -q @{dist.file}" />
			<!-- copy properties after unzip to ensure that zip does not prompt for file existence if properties file is already in distribution. -->
			<remote-scp
				remoteScpFileToCopy="@{properties.file}" remoteScpToDir="@{ssh.user}@@@{ssh.host}:${remote.dir}"
				remoteScpKeyFile="@{ssh.key.file}"
				remoteScpPassphrase="@{ssh.key.passphrase}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="dist-prep" description="Macro for copying files to dist area">
		<attribute name="dist.exploded.dir" default="${dist.exploded.dir}" />
		<attribute name="build.dir" default="${build.dir}" />
		<attribute name="build-utils.dir" default="${build-utils.dir}" />
		<attribute name="common.dir" default="${common.dir}" />
		<attribute name="download.dir" default="${download.dir}" />
		<attribute name="copy.tools.flag" default="Y" />
		<attribute name="default.target" default="install" />
		<sequential>
			<!-- Do some cleanup -->
			<delete>
				<fileset dir="@{dist.exploded.dir}">
					<include name="build.xml" />
					<include name="*properties*" />
				</fileset>
			</delete>

			<!-- Copy install related xml and properties files -->
			<echo message="Copying build and property files"/>
			<copy todir="@{dist.exploded.dir}" overwrite="true">
				<fileset dir="@{build.dir}">
					<include name="install.xml" />
					<include name="install.properties" />
					<include name="upgrade.properties" />
					<include name="properties.template" />
					<include name="project.properties" />
				</fileset>
			</copy>

			<!-- Set default target and properyties.file to install and install.properties -->
			<basename file="@{properties.file}" property="properties.file.name"/>
			<replaceregexp file="@{dist.exploded.dir}/install.xml" byline="true" match="(.project.*default=.)\w+(.\s+.*)" replace="\1@{default.target}\2" />
			<replaceregexp file="${dist.exploded.dir}/install.xml" byline="true" match="(.*)install.properties(.*)" replace="\1${properties.file.name}\2" />

			<!-- Rename install.xml to build.xml so manual installs will not need to include the -f optoin on ant, simplifying the install proces. -->
			<move file="@{dist.exploded.dir}/install.xml" tofile="@{dist.exploded.dir}/build.xml" />

			<!-- Copy over build macrodefs and librarires -->
			<echo message="Copying build-utils dir"/>
			<copy todir="@{dist.exploded.dir}/build-utils" overwrite="true">
				<fileset dir="@{build-utils.dir}">
					<include name="**/*" />
				</fileset>
			</copy>

			<!-- This  copies common files over, common files are currently resource files like jboss configuration files and database scripts -->
			<echo message="Copying common dir"/>
			<copy todir="@{dist.exploded.dir}/common" overwrite="true">
				<fileset dir="@{common.dir}">
					<include name="**/resources/**/*" />
				</fileset>
			</copy>

			<if>
				<equals arg1="@{copy.tools.flag}" arg2="Y"/>
				<then>
					<echo message="Copying tools dir"/>
					<!-- Copy over binary distributions downloaded earlier -->
					<copy todir="@{dist.exploded.dir}/tools" overwrite="true">
						<fileset dir="@{download.dir}">
							<include name="**/*" />
						</fileset>
					</copy>
				</then>
				<else>
					<echo message="Not copying tools based on flag"/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="appserver-ssl-configure" description="macro for enabling ssl in jboss">
		<attribute name="appserver.conf.dir" default="${jboss.home}/server/${jboss.server.name}/conf"/>
		<attribute name="appserver.server-xml.file" default="${jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="appserver.server-xml.service.name" default="jboss.web"/>
		<attribute name="appserver.ssl.enable" default="${jboss.ssl.enable}"/>
		<attribute name="appserver.ssl.port" default="8443"/>
		<attribute name="appserver.ssl.keystore.file" default="${jboss.ssl.keystore.file}"/>
		<attribute name="appserver.ssl.keystore.dir" default="${jboss.ssl.keystore.dir}"/>
		<attribute name="appserver.ssl.keystore.pass" default="${jboss.ssl.keystore.pass}"/>
		<attribute name="appserver.ssl.keystore.alias" default="${jboss.ssl.keystore.alias}"/>
		<attribute name="appserver.ssl.fullyqualified.hostname" default="${jboss.ssl.fullyqualified.hostname}"/>

		<sequential>
			<!-- Questions
			If you connect to http will it automatically redirect you to https?
			Will bindnings work?
			-->
			<if>
				<equals arg1="@{appserver.ssl.enable}" arg2="true"/>
				<then>
					<echo message="Install JBoss SSL configurations"/>

					<!-- copy keystore to ${jboss.home}/server/${jboss.server.name}/conf -->
					<copy todir="@{appserver.conf.dir}" file="@{appserver.ssl.keystore.dir}/@{appserver.ssl.keystore.file}"/>

					<!-- modify ${jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml -->
					<xmltask preservetype="true" source="@{appserver.server-xml.file}"
						dest="@{appserver.server-xml.file}">
						<xmlcatalog refid="build.xml.catalog"/>
						<remove	path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@port='@{appserver.ssl.port}']" />
					</xmltask>
					<xmltask preservetype="true" source="@{appserver.server-xml.file}"
						dest="@{appserver.server-xml.file}"
						failWithoutMatch="true" >
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="/Server/Service[@name='@{appserver.server-xml.service.name}']">
							<![CDATA[
							<Connector port="@{appserver.ssl.port}"
								maxThreads="100"
								strategy="ms"
							       	maxHttpHeaderSize="8192"
								emptySessionPath="true"
								scheme="https"
								secure="true"
							       	clientAuth="false"
								keystoreFile="@{appserver.conf.dir}/@{appserver.ssl.keystore.file}"
								keystorePass="@{appserver.ssl.keystore.pass}"
								keyAlias="@{appserver.ssl.keystore.alias}"
								sslProtocol = "TLS"
								protocol="HTTP/1.1"
								SSLEnabled="true"
							       />
							]]>
						</insert>
					</xmltask>
					<!--
							<Connector port="@{appserver.ssl.port}"
							       	address="\${jboss.bind.address}"
								maxThreads="100"
								strategy="ms"
							       	maxHttpHeaderSize="8192"
								emptySessionPath="true"
								scheme="https"
								secure="true"
							       	clientAuth="false"
								keystoreFile="@{appserver.conf.dir}/@{appserver.ssl.keystore.file}"
								keystorePass="@{appserver.ssl.keystore.pass}"
								keyAlias="@{appserver.ssl.keystore.alias}"
							       	sslProtocol = "TLS" />
					-->
				</then>
				<else>
					<echo message="appserver.ssl.enable not set or true so skipping install of JBoss SSL configuration"/>
				</else>
			</if>

		</sequential>
	</macrodef>
	<macrodef name="verify-keystore" description="macro for verifying a keystore">
		<attribute name="appserver.ssl.enable" default="${jboss.ssl.enable}"/>
		<attribute name="appserver.ssl.keystore.file" default="${jboss.ssl.keystore.file}"/>
		<attribute name="appserver.ssl.keystore.dir" default="${jboss.ssl.keystore.dir}"/>
		<attribute name="appserver.ssl.keystore.pass" default="${jboss.ssl.keystore.pass}"/>
		<attribute name="appserver.ssl.keystore.alias" default="${jboss.ssl.keystore.alias}"/>
		<attribute name="appserver.ssl.fullyqualified.hostname" default="${jboss.ssl.fullyqualified.hostname}"/>
		<attribute name="verify.url" default="true"/>
		<sequential>
			<if>
				<equals arg1="@{appserver.ssl.enable}" arg2="true"/>
				<then>
					<var name="keytool.output" unset="true"/>
					<var name="keytool.error" unset="true"/>
					<var name="keytool.result" unset="true"/>
					<echo message="Validating keystore file"/>
					<osfamily property="os.family"/>
					<echo  message="os.family=${os.family}"/>
					<if>
						<or>
							<equals arg1="${os.family}" arg2="unix"/>
							<equals arg1="${os.family}" arg2="mac"/>
						</or>
						<then>
							<property name="os.tmp.dir" value="/tmp/${project.name}"/>
						</then>
					</if>
					<if>
						<equals arg1="${os.family}" arg2="windows"/>
						<then>
							<property name="os.tmp.dir" value="c:/tmp/${project.name}"/>
						</then>
					</if>
					<mkdir dir="${os.tmp.dir}"/>
					<echo message="'@{appserver.ssl.keystore.dir}'	'@{appserver.ssl.keystore.file}'"/>
					<copy file="@{appserver.ssl.keystore.dir}/@{appserver.ssl.keystore.file}" tofile="${os.tmp.dir}/@{appserver.ssl.keystore.file}"/>
					<exec executable="keytool" outputproperty="keytool.output" errorproperty="keytool.error" resultproperty="keytool.result">
						<arg value="-list"/>
						<arg value="-keystore"/>
						<arg value="${os.tmp.dir}/@{appserver.ssl.keystore.file}"/>
						<arg value="-storepass"/>
						<arg value="@{appserver.ssl.keystore.pass}"/>
						<arg value="-alias"/>
						<arg value="@{appserver.ssl.keystore.alias}"/>
						<arg value="-v"/>
					</exec>
					<if>
						<not>
							<equals arg1="${keytool.result}" arg2="0"/>
						</not>
						<then>
							<fail message="keytool failed - ${keytool.output} ${keytool.error}"/>
						</then>
						<else>
							<echo message="debug - ${keytool.result} ${keytool.output} ${keytool.error}"/>
							<if>
								<equals arg1="@{verify.url}" arg2="true"/>
								<then>
			<groovy>
				<arg line="${keytool.output} @{appserver.ssl.fullyqualified.hostname}"/>
				import java.util.regex.Pattern

				String keytoolOutput = args[0]
				String fqhn = args[3]

				keytoolOutput.eachLine
				{ cline ->
				//Owner: CN=*.nci.nih.gov, OU=National Cancer Institute, O=National Institute of Health, L=Rockville, ST=Maryland, C=US
				//m = java.util.regex.Pattern.compile(/^Owner:\s+CN=([\w\d\-\_\.\*]+).*/).matcher(cline)
				m = cline =~ /^Owner:\s+CN=([^\.]+)([\w\d\-\_\.]+).*/
				if (m.matches())
				{
				host = m.group(1)
				domain = m.group(2)
				certfqhn = host + domain
				println "Found host = '${host}' domain = '${domain}' in - ${cline}"
				if (host.equals('*'))
				{
				if (fqhn.indexOf(domain) > 0)
				{
				println "${fqhn} matches ${domain}"
				} else
				{
				System.err.println "${fqhn} FAILED MATCH ${domain}"
				System.exit(2)
				}
				} else
				{
				if (fqhn.equals(certfqhn))
				{
				println "${fqhn} matches ${certfqhn}"
				} else
				{
				System.err.println "${fqhn} FAILED MATCH ${certfqhn}"
				System.exit(2)
				}
				}
				}
				}
			</groovy>
								</then>
							</if>
						</else>
					</if>
				</then>
				<else>
					<echo message="appserver.ssl.enable not set or true so skipping ssl validation"/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="grid-secure-configure-connector" description="Inserts a secure connector configuration into a tomcat configuration, including jboss tomcat">
		<attribute name="appserver.conf.dir" default="${jboss.home}/server/${jboss.server.name}/conf"/>
		<attribute name="appserver.server-xml.file" default="${jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="appserver.server-xml.service.name" default="jboss.web"/>
		<attribute name="grid.secure.enable" default="${grid.secure.enable}"/>
		<attribute name="grid.secure.port" default="@{grid.secure.port}"/>
		<attribute name="grid.secure.dir" default="${grid.secure.dir}"/>
		<attribute name="grid.secure.key.file" default="${grid.secure.key.file}" />
		<attribute name="grid.secure.cert.file" default="${grid.secure.cert.file}" />
		<sequential>
			<if>
				<equals arg1="@{grid.secure.enable}" arg2="true"/>
				<then>
					<var name="is.jboss40" unset="true"/>
					<propertyregex property="is.jboss40"
						input="@{appserver.conf.dir}"
						regexp="jboss-4.*"
						select="true"
						/>
					<var name="is.tomcat50" unset="true"/>
					<propertyregex property="is.tomcat50"
						input="@{appserver.conf.dir}"
						regexp="tomcat-5.0.*"
						select="true"
						/>
					<var name="is.tomcat55" unset="true"/>
					<propertyregex property="is.tomcat55"
						input="@{appserver.conf.dir}"
						regexp="tomcat-5.5.*"
						select="true"
						/>
					<!-- not sure if grid will work with .*tomcat-6.0, assuming it uses same as 5.5-->
					<propertyregex property="is.tomcat55"
						input="@{appserver.conf.dir}"
						regexp=".*tomcat-6.0.*"
						select="true"
						/>
					<var name="is.jboss51" unset="true"/>
					<propertyregex property="is.jboss51"
						input="@{appserver.conf.dir}"
						regexp=".*jboss-5.1.*"
						select="true"
						/>
					<if>
						<or>
							<isset property="is.jboss40"/>
							<isset property="is.jboss51"/>
							<isset property="is.tomcat55"/>
						</or>
						<then>
							<echo message="is.tomcat50 = ${is.tomcat50} is.tomcat55 = ${is.tomcat55} is.jboss40 = ${is.jboss40} "/>
							<var name="tomcat55.extras" value="protocolHandlerClassName="org.apache.coyote.http11.Http11Protocol"${line.separator}socketFactory="org.globus.tomcat.catalina.net.BaseHTTPSServerSocketFactory""/>
						</then>
						<elseif>
							<isset property="is.tomcat50"/>
							<then>
								<echo message="is.tomcat50 = ${is.tomcat50} is.tomcat55 = ${is.tomcat55} is.jboss40 = ${is.jboss40} "/>
								<var name="tomcat55.extras" value=""/>
							</then>
						</elseif>
						<else>
							<echo message="is.tomcat50 = ${is.tomcat50} is.tomcat55 = ${is.tomcat55} is.jboss40 = ${is.jboss40} "/>
							<fail message="Not using Jboss 4.x or Tomcat 5.0.x or Tomcat 5.5.x cannot configure a secure container, failing build.  Please be sure to include the applcation and version as the name of the directory for tomcat.home or jboss.home"/>
						</else>
					</if>

					<echo message="grid.secure.enable set so secure grid is being configured"/>
					<copy todir="@{appserver.conf.dir}" file="@{grid.secure.dir}/@{grid.secure.cert.file}"/>
					<copy todir="@{appserver.conf.dir}" file="@{grid.secure.dir}/@{grid.secure.key.file}"/>
					<xmltask preservetype="true" source="@{appserver.server-xml.file}"
						dest="@{appserver.server-xml.file}" >
						<xmlcatalog refid="build.xml.catalog"/>
						<remove	path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@port='@{grid.secure.port}']" />
					</xmltask>
					<xmltask preservetype="true" source="@{appserver.server-xml.file}"
						dest="@{appserver.server-xml.file}"
						failWithoutMatch="true" >
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="/Server/Service[@name='@{appserver.server-xml.service.name}']">
							<![CDATA[
							<Connector className="org.globus.tomcat.coyote.net.HTTPSConnector"
								port="@{grid.secure.port}"
								maxThreads="150"
								minSpareThreads="25"
								maxSpareThreads="75"
								autoFlush="true"
								disableUploadTimeout="true"
								scheme="https"
								enableLookups="true"
								acceptCount="10"
								debug="0"
								cert="@{appserver.conf.dir}/@{grid.secure.cert.file}"
								key="@{appserver.conf.dir}/@{grid.secure.key.file}"
								${tomcat55.extras}
								/>
							]]>
						</insert>
					</xmltask>
				</then>
				<else>
					<echo message="grid.secure.enable not set so secure grid not configured"/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="grid-secure-configure-valve">
		<attribute name="appserver.server-xml.file" default="${jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="appserver.server-xml.service.name" default="jboss.web"/>
		<sequential>
			<var name="is.jboss40" unset="true"/>
			<propertyregex property="is.jboss40"
				input="@{appserver.server-xml.file}"
				regexp="jboss-4.*"
				select="true"
				/>
			<var name="is.tomcat50" unset="true"/>
			<propertyregex property="is.tomcat50"
				input="@{appserver.server-xml.file}"
				regexp="tomcat-5.0.*"
				select="true"
				/>
			<var name="is.tomcat55" unset="true"/>
			<propertyregex property="is.tomcat55"
				input="@{appserver.server-xml.file}"
				regexp="tomcat-5.5.*"
				select="true"
				/>
			<!-- not sure if grid will work with .*tomcat-6.0, assuming it uses same as 5.5-->
			<var name="is.tomcat60" unset="true"/>
			<propertyregex property="is.tomcat60"
				input="@{appserver.server-xml.file}"
				regexp=".*tomcat-6.0.*"
				select="true"
				/>
			<var name="is.jboss51" unset="true"/>
			<propertyregex property="is.jboss51"
				input="@{appserver.server-xml.file}"
				regexp=".*jboss-5.1.*"
				select="true"
				/>
			<echo message="is.jboss40 = ${is.jboss40}"/>
			<echo message="is.jboss51 = ${is.jboss51}"/>
			<echo message="is.tomcat55 = ${is.tomcat55}"/>
			<echo message="is.tomcat60 = ${is.tomcat60}"/>
			<echo message="@{appserver.server-xml.file}"/>
			<if>
				<or>
					<isset property="is.jboss40"/>
					<isset property="is.jboss51"/>
					<isset property="is.tomcat55"/>
					<isset property="is.tomcat60"/>
				</or>
				<then>
					<var name="valve.name" value="org.globus.tomcat.coyote.valves.HTTPSValve55"/>
				</then>
				<else>
					<var name="valve.name" value="org.globus.tomcat.coyote.valves.HTTPSValve"/>
				</else>
			</if>
			<echo message="Deleting vavle from @{appserver.server-xml.file}"/>
			<xmltask preservetype="true" source="@{appserver.server-xml.file}"
				dest="@{appserver.server-xml.file}">
				<remove path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Engine[@name='@{appserver.server-xml.service.name}']/Valve[@className='${valve.name}']" />
			</xmltask>
			<echo message="Inserting vavle from @{appserver.server-xml.file}"/>
			<xmltask preservetype="true" source="@{appserver.server-xml.file}"
				dest="@{appserver.server-xml.file}"
				failWithoutMatch="true">
				<insert path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Engine[@name='@{appserver.server-xml.service.name}']">
					<![CDATA[
					<Valve className="${valve.name}"/>
					]]>
				</insert>
			</xmltask>
		</sequential>
	</macrodef>

	<macrodef name="grid-secure-configure-secdesc">
		<attribute name="appserver.conf.dir" default="${jboss.home}/server/${jboss.server.name}/conf/"/>
		<attribute name="appserver.webapp.dir" default="${jboss.home}/server/${jboss.server.name}/deploy/"/>
		<attribute name="grid.application.relative.dir" default="${grid.dir.dest}"/>
		<attribute name="grid.secdesc.file" default="@{appserver.webapp.dir}/@{grid.application.relative.dir}/WEB-INF/etc/globus_wsrf_core/global_security_descriptor.xml"/>
		<attribute name="grid.secure.key.file" default="${grid.secure.key.file}" />
		<attribute name="grid.secure.cert.file" default="${grid.secure.cert.file}" />
		<sequential>
			<if>
				<available file="@{grid.secdesc.file}" />
				<then>
					<xmltask preservetype="true" source="@{grid.secdesc.file}"
						dest="@{grid.secdesc.file}">
						<xmlcatalog refid="build.xml.catalog"/>
						<remove path="/*[local-name()='securityConfig']/*[local-name()='gridmap']" />
					</xmltask>
					<xmltask preservetype="true" source="@{grid.secdesc.file}"
						dest="@{grid.secdesc.file}"
						failWithoutMatch="true">
						<xmlcatalog refid="build.xml.catalog"/>
						<attr   path="/*[local-name()='securityConfig']/*[local-name()='credential']/*[local-name()='key-file']"
							attr="value"
							value="@{appserver.conf.dir}/@{grid.secure.key.file}" />
						<attr   path="/*[local-name()='securityConfig']/*[local-name()='credential']/*[local-name()='cert-file']"
							attr="value"
							value="@{appserver.conf.dir}/@{grid.secure.cert.file}" />
					</xmltask>
				</then>
				<else>
					<fail message="Cannot filed security descriptor file @{grid.secdesc.file}"/>
					<!--
					<echoxml file="@{grid.secdesc.file}">
						<securityConfig xmlns="http://www.globus.org">
							<credential>
								<key-file value="@{appserver.conf.dir}/@{grid.secure.key.file}"/>
								<cert-file value="@{appserver.conf.dir}/@{grid.secure.key.file}"/>
							</credential>
						</securityConfig>
					</echoxml>
					-->
				</else>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="grid-configure-server-config">
		<attribute name="appserver.webapp.dir" default="${jboss.home}/server/${jboss.server.name}/deploy/"/>
		<attribute name="grid.application.relative.dir" default="${grid.dir.dest}"/>
		<attribute name="server-config.file" default="@{appserver.webapp.dir}/@{grid.application.relative.dir}/WEB-INF/etc/globus_wsrf_core/server-config.wsdd" />
		<attribute name="grid.secdesc.file" default="@{appserver.webapp.dir}/@{grid.application.relative.dir}/WEB-INF/etc/globus_wsrf_core/global_security_descriptor.xml"/>
		<attribute name="grid.external.secure.host" default="${grid.external.secure.host}"/>
		<attribute name="grid.secure.enable" default="true"/>
		<attribute name="appserver.external.http.host" default="${jboss.external.http.host}"/>
		<sequential>

			<var name="grid.external.secure.host.has.value" unset="true"/>
			<propertyregex property="grid.external.secure.host.has.value"
				input="@{grid.external.secure.host}"
				regexp="\S+"
				select="true"
				/>
			<var name="appserver.external.http.host.has.value" unset="true"/>
			<propertyregex property="appserver.external.http.host.has.value"
				input="@{appserver.external.http.host}"
				regexp="\S+"
				select="true"
				/>

			<if>
				<and>
					<equals arg1="@{grid.secure.enable}" arg2="true"/>
					<isset property="grid.external.secure.host.has.value"/>
				</and>
				<then>
					<echo message="grid.external.secure.host is @{grid.external.secure.host}, proceeding with configuration"/>
					<xmltask preservetype="true" source="@{server-config.file}" dest="@{server-config.file}">
						<xmlcatalog refid="build.xml.catalog"/>
						<remove path="/*[local-name()='deployment']/*[local-name()='globalConfiguration']/*[local-name()='parameter' and @name='logicalHost']" />
						<remove path="/*[local-name()='deployment']/*[local-name()='globalConfiguration']/*[local-name()='parameter' and @name='publishHostName']" />
					</xmltask>
					<xmltask preservetype="true" source="@{server-config.file}" dest="@{server-config.file}" failWithoutMatch="true">
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="/*[local-name()='deployment']/*[local-name()='globalConfiguration']">
							<![CDATA[
							<parameter xmlns="http://xml.apache.org/axis/wsdd/"
								name="logicalHost"
								value="@{grid.external.secure.host}"/>
							<parameter xmlns="http://xml.apache.org/axis/wsdd/"
										name="publishHostName"
								value="true"/>
							<parameter xmlns="http://xml.apache.org/axis/wsdd/"
								name="disableDNS"
										value="true"/>
							]]>
						</insert>
					</xmltask>
				</then>
				<else>
					<echo message="grid.external.secure.host is is not set skipping external host configuration."/>
				</else>
			</if>
			<if>
				<and>
					<not>
						<equals arg1="@{grid.secure.enable}" arg2="true"/>
					</not>
					<isset property="appserver.external.http.host.has.value"/>
				</and>
				<then>
					<echo message="appserver.external.http.host is @{appserver.external.http.host}, proceeding with configuration"/>
					<xmltask preservetype="true" source="@{server-config.file}" dest="@{server-config.file}">
						<xmlcatalog refid="build.xml.catalog"/>
						<remove path="/*[local-name()='deployment']/*[local-name()='globalConfiguration']/*[local-name()='parameter' and @name='logicalHost']" />
						<remove path="/*[local-name()='deployment']/*[local-name()='globalConfiguration']/*[local-name()='parameter' and @name='publishHostName']" />
					</xmltask>
					<xmltask preservetype="true" source="@{server-config.file}" dest="@{server-config.file}" failWithoutMatch="true">
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="/*[local-name()='deployment']/*[local-name()='globalConfiguration']">
							<![CDATA[
							<parameter xmlns="http://xml.apache.org/axis/wsdd/"
								name="logicalHost"
								value="@{appserver.external.http.host}"/>
							<parameter xmlns="http://xml.apache.org/axis/wsdd/"
										name="publishHostName"
								value="true"/>
							<parameter xmlns="http://xml.apache.org/axis/wsdd/"
								name="disableDNS"
										value="true"/>
							]]>
						</insert>
					</xmltask>
				</then>
				<else>
					<echo message="appserver.external.http.host is is not set skipping external host configuration."/>
				</else>
			</if>
			<if>
				<equals arg1="@{grid.secure.enable}" arg2="true" trim="true" />
				<then>
					<xmltask preservetype="true" source="@{server-config.file}" dest="@{server-config.file}">
						<xmlcatalog refid="build.xml.catalog"/>
						<remove path="/*[local-name()='deployment']/*[local-name()='globalConfiguration']/*[local-name()='parameter' and @name='containerSecDesc']" />
						<remove path="/*[local-name()='deployment']/*[local-name()='globalConfiguration']/*[local-name()='requestFlow']/*[local-name()='handler' and @type='java:org.globus.wsrf.impl.security.authentication.transport.TomcatTransportSecurityHandler']" />
					</xmltask>
					<xmltask preservetype="true" source="@{server-config.file}" dest="@{server-config.file}" failWithoutMatch="true">
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="/*[local-name()='deployment']/*[local-name()='globalConfiguration']">
							<![CDATA[
							<parameter xmlns="http://xml.apache.org/axis/wsdd/"
								name="containerSecDesc"
								value="@{grid.secdesc.file}"/>
							]]>
						</insert>
						<insert path="/*[local-name()='deployment']/*[local-name()='globalConfiguration']/*[local-name()='requestFlow']/*[local-name()='handler' and @type='java:org.globus.wsrf.handlers.URLMapper']"
							position="after">
							<![CDATA[
							<handler type="java:org.globus.wsrf.impl.security.authentication.transport.TomcatTransportSecurityHandler"
								xmlns="http://xml.apache.org/axis/wsdd/"/>
							]]>
						</insert>
					</xmltask>
				</then>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="update-grid-web-xml-protocol">
		<attribute name="appserver.webapp.dir" default="${jboss.home}/server/${jboss.server.name}/deploy/"/>
		<attribute name="grid.application.relative.dir" default="${grid.dir.dest}"/>
		<attribute name="web-xml.location" default="@{appserver.webapp.dir}/@{grid.application.relative.dir}/WEB-INF/web.xml"/>
		<attribute name="scheme" default="http" />
		<attribute name="port" default="${jboss.server.port}"/>
		<sequential>
			<xmltask preservetype="true" source="@{web-xml.location}" dest="@{web-xml.location}">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove path="/web-app/servlet[servlet-name='WSRFServlet']/init-param[param-name='defaultProtocol']" />
				<remove path="/web-app/servlet[servlet-name='WSRFServlet']/init-param[param-name='defaultPort']" />
			</xmltask>
			<xmltask preservetype="true" source="@{web-xml.location}" dest="@{web-xml.location}" failWithoutMatch="true">
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="/web-app/servlet[servlet-name='WSRFServlet']/servlet-class"
					position="after">
					<![CDATA[
					<init-param>
						<param-name>defaultProtocol</param-name>
						<param-value>@{scheme}</param-value>
					</init-param>
					<init-param>
						<param-name>defaultPort</param-name>
						<param-value>@{port}</param-value>
					</init-param>
					]]>
				</insert>
			</xmltask>
		</sequential>
	</macrodef>
	<macrodef name="appserver-configure-external-hostname">
		<attribute name="appserver.server-xml.file" default="${jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="appserver.server-xml.service.name" default="jboss.web"/>
		<attribute name="appserver.external.host" default="${jboss.external.ssl.host}"/>
		<attribute name="appserver.external.port" default="${jboss.external.ssl.port}"/>
		<attribute name="proxy.update.connector.port" default="8443"/>
		<sequential>
			<var name="appserver.external.host.has.value" unset="true"/>
			<propertyregex property="appserver.external.host.has.value"
				input="@{appserver.external.host}"
				regexp="\S+"
				select="true"
				/>
			<if>
				<equals arg1="${appserver.external.host.has.value}" arg2="true"/>
				<then>
					<echo message="Grid External Host Name set so configuring proxy settings"/>
					<echo message="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@port='@{proxy.update.connector.port}"/>
					<xmltask preservetype="true" source="@{appserver.server-xml.file}"
						dest="@{appserver.server-xml.file}">
						<xmlcatalog refid="build.xml.catalog"/>
						<attr path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@port='@{proxy.update.connector.port}']"
							attr="proxyPort"
							value="@{appserver.external.port}"/>
						<attr path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@port='@{proxy.update.connector.port}']"
							attr="proxyName"
							value="@{appserver.external.host}"/>
					</xmltask>
				</then>
				<else>
					<echo message="Grid External Host Name not set so doing nothing"/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="tomcat-configure-server-xml-db">
		<attribute name="tomcat.home" default="${tomcat.home}"/>
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.name" default="${database.name}" />
		<attribute name="database.jndi.datasource.name" default="${database.jndi.datasource.name}" />
		<attribute name="database.context.path" default="${database.context.path}" />
		<sequential>
			<var name="datasource.has.value" unset="true"/>
			<propertyregex property="datasource.has.value"
				input="@{database.jndi.datasource.name}"
				regexp="\S+"
				select="true"
				/>
			<var name="datasource.not.variable" unset="true"/>
			<propertyregex property="datasource.not.variable"
				input="@{database.jndi.datasource.name}"
				regexp="\$"
				select="true"
				/>
			<if>
				<and>
					<equals arg1="${datasource.has.value}" arg2="true"/>
					<not>
						<equals arg1="${datasource.not.variable}" arg2="true"/>
					</not>
				</and>
				<then>
					<echo message="Configuring tomcat datasource"/>
					<xmltask preservetype="true" source="@{tomcat.home}/conf/server.xml" dest="@{tomcat.home}/conf/server.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<remove path="/Server/Service[@name='Catalina']/Engine[@name='Catalina']/Host[@name='localhost']/Context[@path='/@{database.context.path}']"/>
					</xmltask>
					<xmltask preservetype="true" source="@{tomcat.home}/conf/server.xml" dest="@{tomcat.home}/conf/server.xml" failWithoutMatch="true">
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="/Server/Service[@name='Catalina']/Engine[@name='Catalina']/Host[@name='localhost']">
							<![CDATA[
							<Context path="/@{database.context.path}" docBase="@{database.context.path}" reloadable="false">
								<Resource name="@{database.jndi.datasource.name}" auth="Container" type="javax.sql.DataSource"
									username="@{database.user}"
									password="@{database.password}"
									driverClassName="@{database.driver}"
									url="@{database.url}?autoReconnect=true"
									maxActive="20" />
									</Context>
							]]>
						</insert>
					</xmltask>
				</then>
				<else>
					<echo message="Not configuring tomcat datasource because database.jndi.datasource.name is not set"/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="tomcat-configure">
		<attribute name="tomcat.port.http" default ="${tomcat.port.http}"/>
		<attribute name="tomcat.port.ssl" default="${tomcat.port.ssl}"/>
		<attribute name="tomcat.port.ajp" default="${tomcat.port.ajp}"/>
		<attribute name="tomcat.port.shutdown" default="${tomcat.port.shutdown}"/>
		<attribute name="tomcat.home" default="${tomcat.home}"/>
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.name" default="${database.name}" />
		<attribute name="database.jndi.datasource.name" default="${database.jndi.datasource.name}" />
		<attribute name="database.context.path" default="${database.jndi.datasource.name}" />

		<!--appserver-ssl-configure -->
		<attribute name="tomcat.conf.dir" default="${tomcat.home}/conf"/>
		<attribute name="tomcat.server-xml.file" default="${tomcat.home}/conf/server.xml"/>
		<attribute name="tomcat.server-xml.service.name" default="Catalina"/>
		<attribute name="tomcat.ssl.enable" default="${tomcat.ssl.enable}"/>
		<attribute name="tomcat.ssl.port" default="${tomcat.port.ssl}"/>
		<attribute name="tomcat.ssl.keystore.file" default="${tomcat.ssl.keystore.file}"/>
		<attribute name="tomcat.ssl.keystore.dir" default="${tomcat.ssl.keystore.dir}"/>
		<attribute name="tomcat.ssl.keystore.pass" default="${tomcat.ssl.keystore.pass}"/>
		<attribute name="tomcat.ssl.keystore.alias" default="${tomcat.ssl.keystore.alias}"/>
		<attribute name="tomcat.ssl.fullyqualified.hostname" default="${tomcat.ssl.fullyqualified.hostname}"/>
		<!-- appserver-configure-external-hostname -->
		<attribute name="tomcat.external.ssl.host" default="${tomcat.external.ssl.host}"/>
		<attribute name="tomcat.external.ssl.port" default="${tomcat.external.ssl.port}"/>
		<attribute name="tomcat.external.http.host" default="${tomcat.external.http.host}"/>
		<attribute name="tomcat.external.http.port" default="${tomcat.external.http.port}"/>
		<attribute name="proxy.update.connector.port.ssl" default="${tomcat.port.ssl}"/>
		<attribute name="proxy.update.connector.port.http" default="8080"/>
		<attribute name="tomcat.external.grid.secure.host" default="${tomcat.external.grid.secure.host}"/>
		<attribute name="tomcat.external.grid.secure.port" default="${tomcat.external.grid.secure.port}"/>
		<!--appserver-configure-hostname -->
		<attribute name="tomcat.hostname" default="${tomcat.hostname}"/>
		<!--grid-secure-configure-connector-->
		<attribute name="tomcat.grid.configure" default="false"/>
		<attribute name="tomcat.grid.secure.enable" default="${tomcat.grid.secure.enable}"/>
		<attribute name="tomcat.grid.secure.port" default="${tomcat.grid.secure.port}"/>
		<attribute name="tomcat.grid.secure.dir" default="${tomcat.grid.secure.dir}"/>
		<attribute name="tomcat.grid.secure.key.file" default="${tomcat.grid.secure.key.file}" />
		<attribute name="tomcat.grid.secure.cert.file" default="${tomcat.grid.secure.cert.file}" />
		<attribute name="tomcat.logs.dir" default="${tomcat.home}/logs"/>
		<attribute name="tomcat.http-connector.remove" default="${tomcat.http-connector.remove}"/>
		<sequential>
			<if>
				<not>
					<equals arg1="${exclude.tomcat-config}" arg2="true"/>
				</not>
				<then>
					<echo message="Configuring datasource for jboss"/>
					<tomcat-configure-server-xml-db
						tomcat.home="@{tomcat.home}"
						database.driver="@{database.driver}"
						database.url="@{database.url}"
						database.user="@{database.user}"
						database.password="@{database.password}"
						database.name="@{database.name}"
						database.jndi.datasource.name="@{database.jndi.datasource.name}"
						database.context.path="@{database.context.path}"
						/>

					<echo message="Securing tomcat app server"/>
					<appserver-ssl-configure
						appserver.conf.dir="@{tomcat.conf.dir}"
								appserver.server-xml.file="@{tomcat.server-xml.file}"
						appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
						appserver.ssl.enable="@{tomcat.ssl.enable}"
						appserver.ssl.port="@{tomcat.ssl.port}"
						appserver.ssl.keystore.file="@{tomcat.ssl.keystore.file}"
						appserver.ssl.keystore.dir="@{tomcat.ssl.keystore.dir}"
						appserver.ssl.keystore.pass="@{tomcat.ssl.keystore.pass}"
						appserver.ssl.keystore.alias="@{tomcat.ssl.keystore.alias}"
						appserver.ssl.fullyqualified.hostname="@{tomcat.ssl.fullyqualified.hostname}"
						/>

					<!-- needs to be done before changing ports -->
					<echo message="Configuring tomcat proxy settings for ssl"/>
					<copy file="@{tomcat.server-xml.file}" tofile="@{tomcat.server-xml.file}.saksa"/>
					<appserver-configure-external-hostname
						appserver.server-xml.file="@{tomcat.server-xml.file}"
						appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
						appserver.external.host="@{tomcat.external.ssl.host}"
						appserver.external.port="@{tomcat.external.ssl.port}"
						proxy.update.connector.port="@{proxy.update.connector.port.ssl}"
						/>
					<!-- needs to be done before changing ports -->
					<echo message="Configuring tomcat proxy settings for http"/>
					<appserver-configure-external-hostname
						appserver.server-xml.file="@{tomcat.server-xml.file}"
						appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
						appserver.external.host="@{tomcat.external.http.host}"
						appserver.external.port="@{tomcat.external.http.port}"
						proxy.update.connector.port="@{proxy.update.connector.port.http}"
						/>
					<!-- needs to be done before changing ports -->
					<!--
					<echo message="Configuring JBoss hostname in server.xml"/>
					<appserver-configure-hostname
						appserver.server-xml.file="@{tomcat.server-xml.file}"
						appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
						appserver.hostname="@{tomcat.hostname}"
						/>
					-->

					<echo message="Updating Tomcat Ports"/>
					<properties-print
						properties.list="tomcat.port.http,tomcat.port.ajp,tomcat.port.ssl,tomcat.port.shutdown"
						/>
					<echo message="@{tomcat.port.http} @{tomcat.port.ajp} @{tomcat.port.ssl} @{tomcat.port.shutdown}"/>
					<xmltask preservetype="true" source="@{tomcat.home}/conf/server.xml" dest="@{tomcat.home}/conf/server.xml" failWithoutMatch="true">
						<xmlcatalog refid="build.xml.catalog"/>
						<replace path="(//Connector)[1]/@port" withtext="@{tomcat.port.http}" />
						<replace path="(//Connector)/@redirectPort" withtext="@{tomcat.port.ssl}" />
						<replace path="(//Connector)[@protocol='AJP/1.3']/@port" withtext="@{tomcat.port.ajp}" />
						<replace path="(//Server)/@port" withtext="@{tomcat.port.shutdown}" />
					</xmltask>

					<if>
						<and>
							<equals arg1="@{tomcat.grid.configure}" arg2="true"/>
							<equals arg1="@{tomcat.grid.secure.enable}" arg2="true"/>
						</and>
						<then>
							<echo message="Configuring secure grid in tomcat"/>
							<grid-secure-configure-connector
								appserver.conf.dir="@{tomcat.conf.dir}"
								appserver.server-xml.file="@{tomcat.server-xml.file}"
								appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
								grid.secure.enable="@{tomcat.grid.secure.enable}"
								grid.secure.port="@{tomcat.grid.secure.port}"
								grid.secure.dir="@{tomcat.grid.secure.dir}"
								grid.secure.cert.file="@{tomcat.grid.secure.cert.file}"
								grid.secure.key.file="@{tomcat.grid.secure.key.file}"
								/>
							<grid-secure-configure-valve
								appserver.server-xml.file="@{tomcat.server-xml.file}"
								appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
								/>
							<appserver-delete-http-connector
								appserver.server-xml.file="@{tomcat.server-xml.file}"
								appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
								appserver.http.port="@{tomcat.port.http}"
								appserver.http-connector.remove="@{tomcat.http-connector.remove}"
								/>
							<!-- needs to be done after adding connector -->
							<if>
								<equals arg1="@{tomcat.grid.secure.enable}" arg2="true"/>
								<then>
									<echo message="Configuring tomcat proxy settings for secure grid"/>
									<appserver-configure-external-hostname
										appserver.server-xml.file="@{tomcat.server-xml.file}"
										appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
										appserver.external.host="@{tomcat.external.grid.secure.host}"
										appserver.external.port="@{tomcat.external.grid.secure.port}"
										proxy.update.connector.port="@{tomcat.grid.secure.port}"
										/>
								</then>
								<else>
									<echo message="Skipping configuring tomcat proxy settings for secure grid since secure grid is not set."/>
								</else>
							</if>
						</then>
						<else>
							<echo message="Skipping configuration of GRID on Tomcat"/>
						</else>
					</if>
					<if>
						<not>
							<equals arg1="${exclude.access-logs}" arg2="true"/>
						</not>
						<then>
							<appserver-accesslog-configure
								appserver.conf.dir="@{tomcat.conf.dir}"
								appserver.logs.dir="@{tomcat.logs.dir}"
								appserver.server-xml.file="@{tomcat.server-xml.file}"
								appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
								appserver.hostname="localhost"
								/>
						</then>
						<else>
							<echo message="Skipping configuring access logs for tomcat because exclude.access-logs is set."/>
						</else>
					</if>
				</then>
				<else>
					<echo message="Skipping Tomcat Config because exclude.tomcat-config is set"/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="jboss-configure">
		<!-- jboss-bindings -->
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.server.ports.name" default="${jboss.server.ports.name}"/>
		<attribute name="jboss.server.bindingfile.location" default="${jboss.home}/bindings/bindings.xml"/>
		<attribute name="jboss.server.binding.template.location" default="${jboss.server.binding.template.location}"/>
		<!-- jboss-login-config -->
		<attribute name="authentication.type" default="${authentication.type}"/>
		<attribute name="login-config.ldap.file" default="${jboss-conf.dir.dest}/login-config.ldap-block.xml"/>
		<attribute name="login-config.db.file" default="${jboss-conf.dir.dest}/login-config.db-block.xml"/>
		<!-- secure-jboss-console -->
		<attribute name="jboss.web.user" default="${jboss.web.user}"/>
		<attribute name="jboss.web.password" default="${jboss.web.password}"/>
		<!-- jboss-update-shutdown -->
		<attribute name="jboss.server.jndi.port" default="${jboss.server.jndi.port}"/>
		<attribute name="jboss.server.port" default="${jboss.server.port}"/>
		<attribute name="jboss.cobraorb.port" default="${jboss.cobraorb.port}"/>
		<attribute name="jboss.ejbinvoker.port" default="${jboss.ejbinvoker.port}"/>
		<attribute name="jboss.hajndi.port" default="${jboss.hajndi.port}"/>
		<attribute name="jboss.hajrmi.port" default="${jboss.hajrmi.port}"/>
		<attribute name="jboss.jms.port" default="${jboss.jms.port}"/>
		<attribute name="jboss.jmx-rmi.port" default="${jboss.jmx-rmi.port}"/>
		<attribute name="jboss.messaging.port" default="${jboss.messaging.port}"/>
		<attribute name="jboss.pooledha.port" default="${jboss.pooledha.port}"/>
		<attribute name="jboss.remoting.port" default="${jboss.remoting.port}"/>
		<attribute name="jboss.server.bind.port" default="${jboss.server.bind.port}"/>
		<attribute name="jboss.server.rmi.port" default="${jboss.server.rmi.port}"/>
		<attribute name="jboss.service.rmiobject.port" default="${jboss.service.rmiobject.port}"/>
		<attribute name="jboss.snmp.port" default="${jboss.snmp.port}"/>
		<attribute name="jboss.snmp-trapd.port" default="${jboss.snmp-trapd.port}"/>
		<attribute name="jboss.web.service.port" default="${jboss.web.service.port}"/>
		<!-- new with 5.1.0-->
		<attribute name="jboss.unifiedinvoker.port" default="${jboss.unifiedinvoker.port}"/>
		<attribute name="jboss.hajndi.auto.port" default="${jboss.hajndi.auto.port}"/>
		<attribute name="jboss.ssl.port" default="${jboss.ssl.port}"/>
		<attribute name="jboss.jms2.netty.port" default="${jboss.jms2.netty.port}"/>
		<attribute name="jboss.jms2.netty-ssl.port" default="${jboss.jms2.netty-ssl.port}"/>
		<attribute name="jboss.transaction.recovery.port" default="${jboss.transaction.recovery.port}"/>
		<attribute name="jboss.transaction.status.port" default="${jboss.transaction.status.port}"/>
		<attribute name="jboss.transaction.processid.port" default="${jboss.transaction.processid.port}"/>

		<!-- appserver-ssl-configure -->
		<attribute name="jboss.conf.dir" default="${jboss.home}/server/${jboss.server.name}/conf"/>
		<attribute name="jboss.server-xml.file" default="${jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="jboss.server-xml.service.name" default="jboss.web"/>
		<attribute name="jboss.ssl.enable" default="${jboss.ssl.enable}"/>
		<!-- This is the value inserted into the connector in server.xml, bindings updates this the real port at runtime. You could use the real value then the bindings would not match  and it would update, so this may change in the future. -->
		<!--<attribute name="jboss.ssl.port" default="8443"/>-->
		<attribute name="jboss.ssl.keystore.file" default="${jboss.ssl.keystore.file}"/>
		<attribute name="jboss.ssl.keystore.dir" default="${jboss.ssl.keystore.dir}"/>
		<attribute name="jboss.ssl.keystore.pass" default="${jboss.ssl.keystore.pass}"/>
		<attribute name="jboss.ssl.keystore.alias" default="${jboss.ssl.keystore.alias}"/>
		<attribute name="jboss.ssl.fullyqualified.hostname" default="${jboss.ssl.fullyqualified.hostname}"/>
		<!-- appserver-configure-external-hostname -->
		<attribute name="jboss.external.ssl.host" default="${jboss.external.ssl.host}"/>
		<attribute name="jboss.external.ssl.port" default="${jboss.external.ssl.port}"/>
		<attribute name="proxy.update.connector.port.ssl" default="8443"/>
		<attribute name="jboss.external.http.host" default="${jboss.external.http.host}"/>
		<attribute name="jboss.external.http.port" default="${jboss.external.http.port}"/>
		<attribute name="proxy.update.connector.port.http" default="8080"/>
		<attribute name="jboss.external.grid.secure.host" default="${jboss.external.grid.secure.host}"/>
		<attribute name="jboss.external.grid.secure.port" default="${jboss.external.grid.secure.port}"/>
		<!--appserver-configure-hostname -->
		<attribute name="jboss.server.hostname" default="${jboss.server.hostname}"/>
		<!-- grid-secure-configure-connector -->
		<attribute name="jboss.grid.configure" default="false"/>
		<attribute name="jboss.grid.secure.dir" default="${jboss.grid.secure.dir}"/>
		<attribute name="jboss.grid.secure.enable" default="${jboss.grid.secure.enable}"/>
		<attribute name="jboss.grid.secure.port" default="${jboss.grid.secure.port}"/>
		<attribute name="jboss.grid.secure.key.file" default="${jboss.grid.secure.key.file}" />
		<attribute name="jboss.grid.secure.cert.file" default="${jboss.grid.secure.cert.file}" />
		<!--jboss-configure-java_opts -->
		<attribute name="jboss.java.opts" default="${jboss.java.opts}"/>
		<attribute name="jboss.logs.dir" default="${jboss.home}/server/${jboss.server.name}/log"/>
		<attribute name="jboss.http-connector.remove" default="${jboss.http-connector.remove}"/>
		<sequential>
			<var name="jboss.is.51" unset="true"/>
			<propertyregex property="jboss.is.51"
				input="@{jboss.binaries.file}"
				regexp=".*jboss-5.1.*"
				select="true"
				/>
			<if>
				<not>
					<equals arg1="${exclude.jboss-config}" arg2="true"/>
				</not>
				<then>
					<if>
						<not>
							<equals arg1="${exclude.jboss-bindings}" arg2="true"/>
						</not>
						<then>
							<echo message="Configuring JBoss ports (bindings)"/>
							<jboss-bindings
								jboss.home="@{jboss.home}"
								jboss.server.name="@{jboss.server.name}"
								jboss.server.ports.name="@{jboss.server.ports.name}"
								jboss.server.bindingfile.location="@{jboss.server.bindingfile.location}"
								jboss.server.binding.template.location="@{jboss.server.binding.template.location}"
								jboss.server.jndi.port="@{jboss.server.jndi.port}"
								jboss.server.port="@{jboss.server.port}"
								jboss.cobraorb.port="@{jboss.cobraorb.port}"
								jboss.ejbinvoker.port="@{jboss.ejbinvoker.port}"
								jboss.hajndi.port="@{jboss.hajndi.port}"
								jboss.hajrmi.port="@{jboss.hajrmi.port}"
								jboss.jms.port="@{jboss.jms.port}"
								jboss.jmx-rmi.port="@{jboss.jmx-rmi.port}"
								jboss.messaging.port="@{jboss.messaging.port}"
								jboss.pooledha.port="@{jboss.pooledha.port}"
								jboss.remoting.port="@{jboss.remoting.port}"
								jboss.server.bind.port="@{jboss.server.bind.port}"
								jboss.server.rmi.port="@{jboss.server.rmi.port}"
								jboss.service.rmiobject.port="@{jboss.service.rmiobject.port}"
								jboss.snmp.port="@{jboss.snmp.port}"
								jboss.snmp-trapd.port="@{jboss.snmp-trapd.port}"
								jboss.web.service.port="@{jboss.web.service.port}"
								jboss.unifiedinvoker.port="@{jboss.unifiedinvoker.port}"
								jboss.hajndi.auto.port="@{jboss.hajndi.auto.port}"
								jboss.ssl.port="@{jboss.ssl.port}"
								jboss.jms2.netty.port="@{jboss.jms2.netty.port}"
								jboss.jms2.netty-ssl.port="@{jboss.jms2.netty-ssl.port}"
								jboss.transaction.recovery.port="@{jboss.transaction.recovery.port}"
								jboss.transaction.status.port="@{jboss.transaction.status.port}"
								jboss.transaction.processid.port="@{jboss.transaction.processid.port}"
								jboss.http-connector.remove="@{jboss.http-connector.remove}"
								grid.secure.port="@{jboss.grid.secure.port}"
								/>
						</then>
						<else>
							<echo message="Skipping configuring JBoss ports (bindings) because exclude.jboss-bindings is set"/>
						</else>
					</if>

					<if>
						<not>
							<equals arg1="${exclude.jboss-login-config}" arg2="true"/>
						</not>
						<then>
							<echo message="Configuring JBoss authentication settins (login-config.xml)"/>
							<jboss-login-config
								authentication.type="@{authentication.type}"
								jboss.home="@{jboss.home}"
								jboss.server.name="@{jboss.server.name}"
								login-config.ldap.file="@{login-config.ldap.file}"
								login-config.db.file="@{login-config.db.file}"
								/>
						</then>
						<else>
							<echo message="Skipping configuring JBoss login-config.xml because exclude.jboss-bindings is set"/>
						</else>
					</if>

					<echo message="Adding user and password to JBoss console apps"/>
					<secure-jboss-console
						jboss.home="@{jboss.home}"
						jboss.server.name="@{jboss.server.name}"
						jboss.web.user="@{jboss.web.user}"
						jboss.web.password="@{jboss.web.password}"
						jboss.ssl.enable="@{jboss.ssl.enable}"
						/>

					<echo message="Updating JBoss shutdown.jar to allow shutdown without command line args"/>
					<jboss-update-shutdown
						jboss.home="@{jboss.home}"
						jboss.server.hostname="@{jboss.server.hostname}"
						jboss.server.jndi.port="@{jboss.server.jndi.port}"
						/>

					<echo message="Enableing SSL for JBoss"/>
					<appserver-ssl-configure
						appserver.conf.dir="@{jboss.conf.dir}"
						appserver.server-xml.file="@{jboss.server-xml.file}"
						appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
						appserver.ssl.enable="@{jboss.ssl.enable}"
						appserver.ssl.port="@{jboss.ssl.port}"
						appserver.ssl.keystore.file="@{jboss.ssl.keystore.file}"
						appserver.ssl.keystore.dir="@{jboss.ssl.keystore.dir}"
						appserver.ssl.keystore.pass="@{jboss.ssl.keystore.pass}"
						appserver.ssl.keystore.alias="@{jboss.ssl.keystore.alias}"
						appserver.ssl.fullyqualified.hostname="@{jboss.ssl.fullyqualified.hostname}"
						/>

					<echo message="Configuring JBoss proxy settings for ssl"/>
					<appserver-configure-external-hostname
						appserver.server-xml.file="@{jboss.server-xml.file}"
						appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
						appserver.external.host="@{jboss.external.ssl.host}"
						appserver.external.port="@{jboss.external.ssl.port}"
						proxy.update.connector.port="@{jboss.ssl.port}"
						/>
					<echo message="Configuring JBoss proxy settings for http"/>
					<appserver-configure-external-hostname
						appserver.server-xml.file="@{jboss.server-xml.file}"
						appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
						appserver.external.host="@{jboss.external.http.host}"
						appserver.external.port="@{jboss.external.http.port}"
						proxy.update.connector.port="@{proxy.update.connector.port.http}"
						/>
					<!--
					<echo message="Configuring JBoss hostname in server.xml"/>
					<appserver-configure-hostname
						appserver.server-xml.file="@{jboss.server-xml.file}"
						appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
						appserver.hostname="@{jboss.server.hostname}"
						/>
					-->

					<echo message="Configuring secure grid in JBoss"/>
					<if>
						<and>
							<equals arg1="@{jboss.grid.configure}" arg2="true"/>
							<equals arg1="@{jboss.grid.secure.enable}" arg2="true"/>
						</and>
						<then>
							<echo message="Configuring grid on JBoss"/>
							<grid-secure-configure-connector
								appserver.conf.dir="@{jboss.conf.dir}"
								appserver.server-xml.file="@{jboss.server-xml.file}"
								appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
								grid.secure.port="@{jboss.grid.secure.port}"
								grid.secure.dir="@{jboss.grid.secure.dir}"
								grid.secure.enable="@{jboss.grid.secure.enable}"
								grid.secure.key.file="@{jboss.grid.secure.key.file}"
								grid.secure.cert.file="@{jboss.grid.secure.cert.file}"
								/>
							<grid-secure-configure-valve
								appserver.server-xml.file="@{jboss.server-xml.file}"
								appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
								/>

							<appserver-delete-http-connector
								appserver.server-xml.file="@{jboss.server-xml.file}"
								appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
								appserver.http.port="@{proxy.update.connector.port.http}"
								appserver.http-connector.remove="@{jboss.http-connector.remove}"
								/>
							<!-- needs to be done after adding connector -->
							<if>
								<equals arg1="@{jboss.grid.secure.enable}" arg2="true"/>
										<then>
									<echo message="Configuring jboss proxy settings for secure grid"/>
									<appserver-configure-external-hostname
										appserver.server-xml.file="@{jboss.server-xml.file}"
										appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
										appserver.external.host="@{jboss.external.grid.secure.host}"
										appserver.external.port="@{jboss.external.grid.secure.port}"
										proxy.update.connector.port="@{jboss.grid.secure.port}"
										/>
								</then>
								<else>
									<echo message="Skipping configuring jboss proxy settings for secure grid since secure grid is not set."/>
								</else>
							</if>
						</then>
						<else>
							<echo message="Skipping configuration of GRID on JBos"/>
						</else>
					</if>
					<if>
						<not>
							<equals arg1="${exclude.access-logs}" arg2="true"/>
						</not>
						<then>
							<appserver-accesslog-configure
								appserver.conf.dir="@{jboss.conf.dir}"
								appserver.server-xml.file="@{jboss.server-xml.file}"
								appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
								appserver.hostname="localhost"
								appserver.logs.dir="@{jboss.logs.dir}"
								/>
						</then>
						<else>
							<echo message="Skipping configuring access logs for jboss because exclude.access-logs is set."/>
						</else>
					</if>
					<jboss-configure-java_opts
						jboss.bin.dir="@{jboss.home}/bin"
						jboss.java.opts="@{jboss.java.opts}"
						/>
					<jboss-configure-java_opts
						jboss.bin.dir="@{jboss.home}/server/@{jboss.server.name}/bin"
						jboss.java.opts="@{jboss.java.opts}"
						/>
					<replaceregexp
						file="@{jboss.server-xml.file}"
						byline="true"
						match="emptySessionPath="true""
						replace="emptySessionPath="false""
						/>
				</then>
				<else>
					<echo message="Skipping jboss configuraiton because exclude.jboss-config is set"/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="appserver-configure-hostname">
		<attribute name="appserver.server-xml.file" default="${jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="appserver.server-xml.service.name" default="jboss.web"/>
		<attribute name="appserver.hostname" default="${jboss.server.hostname}"/>
		<sequential>
			<echo message="Updateing hostname in server.xml"/>
			<xmltask preservetype="true" source="@{appserver.server-xml.file}"
				dest="@{appserver.server-xml.file}">
				<xmlcatalog refid="build.xml.catalog"/>
				<attr path="//Engine[@name='@{appserver.server-xml.service.name}']"
					attr="defaultHost"
					value="@{appserver.hostname}" />
				<attr path="//Engine[@name='@{appserver.server-xml.service.name}']/Host"
					attr="name"
					value="@{appserver.hostname}" />
			</xmltask>
		</sequential>
	</macrodef>
	<macrodef name="jboss-configure-java_opts">
		<attribute name="jboss.bin.dir" default="${jboss.home}/bin" />
		<attribute name="jboss.java.opts" default="${jboss.java.opts}" />
		<sequential>

			<propertyregex property="jboss.java.opts.is.set"
				input="@{jboss.java.opts}"
				regexp="^([^\$]\S+)"
				select="\1"
				/>
			<echo message="jboss.java.opts.is.set = ${jboss.java.opts.is.set}"/>
			<if>
				<and>
					<available file="@{jboss.bin.dir}/run.conf"/>
					<isset property="jboss.java.opts.is.set"/>
				</and>
				<then>
					<echo message="Setting JBoss java options"/>
					<osfamily property="os.family"/>
					<echo message="os.family=${os.family}"/>
					<switch value="${os.family}">
						<case value="unix">
							<replaceregexp file="@{jboss.bin.dir}/run.conf" byline="true"
								match="^(\s+JAVA_OPTS)=(.*)"
								replace="#\1=\2${line.separator}# added by macro${line.separator}\1="@{jboss.java.opts}""
								/>
								</case>
						<case value="mac">
							<replaceregexp file="@{jboss.bin.dir}/run.conf" byline="true"
								match="^(\s+JAVA_OPTS)=(.*)"
								replace="#\1=\2${line.separator}# added by macro${line.separator}\1="@{jboss.java.opts}""
								/>
						</case>
						<case value="windows">
							<var name="run.bat.match" unset="true"/>
							<loadfile
								property="run.bat.match"
								srcFile="@{jboss.bin.dir}/run.bat">
								<filterchain>
									<linecontainsregexp>
										<regexp pattern="JAVA_OPTS.*Dbda=bda"/>
									</linecontainsregexp>
								</filterchain>
							</loadfile>
							<if>
								<isset property="run.bat.match"/>
								<then>
									<replaceregexp file="@{jboss.bin.dir}/run.bat" byline="true"
										match="(.*JAVA_OPTS.*)-Dbda=bda -Dprogram.name=%PROGNAME% (.*)"
										replace="\1 -Dbda=bda -Dprogram.name=%PROGNAME% @{jboss.java.opts}"
										/>
								</then>
								<else>
									<replaceregexp file="@{jboss.bin.dir}/run.bat" byline="true"
										match="^(echo\s+JAVA_OPTS.*)"
										replace=" rem Overriding JAVA_OPTS, added by bda${line.separator}set JAVA_OPTS= -Dbda=bda -Dprogram.name=%PROGNAME% @{jboss.java.opts}${line.separator}\1"
										/>
								</else>
							</if>
						</case>
					</switch>
				</then>
				<else>
					<echo message="Java options not updated because @{jboss.bin.dir} does not exist or jboss.java.opts has not value (@{jboss.java.opts})."/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="database-upgrade-fix" description="Diagnose the host system before the installation">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.driver.file" default="${database.driver.file}" />
		<attribute name="database.changelog.file" default="${os.temp.dir}/${project.name}/db-upgrade.xml" />
		<attribute name="databaseChangeLogTableName" default="databasechangelog" />
		<attribute name="database.schema" default="${upt.central.database.schema.name}" />
		<sequential>
			<basename property="changelog.file" file="@{database.changelog.file}"/>
			<echo message="Updating liquibase metadata file name to @{database.changelog.file}  where filename includes ${changelog.file}"/>
			<sql
				driver="@{database.driver}"
				url="@{database.url}"
				userid="@{database.user}"
				password="@{database.password}"
				expandproperties="true"
				onerror="continue"
				autocommit="true"
				>
				<classpath>
					<pathelement location="@{database.driver.file}" />
				</classpath>
				update @{database.schema}.@{databaseChangeLogTableName} set filename='@{database.changelog.file}' where filename like '%${changelog.file}';
			</sql>
		</sequential>
	</macrodef>
	<macrodef name="appserver-accesslog-configure" description="macro for enabling ssl in jboss">
		<attribute name="appserver.conf.dir" default="${jboss.home}/server/${jboss.server.name}/conf"/>
		<attribute name="appserver.logs.dir" default="${jboss.home}/server/${jboss.server.name}/log"/>
		<attribute name="appserver.server-xml.file" default="${jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="appserver.server-xml.service.name" default="jboss.web"/>
		<attribute name="appserver.hostname" default="${jboss.server.hostname}"/>
		<sequential>
			<echo message="access log @{appserver.conf.dir} @{appserver.server-xml.file} @{appserver.server-xml.service.name} @{appserver.hostname}"/>
			<xmltask preservetype="true" source="@{appserver.server-xml.file}"
				dest="@{appserver.server-xml.file}">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove	path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Engine[@name='@{appserver.server-xml.service.name}']/Host[@name='@{appserver.hostname}']/Valve[@className='org.apache.catalina.valves.AccessLogValve']"/>
			</xmltask>
			<xmltask preservetype="true" source="@{appserver.server-xml.file}"
				dest="@{appserver.server-xml.file}"
				failWithoutMatch="true">
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Engine[@name='@{appserver.server-xml.service.name}']/Host[@name='@{appserver.hostname}']">
					<![CDATA[
					<Valve className="org.apache.catalina.valves.AccessLogValve"
						directory="@{appserver.logs.dir}"
						prefix="localhost_access_log."
						suffix=".txt"
						pattern="common"
						resolveHosts="false"/>
					]]>
				</insert>
			</xmltask>
			<!-- when using proxies can pattern can be changed pattern="%{x-forwarded-for}i %l %u %t %r %s %b" -->
		</sequential>
	</macrodef>

	<macrodef name="validate-appserver-versions">
		<attribute name="jboss.binaries.relative.dir" default="${jboss.binaries.relative.dir}"/>
		<attribute name="tomcat.binaries.relative.dir" default="${tomcat.binaries.relative.dir}"/>
		<sequential>
			<var name="jboss.version.check" unset="true"/>
			<var name="jboss.isset" unset="true"/>
			<propertyregex property="jboss.isset"
				input="@{jboss.binaries.relative.dir}"
				regexp="\S+"
				select="true"
				/>
			<propertyregex property="jboss.version.check"
				input="@{jboss.binaries.relative.dir}"
				regexp="(\d+\.\d+\.\d+).*"
				select="\1"
				/>
			<echo message="checking jboss version - ${jboss.version.check}."/>
			<if>
				<and>
					<equals arg1="${jboss.isset}" arg2="true"/>
					<isset property="jboss.version.check"/>
				</and>
				<then>
					<compare-version-major-min-patch
						version.check="${jboss.version.check}"
						version.min="${jboss.version.min}"
						version.max="${jboss.version.max}"
						/>
				</then>
			</if>

			<var name="tomcat.version.check" unset="true"/>
			<var name="tomcat.isset" unset="true"/>
			<propertyregex property="tomcat.isset"
				input="@{tomcat.binaries.relative.dir}"
				regexp="\S+"
				select="true"
				/>
			<propertyregex property="tomcat.version.check"
				input="@{tomcat.binaries.relative.dir}"
				regexp="(\d+\.\d+\.\d+).*"
				select="\1"
				/>
			<echo message="checking tomcat version - ${tomcat.version.check}."/>
			<if>
				<and>
					<isset property="tomcat.version.check"/>
					<equals arg1="${jboss.isset}" arg2="true"/>
				</and>
				<then>
					<compare-version-major-min-patch
						version.check="${tomcat.version.check}"
						version.min="${tomcat.version.min}"
						version.max="${tomcat.version.max}"
						/>
				</then>
			</if>

		</sequential>
	</macrodef>
	<macrodef name="compare-version-major-min-patch">
		<attribute name="version.check"/>
		<attribute name="version.min"/>
		<attribute name="version.max"/>
		<sequential>
			<groovy>
				<arg line="@{version.check} @{version.min} @{version.max}"/>

				import java.util.regex.Matcher
				import java.util.regex.Pattern

				versionCheck = args[0]
				versionMin = args[1]
				versionMax = args[2]
				BigInteger checkCalcVersion
				BigInteger minCalcVersion
				BigInteger maxCalcVersion

				try {
				checkMatcher =  java.util.regex.Pattern.compile(/(\d+)\.(\d+)\.(\d+)/).matcher(versionCheck)
				checkMatches = checkMatcher.matches()
				Integer checkMajor = checkMatcher.group(1).toInteger()
				Integer checkMinor = checkMatcher.group(2).toInteger()
				Integer checkPatch = checkMatcher.group(3).toInteger()

				checkCalcVersion= ((checkMajor*1000000)+(checkMinor*1000)+checkPatch)
				println "Check version is ${checkCalcVersion}"
				} catch (Throwable ex) {
				println "Check version is not in the format major.minor.patch (up to 3 digits each)."
				System.exit(3)
				}

				try {
				minMatcher =  java.util.regex.Pattern.compile(/(\d+)\.(\d+)\.(\d+)/).matcher(versionMin)
				minMatches = minMatcher.matches()
				Integer minMajor = minMatcher.group(1).toInteger()
				Integer minMinor = minMatcher.group(2).toInteger()
				Integer minPatch = minMatcher.group(3).toInteger()

				minCalcVersion= ((minMajor*1000000)+(minMinor*1000)+minPatch)
				println "Min version is ${minCalcVersion}"
				} catch (Throwable ex) {
				println "Minimum version is not in the format major.minor.patch (up to 3 digits each)."
				System.exit(3)
				}

				try {
				maxMatcher =  java.util.regex.Pattern.compile(/(\d+)\.(\d+)\.(\d+)/).matcher(versionMax)
				maxMatches = maxMatcher.matches()
				Integer maxMajor = maxMatcher.group(1).toInteger()
				Integer maxMinor = maxMatcher.group(2).toInteger()
				Integer maxPatch = maxMatcher.group(3).toInteger()

				maxCalcVersion= ((maxMajor*1000000)+(maxMinor*1000)+maxPatch)
				println "Max version is ${maxCalcVersion}"
				} catch (Throwable ex) {
				println "Maximum version is not in the format major.minor.patch (up to 3 digits each)."
				System.exit(3)
				}

				if ( checkCalcVersion < minCalcVersion)
				{
				println "The check version ${checkCalcVersion} is less than the minium supported version ${minCalcVersion}."
				System.exit(2)
				}

				if ( checkCalcVersion > maxCalcVersion)
				{
				println "The check version ${checkCalcVersion} is greater than the maximum supported version ${maxCalcVersion}."
				System.exit(2)
				}

			</groovy>
		</sequential>
	</macrodef>
	<!--
	<macrodef name="maven">
		<attribute name="maven.profile.list"/>
		<attribute name="maven.goal.list"/>
		<attribute name="maven.dir"/>
		<attribute name="maven.cmdline.opts" default=""/>
		<sequential>
			<condition property="mvn.cmd" value="mvn">
				<or>
					<os family="unix" />
					<os family="mac" />
				</or>
			</condition>
			<condition property="mvn.cmd" value="mvn.bat">
				<os family="windows" />
			</condition>
			<exec executable="${mvn.cmd}" dir="@{maven.dir}" failonerror="true">
				<arg line="@{maven.cmdline.opts} @{maven.profile.list} @{maven.goal.list}"/>
			</exec>
		</sequential>
	</macrodef>
	-->
	<macrodef name="maven">
		<attribute name="maven.profile.list" default="" />
		<attribute name="maven.goal.list" />
		<attribute name="maven.dir" />
		<attribute name="maven.home" default="${env.M2_HOME}"/>
		<attribute name="resultproperty" default="maven.result" />
		<attribute name="maven.mem" default="-Xmx1024m"/>
		<element name="args" implicit="true" optional="true" />
		<sequential>
			<java classname="org.codehaus.classworlds.Launcher" fork="true"
				dir="@{maven.dir}" resultproperty="@{resultproperty}">
				<jvmarg value="-Xmx1024m"/>
				<classpath>
					<fileset dir="@{maven.home}/boot">
						<include name="*.jar" />
					</fileset>
					<fileset dir="@{maven.home}/lib">
						<include name="*.jar" />
					</fileset>
				</classpath>
				<sysproperty key="classworlds.conf" value="@{maven.home}/bin/m2.conf" />
				<sysproperty key="maven.home" value="@{maven.home}" />
				<arg line="--batch-mode @{maven.profile.list} @{maven.goal.list}" />
			</java>
		</sequential>
	</macrodef>

	<macrodef name="get-cacore-sdk">
		<attribute name="cacore-sdk.required" default="${cacore-sdk.required}"/>
		<attribute name="cacore-sdk.src.url" default="${cacore-sdk.src.url}"/>
		<attribute name="download.dir" default="${download.dir}"/>
		<attribute name="cacore-sdk.dir" default="${cacore-sdk.dir}"/>
		<sequential>
			<basename file="@{cacore-sdk.src.url}" property="cacore-sdk.binaries.file"/>
			<mkdir dir="@{download.dir}"/>
			<!-- Download if not already downloaded -->
			<if>
				<and>
					<equals arg1="@{cacore-sdk.required}" arg2="true"/>
					<not>
						<available file="@{download.dir}/${cacore-sdk.binaries.file}"/>
					</not>
				</and>
				<then>
					<get src="@{cacore-sdk.src.url}" dest="@{download.dir}/${cacore-sdk.binaries.file}" />
				</then>
			</if>
			<!-- Extract if not already extracted -->
			<if>
				<and>
					<equals arg1="@{cacore-sdk.required}" arg2="true"/>
					<not>
						<available file="@{cacore-sdk.dir}"/>
					</not>
				</and>
				<then>
					<mkdir dir="@{cacore-sdk.dir}"/>
					<unzip src="@{download.dir}/${cacore-sdk.binaries.file}" dest="@{cacore-sdk.dir}"/>
				</then>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="jboss-update-properties-service">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="property.block"/>
		<sequential>
			<var name="properties-service.file" value="@{jboss.home}/server/@{jboss.server.name}/deploy/properties-service.xml"/>
			<var name="property.block.file" value="${os.temp.dir}/property.block.txt"/>
			<echo message="Creating ${property.block.file}"/>
			<echo message="property block is @{property.block}"/>
			<echo file="${property.block.file}" message="@{property.block}"/>

			<var name="read.property.block" unset="true"/>
			<xmltask source="${properties-service.file}">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="//server/mbean[@name='jboss:type=Service,name=SystemProperties']/attribute[@name='Properties']/text()" property="read.property.block" />
			</xmltask>
			<echo message="read.property.block is ${read.property.block}"/>
			<if>
				<isset property="read.property.block"/>
				<then>

					<echo message="Properties found in ${properties-service.file}, updating"/>
					<copy file="${properties-service.file}" tofile="${properties-service.file}.orig" overwrite="true"/>
					<copy tofile="${os.temp.dir}/updatePropertiesService.groovy" file="${build-utils.resource.dir}/groovy/updatePropertiesService.groovy" overwrite="true"/>
					<groovy src="${os.temp.dir}/updatePropertiesService.groovy">
						<arg line="${property.block.file} ${properties-service.file}"/>
					</groovy>
					<echo message="After groovy"/>
				</then>
				<else>
					<echo message="No properties found in ${properties-service.file}, inserting"/>
					<xmltask  failWithoutMatch="true" source="${properties-service.file}" dest="${properties-service.file}">
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="//server/mbean[@name='jboss:type=Service,name=SystemProperties']">
							<![CDATA[
							<attribute name="Properties">
								@{property.block}
							</attribute>
							]]>
						</insert>
					</xmltask>
				</else>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="jboss-read-bindings-file-location">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.bindings.file.location.property.name" default="jboss.server.bindingfile.location"/>
		<attribute name="jboss.server.ports.name.property.name" default="jboss.server.ports.name"/>
		<sequential>
			<var name="jboss-read-bindingsfile.properties.list" value="@{jboss.bindings.file.location.property.name},@{jboss.server.ports.name.property.name}"/>
			<var name="read.bindings.file" unset="true"/>
			<var name="read.bindings.file.raw" unset="true"/>
			<var name="read.bindings.port.ports.name" unset="true"/>
			<var name="jboss.is.40" unset="true"/>
			<propertyregex property="jboss.is.40"
				input="@{jboss.home}"
				regexp=".*jboss-4.*"
				select="true"
				/>
			<var name="jboss.is.51" unset="true"/>
			<propertyregex property="jboss.is.51"
				input="@{jboss.home}"
				regexp=".*jboss-5.1.*"
				select="true"
				/>
			<if>
				<isset property="jboss.is.40"/>
				<then>
					<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-service.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<copy path="/server/mbean[@code='org.jboss.services.binding.ServiceBindingManager']/attribute[@name='StoreURL']/text()" property="read.bindings.file.raw" />
						<copy path="/server/mbean[@code='org.jboss.services.binding.ServiceBindingManager']/attribute[@name='ServerName']/text()" property="read.bindings.ports.name" />
					</xmltask>
					<trim-property
						trim.property.name="read.bindings.file.raw"
						/>
					<echo message="${read.bindings.file.raw}"/>
					<var name="has.file" unset="true"/>
					<propertyregex property="has.file"
						input="${read.bindings.file.raw}"
						regexp="^file:.*"
						select="true"
						/>
					<if>
						<isset property="has.file"/>
						<then>
							<propertyregex property="read.bindings.file"
								input="${read.bindings.file.raw}"
								regexp="^.*?:(.*)"
								select="\1"
								/>
							<echo message="Stripping file: ${read.bindings.file}"/>
						</then>
						<else>
							<property name="read.bindings.file" value="${read.bindings.file.raw}"/>
						</else>
					</if>

					<echo message="Found bindings file ${read.bindings.file} ${read.bindings.ports.name}"/>
					<property name="@{jboss.server.ports.name.property.name}" value="${read.bindings.ports.name}"/>
					<property name="@{jboss.bindings.file.location.property.name}" value="${read.bindings.file}"/>
					<var name="read.properties.list" value="${read.properties.list},${jboss-read-bindingsfile.properties.list}"/>
				</then>
			</if>
			<if>
				<isset property="jboss.is.51"/>
				<then>
					<property name="@{jboss.server.ports.name.property.name}" value="ports-default"/>
					<property name="@{jboss.bindings.file.location.property.name}" value="@{jboss.home}/server/@{jboss.server.name}/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml"/>
				</then>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="jboss-read-ports">
		<attribute name="jboss.server.ports.name" default="${jboss.server.ports.name}"/>
		<attribute name="jboss.server.bindingfile.location" default="${jboss.server.bindingfile.location}"/>
		<attribute name="jboss.server.jndi.port.property.name" default="jboss.server.jndi.port"/>
		<attribute name="jboss.server.port.property.name" default="jboss.server.port"/>
		<attribute name="jboss.ejbinvoker.port.property.name" default="jboss.ejbinvoker.port"/>
		<attribute name="jboss.server.rmi.port.property.name" default="jboss.server.rmi.port"/>
		<attribute name="jboss.web.service.port.property.name" default="jboss.web.service.port"/>
		<attribute name="jboss.service.rmiobject.port.property.name" default="jboss.service.rmiobject.port"/>
		<attribute name="jboss.server.bind.port.property.name" default="jboss.server.bind.port"/>
		<attribute name="jboss.hajndi.port.property.name" default="jboss.hajndi.port"/>
		<attribute name="jboss.hajrmi.port.property.name" default="jboss.hajrmi.port"/>
		<attribute name="jboss.pooledha.port.property.name" default="jboss.pooledha.port"/>
		<attribute name="jboss.cobraorb.port.property.name" default="jboss.cobraorb.port"/>
		<attribute name="jboss.jmx-rmi.port.property.name" default="jboss.jmx-rmi.port"/>
		<attribute name="jboss.snmp-trapd.port.property.name" default="jboss.snmp-trapd.port"/>
		<attribute name="jboss.snmp.port.property.name" default="jboss.snmp.port"/>
		<attribute name="jboss.jms.port.property.name" default="jboss.jms.port"/>
		<attribute name="jboss.remoting.port.property.name" default="jboss.remoting.port"/>
		<attribute name="jboss.messaging.port.property.name" default="jboss.messaging.port"/>

		<sequential>
			<var name="jboss-read-ports.properties.list" value="@{jboss.server.jndi.port.property.name},@{jboss.server.port.property.name},@{jboss.ejbinvoker.port.property.name},@{jboss.server.rmi.port.property.name},@{jboss.web.service.port.property.name},@{jboss.service.rmiobject.port.property.name},@{jboss.server.bind.port.property.name},@{jboss.hajndi.port.property.name},@{jboss.hajrmi.port.property.name},@{jboss.pooledha.port.property.name},@{jboss.cobraorb.port.property.name},@{jboss.jmx-rmi.port.property.name},@{jboss.snmp-trapd.port.property.name},@{jboss.snmp.port.property.name},@{jboss.jms.port.property.name},@{jboss.remoting.port.property.name},@{jboss.messaging.port.property.name}"/>
			<var name="read.http.port" unset="true"/>
			<var name="read.jndi.port" unset="true"/>
			<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.server.bindingfile.location}">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss.web:service=WebServer']/binding/@port" property="read.http.port" attrValue="true"/>
				<copy path="//service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss:service=Naming']/binding/@port" property="read.jndi.port" attrValue="true"/>
			</xmltask>
			<var name="read.ejb.port" unset="true"/>
			<var name="read.jndi.port" unset="true"/>
			<var name="read.rmi.port" unset="true"/>
			<var name="read.ws.port" unset="true"/>
			<var name="read.rmiobj.port" unset="true"/>
			<var name="read.bind.port" unset="true"/>
			<var name="read.hajndi.port" unset="true"/>
			<var name="read.harmi.port" unset="true"/>
			<var name="read.harmihttp.port" unset="true"/>
			<var name="read.pooledha.port" unset="true"/>
			<var name="read.corba.port" unset="true"/>
			<var name="read.jmx-rmi.port" unset="true"/>
			<var name="read.snmp-trapd.port" unset="true"/>
			<var name="read.snmp.port" unset="true"/>
			<var name="read.jms.port" unset="true"/>
			<var name="read.remoting.port" unset="true"/>
			<var name="read.messaging.port" unset="true"/>
			<xmltask preservetype="true" source="@{jboss.server.bindingfile.location}">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss.remoting:type=Connector,name=DefaultEjb3Connector,handler=ejb3']/binding/@port" property="read.ejb.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss:service=Naming']/binding/@port" property="read.jndi.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss:service=Naming']/delegate-config/attribute[@name='RmiPort']/text()" property="read.rmi.port"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss:service=WebService']/binding/@port" property="read.ws.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss:service=invoker,type=jrmp']/binding/@port" property="read.rmiobj.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss:service=invoker,type=pooled']/binding/@port" property="read.bind.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss:service=HAJNDI']/binding/@port" property="read.hajndi.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss:service=HAJNDI']/delegate-config/attribute[@name='RmiPort']/text()" property="read.harmi.port"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss:service=invoker,type=jrmpha']/binding/@port" property="read.harmihttp.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss:service=invoker,type=pooledha']/binding/@port" property="read.pooledha.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss:service=CorbaORB']/binding/@port" property="read.corba.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss.jmx:type=Connector,name=RMI']/binding/@port" property="read.jmx-rmi.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss.jmx:name=SnmpAgent,service=trapd,type=logger']/binding/@port" property="read.snmp-trapd.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss.jmx:name=SnmpAgent,service=snmp,type=adaptor']/binding/@port" property="read.snmp.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss.mq:service=InvocationLayer,type=UIL2']/binding/@port" property="read.jms.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss.remoting:service=Connector,transport=socket']/binding/@port" property="read.remoting.port" attrValue="true"/>
				<copy path="/service-bindings/server[@name='@{jboss.server.ports.name}']/service-config[@name='jboss.messaging:service=Connector,transport=bisocket']/binding/@port" property="read.messaging.port" attrValue="true"/>
			</xmltask>
			<echo level="debug" message="HTTP port=${read.http.port} = @{jboss.server.port.property.name}"/>
			<echo level="debug" message="JNDI port=${read.jndi.port} = @{jboss.server.jndi.port.property.name}"/>

			<echo  level="debug" message="read.ejb.port=${read.ejb.port}."/>
			<echo  level="debug" message="read.jndi.port=${read.jndi.port}."/>
			<echo  level="debug" message="read.rmi.port=${read.rmi.port}."/>
			<echo  level="debug" message="read.ws.port=${read.ws.port}."/>
			<echo  level="debug" message="read.rmiobj.port=${read.rmiobj.port}."/>
			<echo  level="debug" message="read.bind.port=${read.bind.port}."/>
			<echo  level="debug" message="read.hajndi.port=${read.hajndi.port}."/>
			<echo  level="debug" message="read.harmi.port=${read.harmi.port}."/>
			<echo  level="debug" message="read.harmihttp.port=${read.harmihttp.port}."/>
			<echo  level="debug" message="read.pooledha.port=${read.pooledha.port}."/>
			<echo  level="debug" message="read.corba.port=${read.corba.port}."/>
			<echo  level="debug" message="read.jmx-rmi.port=${read.jmx-rmi.port}."/>
			<echo  level="debug" message="read.snmp-trapd.port=${read.snmp-trapd.port}."/>
			<echo  level="debug" message="read.snmp.port=${read.snmp.port}."/>
			<echo  level="debug" message="read.jms.port=${read.jms.port}."/>
			<echo  level="debug" message="read.remoting.port=${read.remoting.port}."/>
			<echo  level="debug" message="read.messaging.port=${read.messaging.port}."/>

			<property name="@{jboss.server.port.property.name}" value="${read.http.port}"/>
			<property name="@{jboss.server.jndi.port.property.name}" value="${read.jndi.port}"/>
			<property name="@{jboss.ejbinvoker.port.property.name}" value="${read.ejb.port}"/>
			<property name="@{jboss.server.rmi.port.property.name}" value="${read.rmi.port}"/>
			<property name="@{jboss.web.service.port.property.name}" value="${read.ws.port}"/>
			<property name="@{jboss.service.rmiobject.port.property.name}" value="${read.rmiobj.port}"/>
			<property name="@{jboss.server.bind.port.property.name}" value="${read.bind.port}"/>
			<property name="@{jboss.hajndi.port.property.name}" value="${read.hajndi.port}"/>
			<property name="@{jboss.hajrmi.port.property.name}" value="${read.harmi.port}"/>
			<property name="@{jboss.service.rmiobject.port.property.name}" value="${read.harmihttp.port}"/>
			<property name="@{jboss.pooledha.port.property.name}" value="${read.pooledha.port}"/>
			<property name="@{jboss.cobraorb.port.property.name}" value="${read.corba.port}"/>
			<property name="@{jboss.jmx-rmi.port.property.name}" value="${read.jmx-rmi.port}"/>
			<property name="@{jboss.snmp-trapd.port.property.name}" value="${read.snmp-trapd.port}"/>
			<property name="@{jboss.snmp.port.property.name}" value="${read.snmp.port}"/>
			<property name="@{jboss.jms.port.property.name}" value="${read.jms.port}"/>
			<property name="@{jboss.remoting.port.property.name}" value="${read.remoting.port}"/>
			<property name="@{jboss.messaging.port.property.name}" value="${read.messaging.port}"/>
			<properties-print
				properties.list="${jboss-read-ports.properties.list}"
				/>

			<var name="read.properties.list" value="${read.properties.list},${jboss-read-ports.properties.list}"/>
		</sequential>
	</macrodef>

	<macrodef name="jboss-bindings-validate">
		<attribute name="jboss.server.ports.name" default="${jboss.server.ports.name}"/>
		<attribute name="jboss.server.bindingfile.location" default="${jboss.server.bindingfile.location}"/>
		<sequential>
			<var name="bindings.file.has.tokens" unset="true"/>
			<loadfile
				property="bindings.file.has.tokens"
				srcFile="@{jboss.server.bindingfile.location}">
				<filterchain>
					<linecontainsregexp>
						<regexp pattern="\@.+\@"/>
					</linecontainsregexp>
				</filterchain>
			</loadfile>
			<if>
				<isset property="bindings.file.has.tokens"/>
				<then>
					<echo message="FYI - @{jboss.server.bindingfile.location} HAS unexpanded  tokens."/>
				</then>
				<else>
					<echo message="FYI - @{jboss.server.bindingfile.location} has no tokens."/>
				</else>
			</if>
			<var name="bindings.file.has.server" unset="true"/>
			<loadfile
				property="bindings.file.has.server"
				srcFile="@{jboss.server.bindingfile.location}">
				<filterchain>
					<linecontainsregexp>
						<regexp pattern="@{jboss.server.ports.name}"/>
					</linecontainsregexp>
				</filterchain>
			</loadfile>
			<if>
				<not>
					<isset property="bindings.file.has.server"/>
				</not>
				<then>
					<fail message="@{jboss.server.ports.name} not found in @{jboss.server.bindingfile.location}"/>
				</then>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="jboss-read-ssl" description="macro for enabling ssl in jboss">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server-xml.file" default="@{jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="jboss.server-xml.service.name" default="jboss.web"/>
		<attribute name="jboss.ssl.enable.property.name" default="jboss.ssl.enable"/>
		<attribute name="jboss.ssl.port.property.name" default="jboss.ssl.port"/>
		<attribute name="jboss.ssl.keystore.file.property.name" default="jboss.ssl.keystore.file"/>
		<attribute name="jboss.ssl.keystore.dir.property.name" default="jboss.ssl.keystore.dir"/>
		<attribute name="jboss.ssl.keystore.pass.property.name" default="jboss.ssl.keystore.pass"/>
		<attribute name="jboss.ssl.keystore.alias.property.name" default="jboss.ssl.keystore.alias"/>
		<attribute name="jboss.ssl.keystore.location.property.name" default="jboss.ssl.keystore.location"/>
		<attribute name="jboss.ssl.fullyqualified.hostname.property.name" default="jboss.ssl.fullyqualified.hostname"/>
		<attribute name="copied.keystore.dir" default="${jboss.ssl.keystore.dir}"/>
		<sequential>
			<var name="jboss-read-ssl.properties.list" value="@{jboss.ssl.enable.property.name},@{jboss.ssl.port.property.name},@{jboss.ssl.keystore.file.property.name},@{jboss.ssl.keystore.dir.property.name},@{jboss.ssl.keystore.pass.property.name},@{jboss.ssl.keystore.alias.property.name},@{jboss.ssl.fullyqualified.hostname.property.name},@{jboss.ssl.keystore.location.property.name}"/>
			<appserver-read-ssl
				appserver.server-xml.file="@{jboss.server-xml.file}"
				appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
				appserver.ssl.enable.property.name="@{jboss.ssl.enable.property.name}"
				appserver.ssl.port.property.name="@{jboss.ssl.port.property.name}"
				appserver.ssl.keystore.file.property.name="@{jboss.ssl.keystore.file.property.name}"
				appserver.ssl.keystore.pass.property.name="@{jboss.ssl.keystore.pass.property.name}"
				appserver.ssl.keystore.alias.property.name="@{jboss.ssl.keystore.alias.property.name}"
				appserver.ssl.fullyqualified.hostname.property.name="@{jboss.ssl.fullyqualified.hostname.property.name}"
				appserver.ssl.keystore.location.property.name="@{jboss.ssl.keystore.location.property.name}"
				copied.keystore.dir="@{copied.keystore.dir}"
				/>
			<var name="read.properties.list" value="${read.properties.list},${jboss-read-ssl.properties.list}"/>
			<properties-print
				properties.list="${jboss-read-ssl.properties.list}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="tomcat-read-ssl" description="macro for enabling ssl in tomcat">
		<attribute name="tomcat.home" default="${tomcat.home}"/>
		<attribute name="tomcat.server-xml.file" default="@{tomcat.home}/conf/server.xml"/>
		<attribute name="tomcat.server-xml.service.name" default="Catalina"/>
		<attribute name="tomcat.ssl.enable.property.name" default="tomcat.ssl.enable"/>
		<attribute name="tomcat.ssl.port.property.name" default="tomcat.port.ssl"/>
		<attribute name="tomcat.ssl.keystore.file.property.name" default="tomcat.ssl.keystore.file"/>
		<attribute name="tomcat.ssl.keystore.pass.property.name" default="tomcat.ssl.keystore.pass"/>
		<attribute name="tomcat.ssl.keystore.alias.property.name" default="tomcat.ssl.keystore.alias"/>
		<attribute name="tomcat.ssl.keystore.location.property.name" default="tomcat.ssl.keystore.location"/>
		<attribute name="tomcat.ssl.fullyqualified.hostname.property.name" default="tomcat.ssl.fullyqualified.hostname"/>
		<attribute name="copied.keystore.dir" default="${tomcat.ssl.keystore.dir}"/>
		<sequential>
			<var name="tomcat-read-ssl.properties.list" value="@{tomcat.ssl.enable.property.name},@{tomcat.ssl.port.property.name},@{tomcat.ssl.keystore.file.property.name},@{tomcat.ssl.keystore.pass.property.name},@{tomcat.ssl.keystore.alias.property.name},@{tomcat.ssl.fullyqualified.hostname.property.name},@{tomcat.ssl.keystore.location.property.name}"/>
			<appserver-read-ssl
				appserver.server-xml.file="@{tomcat.server-xml.file}"
				appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
				appserver.ssl.enable.property.name="@{tomcat.ssl.enable.property.name}"
				appserver.ssl.port.property.name="@{tomcat.ssl.port.property.name}"
				appserver.ssl.keystore.file.property.name="@{tomcat.ssl.keystore.file.property.name}"
				appserver.ssl.keystore.pass.property.name="@{tomcat.ssl.keystore.pass.property.name}"
				appserver.ssl.keystore.alias.property.name="@{tomcat.ssl.keystore.alias.property.name}"
				appserver.ssl.fullyqualified.hostname.property.name="@{tomcat.ssl.fullyqualified.hostname.property.name}"
				appserver.ssl.keystore.location.property.name="@{tomcat.ssl.keystore.location.property.name}"
				copied.keystore.dir="@{copied.keystore.dir}"
				/>
			<var name="read.properties.list" value="${read.properties.list},${tomcat-read-ssl.properties.list}"/>
			<properties-print
				properties.list="${tomcat-read-ssl.properties.list}"
				/>
		</sequential>
	</macrodef>

	<macrodef name="appserver-read-ssl" description="macro for enabling ssl in jboss">
		<attribute name="appserver.server-xml.file" default="${jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="appserver.server-xml.service.name" default="jboss.web"/>
		<attribute name="appserver.ssl.enable.property.name" default="jboss.ssl.enable"/>
		<attribute name="appserver.ssl.port.property.name" default="jboss.ssl.port"/>
		<attribute name="appserver.ssl.keystore.file.property.name" default="jboss.ssl.keystore.file"/>
		<attribute name="appserver.ssl.keystore.pass.property.name" default="jboss.ssl.keystore.pass"/>
		<attribute name="appserver.ssl.keystore.alias.property.name" default="jboss.ssl.keystore.alias"/>
		<attribute name="appserver.ssl.keystore.location.property.name" default="jboss.ssl.keystore.location"/>
		<attribute name="appserver.ssl.fullyqualified.hostname.property.name" default="jboss.ssl.fullyqualified.hostname"/>
		<attribute name="copied.keystore.dir" default="${jboss.ssl.keystore.dir}"/>
		<sequential>
			<var name="read.ssl.port" unset="true"/>
			<var name="read.keystore.alias" unset="true"/>
			<var name="read.keystore.password" unset="true"/>
			<var name="read.keystore.file.location" unset="true"/>
			<xmltask preservetype="true" source="@{appserver.server-xml.file}">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@secure='true']/@port" property="read.ssl.port" attrValue="true"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@secure='true']/@keystoreFile" property="read.keystore.file.location" attrValue="true"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@secure='true']/@keystorePass" property="read.keystore.password" attrValue="true"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@secure='true']/@keyAlias" property="read.keystore.alias" attrValue="true"/>
			</xmltask>
			<echo message="read.ssl.port = ${read.ssl.port}"/>
			<echo message="read.keystore.file.location = ${read.keystore.file.location}"/>
			<echo message="read.keystore.password = #####"/>
			<echo message="read.keystore.alias = ${read.keystore.alias}"/>
			<echo level="debug" message="read.ssl.port = ${read.ssl.port}"/>

			<var name="ssl.port.set" unset="true"/>
			<propertyregex property="ssl.port.set"
				input="${read.ssl.port}"
				regexp="(\d+)"
				select="\1"
				override="true"
				/>
			<if>
				<isset property="ssl.port.set"/>
				<then>
					<echo message="Setting SSL Properties"/>
					<basename file="${read.keystore.file.location}" property="read.keystore.file"/>
					<dirname file="${read.keystore.file.location}" property="read.keystore.dir"/>
					<mkdir dir="@{copied.keystore.dir}"/>
					<copy file="${read.keystore.file.location}" tofile="@{copied.keystore.dir}/${read.keystore.file}"/>
					<property name="@{appserver.ssl.port.property.name}" value="${read.ssl.port}"/>
					<property name="@{appserver.ssl.keystore.file.property.name}" value="${read.keystore.file}"/>
					<property name="@{appserver.ssl.keystore.pass.property.name}" value="${read.keystore.password}"/>
					<property name="@{appserver.ssl.keystore.alias.property.name}" value="${read.keystore.alias}"/>
					<property name="@{appserver.ssl.keystore.location.property.name}" value="@{copied.keystore.dir}/${read.keystore.file}"/>
					<property name="@{appserver.ssl.enable.property.name}" value="true"/>
					<var name="keytool.output" unset="true"/>
					<var name="keytool.error" unset="true"/>
					<var name="keytool.result" unset="true"/>
					<osfamily property="os.family"/>
					<echo  message="os.family=${os.family}"/>
					<if>
						<or>
							<equals arg1="${os.family}" arg2="unix"/>
							<equals arg1="${os.family}" arg2="mac"/>
						</or>
						<then>
							<property name="os.tmp.dir" value="/tmp/${project.name}"/>
						</then>
					</if>
					<if>
						<equals arg1="${os.family}" arg2="windows"/>
						<then>
							<property name="os.tmp.dir" value="c:/tmp/${project.name}"/>
						</then>
					</if>
					<mkdir dir="${os.tmp.dir}"/>
					<echo message="found keystore file ${read.keystore.file.location}"/>
					<copy file="${read.keystore.file.location}" tofile="${os.tmp.dir}/${read.keystore.file}"/>
					<exec executable="keytool" outputproperty="keytool.output" errorproperty="keytool.error" resultproperty="keytool.result">
						<arg line="-list -keystore ${os.tmp.dir}/${read.keystore.file} -storepass ${read.keystore.password} -alias  ${read.keystore.alias}  -v"/>
					</exec>
					<var name="read.fqhn" unset="true"/>
					<propertyregex property="read.fqhn"
						input="${keytool.output}"
						regexp="Owner: CN=(.*?),"
						select="\1"
						/>
					<if>
						<not>
							<isset property="read.fqhn"/>
						</not>
						<then>
							<echo message="keytool.output= ${keytool.output}"/>
							<echo message="keytool.error= ${keytool.error}"/>
							<echo message="keytool.result= ${keytool.result}"/>
							<fail message="Tried to open keystore file to read FQDN and could not retrieve URL from certificate, see properties and errors above."/>
						</then>
						<else>
							<echo level="debug" message="fqhn= ${read.fqhn}"/>
							<property name="@{appserver.ssl.fullyqualified.hostname.property.name}" value="${read.fqhn}"/>
						</else>
					</if>
				</then>
				<else>
					<echo message="SSL port not configured setting @{appserver.ssl.enable.property.name}=false"/>
					<property name="@{appserver.ssl.enable.property.name}" value="false"/>
					<property name="@{appserver.ssl.port.property.name}" value=""/>
					<property name="@{appserver.ssl.keystore.file.property.name}" value=""/>
					<property name="@{appserver.ssl.keystore.pass.property.name}" value=""/>
					<property name="@{appserver.ssl.keystore.alias.property.name}" value=""/>
					<property name="@{appserver.ssl.keystore.location.property.name}" value=""/>
					<property name="@{appserver.ssl.fullyqualified.hostname.property.name}" value=""/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="jboss-read-external-hostname">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server-xml.file" default="@{jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="jboss.server-xml.service.name" default="jboss.web"/>
		<attribute name="jboss.external.ssl.host.property.name" default="jboss.external.ssl.host"/>
		<attribute name="jboss.external.ssl.port.property.name" default="jboss.external.ssl.port"/>
		<attribute name="jboss.external.http.host.property.name" default="jboss.external.http.host"/>
		<attribute name="jboss.external.http.port.property.name" default="jboss.external.http.port"/>
		<attribute name="jboss.external.grid.secure.host.property.name" default="jboss.external.grid.secure.host"/>
		<attribute name="jboss.external.grid.secure.port.property.name" default="jboss.external.grid.secure.port"/>
		<attribute name="search.ssl.port" default="8443"/>
		<attribute name="search.http.port" default="8080"/>
		<sequential>
			<var name="jboss-read-external.properties.list" value="@{jboss.external.ssl.host.property.name},@{jboss.external.ssl.port.property.name},@{jboss.external.http.host.property.name},@{jboss.external.http.port.property.name},@{jboss.external.grid.secure.host.property.name},@{jboss.external.grid.secure.port.property.name}"/>
			<appserver-read-external-hostname
				appserver.server-xml.file="@{jboss.server-xml.file}"
				appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
				appserver.external.ssl.host.property.name="@{jboss.external.ssl.host.property.name}"
				appserver.external.ssl.port.property.name="@{jboss.external.ssl.port.property.name}"
				appserver.external.http.host.property.name="@{jboss.external.http.host.property.name}"
				appserver.external.http.port.property.name="@{jboss.external.http.port.property.name}"
				appserver.external.grid.secure.host.property.name="@{jboss.external.grid.secure.host.property.name}"
				appserver.external.grid.secure.port.property.name="@{jboss.external.grid.secure.port.property.name}"
				search.ssl.port="@{search.ssl.port}"
				search.http.port="@{search.http.port}"
				/>
			<var name="read.properties.list" value="${read.properties.list},${jboss-read-external.properties.list}"/>
			<properties-print
				properties.list="${jboss-read-external.properties.list}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="tomcat-read-external-hostname">
		<attribute name="tomcat.home" default="${tomcat.home}"/>
		<attribute name="tomcat.server-xml.file" default="@{tomcat.home}/conf/server.xml"/>
		<attribute name="tomcat.server-xml.service.name" default="Catalina"/>
		<attribute name="tomcat.external.ssl.host.property.name" default="tomcat.external.ssl.host"/>
		<attribute name="tomcat.external.ssl.port.property.name" default="tomcat.external.ssl.port"/>
		<attribute name="tomcat.external.http.host.property.name" default="tomcat.external.http.host"/>
		<attribute name="tomcat.external.http.port.property.name" default="tomcat.external.http.port"/>
		<attribute name="tomcat.external.grid.secure.host.property.name" default="tomcat.external.grid.secure.host"/>
		<attribute name="tomcat.external.grid.secure.port.property.name" default="tomcat.external.grid.secure.port"/>
		<attribute name="search.ssl.port" default="${tomcat.port.ssl}"/>
		<attribute name="search.http.port" default="${tomcat.port.http}"/>
		<sequential>
			<var name="tomcat-read-external.properties.list" value="@{tomcat.external.ssl.host.property.name},@{tomcat.external.ssl.port.property.name},@{tomcat.external.http.host.property.name},@{tomcat.external.http.port.property.name},@{tomcat.external.grid.secure.host.property.name},@{tomcat.external.grid.secure.port.property.name}"/>
			<appserver-read-external-hostname
				appserver.server-xml.file="@{tomcat.server-xml.file}"
				appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
				appserver.external.ssl.host.property.name="@{tomcat.external.ssl.host.property.name}"
				appserver.external.ssl.port.property.name="@{tomcat.external.ssl.port.property.name}"
				appserver.external.http.host.property.name="@{tomcat.external.http.host.property.name}"
				appserver.external.http.port.property.name="@{tomcat.external.http.port.property.name}"
				appserver.external.grid.secure.host.property.name="@{tomcat.external.grid.secure.host.property.name}"
				appserver.external.grid.secure.port.property.name="@{tomcat.external.grid.secure.port.property.name}"
				search.ssl.port="@{search.ssl.port}"
				search.http.port="@{search.http.port}"
				/>
			<var name="read.properties.list" value="${read.properties.list},${tomcat-read-external.properties.list}"/>
			<properties-print
				properties.list="${tomcat-read-external.properties.list}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="appserver-read-external-hostname">
		<attribute name="appserver.server-xml.file" default="${jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="appserver.server-xml.service.name" default="jboss.web"/>
		<attribute name="appserver.external.ssl.host.property.name" default="jboss.external.ssl.host"/>
		<attribute name="appserver.external.ssl.port.property.name" default="jboss.external.ssl.port"/>
		<attribute name="appserver.external.http.host.property.name" default="jboss.external.http.host"/>
		<attribute name="appserver.external.http.port.property.name" default="jboss.external.http.port"/>
		<attribute name="appserver.external.grid.secure.host.property.name" default="jboss.external.grid.secure.host"/>
		<attribute name="appserver.external.grid.secure.port.property.name" default="jboss.external.grid.secure.port"/>
		<attribute name="search.ssl.port" default="8443"/>
		<attribute name="search.http.port" default="8080"/>
		<sequential>
			<var name="read.ssl.port" unset="true"/>
			<var name="read.ssl.host" unset="true"/>
			<var name="read.http.host" unset="true"/>
			<var name="read.http.port" unset="true"/>
			<var name="read.grid.host" unset="true"/>
			<var name="read.grid.port" unset="true"/>
			<xmltask preservetype="true" source="@{appserver.server-xml.file}">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@port='@{search.ssl.port}']/@proxyPort" property="read.ssl.port" attrValue="true"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@port='@{search.ssl.port}']/@proxyName" property="read.ssl.host" attrValue="true"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@port='@{search.http.port}']/@proxyPort" property="read.http.port" attrValue="true"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@port='@{search.http.port}']/@proxyName" property="read.http.host" attrValue="true"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@className]/@proxyPort" property="read.grid.port" attrValue="true"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@className]/@proxyName" property="read.grid.host" attrValue="true"/>
			</xmltask>
			<echo level="debug" message="read.ssl.port = ${read.ssl.port}"/>
			<echo level="debug" message="read.ssl.host = ${read.ssl.host}"/>
			<echo level="debug" message="read.http.port = ${read.http.port}"/>
			<echo level="debug" message="read.http.host = ${read.http.host}"/>
			<echo level="debug" message="read.grid.port = ${read.grid.port}"/>
			<echo level="debug" message="read.grid.host = ${read.grid.host}"/>
			<properties-default-blank
				properties.list="read.ssl.port,read.ssl.host,read.http.port,read.http.host,read.grid.port,read.grid.host"
				/>
			<property name="@{appserver.external.ssl.port.property.name}" value="${read.ssl.port}"/>
			<property name="@{appserver.external.ssl.host.property.name}" value="${read.ssl.host}"/>
			<property name="@{appserver.external.http.port.property.name}" value="${read.http.port}"/>
			<property name="@{appserver.external.http.host.property.name}" value="${read.http.host}"/>
			<property name="@{appserver.external.grid.secure.port.property.name}" value="${read.grid.port}"/>
			<property name="@{appserver.external.grid.secure.host.property.name}" value="${read.grid.host}"/>
		</sequential>
	</macrodef>

	<macrodef name="properties-missing" description="Check if any of the properties in the list are not set and set the property referenced properties.missing.property.name to true">
		<attribute name="properties.list" />
		<attribute name="properties.missing.property.name" default="properties.missing"/>
		<attribute name="verbose" default="false"/>
		<sequential>
			<var name="@{properties.missing.property.name}" unset="true"/>
			<for list="@{properties.list}" param="prop.list.item" delimiter=",">
				<sequential>
					<!--<echo message="checking for existance of property @{prop.list.item}"/>-->
					<propertyregex property="prop.list.item.trimmed"
						input="@{prop.list.item}"
						regexp="\s*(\S+)\s*"
						select="\1"
						override="true"
						/>
					<if>
						<not>
							<isset property="${prop.list.item.trimmed}"/>
						</not>
						<then>
							<if>
								<equals arg1="@{verbose}" arg2="true"/>
								<then>
									<echo message="Property ${prop.list.item.trimmed} is not set."/>
								</then>
								<else>
									<property name="@{properties.missing.property.name}" value="true"/>
								</else>
							</if>
						</then>
					</if>
				</sequential>
			</for>
		</sequential>
	</macrodef>
	<macrodef name="properties-print" description="prints list of propeties">
		<attribute name="properties.list" />
		<sequential>
			<for list="@{properties.list}" param="prop.list.item" delimiter=",">
				<sequential>
					<propertyregex property="prop.list.item.trimmed"
						input="@{prop.list.item}"
						regexp="\s*(\S+)\s*"
						select="\1"
						override="true"
						/>
					<echo level="debug" message="propname=${prop.list.item.trimmed}"/>
					<if>
						<isset property="${prop.list.item.trimmed}"/>
						<then>
							<propertycopy name="prop.list.item.value" from="${prop.list.item.trimmed}" override="true" />
							<echo message="[prop-print] ${prop.list.item.trimmed} = ${prop.list.item.value}"/>
						</then>
						<else>
							<echo message="[prop-print] ${prop.list.item.trimmed} = NULL"/>
						</else>
					</if>
				</sequential>
			</for>
		</sequential>
	</macrodef>
	<macrodef name="properties-write" description="prints list of propeties">
		<attribute name="properties.list" />
		<attribute name="output.file" default="properties-write.txt"/>
		<sequential>
			<echo message="Writing output file @{output.file}"/>
			<echo file="@{output.file}" message=""/>
			<for list="@{properties.list}" param="prop.list.item" delimiter=",">
				<sequential>
					<propertyregex property="prop.list.item.trimmed"
						input="@{prop.list.item}"
						regexp="\s*(\S+)\s*"
						select="\1"
						override="true"
						/>
					<echo level="debug" message="propname=${prop.list.item.trimmed}"/>
					<if>
						<isset property="${prop.list.item.trimmed}"/>
						<then>
							<propertycopy name="prop.list.item.value" from="${prop.list.item.trimmed}" override="true" />
							<echo file="@{output.file}" append="true" message="${prop.list.item.trimmed}=${prop.list.item.value}${line.separator}"/>
						</then>
						<else>
							<echo file="@{output.file}" append="true" message="#${prop.list.item.trimmed}=${line.separator}"/>
						</else>
					</if>
				</sequential>
			</for>
		</sequential>
	</macrodef>
	<macrodef name="tomcat-read-ports">
		<attribute name="tomcat.home" default="${tomcat.home}"/>
		<attribute name="tomcat.server-xml.file" default="@{tomcat.home}/conf/server.xml"/>
		<attribute name="tomcat.server-xml.service.name" default="Catalina"/>
		<attribute name="tomcat.port.http.property.name" default="tomcat.port.http"/>
		<attribute name="tomcat.port.ssl.property.name" default="tomcat.port.ssl"/>
		<attribute name="tomcat.port.shutdown.property.name" default="tomcat.port.shutdown"/>
		<attribute name="tomcat.port.ajp.property.name" default="tomcat.port.ajp"/>
		<sequential>
			<var name="tomcat-read-ports.properties.list" value="@{tomcat.port.http.property.name},@{tomcat.port.ssl.property.name},@{tomcat.port.shutdown.property.name},@{tomcat.port.ajp.property.name}"/>
			<var name="read.http.port" unset="true"/>
			<var name="read.ssl.port" unset="true"/>
			<var name="read.ajp.port" unset="true"/>
			<var name="read.shutdown.port" unset="true"/>
			<xmltask preservetype="true" failWithoutMatch="true" source="@{tomcat.server-xml.file}">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="/Server/@port" property="read.shutdown.port" attrValue="true"/>
				<copy path="/Server/Service[@name='@{tomcat.server-xml.service.name}']/Connector[@protocol='AJP/1.3']/@port" property="read.ajp.port" attrValue="true"/>
				<copy path="/Server/Service[@name='@{tomcat.server-xml.service.name}']/Connector[1]/@port" property="read.http.port" attrValue="true"/>
				<copy path="/Server/Service[@name='@{tomcat.server-xml.service.name}']/Connector[1]/@redirectPort" property="read.ssl.port" attrValue="true"/>
			</xmltask>
			<property name="@{tomcat.port.shutdown.property.name}" value="${read.shutdown.port}"/>
			<property name="@{tomcat.port.ajp.property.name}" value="${read.ajp.port}"/>
			<property name="@{tomcat.port.http.property.name}" value="${read.http.port}"/>
			<property name="@{tomcat.port.ssl.property.name}" value="${read.ssl.port}"/>
			<var name="read.properties.list" value="${read.properties.list},${tomcat-read-ports.properties.list}"/>
			<properties-print
				properties.list="${tomcat-read-ports.properties.list}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="jboss-read-java_opts">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.bin.dir" default="@{jboss.home}/bin" />
		<attribute name="jboss.java.opts.property.name" default="jboss.java.opts" />
		<sequential>
			<echo message="Reading JBoss java options"/>
			<osfamily property="os.family"/>
			<if>
				<and>
					<available file="@{jboss.bin.dir}/run.conf"/>
					<or>
						<equals arg1="${os.family}" arg2="unix"/>
						<equals arg1="${os.family}" arg2="mac"/>
					</or>
				</and>
				<then>
					<var name="run.conf.matches" unset="true"/>
					<var name="read.java.opts" unset="true"/>
					<loadfile
						property="run.conf.matches"
						srcFile="@{jboss.bin.dir}/run.conf">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern="^\s*JAVA_OPTS="/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>
					<propertyregex property="read.java.opts"
						input="${run.conf.matches}"
						regexp="^\s*JAVA_OPTS="(.*)""
						select="\1"
						/>
					<if>
						<isset property="read.java.opts"/>
						<then>
							<property name="@{jboss.java.opts.property.name}" value="${read.java.opts}"/>
						</then>
						<else>
							<echo message="Could not find JAVA_OPTS in @{jboss.bin.dir}/run.conf"/>
						</else>
					</if>
				</then>
			</if>
			<if>
				<and>
					<available file="@{jboss.bin.dir}/run.bat"/>
					<equals arg1="${os.family}" arg2="windows"/>
				</and>
				<then>
					<var name="run.bat.matches" unset="true"/>
					<var name="read.java.opts" unset="true"/>
					<loadfile
						property="run.bat.matches"
						srcFile="@{jboss.bin.dir}/run.bat">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern="^\s*set JAVA_OPTS= -Dbda=bda -Dprogram.name"/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>
					<propertyregex property="read.java.opts"
						input="${run.bat.matches}"
						regexp="^\s*set JAVA_OPTS=(.*)"
						select="\1"
						/>
					<if>
						<isset property="read.java.opts"/>
						<then>
							<property name="@{jboss.java.opts.property.name}" value="${read.java.opts}"/>
						</then>
						<else>
							<property name="@{jboss.java.opts.property.name}" value=""/>
							<echo message="Could not find JAVA_OPTS in @{jboss.bin.dir}/run.bat"/>
						</else>
					</if>
				</then>

			</if>
			<var name="read.properties.list" value="${read.properties.list},@{jboss.java.opts.property.name}"/>
			<properties-print
				properties.list="@{jboss.java.opts.property.name}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="jboss-copy-log4j">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.log4j.location" default="@{jboss.home}/server/${jboss.server.name}/conf/log4j.xml"/>
		<attribute name="copied.jboss.log4j.dir" default="${working.dir}/copied-log4j"/>
		<sequential>
			<mkdir dir="@{copied.jboss.log4j.dir}"/>
			<var name="copied.jboss.log4j.file" unset="true"/>
			<basename file="@{jboss.log4j.location}" property="copied.log4j.file"/>
			<copy file="@{jboss.log4j.location}" tofile="@{copied.jboss.log4j.dir}/${copied.log4j.file}"/>
		</sequential>
	</macrodef>
	<macrodef name="grid-read-index-url">
		<attribute name="grid.wsrf.dir" default="${jboss.home}/server/${jboss.server.name}/deploy/wsrf.war" />
		<attribute name="grid.index.url.property.name" default="grid.index.url" />
		<sequential>
			<var name="match.found" unset="true"/>
			<if>
				<available file="@{grid.wsrf.dir}"/>
				<then>
			<for param="registration.file">
				<fileset dir="@{grid.wsrf.dir}">
					<include name="**/*_registration.xml"/>
				</fileset>
				<sequential>
					<if>
						<not>
							<isset property="match.found"/>
						</not>
						<then>
							<var name="read.grid.index.url" unset="true"/>
							<xmltask preservetype="true" source="@{registration.file}">
								<xmlcatalog refid="build.xml.catalog"/>
								<copy path="/:ServiceGroupRegistrationParameters/:ServiceGroupEPR/wsa:Address/text()" property="read.grid.index.url"/>
							</xmltask>
							<if>
								<isset property="read.grid.index.url"/>
								<then>
									<property name="match.found" value="true"/>
									<property name="@{grid.index.url.property.name}" value="${read.grid.index.url}"/>
								</then>
							</if>
						</then>
					</if>
				</sequential>
			</for>
				</then>
				<else>
					<echo message="Grid deployment not found"/>
				</else>
			</if>
			<properties-print
				properties.list="@{grid.index.url.property.name}"
				/>
			<var name="read.properties.list" value="${read.properties.list},@{grid.index.url.property.name}"/>
		</sequential>
	</macrodef>

	<macrodef name="jboss-read-grid-secure" description="macro for enabling ssl in jboss">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server-xml.file" default="@{jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="jboss.server-xml.service.name" default="jboss.web"/>
		<attribute name="jboss.grid.secure.enable.property.name" default="jboss.grid.secure.enable"/>
		<attribute name="jboss.grid.secure.port.property.name" default="jboss.grid.secure.port"/>
		<attribute name="jboss.grid.secure.cert.file.property.name" default="jboss.grid.secure.cert.file"/>
		<attribute name="jboss.grid.secure.key.file.property.name" default="jboss.grid.secure.key.file"/>
		<attribute name="jboss.grid.secure.cert.location.property.name" default="jboss.grid.secure.cert.location"/>
		<attribute name="jboss.grid.secure.key.location.property.name" default="jboss.grid.secure.key.location"/>
		<attribute name="copied.keystore.dir" default="${jboss.ssl.keystore.dir}"/>
		<sequential>
			<var name="jboss.grid.secure.properties.list" value="@{jboss.grid.secure.enable.property.name},@{jboss.grid.secure.port.property.name},@{jboss.grid.secure.cert.file.property.name},@{jboss.grid.secure.key.file.property.name},@{jboss.grid.secure.cert.location.property.name},@{jboss.grid.secure.key.location.property.name}"/>
			<appserver-read-grid-secure
				appserver.server-xml.file="@{jboss.server-xml.file}"
				appserver.server-xml.service.name="@{jboss.server-xml.service.name}"
				appserver.grid.secure.enable.property.name="@{jboss.grid.secure.enable.property.name}"
				appserver.grid.secure.port.property.name="@{jboss.grid.secure.port.property.name}"
				appserver.grid.secure.cert.file.property.name="@{jboss.grid.secure.cert.file.property.name}"
				appserver.grid.secure.key.file.property.name="@{jboss.grid.secure.key.file.property.name}"
				appserver.grid.secure.cert.location.property.name="@{jboss.grid.secure.cert.location.property.name}"
				appserver.grid.secure.key.location.property.name="@{jboss.grid.secure.key.location.property.name}"
				copied.keystore.dir="@{copied.keystore.dir}"
				/>
			<var name="read.grid.port" unset="true"/>
			<properties-print
				properties.list="${jboss.grid.secure.properties.list}"
				/>
			<var name="read.properties.list" value="${read.properties.list},${jboss.grid.secure.properties.list}"/>
		</sequential>
	</macrodef>
	<macrodef name="tomcat-read-grid-secure" description="macro for enabling ssl in jboss">
		<attribute name="tomcat.home" default="${tomcat.home}"/>
		<attribute name="tomcat.server-xml.file" default="@{tomcat.home}/conf/server.xml"/>
		<attribute name="tomcat.server-xml.service.name" default="Catalina"/>
		<attribute name="tomcat.grid.secure.enable.property.name" default="tomcat.grid.secure.enable"/>
		<attribute name="tomcat.grid.secure.port.property.name" default="tomcat.grid.secure.port"/>
		<attribute name="tomcat.grid.secure.cert.file.property.name" default="tomcat.grid.secure.cert.file"/>
		<attribute name="tomcat.grid.secure.key.file.property.name" default="tomcat.grid.secure.key.file"/>
		<attribute name="tomcat.grid.secure.cert.location.property.name" default="tomcat.grid.secure.cert.location"/>
		<attribute name="tomcat.grid.secure.key.location.property.name" default="tomcat.grid.secure.key.location"/>
		<attribute name="copied.keystore.dir" default="${tomcat.ssl.keystore.dir}"/>
		<sequential>
			<var name="tomcat.grid.secure.properties.list" value="@{tomcat.grid.secure.enable.property.name},@{tomcat.grid.secure.port.property.name},@{tomcat.grid.secure.cert.file.property.name},@{tomcat.grid.secure.key.file.property.name},@{tomcat.grid.secure.cert.location.property.name},@{tomcat.grid.secure.key.location.property.name}"/>
			<appserver-read-grid-secure
				appserver.server-xml.file="@{tomcat.server-xml.file}"
				appserver.server-xml.service.name="@{tomcat.server-xml.service.name}"
				appserver.grid.secure.enable.property.name="@{tomcat.grid.secure.enable.property.name}"
				appserver.grid.secure.port.property.name="@{tomcat.grid.secure.port.property.name}"
				appserver.grid.secure.cert.file.property.name="@{tomcat.grid.secure.cert.file.property.name}"
				appserver.grid.secure.key.file.property.name="@{tomcat.grid.secure.key.file.property.name}"
				appserver.grid.secure.cert.location.property.name="@{tomcat.grid.secure.cert.location.property.name}"
				appserver.grid.secure.key.location.property.name="@{tomcat.grid.secure.key.location.property.name}"
				copied.keystore.dir="@{copied.keystore.dir}"
				/>
			<var name="read.grid.port" unset="true"/>
			<properties-print
				properties.list="${tomcat.grid.secure.properties.list}"
				/>
			<var name="read.properties.list" value="${read.properties.list},${tomcat.grid.secure.properties.list}"/>
		</sequential>
	</macrodef>

	<macrodef name="appserver-read-grid-secure" description="macro for enabling ssl in jboss">
		<attribute name="appserver.server-xml.file" default="${jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="appserver.server-xml.service.name" default="jboss.web"/>
		<attribute name="appserver.grid.secure.enable.property.name" default="jboss.grid.secure.enable"/>
		<attribute name="appserver.grid.secure.port.property.name" default="jboss.grid.secure.port"/>
		<attribute name="appserver.grid.secure.cert.file.property.name" default="jboss.grid.secure.cert.file"/>
		<attribute name="appserver.grid.secure.key.file.property.name" default="jboss.grid.secure.key.file"/>
		<attribute name="appserver.grid.secure.cert.location.property.name" default="jboss.grid.secure.cert.location"/>
		<attribute name="appserver.grid.secure.key.location.property.name" default="jboss.grid.secure.key.location"/>
		<attribute name="copied.keystore.dir" default="${jboss.ssl.keystore.dir}"/>
		<sequential>
			<var name="read.grid.port" unset="true"/>
			<var name="read.key.file.location" unset="true"/>
			<var name="read.cert.file.location" unset="true"/>
			<xmltask preservetype="true" source="@{appserver.server-xml.file}">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@className]/@port" property="read.grid.port" attrValue="true"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@className]/@key" property="read.key.file.location" attrValue="true"/>
				<copy path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@className]/@cert" property="read.cert.file.location" attrValue="true"/>
			</xmltask>
			<echo level="debug" message="read.grid.port = ${read.grid.port}"/>
			<echo level="debug" message="read.key.file.location = ${read.key.file.location}"/>
			<echo level="debug" message="read.cert.file.location = ${read.cert.file.location}"/>

			<var name="ssl.port.set" unset="true"/>
			<propertyregex property="ssl.port.set"
				input="${read.grid.port}"
				regexp="(\d+)"
				select="\1"
				override="true"
				/>
			<if>
				<isset property="ssl.port.set"/>
				<then>
					<echo message="Setting SSL Properties"/>
					<basename file="${read.key.file.location}" property="read.key.file"/>
					<dirname file="${read.key.file.location}" property="read.key.dir"/>
					<basename file="${read.cert.file.location}" property="read.cert.file"/>
					<dirname file="${read.cert.file.location}" property="read.cert.dir"/>
					<mkdir dir="@{copied.keystore.dir}"/>
					<copy file="${read.key.file.location}" tofile="@{copied.keystore.dir}/${read.key.file}"/>
					<copy file="${read.cert.file.location}" tofile="@{copied.keystore.dir}/${read.cert.file}"/>

					<property name="@{appserver.grid.secure.enable.property.name}" value="true"/>
					<property name="@{appserver.grid.secure.port.property.name}" value="${read.grid.port}"/>
					<property name="@{appserver.grid.secure.key.file.property.name}" value="${read.key.file}"/>
					<property name="@{appserver.grid.secure.cert.file.property.name}" value="${read.cert.file}"/>
					<property name="@{appserver.grid.secure.key.location.property.name}" value="@{copied.keystore.dir}/${read.key.file}"/>
					<property name="@{appserver.grid.secure.cert.location.property.name}" value="@{copied.keystore.dir}/${read.cert.file}"/>
				</then>
				<else>
					<echo message="SSL port not configured setting @{appserver.grid.secure.enable.property.name}=false"/>
					<property name="@{appserver.grid.secure.enable.property.name}" value="false"/>
					<property name="@{appserver.grid.secure.port.property.name}" value=""/>
					<property name="@{appserver.grid.secure.key.file.property.name}" value=""/>
					<property name="@{appserver.grid.secure.cert.file.property.name}" value=""/>
					<property name="@{appserver.grid.secure.key.location.property.name}" value=""/>
					<property name="@{appserver.grid.secure.cert.location.property.name}" value=""/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="grid-read-poc">
		<attribute name="grid.wsrf.dir" default="${jboss.home}/server/${jboss.server.name}/deploy/wsrf.war" />
		<attribute name="grid.service.name" />
		<attribute name="grid.poc.tech.researchCenter.displayname.property.name" default="grid.poc.tech.researchCenter.displayname"/>
		<attribute name="grid.poc.tech.researchCenter.shortname.property.name" default="grid.poc.tech.researchCenter.shortname"/>
		<attribute name="grid.poc.tech.addr.country.property.name" default="grid.poc.tech.addr.country"/>
		<attribute name="grid.poc.tech.addr.locality.property.name" default="grid.poc.tech.addr.locality"/>
		<attribute name="grid.poc.tech.addr.postalCode.property.name" default="grid.poc.tech.addr.postalCode"/>
		<attribute name="grid.poc.tech.addr.stateProvince.property.name" default="grid.poc.tech.addr.stateProvince"/>
		<attribute name="grid.poc.tech.addr.street1.property.name" default="grid.poc.tech.addr.street1"/>
		<attribute name="grid.poc.tech.addr.street2.property.name" default="grid.poc.tech.addr.street2"/>
		<attribute name="grid.poc.tech.affiliation.property.name" default="grid.poc.tech.affiliation"/>
		<attribute name="grid.poc.tech.name.last.property.name" default="grid.poc.tech.name.last"/>
		<attribute name="grid.poc.tech.name.first.property.name" default="grid.poc.tech.name.first"/>
		<attribute name="grid.poc.tech.phone.property.name" default="grid.poc.tech.phone"/>
		<attribute name="grid.poc.tech.email.property.name" default="grid.poc.tech.email"/>
		<attribute name="grid.poc.tech.role.property.name" default="grid.poc.tech.role"/>
		<attribute name="grid.poc.science.affiliation.property.name" default="grid.poc.science.affiliation"/>
		<attribute name="grid.poc.science.name.last.property.name" default="grid.poc.science.name.last"/>
		<attribute name="grid.poc.science.name.first.property.name" default="grid.poc.science.name.first"/>
		<attribute name="grid.poc.science.phone.property.name" default="grid.poc.science.phone"/>
		<attribute name="grid.poc.science.email.property.name" default="grid.poc.science.email"/>
		<attribute name="grid.poc.science.role.property.name" default="grid.poc.science.role"/>
		<sequential>
			<if>
				<available file="@{grid.wsrf.dir}"/>
				<then>
					<var name="grid.poc.properties.list" value="@{grid.poc.tech.researchCenter.displayname.property.name},@{grid.poc.tech.researchCenter.shortname.property.name},@{grid.poc.tech.addr.country.property.name},@{grid.poc.tech.addr.locality.property.name},@{grid.poc.tech.addr.postalCode.property.name},@{grid.poc.tech.addr.stateProvince.property.name},@{grid.poc.tech.addr.street1.property.name},@{grid.poc.tech.addr.street2.property.name},@{grid.poc.tech.affiliation.property.name},@{grid.poc.tech.name.last.property.name},@{grid.poc.tech.name.first.property.name},@{grid.poc.tech.phone.property.name},@{grid.poc.tech.email.property.name},@{grid.poc.tech.role.property.name},@{grid.poc.science.affiliation.property.name},@{grid.poc.science.name.last.property.name},@{grid.poc.science.name.first.property.name},@{grid.poc.science.phone.property.name},@{grid.poc.science.email.property.name},@{grid.poc.science.role.property.name}"/>
					<!-- Read ns3:Point of Contact Lines -->
					<var name="science.poc.lines" unset="true"/>
					<loadfile
						property="science.poc.lines"
						srcFile="@{grid.wsrf.dir}/WEB-INF/etc/cagrid_@{grid.service.name}/serviceMetadata.xml">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern="ns3:PointOfContact"/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>
					<!-- Parse out each value from string buffer -->
					<var name="read.science.affiliation" unset="true"/>
					<propertyregex property="read.science.affiliation"
						input="${science.poc.lines}"
						regexp="affiliation="(.*?)""
						select="\1"
						/>
					<var name="read.science.email" unset="true"/>
					<propertyregex property="read.science.email"
						input="${science.poc.lines}"
						regexp="email="(.*?)""
						select="\1"
						/>
					<var name="read.science.fname" unset="true"/>
					<propertyregex property="read.science.fname"
						input="${science.poc.lines}"
						regexp="firstName="(.*?)""
						select="\1"
						/>
					<var name="read.science.lname" unset="true"/>
					<propertyregex property="read.science.lname"
						input="${science.poc.lines}"
						regexp="lastName="(.*?)""
						select="\1"
						/>
					<var name="read.science.phone" unset="true"/>
					<propertyregex property="read.science.phone"
						input="${science.poc.lines}"
						regexp="phoneNumber="(.*?)""
						select="\1"
						/>
					<var name="read.science.role" unset="true"/>
					<propertyregex property="read.science.role"
						input="${science.poc.lines}"
						regexp="role="(.*?)""
						select="\1"
						/>
					<!-- Set any properties that are unset to ="" -->
					<properties-default-blank
						properties.list="read.science.affiliation,read.science.email,read.science.fname,read.science.lname,read.science.phone,read.science.role"
						/>
					<echo level="debug" message="read.science.affiliation= ${read.science.affiliation}"/>
					<echo level="debug" message="read.science.email= ${read.science.email}"/>
					<echo level="debug" message="read.science.fname= ${read.science.fname}"/>
					<echo level="debug" message="read.science.lname= ${read.science.lname}"/>
					<echo level="debug" message="read.science.phone= ${read.science.phone}"/>
					<echo level="debug" message="read.science.role= ${read.science.role}"/>

					<!-- Parse ResearchCenter lines -->
					<var name="research.center.lines" unset="true"/>
					<loadfile
						property="research.center.lines"
						srcFile="@{grid.wsrf.dir}/WEB-INF/etc/cagrid_@{grid.service.name}/serviceMetadata.xml">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern=":ResearchCenter"/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>
					<echo message="${research.center.lines}"/>
					<!-- Parse out the ns used by this one since it will vary -->
					<var name="ns.name" unset="true"/>
					<propertyregex property="ns.name"
						input="${research.center.lines}"
						regexp="^.*<(.*?):ResearchCenter"
						select="\1"
						/>
					<echo level="info" message="Read namespace from :ResearchCenter as ${ns.name}"/>
					<!-- Parse out properties from Research Center line -->
					<var name="read.rc.sname" unset="true"/>
					<propertyregex property="read.rc.sname"
						input="${research.center.lines}"
						regexp="shortName="(.*?)""
						select="\1"
						/>
					<var name="read.rc.dname" unset="true"/>
					<propertyregex property="read.rc.dname"
						input="${research.center.lines}"
						regexp="displayName="(.*?)""
						select="\1"
						/>
					<properties-default-blank
						properties.list="read.rc.sname,read.rc.dname"
						/>
					<echo level="debug" message="read.rc.sname= ${read.rc.sname}"/>
					<echo level="debug" message="read.rc.dname= ${read.rc.dname}"/>

					<!-- Parse out address line from same NS as research center -->
					<var name="address.lines" unset="true"/>
					<loadfile
						property="address.lines"
						srcFile="@{grid.wsrf.dir}/WEB-INF/etc/cagrid_@{grid.service.name}/serviceMetadata.xml">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern=":Address"/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>
					<!-- Process out address values -->
					<var name="read.addr.country" unset="true"/>
					<propertyregex property="read.addr.country"
						input="${address.lines}"
						regexp="country="(.*?)""
						select="\1"
						/>
					<var name="read.addr.locality" unset="true"/>
					<propertyregex property="read.addr.locality"
						input="${address.lines}"
						regexp="locality="(.*?)""
						select="\1"
						/>
					<var name="read.addr.zip" unset="true"/>
					<propertyregex property="read.addr.zip"
						input="${address.lines}"
						regexp="postalCode="(.*?)""
						select="\1"
						/>
					<var name="read.addr.state" unset="true"/>
					<propertyregex property="read.addr.state"
						input="${address.lines}"
						regexp="stateProvince="(.*?)""
						select="\1"
						/>
					<var name="read.addr.street1" unset="true"/>
					<propertyregex property="read.addr.street1"
						input="${address.lines}"
						regexp="street1="(.*?)""
						select="\1"
						/>
					<var name="read.addr.street2" unset="true"/>
					<propertyregex property="read.addr.street1"
						input="${address.lines}"
						regexp="street2="(.*?)""
						select="\1"
						/>

					<properties-default-blank
						properties.list="read.addr.country,read.addr.locality,read.addr.zip,read.addr.state,read.addr.street1,read.addr.street2"
						/>
					<echo level="debug" message="read.addr.country= ${read.addr.country}"/>
					<echo level="debug" message="read.addr.locality= ${read.addr.locality}"/>
					<echo level="debug" message="read.addr.zip= ${read.addr.zip}"/>
					<echo level="debug" message="read.addr.state= ${read.addr.state}"/>
					<echo level="debug" message="read.addr.street1= ${read.addr.street1}"/>
					<echo level="debug" message="read.addr.street2= ${read.addr.street2}"/>

					<!-- Parse out POC lines for same NS as RC -->
					<var name="tech.poc.lines" unset="true"/>
					<loadfile
						property="tech.poc.lines"
						srcFile="@{grid.wsrf.dir}/WEB-INF/etc/cagrid_@{grid.service.name}/serviceMetadata.xml">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern="${ns.name}:PointOfContact"/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>
					<!--  Parse out values -->
					<var name="read.tech.affiliation" unset="true"/>
					<propertyregex property="read.tech.affiliation"
						input="${tech.poc.lines}"
						regexp="affiliation="(.*?)""
						select="\1"
						/>
					<var name="read.tech.email" unset="true"/>
					<propertyregex property="read.tech.email"
						input="${tech.poc.lines}"
						regexp="email="(.*?)""
						select="\1"
						/>
					<var name="read.tech.fname" unset="true"/>
					<propertyregex property="read.tech.fname"
						input="${tech.poc.lines}"
						regexp="firstName="(.*?)""
						select="\1"
						/>
					<var name="read.tech.lname" unset="true"/>
					<propertyregex property="read.tech.lname"
						input="${tech.poc.lines}"
						regexp="lastName="(.*?)""
						select="\1"
						/>
					<var name="read.tech.phone" unset="true"/>
					<propertyregex property="read.tech.phone"
						input="${tech.poc.lines}"
						regexp="phoneNumber="(.*?)""
						select="\1"
						/>
					<var name="read.tech.role" unset="true"/>
					<propertyregex property="read.tech.role"
						input="${tech.poc.lines}"
						regexp="role="(.*?)""
						select="\1"
						/>
					<properties-default-blank
						properties.list="read.tech.affiliation,read.tech.email,read.tech.fname,read.tech.lname,read.tech.phone,read.tech.role"
						/>
					<echo level="debug" message="read.tech.affiliation= ${read.tech.affiliation}"/>
					<echo level="debug" message="read.tech.email= ${read.tech.email}"/>
					<echo level="debug" message="read.tech.fname= ${read.tech.fname}"/>
					<echo level="debug" message="read.tech.lname= ${read.tech.lname}"/>
					<echo level="debug" message="read.tech.phone= ${read.tech.phone}"/>
					<echo level="debug" message="read.tech.role= ${read.tech.role}"/>

					<!-- Set properties to parsed values -->
					<property name="@{grid.poc.tech.addr.country.property.name}" value="${read.addr.country}"/>
					<property name="@{grid.poc.tech.addr.locality.property.name}" value="${read.addr.locality}"/>
					<property name="@{grid.poc.tech.addr.postalCode.property.name}" value="${read.addr.zip}"/>
					<property name="@{grid.poc.tech.addr.stateProvince.property.name}" value="${read.addr.state}"/>
					<property name="@{grid.poc.tech.addr.street1.property.name}" value="${read.addr.street1}"/>
					<property name="@{grid.poc.tech.addr.street2.property.name}" value="${read.addr.street2}"/>
					<property name="@{grid.poc.tech.researchCenter.shortname.property.name}" value="${read.rc.sname}"/>
					<property name="@{grid.poc.tech.researchCenter.displayname.property.name}" value="${read.rc.dname}"/>
					<property name="@{grid.poc.science.affiliation.property.name}" value="${read.science.affiliation}"/>
					<property name="@{grid.poc.science.email.property.name}" value="${read.science.email}"/>
					<property name="@{grid.poc.science.name.first.property.name}" value="${read.science.fname}"/>
					<property name="@{grid.poc.science.name.last.property.name}" value="${read.science.lname}"/>
					<property name="@{grid.poc.science.phone.property.name}" value="${read.science.phone}"/>
					<property name="@{grid.poc.science.role.property.name}" value="${read.science.role}"/>
					<property name="@{grid.poc.tech.affiliation.property.name}" value="${read.tech.affiliation}"/>
					<property name="@{grid.poc.tech.email.property.name}" value="${read.tech.email}"/>
					<property name="@{grid.poc.tech.name.first.property.name}" value="${read.tech.fname}"/>
					<property name="@{grid.poc.tech.name.last.property.name}" value="${read.tech.lname}"/>
					<property name="@{grid.poc.tech.phone.property.name}" value="${read.tech.phone}"/>
					<property name="@{grid.poc.tech.role.property.name}" value="${read.tech.role}"/>

					<!-- Print discovered props and values add these props to list -->
					<properties-print
						properties.list="${grid.poc.properties.list}"
						/>
					<var name="read.properties.list" value="${read.properties.list},${grid.poc.properties.list}"/>
				</then>
				<else>
					<echo message="Grid installation not found."/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="properties-default-blank" description="prints list of propeties">
		<attribute name="properties.list" />
		<sequential>
			<for list="@{properties.list}" param="prop.list.item" delimiter=",">
				<sequential>
					<propertyregex property="prop.list.item.trimmed"
						input="@{prop.list.item}"
						regexp="\s*(\S+)\s*"
						select="\1"
						override="true"
						/>
					<echo level="debug" message="propname=${prop.list.item.trimmed}"/>
					<if>
						<not>
							<isset property="${prop.list.item.trimmed}"/>
						</not>
						<then>
							<property name="${prop.list.item.trimmed}" value=""/>
						</then>
					</if>
				</sequential>
			</for>
		</sequential>
	</macrodef>
	<macrodef name="jboss-nci-customizations" description="deploys customized jboss management files, this target only works for linux">
		<attribute name="jboss.home" default="${jboss.home}" />
		<attribute name="jboss.server.name" default="${jboss.server.name}" />
		<attribute name="application.base.path" default="${application.base.path}"/>
		<attribute name="project.name" default="${project.name}"/>
		<attribute name="logname" default="${env.LOGNAME}"/>
		<attribute name="java.home" default="${env.JAVA_HOME}"/>
		<attribute name="jboss.server.jndi.port" default="${jboss.server.jndi.port}"/>
		<attribute name="filterset.name" default="jboss.nci.custom"/>
		<attribute name="jboss.java.opts" default="${jboss.java.opts}"/>
		<attribute name="database.type" default="${database.type}"/>
		<attribute name="start.jboss" default="Y"/>
		<attribute name="env.name" default="${env.name}"/>
		<attribute name="jboss.init.file.location" default="@{jboss.home}/bin/init.conf"/>
		<attribute name="jboss.server.port" default="${jboss.server.port}"/>
		<attribute name="jboss.major.version" default="${jboss.major.version}"/>
		<sequential>
			<var name="nci.env" unset="true"/>
			<if>
				<or>
					<equals arg1="@{env.name}" arg2="dev"/>
					<equals arg1="@{env.name}" arg2="qa"/>
					<equals arg1="@{env.name}" arg2="stage"/>
					<equals arg1="@{env.name}" arg2="prod"/>
					<equals arg1="@{env.name}" arg2="train"/>
					<equals arg1="@{env.name}" arg2="data-refresh"/>
					<equals arg1="@{env.name}" arg2="data-validation"/>
					<equals arg1="@{env.name}" arg2="infrastructure"/>
				</or>
				<then>
					<property name="nci.env" value="true"/>
				</then>
			</if>

			<switch value="@{jboss.major.version}">
				<case value="4">
					<if>
						<and>
							<or>
								<os family="unix"/>
								<os family="mac"/>
							</or>
							<equals arg1="${nci.env}" arg2="true"/>
						</and>
						<then>
							<jboss41-nci-customizations
								jboss.home="@{jboss.home}"
								jboss.server.name="@{jboss.server.name}"
								application.base.path="@{application.base.path}"
								project.name="@{project.name}"
								logname="@{logname}"
								java.home="@{java.home}"
								jboss.server.jndi.port="@{jboss.server.jndi.port}"
								filterset.name="@{filterset.name}"
								jboss.java.opts="@{jboss.java.opts}"
								database.type="@{database.type}"
								start.jboss="@{start.jboss}"
								env.name="@{env.name}"
								/>
						</then>
						<else>
							<echo message="Not setting up NCI customizations because jboss version = 4 and not running unix/mac or not a tier env.name"/>

						</else>
					</if>
				</case>
				<case value="5">
					<propertyregex property="nci.jboss"
						input="@{jboss.home}"
						regexp="nci$"
						select="true"
						override="true"
						/>
					<if>
						<equals arg1="${nci.jboss}" arg2="true"/>
						<then>
							<echo message="Using JBoss 5 but not using NCI provided version, filtering init.conf file only."/>
							<jboss51-nci-filter
								jboss.home="@{jboss.home}"
								jboss.server.name="@{jboss.server.name}"
								jboss.init.file.location="@{jboss.init.file.location}"
								project.name="@{project.name}"
								application.base.path="@{application.base.path}"
								jboss.server.port="@{jboss.server.port}"
								jboss.server.jndi.port="@{jboss.server.jndi.port}"
								/>
						</then>
						<else>
							<echo message="Using JBoss 5 but not and using NCI provided distribution do full customization."/>
							<jboss51-nci-customizations
								jboss.home="@{jboss.home}"
								jboss.server.name="@{jboss.server.name}"
								application.base.path="@{application.base.path}"
								project.name="@{project.name}"
								logname="@{logname}"
								java.home="@{java.home}"
								jboss.server.jndi.port="@{jboss.server.jndi.port}"
								filterset.name="@{filterset.name}"
								jboss.java.opts="@{jboss.java.opts}"
								database.type="@{database.type}"
								start.jboss="@{start.jboss}"
								env.name="@{env.name}"
								/>
						</else>
					</if>
				</case>
				<default>
					<fail message="JBoss major version must be 4 or 5."/>
				</default>
			</switch>
		</sequential>
	</macrodef>
	<macrodef name="read-property-from-properties-service">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="properties-service-xml.file" default="@{jboss.home}/server/${jboss.server.name}/deploy/properties-service.xml"/>
		<attribute name="property.name"/>
		<sequential>
			<var name="prop-service.prop.list" value="@{property.name}"/>
			<var name="@{property.name}.read" unset="true"/>
			<xmltask source="@{properties-service-xml.file}">
				<!-- no xmlcatalog necessary -->
				<!-- trim + starts-with would be better than contains, but requires xpath 2 -->
				<copy path="//attribute[@name='Properties']/text()[contains(.,'@{property.name}=')]"
					property="@{property.name}.read"/>
			</xmltask>
			<if>
				<and>
					<not>
						<isset property="@{property.name}"/>
					</not>
					<isset property="@{property.name}.read"/>
				</and>
				<then>
					<groovy>
						def tempProperty = properties["@{property.name}.read"]
						tempProperty.eachLine
						{ line ->
						if(line.contains("@{property.name}="))
						{
						def equalIndex = line.indexOf('=');
						if(equalIndex==-1) {
						println "Warning: malformed property @{property.name} has no equal";
						}
						else {
						properties["@{property.name}"] = line.substring(equalIndex+1).trim();
						}
						}
						}
					</groovy>
				</then>
			</if>
			<property name="@{property.name}" value=""/>
			<properties-print
				properties.list="${prop-service.prop.list}"
				/>
			<var name="read.properties.list" value="${read.properties.list},${prop-service.prop.list}"/>
		</sequential>
	</macrodef>
	<macrodef name="validate-env-name">
		<sequential>
			<switch value="${env.name}">
				<case value="local">
					<echo message="Environment name validated as ${env.name}"/>
				</case>
				<case value="dev">
					<echo message="Environment name validated as ${env.name}"/>
				</case>
				<case value="qa">
					<echo message="Environment name validated as ${env.name}"/>
				</case>
				<case value="stage">
					<echo message="Environment name validated as ${env.name}"/>
				</case>
				<case value="prod">
					<echo message="Environment name validated as ${env.name}"/>
				</case>
				<case value="train">
					<echo message="Environment name validated as ${env.name}"/>
				</case>
				<case value="data-refresh">
					<echo message="Environment name validated as ${env.name}"/>
				</case>
				<case value="data-validation">
					<echo message="Environment name validated as ${env.name}"/>
				</case>
				<case value="external">
					<echo message="Environment name validated as ${env.name}"/>
				</case>
				<case value="custom">
					<echo message="Environment name validated as ${env.name}"/>
				</case>
				<case value="infrastructure">
					<echo message="Environment name validated as ${env.name}"/>
				</case>
				<default>
					<fail message="Please make sure to set the env.name property in your ${properties.file}.  Also please set it to one of the values below that best describes your target environment.  If you are not sure what to set this to send an email to ncicbiitbda@mail.nih.gov.${line.separator}
						local - workstation or ci ${line.separator}
						dev - dev tier at nci ${line.separator}
						qa - qa tier at nci ${line.separator}
						stage - stage tier at nci ${line.separator}
						prod - prod tier at nci ${line.separator}
						train - training tier at nci ${line.separator}
						data-refresh - a data refresh tier at nci ${line.separator}
						data-validation - a data validation tier at nci ${line.separator}
						external - an install at a site other than nci  ${line.separator}
						infrastructure - a infrastructure tier, shared service used by other projects in pre-produciton environments (like UPT) ${line.separator}
						"/>
				</default>
			</switch>
		</sequential>
	</macrodef>

	<macrodef name="validate-jboss-home">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.binaries.relative.dir" default="${jboss.binaries.relative.dir}"/>
		<sequential>
			<var name="jboss.home.good" unset="true"/>
			<propertyregex property="jboss.home.good"
				input="@{jboss.home}"
				regexp="\S+jboss-\d.\d.\d.*"
				select="true"
				/>
			<if>
				<isset property="jboss.home.good"/>
				<then>
					<echo message="Validated jboss.home '${jboss.home}' ends with 'jboss-X.X.X.*' (where X is a number)"/>
				</then>
				<else>
					<fail message="Error- jboss.home '${jboss.home}' must end with jboss.binaries.relative.dir 'jboss-X.X.X.*' (where X is a number)"/>
				</else>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="validate-pre-install-database" description="Diagnose the host system before the installation">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.system.url" default="${database.system.url}" />
		<attribute name="database.system.user" default="${database.system.user}" />
		<attribute name="database.system.password" default="${database.system.password}" />
		<attribute name="database.url" default="${database.url}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.version" default="5.5.0" />
		<attribute name="database.name" default="${database.name}" />
		<attribute name="database.server" default="${database.server}"/>
		<attribute name="database.port" default="${database.port}"/>
		<attribute name="mysql.lowercasetablenames" default="${mysql.lowercasetablenames}"/>
		<attribute name="database.type" default="${database.type}" />
		<attribute name="database.re-create" default="${database.re-create}" />
		<attribute name="database.drop-schema" default="${database.drop-schema}" />
		<sequential>

			<echo message="
				database.driver=@{database.driver}
				database.system.url=@{database.system.url}
				database.system.user=@{database.system.user}
				database.system.password=@{database.system.password}
				database.url=@{database.url}
				database.user=@{database.user}
				database.password=#######
				database.version=@{database.version}
				database.name=@{database.name}
				"/>

			<validate-database
				database.driver="@{database.driver}"
				database.system.url="@{database.system.url}"
				database.system.user="@{database.system.user}"
				database.system.password="@{database.system.password}"
				database.url="@{database.url}"
				database.user="@{database.user}"
				database.password="@{database.password}"
				database.version="@{database.version}"
				database.name="@{database.name}"
				database.type="@{database.type}"
				database.drop-schema="@{database.drop-schema}"
				database.re-create="@{database.re-create}"
				/>
			<!-- Make sure system and app user are different -->
			<if>
				<equals arg1="@{database.system.user}" arg2="@{database.user}"/>
				<then>
					<fail message="The database.system.user and database.user properties cannot be the same.  The database.system.user drops the database.user if you are using database.re-create=true, the user would in effect drop and re-create himself, which could cause build failures."/>
				</then>
				<else>
					<echo message="database.system.user and database.system are not the same, passed."/>
				</else>
			</if>
			<switch value="@{database.type}">
				<case value="mysql">
					<switch  value="@{database.name}">
						<case value="mysql">
							<fail  message="database name of mysql not allowed"/>
						</case>
						<case value="information_schema">
							<fail  message="database name of information_schema not allowed"/>
						</case>
						<case value="test">
							<fail  message="database name of test not allowed"/>
						</case>
						<default>
							<echo message="database.name of @{database.name} okay"/>
						</default>
					</switch>
				</case>
				<default>
					<echo message="This function for the value @{database.type} of property database.type is not defined" />
				</default>
			</switch>
			<check-database-exists
				database.driver="@{database.driver}"
				database.url="@{database.url}"
				database.user="@{database.user}"
				database.password="@{database.password}"
				database.name="@{database.name}"
				database.type="@{database.type}"
				/>
			<!-- allow for checks for different types of db, right now only mysql-->
			<switch value="@{database.type}">
				<case value="mysql">
					<if>
						<equals arg1="@{database.re-create}" arg2="true"/>
						<then>
							<validate-mysql-lower_case_table_name
								database.driver="@{database.driver}"
								database.user="@{database.system.user}"
								database.password="@{database.system.password}"
								database.server="@{database.server}"
								database.port="@{database.port}"
								mysql.lowercasetablenames="@{mysql.lowercasetablenames}"
								/>
						</then>
						<else>
							<validate-mysql-lower_case_table_name
								database.driver="@{database.driver}"
								database.user="@{database.user}"
								database.password="@{database.password}"
								database.server="@{database.server}"
								database.port="@{database.port}"
								mysql.lowercasetablenames="@{mysql.lowercasetablenames}"
								/>
						</else>
					</if>
				</case>
				<default>
					<echo message="This function for the value @{database.type} of property database.type is not defined" />
				</default>
			</switch>
		</sequential>
	</macrodef>

	<macrodef name="validate-pre-install-common" description="Diagnose the host system before the installation">
		<attribute name="ant.check.version" default="1.8.0" />
		<attribute name="java.check.version.major" default="1.7" />
		<attribute name="java.check.version.minor" default="1.7.0" />
		<attribute name="property.template.file" default="${properties.template.file}"/>
		<attribute name="envpropertyfile" default="${properties.file}"/>
		<attribute name="property.exclude.pattern.list" default="tomcat.*,jboss.*,grid.*"/>
		<!-- New verification for jar-signing -->
		<attribute name="jar-signing.keystore.abs-location" default="${jar-signing.keystore.abs-location}"/>
		<attribute name="jar-signing.keystore.password" default="${jar-signing.keystore.password}"/>
		<attribute name="jar-signing.keystore.alias" default="${jar-signing.keystore.alias}"/>
		<attribute name="jar-signing.keystore.cert.cn" default="${jar-signing.keystore.cert.cn}"/>
		<attribute name="jar-signing.keystore.cert.ou" default="${jar-signing.keystore.cert.ou}"/>
		<attribute name="jar-signing.keystore.cert.o" default="${jar-signing.keystore.cert.o}"/>
		<attribute name="jar-signing.keystore.cert.c" default="${jar-signing.keystore.cert.c}"/>
		<attribute name="jar-signing.execution.time" default="${jar-signing.execution.time}"/>
		<sequential>
			<validate-environment
				ant.check.version="@{ant.check.version}"
				java.check.version.major="@{java.check.version.major}"
				java.check.version.minor="@{java.check.version.minor}"
				/>
			<propertyvalidator keyFile="@{property.template.file}"
				compareFile="@{envpropertyfile}"
				readInMemory="true"
				match="atleast"
				excludePatternList="@{property.exclude.pattern.list}"
				/>
			<!--
			<compare-properties
				property.template.file="@{property.template.file}"
				envpropertyfile="@{envpropertyfile}"
				/>
			-->
			<check-absolute-directory
				directory.property="application.base.path"
				/>
			<check-valid-directory-name
				directory.property="application.base.path"
				/>
			<validate-env-name
				 />
			 <if>
				 <equals arg1="@{jar-signing.execution.time}" arg2="install"/>
				 <then>
					<echo message="jar-signing.execution.time=install, verifying keystore"/>
					<verify-jar-signing-keystore
						jar-signing.keystore.abs-location="@{jar-signing.keystore.abs-location}"
						jar-signing.keystore.password="@{jar-signing.keystore.password}"
						jar-signing.keystore.alias="@{jar-signing.keystore.alias}"
						jar-signing.keystore.cert.cn="@jar-signing.keystore.cert.cn}"
						jar-signing.keystore.cert.ou="@jar-signing.keystore.cert.ou}"
						jar-signing.keystore.cert.o="@jar-signing.keystore.cert.o}"
						jar-signing.keystore.cert.c="@jar-signing.keystore.cert.c}"
						/>
				</then>
			</if>

			<verify-password-value
				/>
		</sequential>
	</macrodef>

	<macrodef name="validate-pre-install-jboss" description="Diagnose the host system before the installation">
		<attribute name="jboss.ssl.enable" default="${jboss.ssl.enable}"/>
		<attribute name="jboss.ssl.keystore.file" default="${jboss.ssl.keystore.file}"/>
		<attribute name="jboss.ssl.keystore.dir" default="${jboss.ssl.keystore.dir}"/>
		<attribute name="jboss.ssl.keystore.pass" default="${jboss.ssl.keystore.pass}"/>
		<attribute name="jboss.ssl.keystore.alias" default="${jboss.ssl.keystore.alias}"/>
		<attribute name="jboss.ssl.fullyqualified.hostname" default="${jboss.ssl.fullyqualified.hostname}"/>
		<attribute name="jboss.binaries.relative.dir" default="${jboss.binaries.relative.dir}"/>
		<attribute name="validation.pre.port.list" default="${validation.pre.port.list}" />
		<attribute name="property.template.file" default="${properties.template.file}"/>
		<attribute name="envpropertyfile" default="${properties.file}"/>
		<attribute name="property.exclude.pattern.list" default="tomcat.*"/>
		<sequential>
			<propertyvalidator keyFile="@{property.template.file}"
				compareFile="@{envpropertyfile}"
				readInMemory="true"
				match="atleast"
				excludePatternList="@{property.exclude.pattern.list}"
				/>
			<validate-appserver-versions
				jboss.binaries.relative.dir="@{jboss.binaries.relative.dir}"
				tomcat.binaries.relative.dir=""
				/>
			<validate-jboss-home
				/>
			<verify-keystore
				appserver.ssl.enable="@{jboss.ssl.enable}"
				appserver.ssl.keystore.file="@{jboss.ssl.keystore.file}"
				appserver.ssl.keystore.pass="@{jboss.ssl.keystore.pass}"
				appserver.ssl.keystore.alias="@{jboss.ssl.keystore.alias}"
				appserver.ssl.fullyqualified.hostname="@{jboss.ssl.fullyqualified.hostname}"
				appserver.ssl.keystore.dir="@{jboss.ssl.keystore.dir}"
				/>
			<check-application-exists
				application.dir.property="jboss.home"
				/>
		</sequential>
	</macrodef>
	<macrodef name="validate-pre-install-tomcat" description="Diagnose the host system before the installation">
		<attribute name="tomcat.ssl.enable" default="${tomcat.ssl.enable}"/>
		<attribute name="tomcat.ssl.keystore.file" default="${tomcat.ssl.keystore.file}"/>
		<attribute name="tomcat.ssl.keystore.dir" default="${tomcat.ssl.keystore.dir}"/>
		<attribute name="tomcat.ssl.keystore.pass" default="${tomcat.ssl.keystore.pass}"/>
		<attribute name="tomcat.ssl.keystore.alias" default="${tomcat.ssl.keystore.alias}"/>
		<attribute name="tomcat.ssl.fullyqualified.hostname" default="${tomcat.ssl.fullyqualified.hostname}"/>
		<attribute name="tomcat.binaries.relative.dir" default="${tomcat.binaries.relative.dir}"/>
		<attribute name="property.template.file" default="${properties.template.file}"/>
		<attribute name="envpropertyfile" default="${properties.file}"/>
		<attribute name="property.exclude.pattern.list" default="jboss.*,authentication.type"/>
		<sequential>
			<propertyvalidator keyFile="@{property.template.file}"
				compareFile="@{envpropertyfile}"
				readInMemory="true"
				match="atleast"
				excludePatternList="@{property.exclude.pattern.list}"
				/>
			<validate-appserver-versions
				jboss.binaries.relative.dir=""
				tomcat.binaries.relative.dir="@{tomcat.binaries.relative.dir}"
				/>
			<verify-keystore
				appserver.ssl.enable="@{tomcat.ssl.enable}"
				appserver.ssl.keystore.file="@{tomcat.ssl.keystore.file}"
				appserver.ssl.keystore.pass="@{tomcat.ssl.keystore.pass}"
				appserver.ssl.keystore.alias="@{tomcat.ssl.keystore.alias}"
				appserver.ssl.fullyqualified.hostname="@{tomcat.ssl.fullyqualified.hostname}"
				appserver.ssl.keystore.dir="@{tomcat.ssl.keystore.dir}"
				/>
		</sequential>
	</macrodef>

	<macrodef name="validate-post-jboss" description="Diagnose the host system after the installation">
		<attribute name="jboss.socket.list" default="${jboss.socket.list}" />
		<attribute name="jboss.home" default="${jboss.home}" />
		<attribute name="jboss.hostname" default="${jboss.server.hostname}" />
		<attribute name="jboss.application.url" default="${jboss.application.url}" />
		<attribute name="connect.wait.seconds" default="90"/>
		<sequential>
			<!-- Give JBOSS another couple of seconds to come up -->
			<echo message="Waiting for @{jboss.application.url} to respond."/>
			<waitfor maxwait="@{connect.wait.seconds}" maxwaitunit="second" checkevery="5" checkeveryunit="second" timeoutproperty="jboss.timeout">
				<http url="@{jboss.application.url}"/>
			</waitfor>

			<var name="jboss.socket.list.has.values" unset="true"/>
			<propertyregex property="jboss.socket.list.has.values"
				input="@{jboss.socket.list}"
				regexp="[\d\,]+"
				select="true"
				/>
			<!-- For each socket port call validate:post:socket -->
			<if>
				<and>
					<isset property="jboss.socket.list.has.values"/>
					<not>
						<isset property="jboss.timeout"/>
					</not>
				</and>
				<then>
					<for list="@{jboss.socket.list}" param="validate.port" >
						<sequential>
							<echo message="Checking if @{validate.port} is running."/>
							<if>
								<socket server="@{jboss.hostname}" port="@{validate.port}" />
								<then>
									<echo message="Port is @{validate.port} RUNNNING as expected."/>
								</then>
								<else>
									<echo message="Unable to reach @{hostname}:@{validate.port}. You may experience problems using the application."/>
								</else>
							</if>
						</sequential>
					</for>
				</then>
			</if>
			<echo message="******* INSTALLATION COMPLETED SUCESSFULLY *******"/>
			<echo message="${line.separator}To view your application goto @{jboss.application.url}."/>
		</sequential>
	</macrodef>
	<macrodef name="validate-post-tomcat" description="Diagnose the host system after the installation">
		<attribute name="tomcat.socket.list" default="${tomcat.socket.list}" />
		<attribute name="tomcat.home" default="${tomcat.home}" />
		<attribute name="tomcat.hostname" default="${tomcat.server.hostname}" />
		<attribute name="tomcat.application.url" default="${tomcat.application.url}" />
		<attribute name="connect.wait.seconds" default="90"/>
		<sequential>
			<!-- Give JBOSS another couple of seconds to come up -->
			<echo message="Waiting for @{tomcat.application.url} to respond."/>
			<waitfor maxwait="@{connect.wait.seconds}" maxwaitunit="second" checkevery="5" checkeveryunit="second" timeoutproperty="tomcat.timeout">
				<http url="@{tomcat.application.url}"/>
			</waitfor>

			<var name="tomcat.socket.list.has.values" unset="true"/>
			<propertyregex property="tomcat.socket.list.has.values"
				input="@{tomcat.socket.list}"
				regexp="[\d\,]+"
				select="true"
				/>
			<!-- For each socket port call validate:post:socket -->
			<if>
				<and>
					<isset property="tomcat.socket.list.has.values"/>
					<not>
						<isset property="tomcat.timeout"/>
					</not>
				</and>
				<then>
					<for list="@{tomcat.socket.list}" param="validate.port" >
						<sequential>
							<echo message="Checking if @{validate.port} is running."/>
							<if>
								<socket server="@{tomcat.hostname}" port="@{validate.port}" />
								<then>
									<echo message="Port is @{validate.port} RUNNNING as expected."/>
								</then>
								<else>
									<echo message="Unable to reach @{hostname}:@{validate.port}. You may experience problems using the application."/>
								</else>
							</if>
						</sequential>
					</for>
				</then>
			</if>
			<echo message="******* INSTALLATION COMPLETED SUCESSFULLY *******"/>
			<echo message="${line.separator}To view your application goto ${tomcat.application.url}."/>
		</sequential>
	</macrodef>
	<macrodef name="validate-post-common" description="Diagnose the host system after the installation">
		<attribute name="application.base.path" default="${application.base.path}"/>
		<attribute name="propertyfile.backup.location" default="@{application.base.path}/change-logs" />
		<sequential>
			<echoproperties > <propertyset negate="yes" > <propertyref regex="passw" /> </propertyset> </echoproperties>
			<tstamp>
				<format property="run.date" pattern="yyMMddHHmm"/>
			</tstamp>
			<basename file="${properties.file}" property="properties.file.name"/>
			<var name="backup.properties.file" value="${properties.file.name}-${run.date}"/>
			<mkdir dir="@{propertyfile.backup.location}"/>
			<copy tofile="@{propertyfile.backup.location}/${backup.properties.file}" file="${properties.file}"/>
		</sequential>
	</macrodef>
	<macrodef name="validate-pre-jboss-ports" description="Diagnose the host system before the installation">
		<attribute name="jboss.socket.ports" default="${jboss.socket.ports}" />
		<attribute name="hostname" default="${jboss.server.hostname}" />
		<sequential>
 			<echo message="Validationg Ports Are not in use..."/>
 			<for list="@{jboss.socket.ports}" param="validate.port">
				<sequential>
					<var name="is.number" unset="true"/>
					<propertyregex property="is.number"
						input="@{validate.port}"
						regexp="^\d+$"
						select="true"
						/>

					<if>
						<isset property="is.number"/>
						<then>
				 			<echo message="Checking if @{validate.port} is running."/>
							<if>
		 						<socket server="@{hostname}" port="@{validate.port}" />
								<then>
									<fail message="${line.separator}${line.separator}    Port is listening at @{hostname}:@{validate.port}.${line.separator}Verify the JBoss server is not running at @{hostname}:@{validate.port}. If it is not, there may be a different process or application using this port (@{validate.port}).  You can either change the port this application uses by updating your *-install.properties file or change your other application to resolve this issue and continue installing."/>
 								</then>
								<else>
									<echo message="Ports check: PASSED" />
								</else>
							</if>
						</then>
					</if>
				</sequential>
			</for>
		</sequential>
	</macrodef>
	<macrodef name="validate-pre-tomcat-ports" description="Diagnose the host system before the installation">
		<attribute name="tomcat.socket.ports" default="${tomcat.socket.ports}" />
		<attribute name="hostname" default="${tomcat.hostname}" />
		<sequential>
 			<echo message="Validationg Ports Are not in use..."/>
 			<for list="@{tomcat.socket.ports}" param="validate.port">
				<sequential>
					<var name="is.number" unset="true"/>
					<propertyregex property="is.number"
						input="@{validate.port}"
						regexp="^\d+$"
						select="true"
						/>

					<if>
						<isset property="is.number"/>
						<then>
				 			<echo message="Checking if @{validate.port} is running."/>
							<if>
		 						<socket server="@{hostname}" port="@{validate.port}" />
								<then>
									<fail message="${line.separator}${line.separator}    Port is listening at @{hostname}:@{validate.port}.${line.separator}Verify the JBoss server is not running at @{hostname}:@{validate.port}. If it is not, there may be a different process or application using this port (@{validate.port}).  You can either change the port this application uses by updating your *-install.properties file or change your other application to resolve this issue and continue installing."/>
 								</then>
								<else>
									<echo message="Ports check: PASSED" />
								</else>
							</if>
						</then>
					</if>
				</sequential>
			</for>
		</sequential>
	</macrodef>

	<macrodef name="tomcat-read-dbconfig" description="macro for enabling ssl in jboss">
		<attribute name="tomcat.home" default="${tomcat.home}"/>
		<attribute name="tomcat.server-xml.file" default="@{tomcat.home}/conf/server.xml"/>
		<attribute name="tomcat.server-xml.service.name" default="Catalina"/>
		<attribute name="database.url.property.name" default="database.url" />
		<attribute name="database.name.property.name" default="database.name" />
		<attribute name="database.user.property.name" default="database.user" />
		<attribute name="database.password.property.name" default="database.password" />
		<attribute name="database.server.property.name" default="database.server" />
		<attribute name="database.port.property.name" default="database.port" />
		<attribute name="database.type.property.name" default="database.type" />
		<attribute name="database.schema.property.name" default="database.schema" />
		<sequential>
			<var name="db.properties.list" value="@{database.url.property.name},@{database.name.property.name},@{database.user.property.name},@{database.password.property.name},@{database.server.property.name},@{database.port.property.name},@{database.type.property.name}"/>
			<properties-missing
				properties.list="${db.properties.list}"
				properties.missing.property.name="db.properties.missing"
				/>
			<available file="@{tomcat.home}/conf/server.xml" property="ds.exists"/>
			<if>
				<isset property="db.properties.missing"/>
				<then>
					<if>
						<not>
							<isset property="ds.exists" />
						</not>
						<then>
							<fail message="Some or all required database properties are not set and @{jboss.home}/server/@{jboss.server.name}/deploy/@{jboss.ds-xml.file} is not found.   Ensure arguments passed to this macro are correct or set required database properties in your property file."/>
						</then>
						<else>
							<echo message="Reading database properties: ${db.properties.list}"/>
							<!-- Blank props to be able to run this macro multiple times -->
							<var name="read.database.url" unset="true"/>
							<var name="read.database.user" unset="true"/>
							<var name="read.database.password" unset="true"/>
							<var name="read.database.driver" unset="true"/>
							<xmltask preservetype="true" source="@{tomcat.home}/conf/server.xml">
								<xmlcatalog refid="build.xml.catalog"/>
								<copy path="/Server/Service[@name='Catalina']/Engine[@name='Catalina']/Host[@name='localhost']/Context/Resource/@url" property="read.database.url" attrValue="true"/>
								<copy path="//Server/Service[@name='Catalina']/Engine[@name='Catalina']/Host[@name='localhost']/Context/Resource/@username" property="read.database.user" attrValue="true"/>
								<copy path="//Server/Service[@name='Catalina']/Engine[@name='Catalina']/Host[@name='localhost']/Context/Resource/@password" property="read.database.password" attrValue="true"/>
								<copy path="//Server/Service[@name='Catalina']/Engine[@name='Catalina']/Host[@name='localhost']/Context/Resource/@driverClassName" property="read.database.driver" attrValue="true"/>
							</xmltask>

							<dbconfig property="db.appuser.works"
										driver="${read.database.driver}"
								url="${read.database.url}"
								user="${read.database.user}"
								password="${read.database.password}">
								<validate />
							</dbconfig>
							<propertyregex property="read.database.name"
								input="${read.database.url}"
								regexp=".*[\/](.*)\?*"
								select="\1"
								/>
							<propertyregex property="read.database.server"
								input="${read.database.url}"
								regexp=".*\/\/(.*):.*"
								select="\1"
								/>
							<propertyregex property="read.database.port"
								input="${read.database.url}"
								regexp=".*:(.*)\/.*"
								select="\1"
								/>
							<var name="read.database.type" unset="true"/>
							<propertyregex property="read.database.type"
								input="${read.database.driver}"
								regexp="mysql"
								select="mysql"
								/>
							<propertyregex property="read.database.type"
								input="${read.database.driver}"
								regexp="oracle"
								select="oracle"
								/>
							<propertyregex property="read.database.type"
								input="${read.database.driver}"
								regexp="postgresql"
								select="postgresql"
								/>

							<property name="@{database.url.property.name}" value="${read.database.url}" />
							<property name="@{database.user.property.name}" value="${read.database.user}" />
							<property name="@{database.password.property.name}" value="${read.database.password}" />
							<property name="@{database.name.property.name}" value="${read.database.name}" />
							<property name="@{database.server.property.name}" value="${read.database.server}" />
							<property name="@{database.port.property.name}" value="${read.database.port}" />
							<property name="@{database.type.property.name}" value="${read.database.type}" />

							<propertycopy name="db.type" from="@{database.type.property.name}" override="true"/>
							<switch value="${db.type}">
								<case value="oracle">
									<var name="@{database.schema.property.name}" value="${database.user}"/>
								</case>
								<case value="mysql">
									<var name="@{database.schema.property.name}" value="${database.name}"/>
								</case>
								<case value="postgresql">
									<var name="@{database.schema.property.name}" value="public"/>
								</case>
							</switch>
							<if>
								<isset property="db.appuser.works"/>
								<then>
									<echo level="debug" message="Read application database configuration from ${jboss.home}/server/${jboss.server.name}/deploy/@{jboss.ds-xml.file}"/>
									<echo level="debug"  message="Value after read of *-ds.xml: TYPE - ${read.database.type} URL- ${database.url}  USER- ${database.user} PASS- ##### NAME- ${database.name} SERVER- ${database.server} PORT- ${database.port}"/>
								</then>
								<else>
									<fail  message="Failed to connect to database TYPE - ${read.database.type} URL- ${database.url}  USER- ${database.user} PASS- ${database.password} NAME- ${database.name} SERVER- ${database.server} PORT- ${database.port}"/>
								</else>
							</if>
						</else>
					</if>
				</then>
			</if>
			<properties-print
				properties.list="${db.properties.list}"
				/>
			<var name="read.properties.list" value="${read.properties.list},${db.properties.list}"/>
		</sequential>
	</macrodef>
	<macrodef name="test-groovy-exec" description="macro for enabling ssl in jboss">
		<attribute name="working.dir" default="${dist.exploded.dir}"/>
		<attribute name="properties.file" default="${proeprties.file}"/>
		<attribute name="target.name"/>
		<sequential>
			<groovy>
				<arg line="@{working.dir} @{target.name} @{properties.file}"/>
				import org.apache.tools.ant.Project
				import org.apache.tools.ant.ProjectHelper
				import org.apache.commons.logging.Log;
				import org.apache.commons.logging.LogFactory;
				import org.apache.tools.ant.DefaultLogger;

				workingDir=new File(args[0]).getAbsoluteFile()
				targetName=args[1]
				propertiesFile=args[2]
				println "dir= " + workingDir.toString()
				println "target =" + targetName
				println "properties.file= " + propertiesFile

				File buildFile = new File(workingDir.toString() + "/build.xml")
				Project project = new Project()
				project.init()
				project.setBaseDir(workingDir)
				DefaultLogger logger = new DefaultLogger();
				logger.setMessageOutputLevel(Project.MSG_INFO);
				logger.setErrorPrintStream(System.out);
				logger.setOutputPrintStream(System.out);
				project.addBuildListener(logger);

				ProjectHelper.configureProject(project, buildFile)
				project.setProperty("force.reinstall", "true")
				project.setProperty("properties.file", propertiesFile)
				try
				{
				project.executeTarget(targetName)
				println "Ran sucessfully"
				}
				catch(Exception err)
				{
				println "Execution of ant failed with the following error:"
				println err
				System.exit 1
				}
			</groovy>
		</sequential>
	</macrodef>

	<macrodef name="upt-application-configure" description="macro for configuring upt application">
		<attribute name="upt.application.url" default="${upt.application.url}"/>
		<attribute name="upt.application.user" default="superadmin"/>
		<attribute name="upt.application.password"/>
		<attribute name="upt.application.contextname" default="csmupt"/>
		<attribute name="new.user.logonid" default="${new.user.logonid}"/>
		<attribute name="new.user.firstname" default="${new.user.firstname}"/>
		<attribute name="new.user.lastname" default="${new.user.lastname}"/>
		<attribute name="new.user.password" default="${new.user.password}"/>
		<attribute name="application.name" default="${application.name}"/>
		<attribute name="application.description" default="${application.description}"/>
		<attribute name="application.connection.url" default="${database.url}"/>
		<attribute name="application.dbusername" default="${database.user}"/>
		<attribute name="application.dbpassword" default="${database.password}"/>
		<attribute name="application.dbdialect" default="${database.dialect}"/>
		<attribute name="application.dbdriver" default="${database.driver}"/>
		<sequential>
			<uptconfigurator
			    uptUrl="@{upt.url}"
			    uptAppUser="@{upt.application.user}"
			    uptAppPassword="@{upt.application.password}"
			    appContextName="@{upt.application.contextname}"
			    userLogonID="@{new.user.logonid}"
			    userFirstName="@{new.user.firstname}"
			    userLastName="@{new.user.lastname}"
			    userPassword="@{new.user.password}"
			    applicationName="@{application.name}"
			    applicationDesc="@{application.description}"
			    applicationConnectionUrl="@{application.connection.url}"
			    applicationDBUserName="@{application.dbusername}"
			    applicationDBPassword="@{application.dbpassword}"
			    applicationDBDialect="@{application.dbdialect}"
			    applicationDBDriver="@{application.dbdriver}"
			    />
		</sequential>
	</macrodef>
	<macrodef name="jboss51-read-ports">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.server.ports.name" default="${jboss.server.ports.name}"/>
		<attribute name="jboss.server.bindingfile.location" default="${jboss.server.bindingfile.location}"/>
		<attribute name="jboss.server.jndi.port.property.name" default="jboss.server.jndi.port"/>
		<attribute name="jboss.server.port.property.name" default="jboss.server.port"/>
		<attribute name="jboss.ejbinvoker.port.property.name" default="jboss.ejbinvoker.port"/>
		<attribute name="jboss.server.rmi.port.property.name" default="jboss.server.rmi.port"/>
		<attribute name="jboss.web.service.port.property.name" default="jboss.web.service.port"/>
		<attribute name="jboss.service.rmiobject.port.property.name" default="jboss.service.rmiobject.port"/>
		<attribute name="jboss.server.bind.port.property.name" default="jboss.server.bind.port"/>
		<attribute name="jboss.hajndi.port.property.name" default="jboss.hajndi.port"/>
		<attribute name="jboss.hajrmi.port.property.name" default="jboss.hajrmi.port"/>
		<attribute name="jboss.pooledha.port.property.name" default="jboss.pooledha.port"/>
		<attribute name="jboss.cobraorb.port.property.name" default="jboss.cobraorb.port"/>
		<attribute name="jboss.jmx-rmi.port.property.name" default="jboss.jmx-rmi.port"/>
		<attribute name="jboss.snmp-trapd.port.property.name" default="jboss.snmp-trapd.port"/>
		<attribute name="jboss.snmp.port.property.name" default="jboss.snmp.port"/>
		<!--<attribute name="jboss.jms.port.property.name" default="jboss.jms.port"/>-->
		<!--<attribute name="jboss.remoting.port.property.name" default="jboss.remoting.port"/>-->
		<attribute name="jboss.messaging.port.property.name" default="jboss.messaging.port"/>
		<!-- new with 5.1.0-->
		<attribute name="jboss.unifiedinvoker.port.property.name" default="jboss.unifiedinvoker.port"/>
		<attribute name="jboss.hajndi.auto.port.property.name" default="jboss.hajndi.auto.port"/>
		<attribute name="jboss.ssl.port.property.name" default="jboss.ssl.port"/>
		<attribute name="jboss.jms2.netty.port.property.name" default="jboss.jms2.netty.port"/>
		<attribute name="jboss.jms2.netty-ssl.port.property.name" default="jboss.jms2.netty-ssl.port"/>
		<attribute name="jboss.transaction.recovery.port.property.name" default="jboss.transaction.recovery.port"/>
		<attribute name="jboss.transaction.status.port.property.name" default="jboss.transaction.status.port"/>
		<attribute name="jboss.transaction.processid.port.property.name" default="jboss.transaction.processid.port"/>
		<sequential>
			<var name="jboss-read-ports.properties.list" value="@{jboss.ejbinvoker.port.property.name},@{jboss.server.jndi.port.property.name},@{jboss.server.port.property.name},@{jboss.cobraorb.port.property.name},@{jboss.hajndi.port.property.name},@{jboss.hajrmi.port.property.name},@{jboss.jmx-rmi.port.property.name},@{jboss.messaging.port.property.name},@{jboss.pooledha.port.property.name},@{jboss.server.bind.port.property.name},@{jboss.server.rmi.port.property.name},@{jboss.service.rmiobject.port.property.name},@{jboss.snmp.port.property.name},@{jboss.snmp-trapd.port.property.name},@{jboss.web.service.port.property.name},@{jboss.unifiedinvoker.port.property.name},@{jboss.hajndi.auto.port.property.name},@{jboss.ssl.port.property.name},@{jboss.jms2.netty.port.property.name},@{jboss.jms2.netty-ssl.port.property.name},@{jboss.transaction.recovery.port.property.name},@{jboss.transaction.status.port.property.name},@{jboss.transaction.processid.port.property.name}"/>
			<var name="read.ejbinvoker.port" unset="true"/>
			<var name="read.server.jndi.port" unset="true"/>
			<var name="read.server.port" unset="true"/>
			<var name="read.cobraorb.port" unset="true"/>
			<var name="read.hajndi.port" unset="true"/>
			<var name="read.hajrmi.port" unset="true"/>
			<var name="read.jmx-rmi.port" unset="true"/>
			<var name="read.messaging.port" unset="true"/>
			<var name="read.pooledha.port" unset="true"/>
			<var name="read.server.bind.port" unset="true"/>
			<var name="read.server.rmi.port" unset="true"/>
			<var name="read.service.rmiobject.port" unset="true"/>
			<var name="read.snmp.port" unset="true"/>
			<var name="read.snmp-trapd.port" unset="true"/>
			<var name="read.web.service.port" unset="true"/>
			<var name="read.unifiedinvoker.port" unset="true"/>
			<var name="read.hajndi.auto.port" unset="true"/>
			<var name="read.ssl.port" unset="true"/>
			<var name="read.jms2.netty.port" unset="true"/>
			<var name="read.jms2.netty-ssl.port" unset="true"/>
			<var name="read.transaction.recovery.port" unset="true"/>
			<var name="read.transaction.status.port" unset="true"/>
			<var name="read.transaction.processid.port" unset="true"/>
			<xmltask failWithoutMatch="true" preservetype="true" source="@{jboss.server.bindingfile.location}">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss.web:service=WebServer']/../:property[@name='port']/text()" property="read.server.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=Naming']/../:property[text()='Port']/../:property[@name='port']/text()" property="read.server.jndi.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=Naming']/../:property[text()='RmiPort']/../:property[@name='port']/text()" property="read.server.rmi.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=WebService']/../:property[@name='port']/text()" property="read.web.service.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='UnifiedInvokerConnector']/../:property[@name='port']/text()" property="read.unifiedinvoker.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=invoker,type=jrmp']/../:property[@name='port']/text()" property="read.service.rmiobject.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=invoker,type=pooled']/../:property[@name='port']/text()" property="read.server.bind.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=HAJNDI']/../:property[text()='Port']/../:property[@name='port']/text()" property="read.hajndi.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=HAJNDI']/../:property[text()='RmiPort']/../:property[@name='port']/text()" property="read.hajrmi.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='AutoDiscovery']/../:property[@name='port']/text()" property="read.hajndi.auto.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=invoker,type=jrmpha']/../:property[@name='port']/text()" property="read.service.rmiobject.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=invoker,type=pooledha']/../:property[@name='port']/text()" property="read.pooledha.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=CorbaORB']/../:property[@name='port']/text()" property="read.cobraorb.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss.jmx:name=SnmpAgent,service=trapd,type=logger']/../:property[@name='port']/text()" property="read.snmp-trapd.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss.jmx:name=SnmpAgent,service=snmp,type=adaptor']/../:property[@name='port']/text()" property="read.snmp.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss.remoting:service=JMXConnectorServer,protocol=rmi']/../:property[@name='port']/text()" property="read.jmx-rmi.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss.web:service=WebServer']/../:property[text()='HttpsConnector']/../:property[@name='port']/text()" property="read.ssl.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss.messaging:service=Connector,transport=bisocket']/../:property[@name='port']/text()" property="read.messaging.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='netty-port']/../:property[@name='port']/text()" property="read.jms2.netty.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='netty-ssl-port']/../:property[@name='port']/text()" property="read.jms2.netty-ssl.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='recoveryManager']/../:property[@name='port']/text()" property="read.transaction.recovery.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='transactionStatusManager']/../:property[@name='port']/text()" property="read.transaction.status.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='socketProcessId']/../:property[@name='port']/text()" property="read.transaction.processid.port"/>
			</xmltask>
			<xmltask failWithoutMatch="true" preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/ejb3-connectors-jboss-beans.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="/:deployment/:bean[@name='org.jboss.ejb3.RemotingConnector']/:property[@name='invokerLocator']/:value-factory/:parameter[5]/text()" property="read.ejbinvoker.port"/>
			</xmltask>
			<echo  level="debug" message="read.ejbinvoker.port=${read.ejbinvoker.port}"/>
			<echo  level="debug" message="read.server.jndi.port=${read.server.jndi.port}"/>
			<echo  level="debug" message="read.server.port=${read.server.port}"/>
			<echo  level="debug" message="read.cobraorb.port=${read.cobraorb.port}"/>
			<echo  level="debug" message="read.hajndi.port=${read.hajndi.port}"/>
			<echo  level="debug" message="read.hajrmi.port=${read.hajrmi.port}"/>
			<echo  level="debug" message="read.jmx-rmi.port=${read.jmx-rmi.port}"/>
			<echo  level="debug" message="read.messaging.port=${read.messaging.port}"/>
			<echo  level="debug" message="read.pooledha.port=${read.pooledha.port}"/>
			<echo  level="debug" message="read.server.bind.port=${read.server.bind.port}"/>
			<echo  level="debug" message="read.server.rmi.port=${read.server.rmi.port}"/>
			<echo  level="debug" message="read.service.rmiobject.port=${read.service.rmiobject.port}"/>
			<echo  level="debug" message="read.snmp.port=${read.snmp.port}"/>
			<echo  level="debug" message="read.snmp-trapd.port=${read.snmp-trapd.port}"/>
			<echo  level="debug" message="read.web.service.port=${read.web.service.port}"/>
			<echo  level="debug" message="read.unifiedinvoker.port=${read.unifiedinvoker.port}"/>
			<echo  level="debug" message="read.hajndi.auto.port=${read.hajndi.auto.port}"/>
			<echo  level="debug" message="read.ssl.port=${read.ssl.port}"/>
			<echo  level="debug" message="read.jms2.netty.port=${read.jms2.netty.port}"/>
			<echo  level="debug" message="read.jms2.netty-ssl.port=${read.jms2.netty-ssl.port}"/>
			<echo  level="debug" message="read.transaction.recovery.port=${read.transaction.recovery.port}"/>
			<echo  level="debug" message="read.transaction.status.port=${read.transaction.status.port}"/>
			<echo  level="debug" message="read.transaction.processid.port=${read.transaction.processid.port}"/>
			<property name="@{jboss.ejbinvoker.port.property.name}" value="${read.ejbinvoker.port}"/>
			<property name="@{jboss.server.jndi.port.property.name}" value="${read.server.jndi.port}"/>
			<property name="@{jboss.server.port.property.name}" value="${read.server.port}"/>
			<property name="@{jboss.cobraorb.port.property.name}" value="${read.cobraorb.port}"/>
			<property name="@{jboss.hajndi.port.property.name}" value="${read.hajndi.port}"/>
			<property name="@{jboss.hajrmi.port.property.name}" value="${read.hajrmi.port}"/>
			<property name="@{jboss.jmx-rmi.port.property.name}" value="${read.jmx-rmi.port}"/>
			<property name="@{jboss.messaging.port.property.name}" value="${read.messaging.port}"/>
			<property name="@{jboss.pooledha.port.property.name}" value="${read.pooledha.port}"/>
			<property name="@{jboss.server.bind.port.property.name}" value="${read.server.bind.port}"/>
			<property name="@{jboss.server.rmi.port.property.name}" value="${read.server.rmi.port}"/>
			<property name="@{jboss.service.rmiobject.port.property.name}" value="${read.service.rmiobject.port}"/>
			<property name="@{jboss.snmp.port.property.name}" value="${read.snmp.port}"/>
			<property name="@{jboss.snmp-trapd.port.property.name}" value="${read.snmp-trapd.port}"/>
			<property name="@{jboss.web.service.port.property.name}" value="${read.web.service.port}"/>
			<property name="@{jboss.unifiedinvoker.port.property.name}" value="${read.unifiedinvoker.port}"/>
			<property name="@{jboss.hajndi.auto.port.property.name}" value="${read.hajndi.auto.port}"/>
			<property name="@{jboss.ssl.port.property.name}" value="${read.ssl.port}"/>
			<property name="@{jboss.jms2.netty.port.property.name}" value="${read.jms2.netty.port}"/>
			<property name="@{jboss.jms2.netty-ssl.port.property.name}" value="${read.jms2.netty-ssl.port}"/>
			<property name="@{jboss.transaction.recovery.port.property.name}" value="${read.transaction.recovery.port}"/>
			<property name="@{jboss.transaction.status.port.property.name}" value="${read.transaction.status.port}"/>
			<property name="@{jboss.transaction.processid.port.property.name}" value="${read.transaction.processid.port}"/>

			<properties-print
				properties.list="${jboss-read-ports.properties.list}"
				/>

			<var name="read.properties.list" value="${read.properties.list},${jboss-read-ports.properties.list}"/>
		</sequential>
	</macrodef>
	<macrodef name="trim-property">
		<attribute name="trim.property.name"/>
		<sequential>
			<var name="temp.property.value" unset="true"/>
			<property name="temp.property.value" value="${@{trim.property.name}}"/>
			<echo message="old property value @{trim.property.name} -'${@{trim.property.name}}'"/>
			<var name="fixed.value" unset="true"/>
			<propertyregex property="fixed.value"
				input="${@{trim.property.name}}"
				regexp="^\s*(.*)"
				select="\1"
				/>
			<echo message="new property value @{trim.property.name} - '${fixed.value}'"/>
			<var name="@{trim.property.name}" unset="true"/>
			<property name="@{trim.property.name}" value="${fixed.value}"/>
		</sequential>
	</macrodef>
	<macrodef name="validate-mysql-lower_case_table_name" description="Diagnose the host system before the installation">
		<attribute name="database.driver" default="${database.driver}" />
		<attribute name="database.user" default="${database.user}" />
		<attribute name="database.password" default="${database.password}" />
		<attribute name="database.server" default="${database.server}" />
		<attribute name="database.port" default="${database.port}" />
		<attribute name="mysql.lowercasetablenames" default="${mysql.lowercasetablenames}"/>
		<sequential>
			<if>
				<equals arg1="@{mysql.lowercasetablenames}" arg2="true"/>
				<then>
					<echo message="Checking that lower_case_table_names=1"/>
					<var name="out.file" unset="true"/>
					<mkdir dir="${temp.dir}"/>
					<property name="out.file" value="${temp.dir}/lctn.txt"/>
					<sql
						driver="@{database.driver}"
						url="jdbc:mysql://@{database.server}:@{database.port}/information_schema"
						userid="@{database.user}"
						password="@{database.password}"
						onerror="abort"
						print="true"
						output="${out.file}"
						>
						<classpath>
							<pathelement location="${database.driver.file}" />
						</classpath>
						show variables;
					</sql>
					<!--
						select * from SESSION_VARIABLES where VARIABLE_NAME='LOWER_CASE_TABLE_NAMES' order by 1;
					-->
					<var name="lctn.match" unset="true"/>
					<loadfile
						property="lctn.match"
						srcFile="${out.file}">
						<filterchain>
							<linecontainsregexp>
								<regexp pattern="lower_case_table_names"/>
							</linecontainsregexp>
						</filterchain>
					</loadfile>
					<trim-property
						trim.property.name="lctn.match"
						/>
					<echo message="query returned '${lctn.match}'"/>
					<var name="lctn.value" unset="true"/>
					<propertyregex property="lctn.value"
						input="${lctn.match}"
						regexp="lower_case_table_names,(\d)"
						select="\1"
						/>
					<if>
						<equals arg1="${lctn.value}" arg2="1"/>
						<then>
							<echo message="lower_case_table_names=1, proceding with build"/>
						</then>
						<else>
							<fail message="lower_case_table_names=${lctn.value}, must be set to one, build failing."/>
						</else>
					</if>
				</then>
				<else>
					<echo message="Skipping mysql lower_case_table_names=1 check"/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="sign-jars">
		<!-- jar related attribs -->
		<attribute name="jar-signing.keystore.abs-location" default="${jar-signing.keystore.abs-location}"/>
		<attribute name="jar-signing.keystore.password" default="${jar-signing.keystore.password}"/>
		<attribute name="jar-signing.keystore.alias" default="${jar-signing.keystore.alias}"/>
		<attribute name="jar-signing.execution.time" default="${jar-signing.execution.time}"/>
		<!-- if jar-signing.exection.time=build -->
		<attribute name="jars.dir" default=""/>
		<!-- if jar-signing.exection.time=install -->
		<attribute name="jars.archive.file" default=""/>
		<attribute name="jars.archive.relative.dir" default="."/>
		<!-- global attribs -->
		<attribute name="working.dir" default="${working.dir}"/>
		<attribute name="jar-signing.jar.list" default="${jar-signing.jar.list}"/>
		<sequential>
			<var name="jars.dir.working" unset="true"/>
			<if>
				<equals arg1="@{jar-signing.execution.time}" arg2="install"/>
				<then>
					<echo message="Signing jars in an archive"/>
					<var name="archive.working.dir" unset="true"/>
					<var name="archive.file" unset="true"/>
					<basename file="@{jars.archive.file}" property="archive.file"/>
					<property name="archive.working.dir" value="@{working.dir}/tmp/${archive.file}.dir"/>
					<mkdir dir="${archive.working.dir}"/>
					<delete dir="${archive.working.dir}"/>
					<mkdir dir="${archive.working.dir}"/>
					<unzip src="@{jars.archive.file}" dest="${archive.working.dir}"/>
					<property name="jars.dir.working" value="${archive.working.dir}/@{jars.archive.relative.dir}"/>
					<echo message="Signing jars in an archive - ${jars.dir.working}"/>
				</then>
				<else>
					<echo message="Signing jars in a directory  - ${jars.dir.working}"/>
					<property name="jars.dir.working" value="@{jars.dir}"/>
				</else>
			</if>
			<!-- sign jars -->
			<for list="@{jar-signing.jar.list}" param="jar.file.name">
				<sequential>
					<echo message="Lookging for @{jar.file.name}"/>
					<signjar
						destDir="${jars.dir.working}"
						alias="@{jar-signing.keystore.alias}"
						keystore="@{jar-signing.keystore.abs-location}"
						storepass="@{jar-signing.keystore.password}"
						keypass="@{jar-signing.keystore.password}"
						lazy="true">
						<path>
							<fileset dir="${jars.dir.working}" includes="@{jar.file.name}" />
						</path>
					</signjar>
				</sequential>
			</for>

			<if>
				<equals arg1="@{jar-signing.execution.time}" arg2="install"/>
				<then>
					<!-- repackage archive -->
					<echo message="Re-creating Archive"/>
					<move file="@{jars.archive.file}" tofile="@{jars.archive.file}.pre-signjar"/>
					<zip destfile="@{jars.archive.file}" basedir="${archive.working.dir}" compress="false"/>
				</then>
			</if>
		</sequential>
	</macrodef>

	<macrodef name="generate-jar-signing-keystore">
		<attribute name="jar-signing.keystore.abs-location" default="${jar-signing.keystore.abs-location}"/>
		<attribute name="jar-signing.keystore.password" default="${jar-signing.keystore.password}"/>
		<attribute name="jar-signing.keystore.alias" default="${jar-signing.keystore.alias}"/>
		<attribute name="jar-signing.generate-selfsigned" default="${jar-signing.generate-selfsigned}"/>
		<attribute name="jar-signing.keystore.cert.cn" default="${jar-signing.keystore.cert.cn}"/>
		<attribute name="jar-signing.keystore.cert.ou" default="${jar-signing.keystore.cert.ou}"/>
		<attribute name="jar-signing.keystore.cert.o" default="${jar-signing.keystore.cert.o}"/>
		<attribute name="jar-signing.keystore.cert.c" default="${jar-signing.keystore.cert.c}"/>
		<sequential>
			<tstamp>
				<format property="install.time" pattern="yyyy-MM-dd-HH-mm-ss" />
			</tstamp>
			<if>
				<equals arg1="@{jar-signing.generate-selfsigned}" arg2="true"/>
				<then>
					<echo message="Generating self-signed certificate for use with jar signing."/>
					<if>
						<available file="@{jar-signing.keystore.abs-location}"/>
						<then>
							<move file="@{jar-signing.keystore.abs-location}" tofile="@{jar-signing.keystore.abs-location}-${install.time}"/>
						</then>
					</if>
					<genkey alias="@{jar-signing.keystore.alias}" storepass="@{jar-signing.keystore.password}" keystore="@{jar-signing.keystore.abs-location}" validity="1825">
						<dname>
							<param name="CN" value="@{jar-signing.keystore.cert.cn}"/>
							<param name="OU" value="@{jar-signing.keystore.cert.ou}"/>
							<param name="O"  value="@{jar-signing.keystore.cert.o}"/>
							<param name="C"  value="@{jar-signing.keystore.cert.c}"/>
						</dname>
					</genkey>
				</then>
				<else>
					<echo message="Using existing certificate for jar signing."/>
				</else>
			</if>
			<verify-jar-signing-keystore
				jar-signing.keystore.abs-location="@{jar-signing.keystore.abs-location}"
				jar-signing.keystore.password="@{jar-signing.keystore.password}"
				jar-signing.keystore.alias="@{jar-signing.keystore.alias}"
				jar-signing.keystore.cert.cn="@jar-signing.keystore.cert.cn}"
				jar-signing.keystore.cert.ou="@jar-signing.keystore.cert.ou}"
				jar-signing.keystore.cert.o="@jar-signing.keystore.cert.o}"
				jar-signing.keystore.cert.c="@jar-signing.keystore.cert.c}"
				/>

		</sequential>
	</macrodef>
	<macrodef name="verify-jar-signing-keystore">
		<attribute name="jar-signing.keystore.abs-location" default="${jar-signing.keystore.abs-location}"/>
		<attribute name="jar-signing.keystore.password" default="${jar-signing.keystore.password}"/>
		<attribute name="jar-signing.keystore.alias" default="${jar-signing.keystore.alias}"/>
		<attribute name="jar-signing.keystore.cert.cn" default="${jar-signing.keystore.cert.cn}"/>
		<attribute name="jar-signing.keystore.cert.ou" default="${jar-signing.keystore.cert.ou}"/>
		<attribute name="jar-signing.keystore.cert.o" default="${jar-signing.keystore.cert.o}"/>
		<attribute name="jar-signing.keystore.cert.c" default="${jar-signing.keystore.cert.c}"/>
		<sequential>
			<if>
				<available file="@{jar-signing.keystore.abs-location}"/>
				<then>
					<echo message="Found signing jar file at @{jar-signing.keystore.abs-location}, validating."/>
					<basename file="@{jar-signing.keystore.abs-location}" property="jar-signing.keystore.file"/>
					<dirname file="@{jar-signing.keystore.abs-location}" property="jar-signing.keystore.dir"/>
					<verify-keystore
						appserver.ssl.enable="true"
						appserver.ssl.keystore.file="${jar-signing.keystore.file}"
						appserver.ssl.keystore.dir="${jar-signing.keystore.dir}"
						appserver.ssl.keystore.pass="@{jar-signing.keystore.password}"
						appserver.ssl.keystore.alias="@{jar-signing.keystore.alias}"
						appserver.ssl.fullyqualified.hostname=""
						verify.url="false"
						/>
				</then>
				<else>
					<echo message="Signing jar file at @{jar-signing.keystore.abs-location} not found, skipping validation."/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="verify-password-value">
		<sequential>
			<copy tofile="${os.temp.dir}/verifyPasswordValue.groovy" file="${build-utils.resource.dir}/groovy/verifyPasswordValue.groovy" overwrite="true"/>
			<groovy src="${os.temp.dir}/verifyPasswordValue.groovy"/>
		</sequential>
	</macrodef>
	<macrodef name="appserver-delete-http-connector" description="macro for enabling ssl in jboss">
		<attribute name="appserver.server-xml.file" default="${jboss.home}/server/${jboss.server.name}/deploy/jbossweb-tomcat55.sar/server.xml"/>
		<attribute name="appserver.server-xml.service.name" default="jboss.web"/>

		<attribute name="appserver.http.port" default="${jboss.server.port}"/>
		<attribute name="appserver.http-connector.remove" default="false"/>
		<sequential>
			<echo message="@{appserver.http-connector.remove} @{appserver.http.port}"/>
			<if>
				<equals arg1="@{appserver.http-connector.remove}" arg2="true"/>
				<then>
					<echo message="Remove HTTP Connect from @{appserver.server-xml.file} because *.http-conector.remove=true"/>
					<xmltask preservetype="true" failWithoutMatch="true" source="@{appserver.server-xml.file}"
						dest="@{appserver.server-xml.file}">
						<xmlcatalog refid="build.xml.catalog"/>
						<remove path="/Server/Service[@name='@{appserver.server-xml.service.name}']/Connector[@port='@{appserver.http.port}']"/>
					</xmltask>
				</then>
				<else>
					<echo message="*.http-conector.remove!=true, skipping removing http connector"/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="jboss-version">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.version.property.name" default="jboss.version"/>
		<attribute name="jboss.major.version.property.name" default="jboss.major.version"/>
		<attribute name="jboss.minor.version.property.name" default="jboss.minor.version"/>
		<attribute name="jboss.patch.version.property.name" default="jboss.patch.version"/>
		<sequential>
			<var name="jboss.version.dir" unset="true"/>
			<basename file="@{jboss.home}" property="jboss.version.dir"/>
			<echo message="Determining JBoss Version"/>
			<var name="@{jboss.version.property.name}" unset="true"/>
			<propertyregex property="@{jboss.version.property.name}"
				input="${jboss.version.dir}"
				regexp="(\d+\.\d+\.\d+).*"
				select="\1"
				/>
			<echo message="JBoss version is ${@{jboss.version.property.name}}"/>

			<var name="@{jboss.major.version.property.name}" unset="true"/>
			<propertyregex property="@{jboss.major.version.property.name}"
				input="${jboss.version.dir}"
				regexp="(\d+)\.\d+\.\d+.*"
				select="\1"
				/>
			<echo message="JBoss major version is ${@{jboss.major.version.property.name}}"/>
			<var name="@{jboss.minor.version.property.name}" unset="true"/>
			<propertyregex property="@{jboss.minor.version.property.name}"
				input="${jboss.version.dir}"
				regexp="\d+\.(\d+)\.\d+.*"
				select="\1"
				/>
			<echo message="JBoss minor version is ${@{jboss.minor.version.property.name}}"/>
			<var name="@{jboss.patch.version.property.name}" unset="true"/>
			<propertyregex property="@{jboss.patch.version.property.name}"
				input="${jboss.version.dir}"
				regexp="\d+\.\d+\.(\d+).*"
				select="\1"
				/>
			<echo message="JBoss patch version is ${@{jboss.patch.version.property.name}}"/>
		</sequential>
	</macrodef>
	<macrodef name="tomcat-version">
		<attribute name="tomcat.home" default="${tomcat.home}"/>
		<attribute name="tomcat.version.property.name" default="tomcat.version"/>
		<attribute name="tomcat.major.version.property.name" default="tomcat.major.version"/>
		<attribute name="tomcat.minor.version.property.name" default="tomcat.minor.version"/>
		<attribute name="tomcat.patch.version.property.name" default="tomcat.patch.version"/>
		<sequential>
			<var name="tomcat.version.dir" unset="true"/>
			<basename file="@{tomcat.home}" property="tomcat.version.dir"/>
			<echo message="Determining Tomcat Version"/>
			<var name="@{tomcat.version.property.name}" unset="true"/>
			<propertyregex property="@{tomcat.version.property.name}"
				input="${tomcat.version.dir}"
				regexp="(\d+\.\d+\.\d+).*"
				select="\1"
				/>
			<echo message="Tomcat version is ${@{tomcat.version.property.name}}"/>

			<var name="@{tomcat.major.version.property.name}" unset="true"/>
			<propertyregex property="@{tomcat.major.version.property.name}"
				input="${tomcat.version.dir}"
				regexp="(\d+)\.\d+\.\d+.*"
				select="\1"
				/>
			<echo message="Tomcat major version is ${@{tomcat.major.version.property.name}}"/>
			<var name="@{tomcat.minor.version.property.name}" unset="true"/>
			<propertyregex property="@{tomcat.minor.version.property.name}"
				input="${tomcat.version.dir}"
				regexp="\d+\.(\d+)\.\d+.*"
				select="\1"
				/>
			<echo message="Tomcat minor version is ${@{tomcat.minor.version.property.name}}"/>
			<var name="@{tomcat.patch.version.property.name}" unset="true"/>
			<propertyregex property="@{tomcat.patch.version.property.name}"
				input="${tomcat.version.dir}"
				regexp="\d+\.\d+\.(\d+).*"
				select="\1"
				/>
			<echo message="Tomcat patch version is ${@{tomcat.patch.version.property.name}}"/>
		</sequential>
	</macrodef>
	<macrodef name="appserver-install-sync-gts">
		<attribute name="appserver.home" default="${jboss.home}"/>
		<attribute name="appserver.server.name" default="${jboss.server.name}"/>
		<attribute name="grid.dir.dest" default="${grid.dir.dest.jboss}"/>
		<attribute name="appserver.grid.secure.enable" default="${jboss.grid.secure.enable}"/>
		<attribute name="sync-gts.build.dir" default="${sync-gts.build.dir}"/>
		<attribute name="cagrid-target.dir" default="${cagrid-target.dir}"/>
		<attribute name="grid.target" default="${grid.target}"/>
		<sequential>
			<if>
				<equals arg1="@{appserver.grid.secure.enable}" arg2="true"/>
				<then>
					<echo message="appserver.home - @{appserver.home}"/>
					<echo message="appserver.server.name - @{appserver.server.name}"/>
					<echo message="grid.dir.dest - @{grid.dir.dest}"/>
					<echo message="appserver.grid.secure.enable - @{appserver.grid.secure.enable}"/>
					<echo message="sync-gts.build.dir - @{sync-gts.build.dir}"/>
					<echo message="cagrid-target.dir - @{cagrid-target.dir}"/>
					<echo message="grid.target -@{grid.target}"/>
					<echo message="Installing sync-gts in support of Secure Grid being enabled"/>
					<copy todir="@{sync-gts.build.dir}/ext/target_grid" file="@{cagrid-target.dir}/@{grid.target}/sync-description.xml"/>
					<copy todir="@{sync-gts.build.dir}/ext/target_grid/certificates">
						<fileset dir="@{cagrid-target.dir}/@{grid.target}/certificates"/>
					</copy>

					<var name="is.jre" unset="true"/>
					<propertyregex property="is.jre"
						input="${java.home}"
						regexp="jre"
						select="true"
						/>
					<if>
						<isset property="is.jre"/>
						<then>
							<echo message="Configuring syncgts to target grid"/>
							<exec osfamily="windows" executable="ant.bat" dir="@{sync-gts.build.dir}" failonerror="true">
								<arg line="all" />
								<env key="GLOBUS_LOCATION" value="${env.GLOBUS_LOCATION}"/>
							</exec>
							<exec osfamily="unix" executable="ant" dir="@{sync-gts.build.dir}" failonerror="true">
								<arg line="all" />
								<env key="GLOBUS_LOCATION" value="${env.GLOBUS_LOCATION}"/>
							</exec>

							<echo message="Syncing with fabric"/>
							<exec osfamily="windows" executable="ant.bat" dir="@{sync-gts.build.dir}" failonerror="true">
								<arg line="syncWithTrustFabric" />
								<env key="GLOBUS_LOCATION" value="${env.GLOBUS_LOCATION}"/>
							</exec>
							<exec osfamily="unix" executable="ant" dir="@{sync-gts.build.dir}" failonerror="true">
								<arg line="syncWithTrustFabric" />
								<env key="GLOBUS_LOCATION" value="${env.GLOBUS_LOCATION}"/>
							</exec>
						</then>
						<else>
							<!-- configure syncgts to target grid -->
							<echo message="Configuring syncgts to target grid"/>
							<ant inheritAll="false" inheritRefs="false"
								antfile="build.xml"
								target="all"
								dir="@{sync-gts.build.dir}"
								>
								<property name="env.GLOBUS_LOCATION" value="${env.GLOBUS_LOCATION}"/>
							</ant>
							<!-- sync with fabric-->
							<echo message="Syncing with fabric"/>
							<ant inheritAll="false" inheritRefs="false"
								antfile="build.xml"
								target="syncWithTrustFabric"
								dir="@{sync-gts.build.dir}"
								>
								<property name="env.GLOBUS_LOCATION" value="${env.GLOBUS_LOCATION}"/>
							</ant>
						</else>
					</if>
					<!-- only run if jboss -->
					<var name="is.jboss" unset="true"/>
					<propertyregex property="is.jboss"
						input="@{appserver.home}"
						regexp="jboss"
						select="true"
						/>
					<if>
						<isset property="is.jboss"/>
						<then>
							<echo message="Setting server name in build-deploy.xml"/>
							<replaceregexp file="@{sync-gts.build.dir}/build-deploy.xml"
								match="jboss.dir}/server/.*?/"
								replace="jboss.dir}/server/@{appserver.server.name}/"
								/>
							<!-- Deploy to app server -->
							<echo message="Deploying to App Server"/>
							<if>
								<isset property="is.jre"/>
								<then>
									<exec osfamily="windows" executable="ant.bat" dir="@{sync-gts.build.dir}" failonerror="true">
										<arg line="-Denv.JBOSS_HOME=@{appserver.home} deployJBoss" />
										<env key="GLOBUS_LOCATION" value="${env.GLOBUS_LOCATION}"/>
									</exec>
									<exec osfamily="unix" executable="ant" dir="@{sync-gts.build.dir}" failonerror="true">
										<arg line="-Denv.JBOSS_HOME=@{appserver.home} deployJBoss" />
										<env key="GLOBUS_LOCATION" value="${env.GLOBUS_LOCATION}"/>
									</exec>
								</then>
								<else>

									<ant inheritAll="false" inheritRefs="false"
										antfile="build.xml"
										target="deployJBoss"
										dir="@{sync-gts.build.dir}"
										>
										<property name="env.JBOSS_HOME" location="@{appserver.home}"/>
										<property name="env.GLOBUS_LOCATION" value="${env.GLOBUS_LOCATION}"/>
									</ant>
								</else>
							</if>
							<if>
								<available file="@{appserver.home}/server/@{appserver.server.name}/deploy/@{grid.dir.dest}/WEB-INF/etc/cagrid_SyncGTS"/>
								<then>
									<echo message="Sync GTS installed in grid service correctly(jboss)"/>
								</then>
								<else>
									<fail message="Sync GTS failed to install into grid service correctly."/>
								</else>
							</if>
						</then>
					</if>
					<!-- Verify it was installed to appserver -->
					<echo message="jboss - @{appserver.home}/server/@{appserver.server.name}/deploy/@{grid.dir.dest}/WEB-INF/etc/cagrid_SyncGTS"/>
					<echo message="tomcat - @{appserver.home}/webapps/@{grid.dir.dest}/WEB-INF/etc/cagrid_SyncGTS"/>

					<if>
						<not>
							<isset property="is.jboss"/>
						</not>
						<then>
							<echo message="Deploying to App Server"/>
							<if>
								<isset property="is.jre"/>
								<then>
									<exec osfamily="windows" executable="ant.bat" dir="@{sync-gts.build.dir}" failonerror="true">
										<arg line="-Denv.CATALINA_HOME=@{appserver.home} deployTomcat" />
										<env key="GLOBUS_LOCATION" value="${env.GLOBUS_LOCATION}"/>
									</exec>
									<exec osfamily="unix" executable="ant" dir="@{sync-gts.build.dir}" failonerror="true">
										<arg line="-Denv.CATALINA_HOME=@{appserver.home} deployTomcat" />
										<env key="GLOBUS_LOCATION" value="${env.GLOBUS_LOCATION}"/>
									</exec>
								</then>
								<else>

									<ant inheritAll="false" inheritRefs="false"
										antfile="build.xml"
										target="deployTomcat"
										dir="@{sync-gts.build.dir}"
										>
										<property name="env.CATALINA_HOME" location="@{appserver.home}"/>
										<property name="env.GLOBUS_LOCATION" value="${env.GLOBUS_LOCATION}"/>
									</ant>
								</else>
							</if>
							<if>
								<available file="@{appserver.home}/webapps/@{grid.dir.dest}/WEB-INF/etc/cagrid_SyncGTS"/>
								<then>
									<echo message="Sync GTS installed in grid service correctly"/>
								</then>
								<else>
									<fail message="Sync GTS failed to install into grid service correctly(tomcat)."/>
								</else>
							</if>
						</then>
					</if>
				</then>
				<else>
					<echo message="Not installing sync-gts"/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="override-properties-prep">
		<attribute name="override.properties" default="${override.properties}"/>
		<attribute name="override.properties.delimiter" default="${override.properties.delimiter}"/>
		<attribute name="override.properties.string.property.name" default="override.properties.string"/>
		<sequential>
			<var name="@{override.properties.string.property.name}" value=""/>
			<echo message="override.properties=@{override.properties}"/>
			<echo message="override.properties.delimiter=@{override.properties.delimiter}"/>
			<var name="override.props.set" unset="true"/>
			<propertyregex property="override.props.set"
				input="@{override.properties}"
				regexp="\$\{override.properties\}"
				select="true"
				/>
			<if>
				<not>
					<isset property="override.props.set"/>
				</not>
				<then>

					<for list="@{override.properties}" param="prop.val" delimiter="@{override.properties.delimiter}">
						<sequential>
							<var name="prop" unset="true"/>
							<propertyregex property="prop"
								input="@{prop.val}"
								regexp="^(.*)=(.*)"
								select="\1"
								/>
							<var name="val" unset="true"/>
							<propertyregex property="val"
								input="@{prop.val}"
								regexp="^(.*)=(.*)"
								select="\2"
								/>
							<var name="@{override.properties.string.property.name}" value="${@{override.properties.string.property.name}} -D${prop}="${val}""/>
						</sequential>
					</for>
				</then>
				<else>
					<echo message="Override Properties not set, setting command line option to plank."/>
				</else>
			</if>
			<echo message="override.properties.string=${@{override.properties.string.property.name}}"/>
		</sequential>
	</macrodef>
	<macrodef name="jboss51-read-ports-nci">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.server.ports.name" default="${jboss.server.ports.name}"/>
		<attribute name="jboss.server.bindingfile.location" default="@{jboss.home}/server/@{jboss.server.name}/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml"/>
		<attribute name="jboss.server.ejbfile.location" default="@{jboss.home}/server/@{jboss.server.name}/deploy/ejb3-connectors-jboss-beans.xml"/>
		<attribute name="jboss.server.jndi.port.property.name" default="jboss.server.jndi.port"/>
		<attribute name="jboss.server.port.property.name" default="jboss.server.port"/>
		<attribute name="jboss.ejbinvoker.port.property.name" default="jboss.ejbinvoker.port"/>
		<attribute name="jboss.server.rmi.port.property.name" default="jboss.server.rmi.port"/>
		<attribute name="jboss.web.service.port.property.name" default="jboss.web.service.port"/>
		<attribute name="jboss.service.rmiobject.port.property.name" default="jboss.service.rmiobject.port"/>
		<attribute name="jboss.server.bind.port.property.name" default="jboss.server.bind.port"/>
		<attribute name="jboss.hajndi.port.property.name" default="jboss.hajndi.port"/>
		<attribute name="jboss.hajrmi.port.property.name" default="jboss.hajrmi.port"/>
		<attribute name="jboss.pooledha.port.property.name" default="jboss.pooledha.port"/>
		<attribute name="jboss.cobraorb.port.property.name" default="jboss.cobraorb.port"/>
		<attribute name="jboss.jmx-rmi.port.property.name" default="jboss.jmx-rmi.port"/>
		<attribute name="jboss.snmp-trapd.port.property.name" default="jboss.snmp-trapd.port"/>
		<attribute name="jboss.snmp.port.property.name" default="jboss.snmp.port"/>
		<!--<attribute name="jboss.jms.port.property.name" default="jboss.jms.port"/>-->
		<!--<attribute name="jboss.remoting.port.property.name" default="jboss.remoting.port"/>-->
		<attribute name="jboss.messaging.port.property.name" default="jboss.messaging.port"/>
		<!-- new with 5.1.0-->
		<attribute name="jboss.unifiedinvoker.port.property.name" default="jboss.unifiedinvoker.port"/>
		<attribute name="jboss.hajndi.auto.port.property.name" default="jboss.hajndi.auto.port"/>
		<attribute name="jboss.ssl.port.property.name" default="jboss.ssl.port"/>
		<attribute name="jboss.jms2.netty.port.property.name" default="jboss.jms2.netty.port"/>
		<attribute name="jboss.jms2.netty-ssl.port.property.name" default="jboss.jms2.netty-ssl.port"/>
		<attribute name="jboss.transaction.recovery.port.property.name" default="jboss.transaction.recovery.port"/>
		<attribute name="jboss.transaction.status.port.property.name" default="jboss.transaction.status.port"/>
		<attribute name="jboss.transaction.processid.port.property.name" default="jboss.transaction.processid.port"/>
		<sequential>
			<!-- Added to support offset -->
			<var name="binding.offset" unset="true"/>
			<xmltask failWithoutMatch="true" preservetype="true" source="@{jboss.server.bindingfile.location}">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="/:deployment/:bean[@class='org.jboss.services.binding.impl.ServiceBindingSet']/:constructor/:parameter[text()='@{jboss.server.ports.name}']/../:parameter[3]/text()" property="binding.offset"/>
			</xmltask>
			<echo message="binding.offset= ${binding.offset}"/>
			<var name="jboss-read-ports.properties.list" value="@{jboss.ejbinvoker.port.property.name},@{jboss.server.jndi.port.property.name},@{jboss.server.port.property.name},@{jboss.cobraorb.port.property.name},@{jboss.hajndi.port.property.name},@{jboss.hajrmi.port.property.name},@{jboss.jmx-rmi.port.property.name},@{jboss.messaging.port.property.name},@{jboss.pooledha.port.property.name},@{jboss.server.bind.port.property.name},@{jboss.server.rmi.port.property.name},@{jboss.service.rmiobject.port.property.name},@{jboss.snmp.port.property.name},@{jboss.snmp-trapd.port.property.name},@{jboss.web.service.port.property.name},@{jboss.unifiedinvoker.port.property.name},@{jboss.hajndi.auto.port.property.name},@{jboss.ssl.port.property.name},@{jboss.jms2.netty.port.property.name},@{jboss.jms2.netty-ssl.port.property.name},@{jboss.transaction.recovery.port.property.name},@{jboss.transaction.status.port.property.name},@{jboss.transaction.processid.port.property.name}"/>
			<var name="read.ejbinvoker.port" unset="true"/>
			<var name="read.server.jndi.port" unset="true"/>
			<var name="read.server.port" unset="true"/>
			<var name="read.cobraorb.port" unset="true"/>
			<var name="read.hajndi.port" unset="true"/>
			<var name="read.hajrmi.port" unset="true"/>
			<var name="read.jmx-rmi.port" unset="true"/>
			<var name="read.messaging.port" unset="true"/>
			<var name="read.pooledha.port" unset="true"/>
			<var name="read.server.bind.port" unset="true"/>
			<var name="read.server.rmi.port" unset="true"/>
			<var name="read.service.rmiobject.port" unset="true"/>
			<var name="read.snmp.port" unset="true"/>
			<var name="read.snmp-trapd.port" unset="true"/>
			<var name="read.web.service.port" unset="true"/>
			<var name="read.unifiedinvoker.port" unset="true"/>
			<var name="read.hajndi.auto.port" unset="true"/>
			<var name="read.ssl.port" unset="true"/>
			<var name="read.jms2.netty.port" unset="true"/>
			<var name="read.jms2.netty-ssl.port" unset="true"/>
			<var name="read.transaction.recovery.port" unset="true"/>
			<var name="read.transaction.status.port" unset="true"/>
			<var name="read.transaction.processid.port" unset="true"/>
			<xmltask failWithoutMatch="true" preservetype="true" source="@{jboss.server.bindingfile.location}">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss.web:service=WebServer']/../:property[@name='port']/text()" property="read.server.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=Naming']/../:property[text()='Port']/../:property[@name='port']/text()" property="read.server.jndi.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=Naming']/../:property[text()='RmiPort']/../:property[@name='port']/text()" property="read.server.rmi.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=WebService']/../:property[@name='port']/text()" property="read.web.service.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='UnifiedInvokerConnector']/../:property[@name='port']/text()" property="read.unifiedinvoker.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=invoker,type=jrmp']/../:property[@name='port']/text()" property="read.service.rmiobject.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=invoker,type=pooled']/../:property[@name='port']/text()" property="read.server.bind.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=HAJNDI']/../:property[text()='Port']/../:property[@name='port']/text()" property="read.hajndi.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=HAJNDI']/../:property[text()='RmiPort']/../:property[@name='port']/text()" property="read.hajrmi.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='AutoDiscovery']/../:property[@name='port']/text()" property="read.hajndi.auto.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=invoker,type=jrmpha']/../:property[@name='port']/text()" property="read.service.rmiobject.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=invoker,type=pooledha']/../:property[@name='port']/text()" property="read.pooledha.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss:service=CorbaORB']/../:property[@name='port']/text()" property="read.cobraorb.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss.jmx:name=SnmpAgent,service=trapd,type=logger']/../:property[@name='port']/text()" property="read.snmp-trapd.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss.jmx:name=SnmpAgent,service=snmp,type=adaptor']/../:property[@name='port']/text()" property="read.snmp.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss.remoting:service=JMXConnectorServer,protocol=rmi']/../:property[@name='port']/text()" property="read.jmx-rmi.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss.web:service=WebServer']/../:property[text()='HttpsConnector']/../:property[@name='port']/text()" property="read.ssl.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='jboss.messaging:service=Connector,transport=bisocket']/../:property[@name='port']/text()" property="read.messaging.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='netty-port']/../:property[@name='port']/text()" property="read.jms2.netty.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='netty-ssl-port']/../:property[@name='port']/text()" property="read.jms2.netty-ssl.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='recoveryManager']/../:property[@name='port']/text()" property="read.transaction.recovery.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='transactionStatusManager']/../:property[@name='port']/text()" property="read.transaction.status.port"/>
				<copy path="/:deployment/:bean[@name='StandardBindings']/:constructor/:parameter/:set/:bean/:property[text()='socketProcessId']/../:property[@name='port']/text()" property="read.transaction.processid.port"/>
			</xmltask>
			<xmltask failWithoutMatch="true" preservetype="true" source="@{jboss.server.ejbfile.location}">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="/:deployment/:bean[@name='org.jboss.ejb3.RemotingConnector']/:property[@name='invokerLocator']/:value-factory/:parameter[5]/text()" property="read.ejbinvoker.port"/>
			</xmltask>
			<echo  level="debug" message="read.ejbinvoker.port=${read.ejbinvoker.port}"/>
			<echo  level="debug" message="read.server.jndi.port=${read.server.jndi.port}"/>
			<echo  level="debug" message="read.server.port=${read.server.port}"/>
			<echo  level="debug" message="read.cobraorb.port=${read.cobraorb.port}"/>
			<echo  level="debug" message="read.hajndi.port=${read.hajndi.port}"/>
			<echo  level="debug" message="read.hajrmi.port=${read.hajrmi.port}"/>
			<echo  level="debug" message="read.jmx-rmi.port=${read.jmx-rmi.port}"/>
			<echo  level="debug" message="read.messaging.port=${read.messaging.port}"/>
			<echo  level="debug" message="read.pooledha.port=${read.pooledha.port}"/>
			<echo  level="debug" message="read.server.bind.port=${read.server.bind.port}"/>
			<echo  level="debug" message="read.server.rmi.port=${read.server.rmi.port}"/>
			<echo  level="debug" message="read.service.rmiobject.port=${read.service.rmiobject.port}"/>
			<echo  level="debug" message="read.snmp.port=${read.snmp.port}"/>
			<echo  level="debug" message="read.snmp-trapd.port=${read.snmp-trapd.port}"/>
			<echo  level="debug" message="read.web.service.port=${read.web.service.port}"/>
			<echo  level="debug" message="read.unifiedinvoker.port=${read.unifiedinvoker.port}"/>
			<echo  level="debug" message="read.hajndi.auto.port=${read.hajndi.auto.port}"/>
			<echo  level="debug" message="read.ssl.port=${read.ssl.port}"/>
			<echo  level="debug" message="read.jms2.netty.port=${read.jms2.netty.port}"/>
			<echo  level="debug" message="read.jms2.netty-ssl.port=${read.jms2.netty-ssl.port}"/>
			<echo  level="debug" message="read.transaction.recovery.port=${read.transaction.recovery.port}"/>
			<echo  level="debug" message="read.transaction.status.port=${read.transaction.status.port}"/>
			<echo  level="debug" message="read.transaction.processid.port=${read.transaction.processid.port}"/>

			<math datatype="int" result="@{jboss.ejbinvoker.port.property.name}" operand1="${read.ejbinvoker.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.server.jndi.port.property.name}" operand1="${read.server.jndi.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.server.port.property.name}" operand1="${read.server.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.cobraorb.port.property.name}" operand1="${read.cobraorb.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.hajndi.port.property.name}" operand1="${read.hajndi.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.hajrmi.port.property.name}" operand1="${read.hajrmi.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.jmx-rmi.port.property.name}" operand1="${read.jmx-rmi.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.messaging.port.property.name}" operand1="${read.messaging.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.pooledha.port.property.name}" operand1="${read.pooledha.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.server.bind.port.property.name}" operand1="${read.server.bind.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.server.rmi.port.property.name}" operand1="${read.server.rmi.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.service.rmiobject.port.property.name}" operand1="${read.service.rmiobject.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.snmp.port.property.name}" operand1="${read.snmp.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.snmp-trapd.port.property.name}" operand1="${read.snmp-trapd.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.web.service.port.property.name}" operand1="${read.web.service.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.unifiedinvoker.port.property.name}" operand1="${read.unifiedinvoker.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.hajndi.auto.port.property.name}" operand1="${read.hajndi.auto.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.ssl.port.property.name}" operand1="${read.ssl.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.jms2.netty.port.property.name}" operand1="${read.jms2.netty.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.jms2.netty-ssl.port.property.name}" operand1="${read.jms2.netty-ssl.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.transaction.recovery.port.property.name}" operand1="${read.transaction.recovery.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.transaction.status.port.property.name}" operand1="${read.transaction.status.port}" operation="+" operand2="${binding.offset}"/>
			<math datatype="int" result="@{jboss.transaction.processid.port.property.name}" operand1="${read.transaction.processid.port}" operation="+" operand2="${binding.offset}"/>
			<properties-print
				properties.list="${jboss-read-ports.properties.list}"
				/>

			<var name="read.properties.list" value="${read.properties.list},${jboss-read-ports.properties.list}"/>
		</sequential>
	</macrodef>
	<macrodef name="jboss51-read-ports">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.ncicb-standard.port-config" default="${jboss.ncicb-standard.port-config}"/>
		<attribute name="jboss.server.ports.name" default="${jboss.server.ports.name}"/>
		<attribute name="jboss.server.bindingfile.location" default="@{jboss.home}/server/@{jboss.server.name}/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml"/>
		<attribute name="jboss.server.jndi.port.property.name" default="jboss.server.jndi.port"/>
		<attribute name="jboss.server.port.property.name" default="jboss.server.port"/>
		<attribute name="jboss.ejbinvoker.port.property.name" default="jboss.ejbinvoker.port"/>
		<attribute name="jboss.server.rmi.port.property.name" default="jboss.server.rmi.port"/>
		<attribute name="jboss.web.service.port.property.name" default="jboss.web.service.port"/>
		<attribute name="jboss.service.rmiobject.port.property.name" default="jboss.service.rmiobject.port"/>
		<attribute name="jboss.server.bind.port.property.name" default="jboss.server.bind.port"/>
		<attribute name="jboss.hajndi.port.property.name" default="jboss.hajndi.port"/>
		<attribute name="jboss.hajrmi.port.property.name" default="jboss.hajrmi.port"/>
		<attribute name="jboss.pooledha.port.property.name" default="jboss.pooledha.port"/>
		<attribute name="jboss.cobraorb.port.property.name" default="jboss.cobraorb.port"/>
		<attribute name="jboss.jmx-rmi.port.property.name" default="jboss.jmx-rmi.port"/>
		<attribute name="jboss.snmp-trapd.port.property.name" default="jboss.snmp-trapd.port"/>
		<attribute name="jboss.snmp.port.property.name" default="jboss.snmp.port"/>
		<!--<attribute name="jboss.jms.port.property.name" default="jboss.jms.port"/>-->
		<!--<attribute name="jboss.remoting.port.property.name" default="jboss.remoting.port"/>-->
		<attribute name="jboss.messaging.port.property.name" default="jboss.messaging.port"/>
		<!-- new with 5.1.0-->
		<attribute name="jboss.unifiedinvoker.port.property.name" default="jboss.unifiedinvoker.port"/>
		<attribute name="jboss.hajndi.auto.port.property.name" default="jboss.hajndi.auto.port"/>
		<attribute name="jboss.ssl.port.property.name" default="jboss.ssl.port"/>
		<attribute name="jboss.jms2.netty.port.property.name" default="jboss.jms2.netty.port"/>
		<attribute name="jboss.jms2.netty-ssl.port.property.name" default="jboss.jms2.netty-ssl.port"/>
		<attribute name="jboss.transaction.recovery.port.property.name" default="jboss.transaction.recovery.port"/>
		<attribute name="jboss.transaction.status.port.property.name" default="jboss.transaction.status.port"/>
		<attribute name="jboss.transaction.processid.port.property.name" default="jboss.transaction.processid.port"/>
		<sequential>
			<if>
				<equals arg1="@{jboss.ncicb-standard.port-config}" arg2="true"/>
				<then>
					<echo message="Using standard port configs calling jboss51-read-ports-nci."/>
					<jboss51-read-ports-nci
						jboss.home="@{jboss.home}"
						jboss.server.name="@{jboss.server.name}"
						jboss.server.ports.name="@{jboss.server.ports.name}"
						jboss.server.bindingfile.location="@{jboss.server.bindingfile.location}"
						jboss.server.jndi.port.property.name="@{jboss.server.jndi.port.property.name}"
						jboss.server.port.property.name="@{jboss.server.port.property.name}"
						jboss.ejbinvoker.port.property.name="@{jboss.ejbinvoker.port.property.name}"
						jboss.server.rmi.port.property.name="@{jboss.server.rmi.port.property.name}"
						jboss.web.service.port.property.name="@{jboss.web.service.port.property.name}"
						jboss.service.rmiobject.port.property.name="@{jboss.service.rmiobject.port.property.name}"
						jboss.server.bind.port.property.name="@{jboss.server.bind.port.property.name}"
						jboss.hajndi.port.property.name="@{jboss.hajndi.port.property.name}"
						jboss.hajrmi.port.property.name="@{jboss.hajrmi.port.property.name}"
						jboss.pooledha.port.property.name="@{jboss.pooledha.port.property.name}"
						jboss.cobraorb.port.property.name="@{jboss.cobraorb.port.property.name}"
						jboss.jmx-rmi.port.property.name="@{jboss.jmx-rmi.port.property.name}"
						jboss.snmp-trapd.port.property.name="@{jboss.snmp-trapd.port.property.name}"
						jboss.snmp.port.property.name="@{jboss.snmp.port.property.name}"
						jboss.messaging.port.property.name="@{jboss.messaging.port.property.name}"
						jboss.unifiedinvoker.port.property.name="@{jboss.unifiedinvoker.port.property.name}"
						jboss.hajndi.auto.port.property.name="@{jboss.hajndi.auto.port.property.name}"
						jboss.ssl.port.property.name="@{jboss.ssl.port.property.name}"
						jboss.jms2.netty.port.property.name="@{jboss.jms2.netty.port.property.name}"
						jboss.jms2.netty-ssl.port.property.name="@{jboss.jms2.netty-ssl.port.property.name}"
						jboss.transaction.recovery.port.property.name="@{jboss.transaction.recovery.port.property.name}"
						jboss.transaction.status.port.property.name="@{jboss.transaction.status.port.property.name}"
						jboss.transaction.processid.port.property.name="@{jboss.transaction.processid.port.property.name}"
						/>
				</then>
				<else>
					<echo message="NOT using standard port configs calling jboss51-read-ports."/>
					<jboss51-read-ports
						jboss.home="@{jboss.home}"
						jboss.server.name="@{jboss.server.name}"
						jboss.server.ports.name="@{jboss.server.ports.name}"
						jboss.server.bindingfile.location="@{jboss.server.bindingfile.location}"
						jboss.server.jndi.port.property.name="@{jboss.server.jndi.port.property.name}"
						jboss.server.port.property.name="@{jboss.server.port.property.name}"
						jboss.ejbinvoker.port.property.name="@{jboss.ejbinvoker.port.property.name}"
						jboss.server.rmi.port.property.name="@{jboss.server.rmi.port.property.name}"
						jboss.web.service.port.property.name="@{jboss.web.service.port.property.name}"
						jboss.service.rmiobject.port.property.name="@{jboss.service.rmiobject.port.property.name}"
						jboss.server.bind.port.property.name="@{jboss.server.bind.port.property.name}"
						jboss.hajndi.port.property.name="@{jboss.hajndi.port.property.name}"
						jboss.hajrmi.port.property.name="@{jboss.hajrmi.port.property.name}"
						jboss.pooledha.port.property.name="@{jboss.pooledha.port.property.name}"
						jboss.cobraorb.port.property.name="@{jboss.cobraorb.port.property.name}"
						jboss.jmx-rmi.port.property.name="@{jboss.jmx-rmi.port.property.name}"
						jboss.snmp-trapd.port.property.name="@{jboss.snmp-trapd.port.property.name}"
						jboss.snmp.port.property.name="@{jboss.snmp.port.property.name}"
						jboss.messaging.port.property.name="@{jboss.messaging.port.property.name}"
						jboss.unifiedinvoker.port.property.name="@{jboss.unifiedinvoker.port.property.name}"
						jboss.hajndi.auto.port.property.name="@{jboss.hajndi.auto.port.property.name}"
						jboss.ssl.port.property.name="@{jboss.ssl.port.property.name}"
						jboss.jms2.netty.port.property.name="@{jboss.jms2.netty.port.property.name}"
						jboss.jms2.netty-ssl.port.property.name="@{jboss.jms2.netty-ssl.port.property.name}"
						jboss.transaction.recovery.port.property.name="@{jboss.transaction.recovery.port.property.name}"
						jboss.transaction.status.port.property.name="@{jboss.transaction.status.port.property.name}"
						jboss.transaction.processid.port.property.name="@{jboss.transaction.processid.port.property.name}"
						/>
				</else>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="jboss51-bindings-nci">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.server.ports.name" default="${jboss.server.ports.name}"/>
		<attribute name="jboss.ncicb-standard.port-config" default="${jboss.ncicb-standard.port-config}"/>
		<!--<attribute name="jboss.port.offset" default="${jboss.port.offset}"/>-->
		<attribute name="jboss.server.bindingfile.location" default="@{jboss.home}/server/@{jboss.server.name}/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml"/>
		<attribute name="jboss.server.binding.template.location" default="${jboss.server.binding.template.location}"/>
		<sequential>
			<!--
			<var name="port.config" value="@{jboss.server.ports.name}"/>
			<groovy>
				matcher = (properties["port.config"] =~ /[^A-Za-z0-9]/)
				portName = matcher.replaceAll("")
				properties["port.name"]=portName
			</groovy>
			<echo message="port.name=${port.name}"/>
			<xmltask preservetype="true" source="@{jboss.server.bindingfile.location}"
				dest="@{jboss.server.bindingfile.location}">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove	path="/:deployment/:bean[@class='org.jboss.services.binding.impl.ServiceBindingSet']"/>
			</xmltask>
			<xmltask preservetype="true" source="@{jboss.server.bindingfile.location}"
				dest="@{jboss.server.bindingfile.location}"
				failWithoutMatch="true" >
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="/:deployment/:bean[@name='ServiceBindingManagementObject']" position="after">
					<![CDATA[
   <bean name="${port.name}"  class="org.jboss.services.binding.impl.ServiceBindingSet">
      <constructor>
	 <parameter>@{jboss.server.ports.name}</parameter>
         <parameter>${jboss.bind.address}</parameter>
	 <parameter>@{jboss.port.offset}</parameter>
         <parameter><null/></parameter>
      </constructor>
   </bean>
					]]>
				</insert>
			</xmltask>
			<xmltask preservetype="true" source="@{jboss.server.bindingfile.location}"
				dest="@{jboss.server.bindingfile.location}">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove	path="/:deployment/:bean[@name='ServiceBindingManagementObject']"/>
			</xmltask>
			<xmltask preservetype="true" source="@{jboss.server.bindingfile.location}"
				dest="@{jboss.server.bindingfile.location}"
				failWithoutMatch="true" >
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="/:deployment/:bean[@name='ServiceBindingManager']" position="after">
					<![CDATA[
   <bean name="ServiceBindingManagementObject" class="org.jboss.services.binding.managed.ServiceBindingManagementObject">
      <constructor>
	      <parameter>${jboss.service.binding.set:@{jboss.server.ports.name}}</parameter>
         <parameter>
            <set>
		    <inject bean="${port.name}"/>
            </set>
         </parameter>
         <parameter><inject bean="StandardBindings"/></parameter>
      </constructor>
   </bean>
					]]>
				</insert>
			</xmltask>
			-->
			<copy tofile="@{jboss.server.bindingfile.location}" file="@{jboss.server.binding.template.location}" overwrite="true"/>
			<xmltask preservetype="true" source="@{jboss.server.bindingfile.location}"
				dest="@{jboss.server.bindingfile.location}"
				failWithoutMatch="true" >
				<xmlcatalog refid="build.xml.catalog"/>
				<replace path="/:deployment/:bean[@name='ServiceBindingManagementObject']/:constructor/:parameter[1]/text()" withtext="${jboss.service.binding.set:@{jboss.server.ports.name}}"/>
			</xmltask>
			<replaceregexp file="@{jboss.server.bindingfile.location}" byline="true"
				match="xmlns="""
				replace=""
				/>
		</sequential>
	</macrodef>
	<macrodef name="jboss51-read-default-portconfig">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.server.bindingfile.location" default="@{jboss.home}/server/@{jboss.server.name}/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml"/>
		<attribute name="jboss.server.ports.name.property.name" default="jboss.server.ports.name"/>
		<sequential>
			<var name="read.default.raw" unset="true"/>
			<var name="read.default" unset="true"/>
			<xmltask failWithoutMatch="true" preservetype="true" source="@{jboss.server.bindingfile.location}">
				<xmlcatalog refid="build.xml.catalog"/>
				<copy path="/:deployment/:bean[@name='ServiceBindingManagementObject']/:constructor/:parameter[1]/text()" property="read.default.raw"/>
			</xmltask>
			<propertyregex property="read.default"
				input="${read.default.raw}"
				regexp="^(.*):(.*)}"
				select="\2"
				/>
			<echo message="read.default=${read.default}"/>
			<property name="@{jboss.server.ports.name.property.name}" value="${read.default}"/>
		</sequential>
	</macrodef>
	<macrodef name="jboss41-nci-customizations" description="deploys customized jboss management files, this target only works for linux">
		<attribute name="jboss.home" default="${jboss.home}" />
		<attribute name="jboss.server.name" default="${jboss.server.name}" />
		<attribute name="application.base.path" default="${application.base.path}"/>
		<attribute name="project.name" default="${project.name}"/>
		<attribute name="logname" default="${env.LOGNAME}"/>
		<attribute name="java.home" default="${env.JAVA_HOME}"/>
		<attribute name="jboss.server.jndi.port" default="${jboss.server.jndi.port}"/>
		<attribute name="filterset.name" default="jboss.nci.custom"/>
		<attribute name="jboss.java.opts" default="${jboss.java.opts}"/>
		<attribute name="database.type" default="${database.type}"/>
		<attribute name="start.jboss" default="Y"/>
		<attribute name="env.name" default="${env.name}"/>
		<sequential>
			<echo message="Setting up jboss-nci-customizations (this system is Unix or Mac)"/>
			<filterset id="@{filterset.name}">
				<filter token="application.base.path" value="@{application.base.path}"/>
				<filter token="project.name" value="@{project.name}"/>
				<filter token="jboss.home" value="@{jboss.home}"/>
				<filter token="env.LOGNAME" value="@{logname}"/>
				<filter token="jboss.server.name" value="@{jboss.server.name}"/>
				<filter token="env.JAVA_HOME" value="@{java.home}"/>
				<filter token="jboss.server.jndi.port" value="@{jboss.server.jndi.port}"/>
			</filterset>
			<mkdir dir="@{jboss.home}/server/@{jboss.server.name}/bin"/>
			<copy todir="@{jboss.home}/server/@{jboss.server.name}/bin">
						<filterset refid="@{filterset.name}"/>
				<fileset dir="${build-utils.resource.dir}/ncicb/jboss-custom/bin">
					<include name="*"/>
				</fileset>
			</copy>

			<chmod dir="@{jboss.home}/server/@{jboss.server.name}/bin" perm="ug+x" includes="*"/>
			<jboss-configure-java_opts
				jboss.bin.dir="@{jboss.home}/bin"
				jboss.java.opts="@{jboss.java.opts}"
				/>
			<copy tofile="@{jboss.home}/server/@{jboss.server.name}/conf/log4j.xml" file="${build-utils.resource.dir}/ncicb/jboss-custom/conf/log4j.xml" overwrite="true"/>
			<if>
				<equals arg1="@{database.type}" arg2="oracle"/>
				<then>
					<echo message="Database.type is oracle, setting pad=true"/>
					<var name="read.pad" unset="true"/>
					<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-service.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<copy path="/server/mbean[@code='org.jboss.tm.XidFactory']/attribute[@name='Pad']/text()" property="read.pad"/>
					</xmltask>

					<var name="pad.is.set" unset="true"/>
					<propertyregex property="pad.is.set"
						input="${read.pad}"
						regexp="^[^\$]\S+"
						select="\0"
						/>
					<echo message="read.pad = ${read.pad}"/>
					<if>
						<not>
							<isset property="pad.is.set"/>
						</not>
						<then>
							<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-service.xml" dest="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-service.xml">
								<xmlcatalog refid="build.xml.catalog"/>
								<insert path="/server/mbean[@code='org.jboss.tm.XidFactory']">
									<![CDATA[ <attribute name="Pad">true</attribute>]]>
								</insert>
							</xmltask>
						</then>
						<else>
							<echo message="Pad already set"/>
						</else>
					</if>
				</then>
				<else>
					<echo message="Database.type is not oracle, skipping pad"/>
				</else>
			</if>
			<setup-apptab
				jboss.home="@{jboss.home}"
				jboss.server.name="@{jboss.server.name}"
				application.base.path="@{application.base.path}"
				logname="@{logname}"
				start.jboss="@{start.jboss}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="jboss51-nci-customizations" description="deploys customized jboss management files, this target only works for linux">
		<attribute name="jboss.home" default="${jboss.home}" />
		<attribute name="jboss.server.name" default="${jboss.server.name}" />
		<attribute name="application.base.path" default="${application.base.path}"/>
		<attribute name="project.name" default="${project.name}"/>
		<attribute name="logname" default="${env.LOGNAME}"/>
		<attribute name="java.home" default="${env.JAVA_HOME}"/>
		<attribute name="jboss.server.jndi.port" default="${jboss.server.jndi.port}"/>
		<attribute name="filterset.name" default="jboss.nci.custom"/>
		<attribute name="jboss.java.opts" default="${jboss.java.opts}"/>
		<attribute name="database.type" default="${database.type}"/>
		<attribute name="start.jboss" default="Y"/>
		<attribute name="env.name" default="${env.name}"/>
		<sequential>
			<echo message="Setting up jboss-nci-customizations (this system is Unix or Mac)"/>
			<filterset id="@{filterset.name}">
				<filter token="application.base.path" value="@{application.base.path}"/>
				<filter token="project.name" value="@{project.name}"/>
				<filter token="jboss.home" value="@{jboss.home}"/>
				<filter token="env.LOGNAME" value="@{logname}"/>
				<filter token="jboss.server.name" value="@{jboss.server.name}"/>
				<filter token="env.JAVA_HOME" value="@{java.home}"/>
				<filter token="jboss.server.port" value="@{jboss.server.port}"/>
				<filter token="jboss.server.jndi.port" value="@{jboss.server.jndi.port}"/>
			</filterset>
			<copy todir="@{jboss.home}/bin">
						<filterset refid="@{filterset.name}"/>
				<fileset dir="${build-utils.resource.dir}/ncicb/jboss51-custom">
					<include name="*"/>
				</fileset>
			</copy>
			<!-- insert load init.conf into JBOSS_HOME/bin/*.sh -->
			<var name="flist" unset="true"/>
			<property name="flist" value="run.sh,shutdown.sh"/>
			<for list="${flist}" param="file">
				<sequential>
					<var name="sh.file" unset="true"/>
					<var name="file.customized" unset="true"/>
					<property name="sh.file" value="@{jboss.home}/bin/@{file}"/>
					<groovy>
						File shFile = new File(properties["sh.file"])
						List lines = shFile.readLines()
						if(lines.grep("NCI Additions"))
						{
						properties["file.customized"]="true"
						}
					</groovy>
					<if>
						<not>
							<equals arg1="${file.customized}" arg2="true"/>
						</not>
						<then>
							<echo message="${sh.file} is being customized for NCI Tier configuration"/>
							<copy file="${sh.file}" tofile="${sh.file}.orig"/>
							<replaceregexp file="${sh.file}" byline="true"
								match="GREP="grep""
								replace="GREP="grep"${line.separator}##############NCI additions${line.separator}## NCI additions${line.separator}INIT_CONF="$DIRNAME/init.conf"${line.separator}if [ -r "$INIT_CONF" ]; then${line.separator}. "$INIT_CONF"${line.separator}else${line.separator}echo "${PROGNAME}: Missing init.conf! exiting..."${line.separator}exit 1${line.separator}fi${line.separator}## end NCI additions${line.separator}"
								/>
						</then>
						<else>
							<echo message="${sh.file} already customized"/>
						</else>
					</if>
				</sequential>
			</for>
			<var name="sh.file" unset="true"/>
			<var name="file.customized" unset="true"/>
			<property name="sh.file" value="@{jboss.home}/bin/run.sh"/>
			<groovy>
				File shFile = new File(properties["sh.file"])
				List lines = shFile.readLines()
				if(lines.grep("NCI Additions"))
				{
				properties["file.customized"]="true"
				}
			</groovy>
			<if>
				<not>
					<equals arg1="${file.customized}" arg2="true"/>
				</not>
				<then>
					<echo message="${sh.file} is being customized for NCI Tier configuration"/>
					<copy file="${sh.file}" tofile="${sh.file}.orig"/>
					<replaceregexp file="${sh.file}" byline="true"
						match="org.jboss.Main "\$\@"$"
						replace="org.jboss.Main "$\@"${line.separator}# NCI Additions${line.separator}JBOSS_PID=$!${line.separator}echo $JBOSS_PID > $yyyJBOSS_HOMEzzz/bin/$yyyJBOSS_CONF_BASEzzz.pid${line.separator}# END NCI Additions${line.separator}"
						/>
					<replaceregexp file="${sh.file}" byline="true"
						match="xxx"
						replace="$"
						flags="g"
						/>
					<replaceregexp file="${sh.file}" byline="true"
						match="yyy"
						replace="\{"
						flags="g"
						/>
					<replaceregexp file="${sh.file}" byline="true"
						match="zzz"
						replace="\}"
						flags="g"
						/>
				</then>
				<else>
					<echo message="${sh.file} already customized"/>
				</else>
			</if>
			<!-- remove daily appender add size appender -->
			<var name="log4j.file" unset="true"/>
			<var name="file.customized" unset="true"/>
			<property name="log4j.file" value="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-log4j.xml"/>
			<groovy>
				File log4jFile = new File(properties["log4j.file"])
				List lines = log4jFile.readLines()
				if(lines.grep("NCI Additions"))
				{
				properties["file.customized"]="true"
				}
			</groovy>
			<if>
				<not>
					<equals arg1="${file.customized}" arg2="true"/>
				</not>
				<then>
					<echo message="${log4j.file} is being customized for NCI Tier configuration"/>
					<copy file="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-log4j.xml" tofile="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-log4j.xml.nci"/>

					<replaceregexp file="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-log4j.xml"
						byline="true"
						match="^(<!DOCTYPE.*)"
						replace="<!\-\-\1\-\->"
						/>

					<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-log4j.xml" dest="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-log4j.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<remove	path="/log4j:configuration/appender[@class='org.jboss.logging.appender.DailyRollingFileAppender']"/>
					</xmltask>
					<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-log4j.xml" dest="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-log4j.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="log4j:configuration/appender[@class='org.apache.log4j.ConsoleAppender']" position="before">
							<![CDATA[
							<!-- NCI Additions -->
							<!-- A size based file rolling appender -->
							<appender name="FILE" class="org.jboss.logging.appender.RollingFileAppender">
								<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
								<param name="File" value="${jboss.server.log.dir}/server.log"/>
								<param name="Append" value="True"/>
								<param name="MaxFileSize" value="${log4j.maxFileSize}"/>
								<param name="MaxBackupIndex" value="${log4j.maxDays}"/>
								<layout class="org.apache.log4j.PatternLayout">
									<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
								</layout>
							</appender>
							]]>
						</insert>
					</xmltask>
					<replaceregexp file="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-log4j.xml"
						byline="true"
						match="^<!\-\-(<!DOCTYPE.*)\-\->"
						replace="\1"
						/>
					<replaceregexp file="@{jboss.home}/server/@{jboss.server.name}/conf/jboss-log4j.xml"
						byline="true"
						match="^(<log4j:configuration.*)"
						replace="\1${line.separator}<!-- NCI Additions -->"
						/>
				</then>
				<else>
					<echo message="${log4j.file} is already customized for NCI Tier configuration"/>
				</else>
			</if>
			<!-- App Tab -->
			<setup-apptab
				jboss.home="@{jboss.home}"
				jboss.server.name="@{jboss.server.name}"
				application.base.path="@{application.base.path}"
				logname="@{logname}"
				start.jboss="@{start.jboss}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="setup-apptab" description="">
		<attribute name="jboss.home" default="${jboss.home}" />
		<attribute name="jboss.server.name" default="${jboss.server.name}" />
		<attribute name="application.base.path" default="${application.base.path}"/>
		<attribute name="logname" default="${env.LOGNAME}"/>
		<attribute name="start.jboss" default="Y"/>
		<sequential>
			<!-- Write to apptab -->
			<switch value="@{start.jboss}">
				<case value="Y"/>
				<case value="N"/>
				<!-- not supported
				<case value="y"/>
				<case value="n"/>
				-->
				<default>
					<fail message="start.jboss must be Y/N or y/n"/>
				</default>
			</switch>
			<var name="apptab.file.location" unset="true"/>
			<property name="apptab.file.location" location="@{application.base.path}/../apptab"/>
			<var name="apptab.base.entry" unset="true"/>
			<property name="apptab.base.entry" value="@{logname}:@{jboss.home}/server/@{jboss.server.name}"/>
			<var name="jboss.start.flag" value="@{start.jboss}"/>
			<if>
				<not>
					<available file="${apptab.file.location}"/>
				</not>
				<then>
					<echo message="apptab [${apptab.file.location}]file does not exist creating empty file"/>
					<echo file="${apptab.file.location}" message=""/>
				</then>
			</if>
			<groovy>
				String fileName = properties["apptab.file.location"]
				String baseEntry = properties["apptab.base.entry"]
				String startJboss = properties["jboss.start.flag"]
				File apptab = new File(fileName)
				String contents = apptab.text
				String newContents = ""
				if (!contents.contains(baseEntry))
				{
				println "Entry not found, adding entry"
				newContents = contents + baseEntry + ":" + startJboss +"\n"
				}
				else
				{
				println "Found existing entry updating"
				contents.eachLine{
				line ->
				if (line.contains(baseEntry))
				{
				newContents = newContents + baseEntry + ":" + startJboss +"\n"
				}
				else
				{
				newContents = newContents + line + "\n"
				}
				}
				}
				apptab.write(newContents)
			</groovy>
		</sequential>
	</macrodef>
	<macrodef name="secure-jboss-console" description="Diagnose the host system before the installation">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.web.user" default="${jboss.web.user}"/>
		<attribute name="jboss.web.password" default="${jboss.web.password}"/>
		<attribute name="jboss.ssl.enable" default="${jboss.ssl.enable}"/>
		<sequential>
			<var name="jboss-sec.version" unset="true"/>
			<var name="jboss-sec.major.version" unset="true"/>
			<var name="jboss-sec.minor.version" unset="true"/>
			<var name="jboss-sec.patch.version" unset="true"/>

			<jboss-version
				jboss.home="@{jboss.home}"
				jboss.version.property.name="jboss-sec.version"
				jboss.major.version.property.name="jboss-sec.major.version"
				jboss.minor.version.property.name="jboss-sec.minor.version"
				jboss.patch.version.property.name="jboss-sec.patch.version"
				/>
			<if>
				<equals arg1="${jboss-sec.major.version}" arg2="4"/>
				<then>
					<echo message="Securing the WEB console for JBoss 4"/>
					<secure-jboss41-console
						jboss.home="@{jboss.home}"
						jboss.server.name="@{jboss.server.name}"
						jboss.web.user="@{jboss.web.user}"
						jboss.web.password="@{jboss.web.password}"
						/>
				</then>
			</if>
			<if>
				<equals arg1="${jboss-sec.major.version}" arg2="5"/>
				<then>
					<echo message="Securing the WEB console for JBoss 5"/>
					<secure-jboss51-console
						jboss.home="@{jboss.home}"
						jboss.server.name="@{jboss.server.name}"
						jboss.web.user="@{jboss.web.user}"
						jboss.web.password="@{jboss.web.password}"
						jboss.ssl.enable="@{jboss.ssl.enable}"
						/>
				</then>
			</if>
		</sequential>
	</macrodef>
	<macrodef name="secure-jboss51-console" description="Diagnose the host system before the installation">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.web.user" default="${jboss.web.user}"/>
		<attribute name="jboss.web.password" default="${jboss.web.password}"/>
		<attribute name="jboss.ssl.enable" default="${jboss.ssl.enable}"/>
		<sequential>
			<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/jboss-web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/jboss-web.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove	path="/jboss-web/security-domain"/>
			</xmltask>
			<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/jboss-web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/jboss-web.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="/jboss-web" position="under">
					<![CDATA[
					 <security-domain>java:/jaas/jmx-console</security-domain>
					]]>
				</insert>
			</xmltask>
			<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/jboss-web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/jboss-web.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove	path="/jboss-web/security-domain"/>
			</xmltask>
			<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/jboss-web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/jboss-web.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="/jboss-web/depends" position="before">
					<![CDATA[
					<security-domain>java:/jaas/web-console</security-domain>
					]]>
				</insert>
			</xmltask>
			<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/web.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove	path="/:web-webapp/:security-constraint"/>
			</xmltask>
			<if>
				<equals arg1="@{jboss.ssl.enable}" arg2="true"/>
				<then>
					<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/web.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="/:web-app/:login-config" position="before">
							<![CDATA[
							<security-constraint>
								<web-resource-collection>
									<web-resource-name>HtmlAdaptor</web-resource-name>
									<description>An example security config that only allows users with the
										role JBossAdmin to access the HTML JMX console web application
									</description>
									<url-pattern>/*</url-pattern>
									<http-method>GET</http-method>
									<http-method>POST</http-method>
								</web-resource-collection>
								<auth-constraint>
									<role-name>JBossAdmin</role-name>
								</auth-constraint>
								<user-data-constraint>
									<transport-guarantee>CONFIDENTIAL</transport-guarantee>
								</user-data-constraint>
							</security-constraint>

							]]>
						</insert>
					</xmltask>
					<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/web.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<remove	path="/web-app/security-constraint"/>
					</xmltask>
					<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/web.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="/web-app/login-config" position="before">
							<![CDATA[
							<security-constraint>
								<web-resource-collection>
									<web-resource-name>HtmlAdaptor</web-resource-name>
									<description>An example security config that only allows users with the
										role JBossAdmin to access the HTML JMX console web application
									</description>
									<url-pattern>/*</url-pattern>
									<http-method>GET</http-method>
									<http-method>POST</http-method>
								</web-resource-collection>
								<auth-constraint>
									<role-name>JBossAdmin</role-name>
								</auth-constraint>
								<user-data-constraint>
									<transport-guarantee>CONFIDENTIAL</transport-guarantee>
								</user-data-constraint>
							</security-constraint>
							]]>
						</insert>
					</xmltask>
					<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/admin-console.war/WEB-INF/web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/admin-console.war/WEB-INF/web.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<remove	path="/:web-webapp/:security-constraint"/>
					</xmltask>
					<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/admin-console.war/WEB-INF/web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/admin-console.war/WEB-INF/web.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="/:web-app/:login-config" position="before">
							<![CDATA[
							<security-constraint>
								<web-resource-collection>
									<web-resource-name>HtmlAdaptor</web-resource-name>
									<description>An example security config that only allows users with the
										role JBossAdmin to access the HTML JMX console web application
									</description>
									<url-pattern>/*</url-pattern>
									<http-method>GET</http-method>
									<http-method>POST</http-method>
								</web-resource-collection>
								<auth-constraint>
									<role-name>JBossAdmin</role-name>
								</auth-constraint>
								<user-data-constraint>
									<transport-guarantee>CONFIDENTIAL</transport-guarantee>
								</user-data-constraint>
							</security-constraint>

							]]>
						</insert>
					</xmltask>
				</then>
				<else>
					<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/web.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="/:web-app/:login-config" position="before">
							<![CDATA[
							<security-constraint>
								<web-resource-collection>
									<web-resource-name>HtmlAdaptor</web-resource-name>
									<description>An example security config that only allows users with the
										role JBossAdmin to access the HTML JMX console web application
									</description>
									<url-pattern>/*</url-pattern>
									<http-method>GET</http-method>
									<http-method>POST</http-method>
								</web-resource-collection>
								<auth-constraint>
									<role-name>JBossAdmin</role-name>
								</auth-constraint>
							</security-constraint>

							]]>
						</insert>
					</xmltask>
					<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/web.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<remove	path="/web-app/security-constraint"/>
					</xmltask>
					<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/web.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="/web-app/login-config" position="before">
							<![CDATA[
							<security-constraint>
								<web-resource-collection>
									<web-resource-name>HtmlAdaptor</web-resource-name>
									<description>An example security config that only allows users with the
										role JBossAdmin to access the HTML JMX console web application
									</description>
									<url-pattern>/*</url-pattern>
									<http-method>GET</http-method>
									<http-method>POST</http-method>
								</web-resource-collection>
								<auth-constraint>
									<role-name>JBossAdmin</role-name>
								</auth-constraint>
							</security-constraint>
							]]>
						</insert>
					</xmltask>
					<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/admin-console.war/WEB-INF/web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/admin-console.war/WEB-INF/web.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<remove	path="/:web-webapp/:security-constraint"/>
					</xmltask>
					<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/admin-console.war/WEB-INF/web.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/admin-console.war/WEB-INF/web.xml">
						<xmlcatalog refid="build.xml.catalog"/>
						<insert path="/:web-app/:login-config" position="before">
							<![CDATA[
							<security-constraint>
								<web-resource-collection>
									<web-resource-name>HtmlAdaptor</web-resource-name>
									<description>An example security config that only allows users with the
										role JBossAdmin to access the HTML JMX console web application
									</description>
									<url-pattern>/*</url-pattern>
									<http-method>GET</http-method>
									<http-method>POST</http-method>
								</web-resource-collection>
								<auth-constraint>
									<role-name>JBossAdmin</role-name>
								</auth-constraint>
							</security-constraint>

							]]>
						</insert>
					</xmltask>
				</else>
			</if>

			<!-- Clean bogus xmlns="" -->
			<echo message="Cleaning bogus xmlns="""/>
			<replaceregexp file="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/web.xml"
				match=" xmlns="""
				replace=""
				flags="g" byline="true"/>
			<replaceregexp file="@{jboss.home}/server/@{jboss.server.name}/deploy/jmx-console.war/WEB-INF/web.xml"
				match=" xmlns="""
				replace=""
				flags="g" byline="true"/>
			<replaceregexp file="@{jboss.home}/server/@{jboss.server.name}/deploy/admin-console.war/WEB-INF/web.xml"
				match=" xmlns="""
				replace=""
				flags="g" byline="true"/>

			<!-- copy in web-console files-->
			<var name="web-console.classes.dir" value="@{jboss.home}/server/@{jboss.server.name}/deploy/management/console-mgr.sar/web-console.war/WEB-INF/classes"/>
			<var name="jboss.props.dir" value="@{jboss.home}/server/@{jboss.server.name}/conf/props"/>
			<if>
				<not>
					<available file="${jboss.props.dir}/web-console-users.properties"/>
				</not>
				<then>
					<copy todir="${jboss.props.dir}">
						<fileset dir="${web-console.classes.dir}">
							<include name="web-console-*.properties"/>
						</fileset>
					</copy>
				</then>
			</if>

			<!-- fix reference to web.xml files -->
			<var name="login-config.xml" value="@{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml"/>
			<echo message="Updating ${login-config.xml}"/>

			<replaceregexp file="${login-config.xml}"
				match="web-console-"
				replace="props\/web-console-"
				flags="g" byline="true"/>

			<!-- Cleanup users -->
			<var name="file.user.pass.list" value="@{jboss.home}/server/@{jboss.server.name}/conf/props/jmx-console-users.properties::@{jboss.web.user}::@{jboss.web.password},@{jboss.home}/server/@{jboss.server.name}/conf/props/web-console-users.properties::@{jboss.web.user}::@{jboss.web.password}"/>
			<for list="${file.user.pass.list}" param="file.user.pass.item">
				<sequential>
					<var name="file.user.pass" value="@{file.user.pass.item}"/>
					<groovy>
						List tempList=properties["file.user.pass"].split("::")
						println tempList
						File userFile = new File(tempList[0])
						String user=tempList[1]
						String pass=tempList[2]
						Boolean matchFound=false
						String writeBuffer=""
						List lines = userFile.readLines()
						lines.each
						{ line ->
						if (line.matches("^"+user+"=.*"))
						{
						matchFound=true
						writeBuffer=writeBuffer + user + "=" + pass + "\n"
						} else
						{
						writeBuffer=writeBuffer + line + "\n"
						}
						}
						if (! matchFound)
						{
						writeBuffer=writeBuffer + user + "=" + pass + "\n"
						}
						println writeBuffer
						userFile.write(writeBuffer)
					</groovy>
				</sequential>
			</for>
			<var name="file.user.list" value="@{jboss.home}/server/@{jboss.server.name}/conf/props/jmx-console-roles.properties::@{jboss.web.user},@{jboss.home}/server/@{jboss.server.name}/conf/props/web-console-roles.properties::@{jboss.web.user}"/>
			<for list="${file.user.list}" param="file.user.item">
				<sequential>
					<var name="file.user" value="@{file.user.item}"/>
					<groovy>
						List tempList=properties["file.user"].split("::")
						println tempList
						File userFile = new File(tempList[0])
						String user=tempList[1]
						Boolean matchFound=false
						String writeBuffer=""
						List lines = userFile.readLines()
						lines.each
						{ line ->
						if (line.matches("^"+user+"=.*"))
						{
						matchFound=true
						writeBuffer=writeBuffer + user + "=JBossAdmin,HttpInvoker\n"
						} else
						{
						writeBuffer=writeBuffer + line + "\n"
						}
						}
						if (! matchFound)
						{
						writeBuffer=writeBuffer + user + "=JBossAdmin,HttpInvoker\n"
						}
						println writeBuffer
						userFile.write(writeBuffer)
					</groovy>
				</sequential>
			</for>
		</sequential>
	</macrodef>
	<macrodef name="jboss51-encrypt-messaging-passwd">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.server.keystore.location" default="@{jboss.home}/keystore/server.keystore"/>
		<attribute name="jboss.server.keystore.pass" default="jboss51pass"/>
		<attribute name="jboss.server.keystore.alias" default="jboss510"/>
		<attribute  name="messaging.sucker.password" default="password"/>
		<sequential>
			<var name="jboss.server.keystore.dir" unset="true"/>
			<dirname file="@{jboss.server.keystore.location}" property="jboss.server.keystore.dir"/>
			<mkdir dir="${jboss.server.keystore.dir}"/>
			<if>
				<not>
					<available file="@{jboss.server.keystore.location}"/>
				</not>
				<then>
					<echo message="@{jboss.server.keystore.location} NOT found, generating."/>
					<var name="keytool.output" unset="true"/>
					<var name="keytool.error" unset="true"/>
					<var name="keytool.result" unset="true"/>
					<var name="passwordtool.file" value="@{jboss.home}/bin/password_tool.sh"/>
					<var name="mess.pass" value="@{messaging.sucker.password}"/>
					<var name="keystore.location" value="@{jboss.server.keystore.location}"/>
					<var name="keystore.alias" value="@{jboss.server.keystore.alias}"/>
					<var name="keystore.pass" value="@{jboss.server.keystore.pass}"/>
					<exec executable="keytool" outputproperty="keytool.output" errorproperty="keytool.error" resultproperty="keytool.result">
						<arg line="-genkey -alias ${keystore.alias} -keyalg RSA -dname "CN=NCI Computer Services,OU=NCICB,O=National Cancer Institute,L=Rockville,ST=Maryland,C=US" -keystore ${keystore.location} -storepass ${keystore.pass} -validity 3650"/>
					</exec>
					<if>
						<not>
							<equals arg1="${keytool.result}" arg2="0"/>
						</not>
						<then>
							<fail message="keytool failed - ${keytool.output} ${keytool.error}"/>
						</then>
					</if>
					<!-- removed from above -keypass $PASSWORD$ -->
					<groovy>
						import expectj.*
						// Create a new ExpectJ object with a timeout of 5s
						ExpectJ expectinator = new ExpectJ(15);
						// Fork the process
						Spawn shell = expectinator.spawn(properties["passwordtool.file"]);
						// Talk to it
						shell.send("0\n");
						shell.expect("Enter Keystore password");
						shell.send(properties["keystore.pass"] + "\n");
						shell.expect("Enter Salt");
						shell.send("allyourbasebelongtous\n");
						shell.expect("Enter Iterator Count");
						shell.send("1234\n");
						shell.expect("5:Exit");
						shell.send("1\n");
						shell.expect("Enter Keystore location including the file name");
						shell.send(properties["keystore.location"] + "\n");
						shell.expect("Enter Keystore alias");
						shell.send(properties["keystore.alias"] + "\n");
						shell.expect("5:Exit");
						shell.send("2\n");
						shell.expect("Enter security domain");
						shell.send("messaging\n");
						shell.expect("Enter passwd");
						shell.send(properties["mess.pass"] + "\n");
						shell.expect("5:Exit");
						shell.send("5\n");

						//shell.expect("");
						//shell.send(properties[""] + "\n");
						// Done!
					</groovy>
				</then>
				<else>
					<echo message="@{jboss.server.keystore.location} found."/>
				</else>
			</if>
			<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/messaging/messaging-jboss-beans.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/messaging/messaging-jboss-beans.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove	path="/:deployment/:bean[@name='SecurityStore']/:annotation[2]"/>
			</xmltask>
			<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/deploy/messaging/messaging-jboss-beans.xml" dest="@{jboss.home}/server/@{jboss.server.name}/deploy/messaging/messaging-jboss-beans.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="/:deployment/:bean[@name='SecurityStore']/:annotation[1]" position="after">
					<![CDATA[
					<annotation>@org.jboss.security.integration.password.Password(securityDomain="messaging",methodName="setSuckerPassword")</annotation>
					]]>
				</insert>
			</xmltask>
			<!-- Clean bogus xmlns="" -->
			<replaceregexp file="@{jboss.home}/server/@{jboss.server.name}/deploy/messaging/messaging-jboss-beans.xml"
				match="xmlns="""
				replace=""
				flags="g" byline="true"/>
		</sequential>
	</macrodef>
	<macrodef name="jboss51-nci-filter">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.init.file.location" default="@{jboss.home}/bin/init.conf"/>
		<attribute name="project.name" default="${project.name}"/>
		<attribute name="application.base.path" default="${application.base.path}"/>
		<attribute name="jboss.server.port" default="${jboss.server.port}"/>
		<attribute name="jboss.server.jndi.port" default="${jboss.server.jndi.port}"/>
		<attribute name="jboss.start.file.location" default="@{jboss.home}/bin/start_jboss"/>
		<attribute name="jboss.server.ports.name" default="${jboss.server.ports.name}"/>
		<sequential>
			<var name="jboss.version.name" unset="true"/>
			<copy file="@{jboss.init.file.location}" tofile="@{jboss.init.file.location}.orig"/>
			<basename file="@{jboss.home}" property="jboss.version.name"/>
			<replaceregexp file="@{jboss.init.file.location}"
				byline="true"
				match="(APPSRV_HOME)=.*"
				replace="\1=@{application.base.path}"
				/>
			<replaceregexp file="@{jboss.init.file.location}"
				byline="true"
				match="(PROJECT)=.*"
				replace="\1=@{project.name}"
				/>
			<replaceregexp file="@{jboss.init.file.location}"
				byline="true"
				match="(JBOSS_HOME)=.*"
				replace="\1=@{jboss.home}"
				/>
			<replaceregexp file="@{jboss.init.file.location}"
				byline="true"
				match="(JBOSS_USER)=.*"
				replace="\1=${env.LOGNAME}"
				/>
			<replaceregexp file="@{jboss.init.file.location}"
				byline="true"
				match="(JBOSS_CONF_BASE)=.*"
				replace="\1=@{jboss.server.name}"
				/>
			<replaceregexp file="@{jboss.init.file.location}"
				byline="true"
				match="(JAVA_HOME)=.*"
				replace="\1=${env.JAVA_HOME}"
				/>
			<replaceregexp file="@{jboss.init.file.location}"
				byline="true"
				match="(JNDI_PORT)=.*"
				replace="\1=@{jboss.server.jndi.port}"
				/>
			<replaceregexp file="@{jboss.init.file.location}"
				byline="true"
				match="(JBOSS_INST)=.*"
				replace="\1=${jboss.version.name}"
				/>
			<replaceregexp file="@{jboss.init.file.location}"
				byline="true"
				match="(JBOSS_JNDI_PORT)=.*"
				replace="\1=@{jboss.server.jndi.port}"
				/>
			<replaceregexp file="@{jboss.init.file.location}"
				byline="true"
				match="(JBOSS_HTTP_PORT)=.*"
				replace="\1=@{jboss.server.port}"
				/>
			<!--
			<replaceregexp file="@{jboss.init.file.location}"
				byline="true"
				match=""
				replace=""
				/>
			-->
			<copy file="@{jboss.start.file.location}" tofile="@{jboss.start.file.location}.orig"/>
			<replaceregexp file="@{jboss.start.file.location}"
				byline="true"
				match="ports-\$\{JBOSS_HTTP_PORT\}"
				replace="@{jboss.server.ports.name}"
				/>
			<chmod file="@{jboss.start.file.location}" perm="ugo+rx"/>
		</sequential>
	</macrodef>
	<macrodef name="ivy-retrieve">
		<attribute name="software.dir" default="${software.dir}"/>
		<attribute name="ivy.dir" default="${build-utils.resource.dir}/ivy"/>
		<attribute name="ivy.settings.file" default="@{ivy.dir}/cbiit-ivy-settings-with-cagrid12.xml"/>
		<attribute name="project.name" default="${project.name}"/>
		<attribute name="project.ivy.conf" default="rutime"/>
		<attribute name="project.lib.dir" default="${lib.dir}/@{project.name}"/>
		<attribute name="project.org"/>
		<attribute name="project.version"/>
		<attribute name="lib.dir" default="${lib.dir}"/>
		<sequential>
			<ant inheritAll="false" inheritRefs="false" antfile="project-download.xml" target="project-download" dir="@{ivy.dir}">
				<property name="software.dir" location="@{software.dir}" />
				<property name="ivy.settings.file" location="@{ivy.settings.file}"/>
				<property name="project.ivy.conf" value="@{project.ivy.conf}"/>
				<property name="project.lib.dir" location="@{project.lib.dir}"/>
				<property name="project.org" value="@{project.org}"/>
				<property name="project.name" value="@{project.name}"/>
				<property name="project.version" value="@{project.version}"/>
				<property name="ivy.dep.dir" value="@{ivy.dir}"/>
				<property name="lib.dir" location="@{lib.dir}"/>
			</ant>
		</sequential>
	</macrodef>
	<macrodef name="ivy-retrieve-cgmm">
		<attribute name="project.lib.dir.base" default="${lib.dir}"/>
		<attribute name="project.version" default="0.7.0"/>
		<attribute name="ivy.dir" default="${build-utils.resource.dir}/ivy"/>
		<attribute name="ivy.settings.file" default="@{ivy.dir}/cbiit-ivy-settings-with-cagrid13.xml"/>
		<attribute name="lib.dir" default="${lib.dir}"/>
		<sequential>
			<ivy-retrieve
				software.dir="${software.dir}"
				ivy.dir="@{ivy.dir}"
				ivy.settings.file="@{ivy.settings.file}"
				project.name="cgmm"
				project.ivy.conf="cgmm-api"
				project.lib.dir="@{project.lib.dir.base}/cgmm"
				project.org="gov.nih.nci.security"
				project.version="@{project.version}"
				lib.dir="@{lib.dir}"
				/>
			<ivy-retrieve
				software.dir="${software.dir}"
				ivy.dir="@{ivy.dir}"
				ivy.settings.file="@{ivy.settings.file}"
				project.name="cgmm"
				project.ivy.conf="runtime"
				project.lib.dir="@{project.lib.dir.base}/jbossweb-tomcat55-sar-jars"
				project.org="gov.nih.nci.security"
				project.version="@{project.version}"
				lib.dir="@{lib.dir}"
				/>
			<ivy-retrieve
				software.dir="${software.dir}"
				ivy.dir="@{ivy.dir}"
				ivy.settings.file="@{ivy.settings.file}"
				project.name="cgmm"
				project.ivy.conf="jboss-default-lib"
				project.lib.dir="@{project.lib.dir.base}/jboss-default-lib"
				project.org="gov.nih.nci.security"
				project.version="@{project.version}"
				lib.dir="@{lib.dir}"
				/>
		</sequential>
	</macrodef>
	<macrodef name="jboss-configure-cgmm">
		<attribute name="jboss.home" default="${jboss.home}"/>
		<attribute name="jboss.server.name" default="${jboss.server.name}"/>
		<attribute name="jboss.tomcat.dir" default="@{jboss.home}/server/@{jboss.server.name}/deploy/jbossweb-tomcat55.sar"/>
		<attribute name="jboss.lib.dir" default="@{jboss.home}/server/@{jboss.server.name}/lib"/>
		<attribute name="cgmm.conf.dest.dir" default="@{jboss.home}/server/@{jboss.server.name}/cgmm_config"/>
		<attribute name="cgmm.conf.src.dir" default="${jboss-conf.dir.dest}/cgmm"/>
		<attribute name="cgmm.jars.base.dir" default="${basedir}/cgmm-libs"/>
		<attribute name="cgmm.version" default="0.7.0"/>
		<attribute name="cagrid-target.dir" default="${basedir}/cagrid-target"/>
		<attribute name="grid.target" default="${grid.target}"/>
		<attribute name="login-config.policy.file" default="@{cgmm.conf.dest.dir}/login-config.cgmm-block.xml"/>
		<!--
		-->
		<sequential>
			<mkdir dir="@{cgmm.conf.dest.dir}"/>
			<copy todir="@{jboss.tomcat.dir}" overwrite="true">
				<fileset dir="@{cgmm.jars.base.dir}/jbossweb-tomcat55-sar-jars">
					<include name="*.jar"/>
					<exclude name="xerces*.jar"/>
					<exclude name="xalan*.jar"/>
				</fileset>
			</copy>
			<copy file="@{cgmm.jars.base.dir}/cgmm/cgmmapi-@{cgmm.version}.jar" todir="@{jboss.tomcat.dir}" overwrite="true"/>
			<copy file="@{jboss.tomcat.dir}/catalina.jar" tofile="@{jboss.tomcat.dir}/catalina.jar.orig" overwrite="true"/>
			<move file="@{cgmm.jars.base.dir}/jbossweb-tomcat55-sar-jars/catalina-5.0.jar" tofile="@{jboss.tomcat.dir}/catalina.jar"/>
			<copy todir="@{jboss.lib.dir}" overwrite="true">
				<fileset dir="@{cgmm.jars.base.dir}/jboss-default-lib">
					<include name="*.jar"/>
				</fileset>
			</copy>
			<copy todir="@{cgmm.conf.dest.dir}" overwrite="true">
				<fileset dir="@{cgmm.conf.src.dir}">
					<include name="*"/>
				</fileset>
			</copy>
			<if>
				<equals arg1="@{grid.target}" arg2="training-1.3"/>
				<then>
					<echo message="Training grid selected using alternate cgmm-properties.xml."/>
					<copy file="@{cgmm.conf.dest.dir}/cgmm-properties.xml" tofile="@{cgmm.conf.dest.dir}/cgmm-properties.xml-orig" overwrite="true"/>
					<copy file="@{cgmm.conf.dest.dir}/alt-cgmm-properties.xml" tofile="@{cgmm.conf.dest.dir}/cgmm-properties.xml" overwrite="true"/>
				</then>
			</if>
			<copy file="@{cagrid-target.dir}/@{grid.target}/sync-description.xml" todir="@{cgmm.conf.dest.dir}" overwrite="true"/>
			<var name="property.block" value="gov.nih.nci.security.cgmm.syncgts.file=@{cgmm.conf.dest.dir}/sync-description.xml${line.separator}
gov.nih.nci.security.cgmm.properties.file=@{cgmm.conf.dest.dir}/cgmm-properties.xml${line.separator}
gov.nih.nci.security.configFile=@{cgmm.conf.dest.dir}/ApplicationSecurityConfig.xml${line.separator}
gov.nih.nci.security.cgmm.login.config.file=@{cgmm.conf.dest.dir}/cgmm.login.config${line.separator}"/>

			<jboss-update-properties-service
				property.block="${property.block}"
				/>
			<xmltask preservetype="true" source="@{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml"
				dest="@{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<remove path="//policy/application-policy[@name='@{application.context.name}']"/>
			</xmltask>
			<xmltask preservetype="true" failWithoutMatch="true" source="@{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml"
				dest="@{jboss.home}/server/@{jboss.server.name}/conf/login-config.xml">
				<xmlcatalog refid="build.xml.catalog"/>
				<insert path="//policy" file="@{login-config.policy.file}"/>
			</xmltask>
		</sequential>
	</macrodef>
	<macrodef name="set-grid-auth-service">
		<attribute name="grid.target" default="${grid.target}"/>
		<attribute name="grid.auth.service.url.property.name" default="grid.auth.service.url"/>
		<attribute name="grid.auth.service.name.property.name" default="grid.auth.service.name"/>
		<sequential>
			<var name="{grid.auth.service.url.property.name}" unset="true"/>
			<switch value="@{grid.target}">
				<case value="nci_prod-1.3">
					<property name="@{grid.auth.service.url.property.name}" value="https://cagrid-auth.nci.nih.gov:8443/wsrf/services/cagrid/AuthenticationService"/>
					<property name="@{grid.auth.service.name.property.name}" value="nci_prod-1.3-Auth-Svc"/>
				</case>
				<case value="nci_stage-1.3">
					<property name="@{grid.auth.service.url.property.name}" value="https://cagrid-auth-stage.nci.nih.gov:8443/wsrf/services/cagrid/AuthenticationService"/>
					<property name="@{grid.auth.service.name.property.name}" value="nci_stage-1.3-Auth-Svc"/>
				</case>
				<case value="nci_qa-1.3">
					<property name="@{grid.auth.service.url.property.name}" value="https://cagrid-auth-qa.nci.nih.gov:8443/wsrf/services/cagrid/AuthenticationService"/>
					<property name="@{grid.auth.service.name.property.name}" value="nci_qa-1.3-Auth-Svc"/>
				</case>
				<case value="training-1.3">
					<property name="@{grid.auth.service.url.property.name}" value=""/>
					<property name="@{grid.auth.service.name.property.name}" value=""/>
				</case>
				<default>
					<fail message="grid.target=@{grid.target} is an invalid option, please use a valid name (nci_prod-1.3 nci_stage-1.3 nci_qa-1.3 training-1.3)"/>
				</default>
			</switch>
		</sequential>
	</macrodef>
	<macrodef name="migrate-ivy-report">
		<attribute name="groovy.file" default="${build-utils.dir}/resource/groovy/migrateIvy.groovy"/>
		<attribute name="maven.filelist.src" default="https://ncisvn.nci.nih.gov/svn/maven-mirror/trunk/file-list.txt"/>
		<attribute name="maven.filelist.dest" default="${target.dir}/maven-filelist.txt"/>
		<attribute name="cagrid12.filelist.dest" default="${target.dir}/cagrid12-filelist.txt"/>
		<attribute name="cagrid12.filelist.src" default="https://ncisvn.nci.nih.gov/svn/cagrid-repo-copy/trunk/repository-1.2/file-list.txt"/>
		<attribute name="cagrid13.filelist.dest" default="${target.dir}/cagrid13-filelist.txt"/>
		<attribute name="cagrid13.filelist.src" default="https://ncisvn.nci.nih.gov/svn/cagrid-repo-copy/trunk/repository-1.3/file-list.txt"/>
		<attribute name="cbiit-ivy.filelist.dest" default="${target.dir}/cbiit-ivy-filelist.txt"/>
		<attribute name="cbiit-ivy.filelist.src" default="https://ncisvn.nci.nih.gov/svn/cbiit-ivy-repo/trunk/file-list.txt"/>
		<attribute name="ivy.analyze.file" default="${basedir}/ivy.xml"/>
		<attribute name="migrate.out.file" default="${target.dir}/migration-ivy.out"/>
		<sequential>
			<get src="@{maven.filelist.src}" dest="@{maven.filelist.dest}" usetimestamp="true"/>
			<get src="@{cbiit-ivy.filelist.src}" dest="@{cbiit-ivy.filelist.dest}" usetimestamp="true"/>
			<get src="@{cagrid12.filelist.src}" dest="@{cagrid12.filelist.dest}" usetimestamp="true"/>
			<get src="@{cagrid13.filelist.src}" dest="@{cagrid13.filelist.dest}" usetimestamp="true"/>
			<echo message="Executing @{groovy.file}"/>
			<groovy src="@{groovy.file}">
				<arg line="@{maven.filelist.dest} @{cagrid12.filelist.dest} @{cagrid13.filelist.dest} @{cbiit-ivy.filelist.dest} @{ivy.analyze.file} @{migrate.out.file}"/>
			</groovy>
		</sequential>
	</macrodef>
	<macrodef name="tomcat-nci-customizations">
		<attribute name="application.base.path" default="${application.base.path}"/>
		<attribute name="tomcat.home" default="${tomcat.home}"/>
		<attribute name="tomcat.port.http.property.name" default="tomcat.port.http"/>
		<attribute name="tomcat.port.ajp.property.name" default="tomcat.port.ajp"/>
		<attribute name="tomcat.port.ssl.property.name" default="tomcat.port.ssl"/>
		<attribute name="tomcat.port.shutdown.property.name" default="tomcat.port.shutdown"/>
		<attribute name="tomcat.ncicb-standard.port-config" default="${tomcat.ncicb-standard.port-config}"/>
		<attribute name="tomcat.server.ports.name" default="${tomcat.server.ports.name}"/>
		<attribute name="project.name" default="${project.name}"/>
		<attribute name="java.home" default="${env.JAVA_HOME}"/>
		<attribute name="logname" default="${env.LOGNAME}"/>
		<sequential>
			<var name="is.tomcat-nci.distribution" unset="true"/>
			<propertyregex property="is.tomcat-nci.distribution"
				input="@{tomcat.home}"
				regexp=".*nci$"
				select="true"
				/>
			<if>
				<isset property="is.tomcat-nci.distribution"/>
				<then>
					<echo message="This is a NCI distribution of tomcat, starting customizations."/>
					<replaceregexp file="@{tomcat.home}/bin/init.conf" byline="true"
						match="(APPSRV_HOME=).*"
						replace="\1@{application.base.path}"
						flags="g"
						/>
					<replaceregexp file="@{tomcat.home}/bin/init.conf" byline="true"
						match="(CATALINA_HOME=).*"
						replace="\1@{tomcat.home}"
						flags="g"
						/>
					<replaceregexp file="@{tomcat.home}/bin/init.conf" byline="true"
						match="(CATALINA_USER=).*"
						replace="\1@{logname}"
						flags="g"
						/>
					<replaceregexp file="@{tomcat.home}/bin/init.conf" byline="true"
						match="(JAVA_HOME=).*"
						replace="\1${java.home}"
						flags="g"
						/>
					<replaceregexp file="@{tomcat.home}/bin/init.conf" byline="true"
						match="(CATALINA_PROJECT=).*"
						replace="\1"
						flags="g"
						/>
					<var name="flist" unset="true"/>
					<property name="flist" value="startup.sh,shutdown.sh"/>
					<for list="${flist}" param="file">
						<sequential>
							<replaceregexp file="@{tomcat.home}/bin/@{file}" byline="true"
								match="(.*PRG="\$0".*)"
								replace="#### Begin NCI Customization${line.separator}DIRNAME=`dirname $0`${line.separator}INIT_CONF="$DIRNAME/init.conf"${line.separator}if [ -r "$INIT_CONF" ]; then${line.separator}. "$INIT_CONF"${line.separator}else${line.separator}echo "${PROGNAME}: Missing init.conf! exiting..."${line.separator}exit 1${line.separator}fi${line.separator}#### End NCI customization${line.separator}\1"
								/>
						</sequential>
					</for>
					<if>
						<equals arg1="@{tomcat.ncicb-standard.port-config}" arg2="true"/>
						<then>
							<echo message="tomcat.ncicb-standard.port-config is set to true overriding values for tomcat.port.(http|ajp|ssl|shutdown)"/>
							<properties-print
								properties.list="@{tomcat.port.http.property.name},@{tomcat.port.ajp.property.name},@{tomcat.port.ssl.property.name},@{tomcat.port.shutdown.property.name}"
								/>
							<switch value="@{tomcat.server.ports.name}">
								<case value="8080">
									<var name="@{tomcat.port.http.property.name}" unset="true"/>
									<var name="@{tomcat.port.ajp.property.name}" unset="true"/>
									<var name="@{tomcat.port.ssl.property.name}" unset="true"/>
									<var name="@{tomcat.port.shutdown.property.name}" unset="true"/>
									<property name="@{tomcat.port.http.property.name}" value="8080"/>
									<property name="@{tomcat.port.ajp.property.name}" value="8009"/>
									<property name="@{tomcat.port.ssl.property.name}" value="8443"/>
									<property name="@{tomcat.port.shutdown.property.name}" value="8005"/>
									<echo message="Tomcat Ports overriden to following values"/>
									<properties-print
										properties.list="@{tomcat.port.http.property.name},@{tomcat.port.ajp.property.name},@{tomcat.port.ssl.property.name},@{tomcat.port.shutdown.property.name}"
										/>
								</case>
								<case value="18080">
									<var name="@{tomcat.port.http.property.name}" unset="true"/>
									<var name="@{tomcat.port.ajp.property.name}" unset="true"/>
									<var name="@{tomcat.port.ssl.property.name}" unset="true"/>
									<var name="@{tomcat.port.shutdown.property.name}" unset="true"/>
									<property name="@{tomcat.port.http.property.name}" value="18080"/>
									<property name="@{tomcat.port.ajp.property.name}" value="18009"/>
									<property name="@{tomcat.port.ssl.property.name}" value="18443"/>
									<property name="@{tomcat.port.shutdown.property.name}" value="18005"/>
									<echo message="Tomcat Ports overriden to following values"/>
									<properties-print
										properties.list="@{tomcat.port.http.property.name},@{tomcat.port.ajp.property.name},@{tomcat.port.ssl.property.name},@{tomcat.port.shutdown.property.name}"
										/>
								</case>
								<case value="28080">
									<var name="@{tomcat.port.http.property.name}" unset="true"/>
									<var name="@{tomcat.port.ajp.property.name}" unset="true"/>
									<var name="@{tomcat.port.ssl.property.name}" unset="true"/>
									<var name="@{tomcat.port.shutdown.property.name}" unset="true"/>
									<property name="@{tomcat.port.http.property.name}" value="28080"/>
									<property name="@{tomcat.port.ajp.property.name}" value="28009"/>
									<property name="@{tomcat.port.ssl.property.name}" value="28443"/>
									<property name="@{tomcat.port.shutdown.property.name}" value="28005"/>
									<echo message="Tomcat Ports overriden to following values"/>
									<properties-print
										properties.list="@{tomcat.port.http.property.name},@{tomcat.port.ajp.property.name},@{tomcat.port.ssl.property.name},@{tomcat.port.shutdown.property.name}"
										/>
								</case>
								<case value="38080">
									<var name="@{tomcat.port.http.property.name}" unset="true"/>
									<var name="@{tomcat.port.ajp.property.name}" unset="true"/>
									<var name="@{tomcat.port.ssl.property.name}" unset="true"/>
									<var name="@{tomcat.port.shutdown.property.name}" unset="true"/>
									<property name="@{tomcat.port.http.property.name}" value="38080"/>
									<property name="@{tomcat.port.ajp.property.name}" value="38009"/>
									<property name="@{tomcat.port.ssl.property.name}" value="38443"/>
									<property name="@{tomcat.port.shutdown.property.name}" value="38005"/>
									<echo message="Tomcat Ports overriden to following values"/>
									<properties-print
										properties.list="@{tomcat.port.http.property.name},@{tomcat.port.ajp.property.name},@{tomcat.port.ssl.property.name},@{tomcat.port.shutdown.property.name}"
										/>
								</case>
								<case value="48080">
									<var name="@{tomcat.port.http.property.name}" unset="true"/>
									<var name="@{tomcat.port.ajp.property.name}" unset="true"/>
									<var name="@{tomcat.port.ssl.property.name}" unset="true"/>
									<var name="@{tomcat.port.shutdown.property.name}" unset="true"/>
									<property name="@{tomcat.port.http.property.name}" value="48080"/>
									<property name="@{tomcat.port.ajp.property.name}" value="48009"/>
									<property name="@{tomcat.port.ssl.property.name}" value="48443"/>
									<property name="@{tomcat.port.shutdown.property.name}" value="48005"/>
									<echo message="Tomcat Ports overriden to following values"/>
									<properties-print
										properties.list="@{tomcat.port.http.property.name},@{tomcat.port.ajp.property.name},@{tomcat.port.ssl.property.name},@{tomcat.port.shutdown.property.name}"
										/>
								</case>
								<case value="58080">
									<var name="@{tomcat.port.http.property.name}" unset="true"/>
									<var name="@{tomcat.port.ajp.property.name}" unset="true"/>
									<var name="@{tomcat.port.ssl.property.name}" unset="true"/>
									<var name="@{tomcat.port.shutdown.property.name}" unset="true"/>
									<property name="@{tomcat.port.http.property.name}" value="58080"/>
									<property name="@{tomcat.port.ajp.property.name}" value="58009"/>
									<property name="@{tomcat.port.ssl.property.name}" value="58443"/>
									<property name="@{tomcat.port.shutdown.property.name}" value="58005"/>
									<echo message="Tomcat Ports overriden to following values"/>
									<properties-print
										properties.list="@{tomcat.port.http.property.name},@{tomcat.port.ajp.property.name},@{tomcat.port.ssl.property.name},@{tomcat.port.shutdown.property.name}"
										/>
								</case>
								<default>
									<fail message="tomcat.server.ports.name not set to a valid value (8080,18080,28080,38080,48080,58080)"/>
								</default>
							</switch>
						</then>
						<else>
							<echo message="tomcat.ncicb-standard.port-config is not set using set propery values"/>

						</else>
					</if>

				</then>
				<else>
					<echo message="This does not appear to be a NCI distribution of tomcat, skipping customizations."/>
				</else>
			</if>
		</sequential>
	</macrodef>
</project>

redpajama_set_name: RedPajamaGithub