Skip to content

Commit

Permalink
Fix option parser, now treat only the first colon as delimiter betwee…
Browse files Browse the repository at this point in the history
…n a key and a value (before each colon is treated as delimiter)
  • Loading branch information
silverbullettt committed Dec 18, 2023
1 parent d45ff70 commit 34729ee
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/main/java/pascal/taie/config/PlanConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.StringJoiner;

/**
* Configuration for an analysis to be executed.
Expand Down Expand Up @@ -114,15 +115,12 @@ public static List<PlanConfig> readConfigs(Options options) {
.stream()
.map(entry -> {
String id = entry.getKey();
// Convert option string to a valid YAML string
String opts = entry.getValue()
.replace(';', '\n')
.replace(":", ": ");
String optStr = toYAMLString(entry.getValue());
try {
Map<String, Object> optsMap = opts.isEmpty() ?
Map.of() :
Map<String, Object> optsMap = optStr.isBlank()
? Map.of()
// Leverage Jackson to parse YAML string to Map
mapper.readValue(opts, mapType);
: mapper.readValue(optStr, mapType);
return new PlanConfig(id, new AnalysisOptions(optsMap));
} catch (JsonProcessingException e) {
throw new ConfigException("Invalid analysis options: " +
Expand All @@ -132,6 +130,25 @@ public static List<PlanConfig> readConfigs(Options options) {
.toList();
}

/**
* Converts option string to a valid YAML string.
* The option string is of format "key1:value1;key2:value2;...".
*/
private static String toYAMLString(String optValue) {
if (optValue.isBlank()) {
return optValue;
}
StringJoiner joiner = new StringJoiner("\n");
for (String keyValue : optValue.split(";")) {
if (!keyValue.isBlank()) {
int i = keyValue.indexOf(':'); // split keyValue
joiner.add(keyValue.substring(0, i) + ": "
+ keyValue.substring(i + 1));
}
}
return joiner.toString();
}

/**
* Writes a list of PlanConfigs to given file.
*/
Expand Down

0 comments on commit 34729ee

Please sign in to comment.