Skip to content

Commit

Permalink
alternative implementation for resolving the sibling
Browse files Browse the repository at this point in the history
  • Loading branch information
rcannood committed Nov 30, 2023
1 parent 6439fd3 commit 0983df4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,14 @@ def _parseParamList(param_list, Map config) {
// The paths of input files inside a param_list file may have been specified relatively to the
// location of the param_list file. These paths must be made absolute.
if (paramListPath) {

// functionality to resolve a single path (as String) relative to the param_list file
// but only if the file does not specify a remote path
def resolveIfNotRemote = { path, parentPath ->
if (path instanceof String && FileHelper.getUrlProtocol(path) == null) {
return parentPath.resolveSibling(path)
}
return path
}

paramSets = paramSets.collect({ id, data ->
def new_data = data.collectEntries{ parName, parValue ->
def par = config.functionality.allArguments.find{it.plainName == parName}
if (par && par.type == "file" && par.direction == "input") {
if (parValue instanceof Collection) {
parValue = parValue.collect{path -> resolveIfNotRemote(path, paramListPath)}
parValue = parValue.collect{path -> _resolveSiblingIfNotAbsolute(path, paramListPath)}
} else {
parValue = resolveIfNotRemote(parValue, paramListPath)
parValue = _resolveSiblingIfNotAbsolute(parValue, paramListPath)
}
}
[parName, parValue]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Resolve a path relative to the current file.
*
* @param str The path to resolve, as a String.
* @param parentPath The path to resolve relative to, as a Path.
*
* @return The path that may have been resovled, as a Path.
*/

def _resolveSiblingIfNotAbsolute(str, parentPath) {
if (str !instanceof String) {
return str
}
strAsPath = file(str, hidden: true, relative: true)
if (!strAsPath.isAbsolute()) {
return parentPath.resolveSibling(str)
}
return strAsPath
}

0 comments on commit 0983df4

Please sign in to comment.