svn commit: r1800368 - in /ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start: Config.java load-data.properties rmi.properties start.properties test.properties

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1800368 - in /ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start: Config.java load-data.properties rmi.properties start.properties test.properties

Taher Alkhateeb
Author: taher
Date: Fri Jun 30 10:19:50 2017
New Revision: 1800368

URL: http://svn.apache.org/viewvc?rev=1800368&view=rev
Log:
Improved: Refactor Config.java and properties files
(OFBIZ-9435)

Another round of refactoring in the start component with the following changes:

- Change the default adminKey to "NA" since it is only used in the "start"
  context. Other contexts do not require an admin server (test, load-data)
- Simplify and cleanup the locale creation logic in the constructor and move
  things out to the method with a return value
- Simplify the Timezone creation logic by moving it outside the constructor into
  a small method
- Substantially simplify the determineOfbizPropertiesFileName(..) method by
  reversing the order of condition evaluation (first, load-data, then test, then
  anything else is start)
- Change default locale to be 'en' as the system crashes if not provided.
- Remove all comments from properties files except for start.properties and
  refer to it from the other properties files
- Update the properties files accordingly

Thanks: Jacques Le Roux for review and suggestion to remove the comments from
        properties files

Modified:
    ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java
    ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties
    ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties
    ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties
    ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties

