-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Fix environment variable substitutions in list setting #28106
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ | |
| import java.util.NoSuchElementException; | ||
| import java.util.Set; | ||
| import java.util.TreeMap; | ||
| import java.util.ListIterator; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Function; | ||
| import java.util.function.Predicate; | ||
|
|
@@ -414,7 +415,7 @@ public List<String> getAsList(String key, List<String> defaultValue, Boolean com | |
| final Object valueFromPrefix = settings.get(key); | ||
| if (valueFromPrefix != null) { | ||
| if (valueFromPrefix instanceof List) { | ||
| return ((List<String>) valueFromPrefix); // it's already unmodifiable since the builder puts it as a such | ||
| return Collections.unmodifiableList((List<String>) valueFromPrefix); | ||
| } else if (commaDelimited) { | ||
| String[] strings = Strings.splitStringByCommaToArray(get(key)); | ||
| if (strings.length > 0) { | ||
|
|
@@ -1042,7 +1043,7 @@ public Builder putList(String setting, String... values) { | |
| */ | ||
| public Builder putList(String setting, List<String> values) { | ||
| remove(setting); | ||
| map.put(setting, Collections.unmodifiableList(new ArrayList<>(values))); | ||
| map.put(setting, new ArrayList<>(values)); | ||
| return this; | ||
| } | ||
|
|
||
|
|
@@ -1210,10 +1211,23 @@ public boolean shouldRemoveMissingPlaceholder(String placeholderName) { | |
| Iterator<Map.Entry<String, Object>> entryItr = map.entrySet().iterator(); | ||
| while (entryItr.hasNext()) { | ||
| Map.Entry<String, Object> entry = entryItr.next(); | ||
| if (entry.getValue() == null || entry.getValue() instanceof List) { | ||
| if (entry.getValue() == null) { | ||
| // a null value obviously can't be replaced | ||
| continue; | ||
| } | ||
| if (entry.getValue() instanceof List) { | ||
| List<String> ls = (List<String>) entry.getValue(); | ||
| ListIterator<String> li = ls.listIterator(); | ||
|
||
| while(li.hasNext()){ | ||
|
||
| String value = li.next(); | ||
|
||
| String value2 = propertyPlaceholder.replacePlaceholders(value, placeholderResolver); | ||
| if (! value.equals(value2)){ | ||
|
||
| li.set(value2); | ||
| } | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| String value = propertyPlaceholder.replacePlaceholders(Settings.toString(entry.getValue()), placeholderResolver); | ||
| // if the values exists and has length, we should maintain it in the map | ||
| // otherwise, the replace process resolved into removing it | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,17 @@ public void testReplacePropertiesPlaceholderSystemProperty() { | |
| assertThat(settings.get("setting1"), equalTo(value)); | ||
| } | ||
|
|
||
| public void testReplacePropertiesPlaceholderSystemPropertyList() { | ||
| String value = System.getProperty("java.home"); | ||
| assertFalse(value.isEmpty()); | ||
|
||
| Settings settings = Settings.builder() | ||
| .put("property.placeholder", value) | ||
| .putList("setting1", "${property.placeholder}", "${property.placeholder}") | ||
| .replacePropertyPlaceholders() | ||
|
||
| .build(); | ||
| assertThat(settings.getAsList("setting1"), contains(value, value)); | ||
|
||
| } | ||
|
|
||
| public void testReplacePropertiesPlaceholderSystemVariablesHaveNoEffect() { | ||
| final String value = System.getProperty("java.home"); | ||
| assertNotNull(value); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lsis never used again after the next line; do we need this local variable?