From f01f2d35d87a061d60bdb8b930526bcf9b619bd5 Mon Sep 17 00:00:00 2001 From: conors_nli <conor.sheehan.2@ucdconnect.ie> Date: Thu, 26 Jul 2018 09:47:07 -0400 Subject: [PATCH] Improve indexer's VUFIND_HOME handling (#1220) --- import-marc.sh | 10 +++++--- .../src/org/vufind/index/ConfigManager.java | 23 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/import-marc.sh b/import-marc.sh index 9569b084c89..82e8d1b26cc 100755 --- a/import-marc.sh +++ b/import-marc.sh @@ -52,7 +52,6 @@ then INDEX_OPTIONS='-Xms512m -Xmx512m -DentityExpansionLimit=0' fi - ################################################## # Set SOLRCORE ################################################## @@ -61,15 +60,20 @@ then EXTRA_SOLRMARC_SETTINGS="$EXTRA_SOLRMARC_SETTINGS -Dsolr.core.name=$SOLRCORE" fi - ################################################## # Set VUFIND_HOME ################################################## if [ -z "$VUFIND_HOME" ] then - VUFIND_HOME="/usr/local/vufind" + # set VUFIND_HOME to the absolute path of the directory containing this script + # https://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself + export VUFIND_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" fi +if [ -z "$VUFIND_LOCAL_DIR" ] +then + echo "WARNING: VUFIND_LOCAL_DIR environment variable is not set. Is this intentional?" +fi ##################################################### # Build java command diff --git a/import/index_java/src/org/vufind/index/ConfigManager.java b/import/index_java/src/org/vufind/index/ConfigManager.java index d9f25087780..454aace2374 100644 --- a/import/index_java/src/org/vufind/index/ConfigManager.java +++ b/import/index_java/src/org/vufind/index/ConfigManager.java @@ -66,14 +66,15 @@ public class ConfigManager * Given the base name of a configuration file, locate the full path. * @param filename base name of a configuration file */ - private File findConfigFile(String filename) + private File findConfigFile(String filename) throws IllegalStateException { // Find VuFind's home directory in the environment; if it's not available, // try using a relative path on the assumption that we are currently in // VuFind's import subdirectory: String vufindHome = System.getenv("VUFIND_HOME"); if (vufindHome == null) { - vufindHome = ".."; + // this shouldn't happen since import-marc.sh and .bat always set VUFIND_HOME + throw new IllegalStateException("VUFIND_HOME must be set"); } // Check for VuFind 2.0's local directory environment variable: @@ -133,11 +134,21 @@ public class ConfigManager // Retrieve the file if it is not already cached. if (!configCache.containsKey(filename)) { Ini ini = new Ini(); + File configFile = null; try { - ini.load(new FileReader(findConfigFile(filename))); - configCache.putIfAbsent(filename, ini); + configFile = findConfigFile(filename); + } catch (IllegalStateException e) { + dieWithError("Illegal State: " + e.getMessage()); } catch (Throwable e) { - dieWithError("Unable to access " + filename); + dieWithError("Unable to locate " + filename); + } + try { + if (configFile != null) { + ini.load(new FileReader(configFile)); + configCache.putIfAbsent(filename, ini); + } + } catch (Throwable e) { + dieWithError("Unable to access " + configFile.getAbsolutePath()); } } return configCache.get(filename); @@ -231,4 +242,4 @@ public class ConfigManager logger.error(msg); throw new SolrMarcIndexerException(SolrMarcIndexerException.EXIT, msg); } -} \ No newline at end of file +} -- GitLab