Index: main/trunk/greenstone3/build.xml
===================================================================
--- main/trunk/greenstone3/build.xml	(revision 32338)
+++ main/trunk/greenstone3/build.xml	(revision 32339)
@@ -102,4 +102,12 @@
   </if>
 
+<!-- Use macrodef task from ant 1.6+ to define a macro https://ant.apache.org/manual/Tasks/macrodef.html -->
+<macrodef name="propertycopy">
+  <attribute name="name"/>
+  <attribute name="from"/>
+  <sequential>
+    <property name="@{name}" value="${@{from}}"/>
+  </sequential>
+</macrodef>
 
   <!-- If internal.tomcat.port not yet set, work it out based on server.protocol 
@@ -107,17 +115,6 @@
        https://grokbase.com/t/ant/user/04698xjbp3/nested-variables-in-ant
        http://ant.apache.org/faq.html#propertyvalue-as-name-for-property
-       https://marc.info/?l=ant-user&m=111231719328847
-       http://ant-contrib.sourceforge.net/tasks/tasks/propertycopy.html
-       http://www.jguru.com/faq/view.jsp?EID=1072238
-       * propfile:
-       https://ant.apache.org/manual/Tasks/propertyfile.html
-       * valid ports range from 1024â49151
-       https://stackoverflow.com/questions/113224/what-is-the-largest-tcp-ip-network-port-number-allowable-for-ipv4
-  -->
-
-  <!-- If internal.tomcat.port not yet set, work it out based on server.protocol 
-       Would be great if we could just use nested variables in build.properties
-       https://grokbase.com/t/ant/user/04698xjbp3/nested-variables-in-ant
-       http://ant.apache.org/faq.html#propertyvalue-as-name-for-property
+       http://ant.1045680.n5.nabble.com/Property-expansion-in-macrodef-attributes-td5476406.html
+
        https://marc.info/?l=ant-user&m=111231719328847
        http://ant-contrib.sourceforge.net/tasks/tasks/propertycopy.html
@@ -130,32 +127,53 @@
     <if>
       <bool>
-	<not>
-	  <or>
-	    <and>
-	      <equals arg1="${server.protocol}" arg2="http" trim="true" casesensitive="false" forcestring="true"/>	      
-	      <isset property="tomcat.port.http"/>	      
-	      <matches string="${tomcat.port.http}" pattern="^\d{3,4}\s*$"/>
-	    </and>
-	    <and>
-	      <equals arg1="${server.protocol}" arg2="https" trim="true" casesensitive="false" forcestring="true"/>	      
-	      <isset property="tomcat.port.https"/>
-	      <matches string="${tomcat.port.https}" pattern="^\d{3,4}\s*$"/>
-	    </and>
-	  </or>
-	</not>
+	  <and>
+	    <isset property="tomcat.port.http"/>
+	    <not><matches string="${tomcat.port.http}" pattern="^\d{3,4}\s*$"/></not>
+	  </and>	 
       </bool>
-      <fail>ERROR: Unable to set tomcat.port.
-      In file build.properties server.protocol=${server.protocol} and requires at minimum that its
-      matching tomcat.port.${server.protocol} property line be set and is assigned a valid port number.
-      (Ensure any other enabled tomcat port is valid too)</fail>
-      <else>
-	<condition property="internal.tomcat.port" value="${tomcat.port.https}" else="${tomcat.port.http}">
-	  <equals arg1="${server.protocol}" arg2="https" trim="true" casesensitive="false" forcestring="true"/>
-	</condition>
-	<echo>### tomcat.port.http: ${tomcat.port.http}</echo>
-      </else>
-    </if>
-
-  <!-- Set autogenerated properties (properties we calculate here in build.xml)
+      <fail>...
+	********* ERROR: tomcat.port.http in file build.properties is set to an invalid port number.
+	Valid ports range from 1024â49151. But don't choose any port already in use by another application.
+	Try setting to tomcat.port.http=8383
+      </fail>
+    </if>
+
+    <if>
+      <bool>
+	  <and>
+	    <isset property="tomcat.port.https"/>
+	    <not><matches string="${tomcat.port.https}" pattern="^\d{3,4}\s*$"/></not>
+	  </and>
+      </bool>
+      <fail>...
+	********* ERROR: tomcat.port.https in file build.properties is set to an invalid port number.
+	Valid ports range from 1024â49151. But don't choose any port already in use by another application.
+	Try setting tomcat.port.https=8443
+      </fail>
+    </if>
+
+    <!--
+	Now use the macro to use a propertyvalue (server.protocol) as a part of the name for a property
+	So we want do something like ${tomcat.port.${server.protocol}}, which, if server.protocol=http,
+	we want it to turn into tomcat.port.http. Then we want to use the constructed variable name
+	to assign its value to a new variable. Use as follows:
+	propertycopy name="tomcat.port.protocol" from="tomcat.port.${server.protocol}"
+	http://ant.apache.org/faq.html#propertyvalue-as-name-for-property
+	http://ant.1045680.n5.nabble.com/Property-expansion-in-macrodef-attributes-td5476406.html
+    -->
+    <propertycopy name="internal.tomcat.port" from="tomcat.port.${server.protocol}"/>
+    <if>
+	  <bool><matches string="${internal.tomcat.port}" pattern="tomcat"/></bool>
+	  <fail>...
+	  ********* ERROR: Unable to set tomcat.port:
+	  In file build.properties server.protocol=${server.protocol} and requires at minimum that its
+	  matching tomcat.port.${server.protocol} property line is enabled and set to a valid port number.</fail>
+    </if>
+
+    <echo>### PORT PROTOCOL: ${internal.tomcat.port}</echo>
+
+
+  <!-- If we got here, we got a valid tomcat port. Set tomcat.port in build.properties
+       Set autogenerated properties (properties we calculate here in build.xml)
        in build.properties. https://ant.apache.org/manual/Tasks/propertyfile.html
        For now only internal.tomcat.port is determined by build.xml
@@ -165,10 +183,8 @@
        even though we can write it back out again to build.properties.
   -->
-  <if>
-    <bool><isset property="internal.tomcat.port"/></bool>
-    <propertyfile file="build.properties">
-      <entry key="tomcat.port" value="${internal.tomcat.port}"/>
-    </propertyfile>
-  </if>
+  <propertyfile file="build.properties">
+    <entry key="tomcat.port" value="${internal.tomcat.port}"/>
+  </propertyfile>
+
 
   <!-- now we've read in properties, apply defaults -->
