Index: main/trunk/greenstone3/build.properties.svn
===================================================================
--- main/trunk/greenstone3/build.properties.svn	(revision 32333)
+++ main/trunk/greenstone3/build.properties.svn	(revision 32334)
@@ -11,6 +11,6 @@
 # but not remotely
 tomcat.server=localhost
-# The port number that tomcat is/will be run on
-tomcat.port=8383
+tomcat.http.port=8383
+tomcat.https.port=8443
 # Tomcat's shutdown port - this may need to be changed if you are running two or more Tomcats
 tomcat.shutdown.port=8305
@@ -161,2 +161,9 @@
 ##listing and description of all the web services deployable on GS3##
 web.services.list=${base.webservice.name} for Greenstone3's core web services, QBR${base.webservice.name} for Query, Browse and Retrieve services
+
+## ------------------------------------------------------ ##
+## Do not modify any properties that appear after this
+## as they are automatically generated.
+## ------------------------------------------------------ ##
+
+## The port number that tomcat is/will run on by default (i.e. for the default server.protocol value set)
Index: main/trunk/greenstone3/build.xml
===================================================================
--- main/trunk/greenstone3/build.xml	(revision 32333)
+++ main/trunk/greenstone3/build.xml	(revision 32334)
@@ -100,4 +100,78 @@
   <if><bool><available file="${user.home}/build.properties"/></bool>
     <property file="${user.home}/build.properties"/>
+  </if>
+
+
+  <!-- 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
+       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
+       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>
+    <bool><not><isset property="internal.tomcat.port"/></not></bool>-->
+    <if>
+      <bool>
+	<not>
+	  <or>
+	    <and>
+	      <equals arg1="${server.protocol}" arg2="http" trim="true" casesensitive="false" forcestring="true"/>	      
+	      <isset property="tomcat.http.port"/>	      
+	      <matches string="${tomcat.http.port}" pattern="^\d{3,4}\s*$"/>
+	    </and>
+	    <and>
+	      <equals arg1="${server.protocol}" arg2="https" trim="true" casesensitive="false" forcestring="true"/>	      
+	      <isset property="tomcat.https.port"/>
+	      <matches string="${tomcat.https.port}" pattern="^\d{3,4}\s*$"/>
+	    </and>
+	  </or>
+	</not>
+      </bool>
+      <fail>ERROR: Unable to set tomcat.port.
+      In file build.properties server.protocol=${server.protocol} and requires at minimum that its
+      matching tomcat.${server.protocol}.port property line be set and is assigned a valid port number.
+      (Ensure any other enabled tomcat port is valid too)</fail>
+      <!--<echo>Uncomment at least the tomcat.${server.protocol}.port line in build.properties.</echo>-->
+      <!--<property name="internal.tomcat.port" value=""/>-->      
+      <else>
+	<condition property="internal.tomcat.port" value="${tomcat.https.port}" else="${tomcat.http.port}">
+	  <equals arg1="${server.protocol}" arg2="https" trim="true" casesensitive="false" forcestring="true"/>
+	</condition>
+      </else>
+    </if>
+  <!--</if>-->
+
+  <!-- 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
+       and written out to build.properties as tomcat.port.
+       Internally, this file still uses internal.tomcat.port as any old value
+       read in from build.properties for tomcat.port can't be changed in memory
+       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>
 
@@ -851,9 +925,9 @@
 
   <target name="get-default-servlet-url">
-    <echo>${server.protocol}://${tomcat.server}:${tomcat.port}${app.path}${server.default.servlet}</echo>
+    <echo>${server.protocol}://${tomcat.server}:${internal.tomcat.port}${app.path}${server.default.servlet}</echo>
   </target>
 
   <target name="get-solr-servlet-url">
-    <echo>${server.protocol}://${tomcat.server}:${tomcat.port}/${solr.context}</echo>
+    <echo>${server.protocol}://${tomcat.server}:${internal.tomcat.port}/${solr.context}</echo>
   </target>
 
@@ -945,7 +1019,7 @@
     </if>
     <if><bool><isset property="install.flax"/></bool>
-        <property name="url" value="${server.protocol}://${tomcat.server}:${tomcat.port}${app.path}/flax"/>
+        <property name="url" value="${server.protocol}://${tomcat.server}:${internal.tomcat.port}${app.path}/flax"/>
     <else>
