Skip to content

Commit

Permalink
ZIGGY-192: Allow for version numbers in ziggyRoot()
Browse files Browse the repository at this point in the history
  • Loading branch information
wohler committed Dec 9, 2022
1 parent 50f8b6f commit a98e294
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit a98e294

Please sign in to comment.