From b4059fb1ffb3f0c0da7695ac9003ccc64473f8e5 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 23 Jan 2017 12:43:53 -0500 Subject: [PATCH] LP#1646166 Hatch properties file Adds ability to pass configuration data to Hatch via a new hatch.properties file. Adds (for now) one new property "data.directory" which overrides the default data storage directory. Signed-off-by: Bill Erickson --- hatch.properties | 7 +++++ src/org/evergreen_ils/hatch/Hatch.java | 34 +++++++++++++++++++++++++ src/org/evergreen_ils/hatch/RequestHandler.java | 19 +++++++++++--- 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 hatch.properties diff --git a/hatch.properties b/hatch.properties new file mode 100644 index 0000000..25f2215 --- /dev/null +++ b/hatch.properties @@ -0,0 +1,7 @@ +# Hatch Properties File + +# Full path to the data storage directory. Defaults to the $HOME/.evergreen/ +# If you change this you may also want to change the +# java.util.logging.FileHandler.pattern property in logging.properties. +#data.directory=/tmp/foo + diff --git a/src/org/evergreen_ils/hatch/Hatch.java b/src/org/evergreen_ils/hatch/Hatch.java index 8773fc6..3a4ea3f 100644 --- a/src/org/evergreen_ils/hatch/Hatch.java +++ b/src/org/evergreen_ils/hatch/Hatch.java @@ -16,6 +16,10 @@ package org.evergreen_ils.hatch; import java.util.Map; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; import java.util.logging.*; import org.json.*; @@ -79,6 +83,8 @@ public class Hatch extends Application { printRequestQueue = new LinkedBlockingQueue(); static final Logger logger = Logger.getLogger("org.evergreen_ils.hatch"); + + private static Properties configProps; /** * Printable region containing a browser. @@ -170,6 +176,34 @@ public class Hatch extends Application { } } + /** + * Read the configuration properties file. + */ + private static void readProps() { + if (configProps != null) return; // already loaded. + configProps = new Properties(); + InputStream input = null; + + try { + input = new FileInputStream("hatch.properties"); + configProps.load(input); + } catch (IOException e) { + logger.warning("Unable to open Hatch properties file: " + e); + } finally { + if (input != null) { + try { input.close(); } catch (Exception e2) {} + } + } + } + + /** + * Get values for configurable properties + */ + public static String getProp(String name) { + readProps(); + return configProps.getProperty(name); + } + /** * Hatch main. diff --git a/src/org/evergreen_ils/hatch/RequestHandler.java b/src/org/evergreen_ils/hatch/RequestHandler.java index f399a1a..400e02c 100644 --- a/src/org/evergreen_ils/hatch/RequestHandler.java +++ b/src/org/evergreen_ils/hatch/RequestHandler.java @@ -38,12 +38,23 @@ public class RequestHandler extends Thread { // Find the profile directory. // The profile directory + origin string represent the base // directory for all file I/O for this session. - if (profileDirectory == null) { // TODO: make configurable - String home = System.getProperty("user.home"); - profileDirectory = new File(home, ".evergreen").getPath(); + if (profileDirectory == null) { + + // first see if a value is set in the properties file. + profileDirectory = Hatch.getProp("data.directory"); + if (profileDirectory == null) { - logger.warning("Unable to set profile directory"); + // otherwise set the directory to the users's home + // directory + .evergreen + String home = System.getProperty("user.home"); + profileDirectory = new File(home, ".evergreen").getPath(); + + if (profileDirectory == null) { + logger.warning("Unable to set profile directory"); + } } + + logger.info("Using data directory: " + profileDirectory); } } -- 2.11.0