Skip to content

Commit 9a779a0

Browse files
committed
Merge branch '1.2.x'
2 parents 394e52b + 86d5c19 commit 9a779a0

File tree

4 files changed

+68
-8
lines changed

4 files changed

+68
-8
lines changed

eclipse/org.eclipse.jdt.ui.prefs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ sp_cleanup.always_use_this_for_non_static_method_access=false
8787
sp_cleanup.convert_to_enhanced_for_loop=false
8888
sp_cleanup.correct_indentation=false
8989
sp_cleanup.format_source_code=true
90-
sp_cleanup.format_source_code_changes_only=true
90+
sp_cleanup.format_source_code_changes_only=false
9191
sp_cleanup.make_local_variable_final=false
9292
sp_cleanup.make_parameters_final=false
9393
sp_cleanup.make_private_fields_final=false

spring-boot-deployment-tests/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<main.basedir>${basedir}/..</main.basedir>
2121
<java.version>1.7</java.version>
2222
<cargo.timeout>300000</cargo.timeout>
23-
<cargo.container.download-dir>${user.home}/.cargo/installs</cargo.container.download-dir>
23+
<cargo.container.download-dir>${java.io.tmpdir}/cargo/installs</cargo.container.download-dir>
2424
</properties>
2525
<modules>
2626
<module>spring-boot-deployment-test-tomee</module>

spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java

+18-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.Collection;
2020
import java.util.LinkedHashMap;
2121
import java.util.Map;
22+
import java.util.concurrent.ConcurrentHashMap;
23+
import java.util.regex.Pattern;
2224

2325
import org.springframework.beans.MutablePropertyValues;
2426
import org.springframework.beans.PropertyValue;
@@ -37,17 +39,22 @@
3739
* used with the latter.
3840
*
3941
* @author Dave Syer
42+
* @author Phillip Webb
4043
*/
4144
public class PropertySourcesPropertyValues implements PropertyValues {
4245

43-
private final PropertySources propertySources;
46+
private static final Pattern COLLECTION_PROPERTY = Pattern.compile("\\[(\\d+)\\]");
4447

45-
private final Map<String, PropertyValue> propertyValues = new LinkedHashMap<String, PropertyValue>();
48+
private final PropertySources propertySources;
4649

4750
private final Collection<String> nonEnumerableFallbackNames;
4851

4952
private final PropertyNamePatternsMatcher includes;
5053

54+
private final Map<String, PropertyValue> propertyValues = new LinkedHashMap<String, PropertyValue>();
55+
56+
private final ConcurrentHashMap<String, PropertySource<?>> collectionOwners = new ConcurrentHashMap<String, PropertySource<?>>();
57+
5158
/**
5259
* Create a new PropertyValues from the given PropertySources.
5360
* @param propertySources a PropertySources instance
@@ -187,10 +194,15 @@ public PropertyValue getPropertyValue(String propertyName) {
187194
private PropertyValue putIfAbsent(String propertyName, Object value,
188195
PropertySource<?> source) {
189196
if (value != null && !this.propertyValues.containsKey(propertyName)) {
190-
PropertyValue propertyValue = new OriginCapablePropertyValue(propertyName,
191-
value, propertyName, source);
192-
this.propertyValues.put(propertyName, propertyValue);
193-
return propertyValue;
197+
PropertySource<?> collectionOwner = this.collectionOwners.putIfAbsent(
198+
COLLECTION_PROPERTY.matcher(propertyName).replaceAll("[]"), source);
199+
if (collectionOwner == null || collectionOwner == source) {
200+
this.collectionOwners.get(this.collectionOwners);
201+
PropertyValue propertyValue = new OriginCapablePropertyValue(
202+
propertyName, value, propertyName, source);
203+
this.propertyValues.put(propertyName, propertyValue);
204+
return propertyValue;
205+
}
194206
}
195207
return null;
196208
}

spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesPropertyValuesTests.java

+48
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
package org.springframework.boot.bind;
1818

1919
import java.util.ArrayList;
20+
import java.util.Arrays;
2021
import java.util.Collection;
2122
import java.util.Collections;
2223
import java.util.LinkedHashMap;
24+
import java.util.List;
2325
import java.util.Map;
2426

2527
import org.junit.Before;
@@ -31,12 +33,15 @@
3133
import org.springframework.core.env.PropertySource;
3234
import org.springframework.validation.DataBinder;
3335

36+
import static org.hamcrest.Matchers.equalTo;
3437
import static org.junit.Assert.assertEquals;
38+
import static org.junit.Assert.assertThat;
3539

3640
/**
3741
* Tests for {@link PropertySourcesPropertyValues}.
3842
*
3943
* @author Dave Syer
44+
* @author Phillip Webb
4045
*/
4146
public class PropertySourcesPropertyValuesTests {
4247

@@ -192,7 +197,35 @@ public Object getProperty(String name) {
192197
assertEquals(null, target.getName());
193198
}
194199

200+
@Test
201+
public void testCollectionProperty() throws Exception {
202+
ListBean target = new ListBean();
203+
DataBinder binder = new DataBinder(target);
204+
Map<String, Object> map = new LinkedHashMap<String, Object>();
205+
map.put("list[0]", "v0");
206+
map.put("list[1]", "v1");
207+
this.propertySources.addFirst(new MapPropertySource("values", map));
208+
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
209+
assertThat(target.getList(), equalTo(Arrays.asList("v0", "v1")));
210+
}
211+
212+
@Test
213+
public void testFirstCollectionPropertyWins() throws Exception {
214+
ListBean target = new ListBean();
215+
DataBinder binder = new DataBinder(target);
216+
Map<String, Object> first = new LinkedHashMap<String, Object>();
217+
first.put("list[0]", "f0");
218+
Map<String, Object> second = new LinkedHashMap<String, Object>();
219+
second.put("list[0]", "s0");
220+
second.put("list[1]", "s1");
221+
this.propertySources.addFirst(new MapPropertySource("s", second));
222+
this.propertySources.addFirst(new MapPropertySource("f", first));
223+
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
224+
assertThat(target.getList(), equalTo(Collections.singletonList("f0")));
225+
}
226+
195227
public static class TestBean {
228+
196229
private String name;
197230

198231
public String getName() {
@@ -205,6 +238,7 @@ public void setName(String name) {
205238
}
206239

207240
public static class FooBean {
241+
208242
private String foo;
209243

210244
public String getFoo() {
@@ -214,6 +248,20 @@ public String getFoo() {
214248
public void setFoo(String foo) {
215249
this.foo = foo;
216250
}
251+
252+
}
253+
254+
public static class ListBean {
255+
256+
private List<String> list = new ArrayList<String>();
257+
258+
public List<String> getList() {
259+
return this.list;
260+
}
261+
262+
public void setList(List<String> list) {
263+
this.list = list;
264+
}
217265
}
218266

219267
}

0 commit comments

Comments
 (0)