Modified: ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java?rev=1800368&r1=1800367&r2=1800368&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java Fri Jun 30 10:19:50 2017
@@ -54,9 +54,9 @@ public final class Config {
         // set this class fields
         ofbizHome = getOfbizHome(getProperty(props, "ofbiz.home", "."));
         adminAddress = getAdminAddress(getProperty(props, "ofbiz.admin.host", "127.0.0.1"));
-        adminKey = getProperty(props, "ofbiz.admin.key", "so3du5kasd5dn");
+        adminKey = getProperty(props, "ofbiz.admin.key", "NA");
         portOffset = getPortOffsetValue(ofbizCommands, "0");
-        adminPort = getAdminPort(props, 0, portOffset); // see INFRA-6790
+        adminPort = getAdminPort(props, 0, portOffset);
         containerConfig = getAbsolutePath(props, "ofbiz.container.config",
                 "framework/base/config/ofbiz-containers.xml", ofbizHome);
         loaders = Arrays.asList(getProperty(props, "ofbiz.start.loaders", "").split(","));
@@ -71,12 +71,9 @@ public final class Config {
         System.setProperty("java.awt.headless", getProperty(props, "java.awt.headless", "true"));
         System.setProperty("derby.system.home", getProperty(props, "derby.system.home", "runtime/data/derby"));
 
-        // set the default locale
-        setDefaultLocale(getProperty(props, "ofbiz.locale.default", ""));
-
-        // set the default timezone
-        String tzString = props.getProperty("ofbiz.timeZone.default", TimeZone.getDefault().getID());
-        TimeZone.setDefault(TimeZone.getTimeZone(tzString));
+        // set default locale and timezone
+        Locale.setDefault(getDefaultLocale(props, "en"));
+        TimeZone.setDefault(getDefaultTimeZone(props));
     }
 
     private String getProperty(Properties props, String key, String defaultValue) {
@@ -88,8 +85,8 @@ public final class Config {
         return homeProp.equals(".") ? System.getProperty("user.dir").replace('\\', '/') : homeProp;
     }
 
-    private String getAbsolutePath(Properties props, String key, String def, String ofbizHome) {
-        return getProperty(props, key, ofbizHome + "/" + props.getProperty(key, def));
+    private String getAbsolutePath(Properties props, String key, String defaultValue, String ofbizHome) {
+        return getProperty(props, key, ofbizHome + "/" + props.getProperty(key, defaultValue));
     }
 
     private Properties getPropertiesFile(List<StartupCommand> ofbizCommands) throws StartupException {
@@ -108,23 +105,15 @@ public final class Config {
     }
 
     private String determineOfbizPropertiesFileName(List<StartupCommand> ofbizCommands) {
-        String fileName = null;
-        if (ofbizCommands.stream().anyMatch(command ->
-                command.getName().equals(StartupCommandUtil.StartupOption.START.getName())
-                || command.getName().equals(StartupCommandUtil.StartupOption.SHUTDOWN.getName())
-                || command.getName().equals(StartupCommandUtil.StartupOption.STATUS.getName()))
-            || ofbizCommands.isEmpty()
-            || ofbizCommands.stream().allMatch(command ->
-                command.getName().equals(StartupCommandUtil.StartupOption.PORTOFFSET.getName()))) {
-            fileName = "start.properties";
-        } else if(ofbizCommands.stream().anyMatch(
+        if(ofbizCommands.stream().anyMatch(
                 option -> option.getName().equals(StartupCommandUtil.StartupOption.LOAD_DATA.getName()))) {
-            fileName = "load-data.properties";
+            return "load-data.properties";
         } else if(ofbizCommands.stream().anyMatch(
                 option -> option.getName().equals(StartupCommandUtil.StartupOption.TEST.getName()))) {
-            fileName = "test.properties";
+            return "test.properties";
+        } else {
+            return "start.properties";
         }
-        return fileName;
     }
 
     private int getPortOffsetValue(List<StartupCommand> ofbizCommands, String defaultOffset) throws StartupException {
@@ -158,18 +147,27 @@ public final class Config {
         }
     }
 
-    private void setDefaultLocale(String localeString) {
+    private Locale getDefaultLocale(Properties props, String defaultLocale) {
+        String localeString = getProperty(props, "ofbiz.locale.default", defaultLocale);
         String locales[] = localeString.split("_");
+        Locale locale = null;
         switch (locales.length) {
         case 1:
-            Locale.setDefault(new Locale(locales[0]));
+            locale = new Locale(locales[0]);
             break;
         case 2:
-            Locale.setDefault(new Locale(locales[0], locales[1]));
+            locale = new Locale(locales[0], locales[1]);
             break;
         case 3:
-            Locale.setDefault(new Locale(locales[0], locales[1], locales[2]));
+            locale = new Locale(locales[0], locales[1], locales[2]);
+            break;
         }
         System.setProperty("user.language", localeString);
+        return locale;
+    }
+
+    private TimeZone getDefaultTimeZone(Properties props) {
+        String defaultTimezone = getProperty(props, "ofbiz.timeZone.default", TimeZone.getDefault().getID());
+        return TimeZone.getTimeZone(defaultTimezone);
     }
 }

Modified: ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties?rev=1800368&r1=1800367&r2=1800368&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties (original)
+++ ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties Fri Jun 30 10:19:50 2017
@@ -17,46 +17,11 @@
 # under the License.
 ###############################################################################
 
-####################################
+#######################################################################
 # OFBiz Startup Application Settings
-####################################
+# For more information about available properties view start.properties
+#######################################################################
 
-# --- OFBiz startup loaders (comma separated)
 ofbiz.start.loaders=load-data
-
-# --- OFBiz home directory. Default is current directory
-#ofbiz.home=
-
-# --- logs directory relative to ofbiz.home. Default is runtime/logs
-#ofbiz.log.dir=
-
-# --- Derby directory relative to ofbiz.home. Default is runtime/data/derby
-#derby.system.home=
-
-# --- Container config file relative to ofbiz.home.
-#     Default is framework/base/config/ofbiz-containers.xml
-#ofbiz.container.config=
-
-# --- Network host, port and key used by the AdminClient to communicate
-#     with AdminServer for shutting down OFBiz or inquiring on status
-#     Default ofbiz.admin.host 127.0.0.1
-#     Default ofbiz.admin.port 0
-#     Default ofbiz.admin.key so3du5kasd5dn
-#ofbiz.admin.host=
-#ofbiz.admin.port=
-#ofbiz.admin.key=
-
-# -- Enable the JVM shutdown hook. Default is true
 ofbiz.enable.hook=false
-
-# -- Auto-Shutdown after load. Default is false
 ofbiz.auto.shutdown=true
-
-# --- Tells AWT not not require a head (X11). Default is true
-#java.awt.headless=false
-
-# -- The locale for this OFBiz instance. Default depends on JVM environment
-ofbiz.locale.default=en
-
-# -- The time zone for this OFBiz instance. Default depends on JVM environment
-#ofbiz.timeZone.default=GMT

Modified: ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties?rev=1800368&r1=1800367&r2=1800368&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties (original)
+++ ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties Fri Jun 30 10:19:50 2017
@@ -17,46 +17,9 @@
 # under the License.
 ###############################################################################
 
-####################################
+#######################################################################
 # OFBiz Startup Application Settings
-####################################
+# For more information about available properties view start.properties
+#######################################################################
 
-# --- OFBiz startup loaders (comma separated)
 ofbiz.start.loaders=rmi
-
-# --- OFBiz home directory. Default is current directory
-#ofbiz.home=
-
-# --- logs directory relative to ofbiz.home. Default is runtime/logs
-#ofbiz.log.dir=
-
-# --- Derby directory relative to ofbiz.home. Default is runtime/data/derby
-#derby.system.home=
-
-# --- Container config file relative to ofbiz.home.
-#     Default is framework/base/config/ofbiz-containers.xml
-#ofbiz.container.config=
-
-# --- Network host, port and key used by the AdminClient to communicate
-#     with AdminServer for shutting down OFBiz or inquiring on status
-#     Default ofbiz.admin.host 127.0.0.1
-#     Default ofbiz.admin.port 0
-#     Default ofbiz.admin.key so3du5kasd5dn
-#ofbiz.admin.host=
-#ofbiz.admin.port=
-#ofbiz.admin.key=
-
-# -- Enable the JVM shutdown hook. Default is true
-#ofbiz.enable.hook=false
-
-# -- Auto-Shutdown after load. Default is false
-#ofbiz.auto.shutdown=true
-
-# --- Tells AWT not not require a head (X11). Default is true
-#java.awt.headless=false
-
-# -- The locale for this OFBiz instance. Default depends on JVM environment
-#ofbiz.locale.default=en
-
-# -- The time zone for this OFBiz instance. Default depends on JVM environment
-#ofbiz.timeZone.default=GMT

Modified: ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties?rev=1800368&r1=1800367&r2=1800368&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties (original)
+++ ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties Fri Jun 30 10:19:50 2017
@@ -21,7 +21,7 @@
 # OFBiz Startup Application Settings
 ####################################
 
-# --- OFBiz startup loaders (comma separated)
+# --- OFBiz startup loaders comma separated
 ofbiz.start.loaders=main
 
 # --- OFBiz home directory. Default is current directory
@@ -41,10 +41,10 @@ ofbiz.start.loaders=main
 #     with AdminServer for shutting down OFBiz or inquiring on status
 #     Default ofbiz.admin.host 127.0.0.1
 #     Default ofbiz.admin.port 0
-#     Default ofbiz.admin.key so3du5kasd5dn
+#     Default ofbiz.admin.key NA
 #ofbiz.admin.host=
 ofbiz.admin.port=10523
-#ofbiz.admin.key=
+ofbiz.admin.key=so3du5kasd5dn
 
 # -- Enable the JVM shutdown hook. Default is true
 #ofbiz.enable.hook=false
@@ -52,11 +52,11 @@ ofbiz.admin.port=10523
 # -- Auto-Shutdown after load. Default is false
 #ofbiz.auto.shutdown=true
 
-# --- Tells AWT not not require a head (X11). Default is true
+# --- Tells AWT to not require a head (X11). Default is true
 #java.awt.headless=false
 
-# -- The locale for this OFBiz instance. Default depends on JVM environment
-ofbiz.locale.default=en
+# -- The locale for this OFBiz instance. Default is en
+#ofbiz.locale.default=en_US
 
 # -- The time zone for this OFBiz instance. Default depends on JVM environment
 #ofbiz.timeZone.default=GMT

Modified: ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties?rev=1800368&r1=1800367&r2=1800368&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties (original)
+++ ofbiz/ofbiz-framework/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties Fri Jun 30 10:19:50 2017
@@ -17,46 +17,11 @@
 # under the License.
 ###############################################################################
 
-####################################
+#######################################################################
 # OFBiz Startup Application Settings
-####################################
+# For more information about available properties view start.properties
+#######################################################################
 
-# --- OFBiz startup loaders (comma separated)
 ofbiz.start.loaders=test
-
-# --- OFBiz home directory. Default is current directory
-#ofbiz.home=
-
-# --- logs directory relative to ofbiz.home. Default is runtime/logs
-#ofbiz.log.dir=
-
-# --- Derby directory relative to ofbiz.home. Default is runtime/data/derby
-#derby.system.home=
-
-# --- Container config file relative to ofbiz.home.
-#     Default is framework/base/config/ofbiz-containers.xml
-#ofbiz.container.config=
-
-# --- Network host, port and key used by the AdminClient to communicate
-#     with AdminServer for shutting down OFBiz or inquiring on status
-#     Default ofbiz.admin.host 127.0.0.1
-#     Default ofbiz.admin.port 0
-#     Default ofbiz.admin.key so3du5kasd5dn
-#ofbiz.admin.host=
-#ofbiz.admin.port=
-#ofbiz.admin.key=
-
-# -- Enable the JVM shutdown hook. Default is true
 ofbiz.enable.hook=false
-
-# -- Auto-Shutdown after load. Default is false
 ofbiz.auto.shutdown=true
-
-# --- Tells AWT not not require a head (X11). Default is true
-#java.awt.headless=false
-
-# -- The locale for this OFBiz instance. Default depends on JVM environment
-ofbiz.locale.default=en
-
-# -- The time zone for this OFBiz instance. Default depends on JVM environment
-#ofbiz.timeZone.default=GMT