mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2024-12-24 16:00:09 -06:00
allow atfiles to relativize for ${DIR} patterns
This commit is contained in:
parent
77680f480f
commit
e2d8f332fb
@ -104,6 +104,7 @@ public class NBAtFile {
|
||||
|
||||
filepathSpec=(filepathSpec.endsWith(".yaml") ? filepathSpec : filepathSpec+".yaml");
|
||||
Path atPath = Path.of(filepathSpec);
|
||||
|
||||
String argsdata = "";
|
||||
try {
|
||||
argsdata = Files.readString(atPath);
|
||||
@ -128,13 +129,28 @@ public class NBAtFile {
|
||||
throw new RuntimeException("You can not traverse a non-map object type with spec '" + spec + "'");
|
||||
}
|
||||
}
|
||||
return formatted(scopeOfInclude, fmt);
|
||||
LinkedList<String> formatted = formatted(scopeOfInclude, fmt);
|
||||
formatted=interposePath(formatted, atPath);
|
||||
return formatted;
|
||||
} else {
|
||||
throw new RuntimeException("Unable to match at-file specifier: " + spec + " to pattern '" + includePattern.pattern() + "'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static LinkedList<String> interposePath(LinkedList<String> formatted, Path atPath) {
|
||||
Path parent = (atPath.getNameCount()==1 ? Path.of(".") : atPath.getParent());
|
||||
|
||||
ListIterator<String> iter = formatted.listIterator();
|
||||
while (iter.hasNext()) {
|
||||
String word = iter.next();
|
||||
String modified = word.replaceAll("\\$\\{DIR}",parent.toString());
|
||||
iter.remove();
|
||||
iter.add(modified);
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
|
||||
private static LinkedList<String> formatted(Object scopeOfInclude, NBAtFileFormats fmt) {
|
||||
LinkedList<String> emitted = new LinkedList<>();
|
||||
if (scopeOfInclude instanceof Map<?,?> map) {
|
||||
|
@ -31,6 +31,12 @@ class NBAtFileTest {
|
||||
assertThat(strings).containsExactly("arg1","arg2","arg3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelativizedPaths() {
|
||||
LinkedList<String> strings = NBAtFile.includeAt("@src/test/resources/atfiles/relativized.yaml");
|
||||
assertThat(strings).containsExactly("--option1=src/test/resources/atfiles/value1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseSimpleMapDefaultFmt() {
|
||||
LinkedList<String> strings = NBAtFile.includeAt("@src/test/resources/atfiles/simple_map.yaml");
|
||||
|
1
engine-cli/src/test/resources/atfiles/relativized.yaml
Normal file
1
engine-cli/src/test/resources/atfiles/relativized.yaml
Normal file
@ -0,0 +1 @@
|
||||
- --option1=${DIR}/value1
|
Loading…
Reference in New Issue
Block a user