-        <property name="url" value="${server.protocol}://${tomcat.server}:${tomcat.port}${app.path}/"/>
+        <property name="url" value="${server.protocol}://${tomcat.server}:${internal.tomcat.port}${app.path}/"/>
     </else>
     </if>
@@ -1000,6 +1074,9 @@
   <target name="accept-properties" unless="properties.accepted">
     <input addproperty="properties.ok" validargs="y,n">The following properties (among others) are being used from a build.properties file found in this directory:
+      server.protocol=${server.protocol}
       tomcat.server=${tomcat.server}
-      tomcat.port=${tomcat.port} 
+      <!--tomcat.port=${internal.tomcat.port}-->
+      tomcat.http.port=${tomcat.http.port}
+      tomcat.https.port=${tomcat.https.port}
       tomcat.installed.path=${tomcat.installed.path} (this is the location of Tomcat's base dir if it is already installed)
       proxy.host=${proxy.host}
@@ -1014,4 +1091,15 @@
   </target>
   
+  <!-- Need to list this first in depends for any target that will be using internal.tomcat.port -->
+  <target name="tomcat-init">
+    <if>
+      <bool><not><isset property="internal.tomcat.port"/></not></bool>
+      <fail>ERROR: no tomcat port, so tomcat operations won't proceed.
+      tomcat.${server.protocol}.port is not set or not valid.
+      Correct this in build.properties.</fail>
+    </if>
+  </target>
+
+
   <!-- this sets up some initial properties -->
   <target name="init">
@@ -1038,5 +1126,5 @@
     </condition>
     
-    <echo>tomcat.port = ${tomcat.port}</echo>
+    <echo>internal.tomcat.port = ${internal.tomcat.port}</echo>
 
     <condition property="proxy.present">
@@ -1327,5 +1415,5 @@
   </target>
 
-  <target name="configure-web" depends="init,perl-for-building"
+  <target name="configure-web" depends="tomcat-init,init,perl-for-building"
     description="Configure only the web app config files">
     <!-- we want a unix path in the global.properties file -->
@@ -1347,6 +1435,9 @@
     <filter token="gsdl3writablehome" value="${src.gsdl3.writablehome.unix}"/>
     <filter token="gsdl3version" value="${app.version}"/>
+    <filter token="server.protocol" value="${server.protocol}"/>
     <filter token="tomcat.server" value="${tomcat.server}"/>
-    <filter token="tomcat.port" value="${tomcat.port}"/>
+    <filter token="tomcat.port" value="${internal.tomcat.port}"/>
+    <filter token="tomcat.http.port" value="${tomcat.http.port}"/>
+    <filter token="tomcat.https.port" value="${tomcat.https.port}"/>
     <filter token="greenstone.context" value="${greenstone.context}"/>
     <filter token="derbyserver" value="${derby.server}"/>
@@ -1494,10 +1585,10 @@
   <target name="configure-tomcat" depends="init,configure-tomcat-local,configure-tomcat-external"/>
   
-  <target name="configure-tomcat-local" depends="init,perl-for-building" if="tomcat.islocal">
+  <target name="configure-tomcat-local" depends="tomcat-init,init,perl-for-building" if="tomcat.islocal">
     <!-- re-setup the server.xml file -->
     <copy file="${basedir}/resources/tomcat/server_tomcat${tomcat.version.major}.xml.in"
 		tofile="${packages.home}/tomcat/conf/server.xml" overwrite="true">
       <filterset>
-        <filter token="port" value="${tomcat.port}"/>
+        <filter token="port" value="${internal.tomcat.port}"/>
         <filter token="shutdown-port" value="${tomcat.shutdown.port}"/>
       </filterset>
@@ -1575,5 +1666,5 @@
        on how to use this with eclipse
     -->
-  <target name="debug-start-tomcat" description="Startup Tomcat for debugger" depends="init" if="tomcat.islocal">
+  <target name="debug-start-tomcat" description="Startup Tomcat for debugger" depends="tomcat-init,init" if="tomcat.islocal">
     <property name="tomcat.classpath" refid="local.tomcat.classpath"/>
     <property name="tomcat.path" refid="local.tomcat.path"/>
@@ -1622,6 +1713,6 @@
     <waitfor maxwait="5" maxwaitunit="second">
       <and>
-        <socket server="${tomcat.server}" port="${tomcat.port}"/>
-        <http url="${server.protocol}://${tomcat.server}:${tomcat.port}${app.path}/index.html"/>
+        <socket server="${tomcat.server}" port="${internal.tomcat.port}"/>
+        <http url="${server.protocol}://${tomcat.server}:${internal.tomcat.port}${app.path}/index.html"/>
       </and>
     </waitfor>
@@ -1632,5 +1723,5 @@
     <if><bool><istrue value="${tomcat.isstarted}"/></bool>
       <echo>**************************************</echo>
-      <echo>A WEB SERVER IS ALREADY RUNNING ON ${server.protocol}://${tomcat.server}:${tomcat.port}. NOT STARTING.</echo>
+      <echo>A WEB SERVER IS ALREADY RUNNING ON ${server.protocol}://${tomcat.server}:${internal.tomcat.port}. NOT STARTING.</echo>
       <echo>**************************************</echo>
       <else>
@@ -1641,5 +1732,5 @@
 
   <!-- Another way: http://ptrthomas.wordpress.com/2006/03/25/how-to-start-and-stop-tomcat-from-ant/ -->
-  <target name="force-start-tomcat" description="Startup only Tomcat" depends="init" if="tomcat.islocal">
+  <target name="force-start-tomcat" description="Startup only Tomcat" depends="tomcat-init,init" if="tomcat.islocal">
 
     <property name="tomcat.classpath" refid="local.tomcat.classpath"/>
@@ -1687,6 +1778,6 @@
     <waitfor maxwait="5" maxwaitunit="second">
       <and>
-        <socket server="${tomcat.server}" port="${tomcat.port}"/>
-        <http url="${server.protocol}://${tomcat.server}:${tomcat.port}${app.path}/index.html"/>
+        <socket server="${tomcat.server}" port="${internal.tomcat.port}"/>
+        <http url="${server.protocol}://${tomcat.server}:${internal.tomcat.port}${app.path}/index.html"/>
       </and>
     </waitfor>
@@ -1695,14 +1786,14 @@
 
   <!--ant task http: http://www.jajakarta.org/ant/ant-1.6.1/docs/ja/manual/api/org/apache/tools/ant/taskdefs/condition/Http.html-->
-  <target name="reconfigure" description="Reconfigure the message router">
+  <target name="reconfigure" description="Reconfigure the message router" depends="tomcat-init">
     <waitfor maxwait="5" maxwaitunit="second">
-      <http url="${server.protocol}://${tomcat.server}:${tomcat.port}${app.path}${server.default.servlet}?a=s&amp;sa=c"/>
+      <http url="${server.protocol}://${tomcat.server}:${internal.tomcat.port}${app.path}${server.default.servlet}?a=s&amp;sa=c"/>
     </waitfor>
   </target>
 
   <!--Command-line args to Ant: http://www.jguru.com/faq/view.jsp?EID=471794-->
-  <target name="reconfigure-collection" description="Reconfigure the collection">
+  <target name="reconfigure-collection" description="Reconfigure the collection" depends="tomcat-init">
     <waitfor maxwait="5" maxwaitunit="second">
-      <http url="${server.protocol}://${tomcat.server}:${tomcat.port}${app.path}${server.default.servlet}?a=s&amp;sa=c&amp;sc=${collection}"/>
+      <http url="${server.protocol}://${tomcat.server}:${internal.tomcat.port}${app.path}${server.default.servlet}?a=s&amp;sa=c&amp;sc=${collection}"/>
     </waitfor>
   </target>
@@ -1735,8 +1826,8 @@
        might still be in use for some moments. We test the URL with the http condition since it's likelier to
        fail sooner if the server has indeed been stopped. -->
-  <target name="check-tomcat-running">
+  <target name="check-tomcat-running" depends="tomcat-init">
     <condition property="tomcat.isrunning">
-      <!--<http url="${server.protocol}://${tomcat.server}:${tomcat.port}${app.path}"/>-->
-      <http url="${server.protocol}://${tomcat.server}:${tomcat.port}"/>
+      <!--<http url="${server.protocol}://${tomcat.server}:${internal.tomcat.port}${app.path}"/>-->
+      <http url="${server.protocol}://${tomcat.server}:${internal.tomcat.port}"/>
     </condition>
   </target>
@@ -1745,5 +1836,5 @@
       <target name="verbose-check-tomcat-running">
       <condition property="tomcat.isrunning" value="true" else="false">
-      <http url="${server.protocol}://${tomcat.server}:${tomcat.port}"/>
+      <http url="${server.protocol}://${tomcat.server}:${internal.tomcat.port}"/>
       </condition>
       <echo>Tomcat is running: ${tomcat.isrunning}</echo>
@@ -1763,7 +1854,7 @@
        both stop and start, both of which need to do tomcat checks. Each property can be set only once during 
        an invocation with ant. So ant restart will need two properties to store each of the tomcat checks -->
-  <target name="check-tomcat-started">
+  <target name="check-tomcat-started" depends="tomcat-init">
     <condition property="tomcat.isstarted">
-      <http url="${server.protocol}://${tomcat.server}:${tomcat.port}"/>
+      <http url="${server.protocol}://${tomcat.server}:${internal.tomcat.port}"/>
     </condition>
   </target>
@@ -1782,5 +1873,5 @@
      <echo>Waiting for the server to shutdown... (${wait.numchecks} seconds max)</echo>
      <waitfor maxwait="${wait.numchecks}" maxwaitunit="second" checkevery="1" checkeveryunit="second" timeoutproperty="tomcat.timedout">
-       <not><socket server="${tomcat.server}" port="${tomcat.port}"/></not>
+       <not><socket server="${tomcat.server}" port="${internal.tomcat.port}"/></not>
      </waitfor>
      
@@ -1790,5 +1881,5 @@
        </bool>
        <property name="tomcat.isrunning" value="true"/>
-       <echo>WARNING: Checked the socket ${wait.numchecks} times, but port ${tomcat.port} is still busy.</echo>
+       <echo>WARNING: Checked the socket ${wait.numchecks} times, but port ${internal.tomcat.port} is still busy.</echo>
        <else>
 	 <echo>Tomcat is stopped.</echo>
@@ -2055,5 +2146,5 @@
   </target>
 
-  <target name="soap-deploy-site" depends="init,get-sitename,get-siteuri,get-webservices,create-deployment-files,deploy-site"
+  <target name="soap-deploy-site" depends="tomcat-init,init,get-sitename,get-siteuri,get-webservices,create-deployment-files,deploy-site"
     description="Deploy a SOAP web service for a local Greenstone site. Tomcat must be running for this to work."/>
     
@@ -2062,5 +2153,5 @@
       <classpath refid="compile.classpath"/>
       <arg value="-l"/>
-      <arg value="${server.protocol}://${tomcat.server}:${tomcat.port}${app.path}/servlet/AxisServlet"/>
+      <arg value="${server.protocol}://${tomcat.server}:${internal.tomcat.port}${app.path}/servlet/AxisServlet"/>
       <arg file="${basedir}/resources/soap/deploy.wsdd"/>
     </java>
@@ -2068,5 +2159,5 @@
   </target>
   
-  <target name="soap-undeploy-site" depends="get-undeploy-service-name"
+  <target name="soap-undeploy-site" depends="tomcat-init,get-undeploy-service-name"
     description="Undeploy a SOAP web service for a local Greenstone site. Tomcat must be running for this to work.">
     <filter token="servicesname" value="${axis.undeploy.servicename}"/>
@@ -2078,5 +2169,5 @@
       <classpath refid="compile.classpath"/>
       <arg value="-l"/>
-      <arg value="${server.protocol}://${tomcat.server}:${tomcat.port}${app.path}/servlet/AxisServlet"/>
+      <arg value="${server.protocol}://${tomcat.server}:${internal.tomcat.port}${app.path}/servlet/AxisServlet"/>
       <arg file="${basedir}/resources/soap/undeploy.wsdd"/>
     </java>
@@ -2086,5 +2177,5 @@
   <!-- this target used to deploy the default web service SOAPServer (base.webservice.name) on the localsite server
   with the default servicename of localsite-->
-  <target name="deploy-localsite" depends="init" 
+  <target name="deploy-localsite" depends="tomcat-init,init" 
     description="Deploy the SOAP server for localsite. Will start and stop Tomcat.">
     <antcall target="force-start-tomcat"/>
@@ -2110,5 +2201,5 @@
   <target name="get-undeploy-service-name" unless="axis.undeploy.servicename">
     <input addproperty="axis.undeploy.servicename" defaultvalue="localsite">Please enter the full name of the service you wish to undeploy.
-To find out which web services you've got deployed, point your browser to ${server.protocol}://${tomcat.server}:${tomcat.port}/greenstone3/services 
+To find out which web services you've got deployed, point your browser to ${server.protocol}://${tomcat.server}:${internal.tomcat.port}/greenstone3/services 
 Or press Enter for undeploying the default:localsite /&gt;</input>
      <echo>Name of service to undeploy: ${axis.undeploy.servicename}</echo>
@@ -3397,5 +3488,5 @@
   </target>
     
-	<target name="run-collection-tests">
+	<target name="run-collection-tests" depends="tomcat-init">
 		<if><bool><not><available file="${basedir}/ext/testing" type="dir"/></not></bool>
 			<fail>The testing extension is not available. This is required to perform the tests. It can be acquired from SVN by running the command "svn co http://svn.greenstone.org/gs3-extensions/testing/trunk/src testing" in the ext directory of your Greenstone 3 installation. </fail>
@@ -3409,5 +3500,5 @@
 				<java classname="org.junit.runner.JUnitCore" fork="true">
 					<arg value="gstests.TestClass"/>
-					<jvmarg value="-DSERVERURL=${server.protocol}://${tomcat.server}:${tomcat.port}${app.path}${server.default.servlet} "/>
+					<jvmarg value="-DSERVERURL=${server.protocol}://${tomcat.server}:${internal.tomcat.port}${app.path}${server.default.servlet} "/>
 					<classpath>
 						<fileset dir="${basedir}/ext/testing/lib/java">
Index: main/trunk/greenstone3/resources/web/global.properties.svn
===================================================================
--- main/trunk/greenstone3/resources/web/global.properties.svn	(revision 32333)
+++ main/trunk/greenstone3/resources/web/global.properties.svn	(revision 32334)
@@ -15,6 +15,9 @@
 
 # tomcat info
+server.protocol=@server.protocol@
 tomcat.server=@tomcat.server@
 tomcat.port=@tomcat.port@
+tomcat.http.port=@tomcat.http.port@
+tomcat.https.port=@tomcat.https.port@
 tomcat.context=@greenstone.context@
 derby.server.port=@derbyserver.port@
Index: main/trunk/greenstone3/src/java/org/greenstone/server/BaseServerSettings.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/server/BaseServerSettings.java	(revision 32333)
+++ main/trunk/greenstone3/src/java/org/greenstone/server/BaseServerSettings.java	(revision 32334)
@@ -52,4 +52,6 @@
         catch(Exception e){
 	    logger.error(e);
+	    System.err.println("Unable to proceed. Port number property " + BaseServer.Property.WEB_PORT + " doesn't exist\nor contains a non-numeric value");
+	    exit(-1);
 	} 
 
Index: main/trunk/greenstone3/src/java/org/greenstone/util/GlobalProperties.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/util/GlobalProperties.java	(revision 32333)
+++ main/trunk/greenstone3/src/java/org/greenstone/util/GlobalProperties.java	(revision 32334)
@@ -153,5 +153,5 @@
 
 			//protocol
-			if (properties.getProperty("tomcat.protocol") == null || properties.getProperty("tomcat.protocol").equals(""))
+			if (properties.getProperty("server.protocol") == null || properties.getProperty("server.protocol").equals(""))
 			{
 				protocolSpecifier = "http://";
@@ -159,11 +159,11 @@
 			else
 			{
-				if (properties.getProperty("tomcat.protocol").endsWith("://"))
-				{
-					protocolSpecifier = properties.getProperty("tomcat.protocol");
+				if (properties.getProperty("server.protocol").endsWith("://"))
+				{
+					protocolSpecifier = properties.getProperty("server.protocol");
 				}
 				else
 				{
-					protocolSpecifier = properties.getProperty("tomcat.protocol") + "://";
+					protocolSpecifier = properties.getProperty("server.protocol") + "://";
 				}
 			}
