Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codestarts - Fix flattening of log levels #30172

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,22 @@ private void writePropertiesConfig(Path targetPath, Map<String, Object> config)
static void flatten(String prefix, Map<String, String> target, Map<String, ?> map) {
for (Map.Entry entry : map.entrySet()) {
if (entry.getValue() instanceof Map) {
flatten(prefix + entry.getKey() + ".", target, (Map) entry.getValue());
flatten(prefix + quote(entry.getKey().toString()) + ".", target, (Map) entry.getValue());
} else {
// TODO: handle different types of values
target.put(prefix + entry.getKey(), entry.getValue().toString());
target.put(prefix + quote(entry.getKey().toString()), entry.getValue().toString());
}
}
}

private static String quote(String key) {
if (!key.contains(".")) {
return key;
}

return "\"" + key.replaceAll("\"", "\\\"") + "\"";
}

private static String getConfigType(Map<String, Object> data) {
final Optional<String> config = CodestartData.getInputCodestartForType(data, CodestartType.CONFIG);
return config.orElseThrow(() -> new CodestartException("Config type is required"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,27 @@ void testFlatten() {
assertThat(flat).containsEntry("c.c-c.c-c-a", "1");
assertThat(flat).containsEntry("c.c-c.c-c-b", "2");
}

@Test
void testLogLevel() {
final HashMap<String, Object> level = new HashMap<>();
level.put("level", "DEBUG");

final HashMap<String, Object> categoryName = new HashMap<>();
categoryName.put("org.hibernate", level);

final HashMap<String, Object> category = new HashMap<>();
category.put("category", categoryName);

final HashMap<String, Object> log = new HashMap<>();
log.put("log", category);

final HashMap<String, Object> quarkus = new HashMap<>();
quarkus.put("quarkus", log);

final HashMap<String, String> flat = new HashMap<>();
SmartConfigMergeCodestartFileStrategyHandler.flatten("", flat, quarkus);

assertThat(flat).containsEntry("quarkus.log.category.\"org.hibernate\".level", "DEBUG");
}
}