|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2017 the original author or authors.
|
|
|
|
|
* Copyright 2012-2018 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -20,7 +20,6 @@ import java.util.Collection;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
@ -197,40 +196,39 @@ public class CloudFoundryVcapEnvironmentPostProcessor
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
private void flatten(Properties properties, Map<String, Object> input, String path) {
|
|
|
|
|
for (Entry<String, Object> entry : input.entrySet()) {
|
|
|
|
|
String key = getFullKey(path, entry.getKey());
|
|
|
|
|
Object value = entry.getValue();
|
|
|
|
|
input.forEach((key, value) -> {
|
|
|
|
|
String name = getPropertyName(path, key);
|
|
|
|
|
if (value instanceof Map) {
|
|
|
|
|
// Need a compound key
|
|
|
|
|
flatten(properties, (Map<String, Object>) value, key);
|
|
|
|
|
flatten(properties, (Map<String, Object>) value, name);
|
|
|
|
|
}
|
|
|
|
|
else if (value instanceof Collection) {
|
|
|
|
|
// Need a compound key
|
|
|
|
|
Collection<Object> collection = (Collection<Object>) value;
|
|
|
|
|
properties.put(key,
|
|
|
|
|
properties.put(name,
|
|
|
|
|
StringUtils.collectionToCommaDelimitedString(collection));
|
|
|
|
|
int count = 0;
|
|
|
|
|
for (Object item : collection) {
|
|
|
|
|
String itemKey = "[" + (count++) + "]";
|
|
|
|
|
flatten(properties, Collections.singletonMap(itemKey, item), key);
|
|
|
|
|
flatten(properties, Collections.singletonMap(itemKey, item), name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (value instanceof String) {
|
|
|
|
|
properties.put(key, value);
|
|
|
|
|
properties.put(name, value);
|
|
|
|
|
}
|
|
|
|
|
else if (value instanceof Number) {
|
|
|
|
|
properties.put(key, value.toString());
|
|
|
|
|
properties.put(name, value.toString());
|
|
|
|
|
}
|
|
|
|
|
else if (value instanceof Boolean) {
|
|
|
|
|
properties.put(key, value.toString());
|
|
|
|
|
properties.put(name, value.toString());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
properties.put(key, value == null ? "" : value);
|
|
|
|
|
properties.put(name, value == null ? "" : value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getFullKey(String path, String key) {
|
|
|
|
|
private String getPropertyName(String path, String key) {
|
|
|
|
|
if (!StringUtils.hasText(path)) {
|
|
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|