From a98e2949454ed84cf1da36465dcc92bf2e60d2e3 Mon Sep 17 00:00:00 2001 From: Bill Wohler Date: Thu, 8 Dec 2022 12:34:12 -0800 Subject: [PATCH] ZIGGY-192: Allow for version numbers in ziggyRoot() --- .../services/config/ZiggyConfiguration.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/gov/nasa/ziggy/services/config/ZiggyConfiguration.java b/src/main/java/gov/nasa/ziggy/services/config/ZiggyConfiguration.java index 8d25efc..c4d37c3 100644 --- a/src/main/java/gov/nasa/ziggy/services/config/ZiggyConfiguration.java +++ b/src/main/java/gov/nasa/ziggy/services/config/ZiggyConfiguration.java @@ -143,7 +143,7 @@ private static String getEnvVar(String envVarName) { /** * Locates the pipeline config file via the PIPELINE_CONFIG_PATH environment variable. If no * environment variable is defined, or the file it points to does not exist, the default - * properties file (ziggy/config/ziggy.properties) will be used if it can be found. + * properties file (ziggy/etc/ziggy.properties) will be used if it can be found. */ public static File getConfigServicesFile() { File configServicesFile = null; @@ -154,8 +154,9 @@ public static File getConfigServicesFile() { configServicesFile = new File(configFileEnvValue); } if (configServicesFile == null || !configServicesFile.exists()) { - Path ziggyDefaultConfig = Paths.get(ziggyRoot(), CONFIG_SERVICE_PROPERTIES_DEFAULT_DIR, - CONFIG_SERVICE_PROPERTIES_DEFAULT_FILE); + Path ziggyDefaultConfig = Paths.get( + ziggyRoot(System.getProperty(PropertyNames.CURRENT_DIR_PROP_NAME)), + CONFIG_SERVICE_PROPERTIES_DEFAULT_DIR, CONFIG_SERVICE_PROPERTIES_DEFAULT_FILE); configServicesFile = ziggyDefaultConfig.toFile(); } if (!configServicesFile.exists()) { @@ -165,14 +166,22 @@ public static File getConfigServicesFile() { return configServicesFile; } - public static String ziggyRoot() { - String ziggyRoot = null; - String workingDir = System.getProperty(PropertyNames.CURRENT_DIR_PROP_NAME); - int ziggyLocation = workingDir.lastIndexOf(ZIGGY_RELATIVE_PATH); - if (ziggyLocation > 0) { - ziggyRoot = workingDir.substring(0, ziggyLocation + ZIGGY_RELATIVE_PATH.length()); + public static String ziggyRoot(String directory) { + if (directory == null || directory.isEmpty()) { + return null; + } + + // Does this path appear to contain "ziggy"? + int ziggyLocation = directory.lastIndexOf(ZIGGY_RELATIVE_PATH); + if (ziggyLocation < 0) { + return null; } - return ziggyRoot; + + // Does the path have directories after "ziggy"? + int separatorLocation = directory.indexOf(File.separator, ziggyLocation); + + // If so, remove them. + return separatorLocation > 0 ? directory.substring(0, separatorLocation) : directory; } /**