Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 46292bd

Browse files
committed
Manual Merge of pull request
Merge branch 'master' of https://github.com/normanatashbar/ReloadablePropertiesAnnotation into normanatashbar-master
2 parents 819159a + 351127f commit 46292bd

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

src/main/java/com/morgan/design/properties/internal/ReadablePropertySourcesPlaceholderConfigurer.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,16 @@ public void startWatching() {
9494
}
9595

9696
public Object resolveProperty(final Object property) {
97-
final Object resolvedPropertyValue = this.properties.get(this.propertyResolver.resolveProperty(property));
98-
if (this.propertyResolver.requiresFurtherResoltuion(resolvedPropertyValue)) {
99-
return resolveProperty(resolvedPropertyValue);
97+
Object resolvedPropertyValue = this.properties.get(this.propertyResolver.resolveProperty(property));
98+
if (!(resolvedPropertyValue instanceof String))
99+
return resolvedPropertyValue;
100+
while (this.propertyResolver.requiresFurtherResoltuion(resolvedPropertyValue)) {
101+
String resolvedValueStr = resolvedPropertyValue.toString();
102+
int startingIndex = resolvedValueStr.indexOf("${");
103+
int endingIndex = resolvedValueStr.indexOf("}", startingIndex) + 1;
104+
String toResolve = resolvedValueStr.substring(startingIndex, endingIndex);
105+
String resolved = resolveProperty(toResolve).toString();
106+
resolvedPropertyValue = resolvedValueStr.substring(0, startingIndex) + resolved + resolvedValueStr.substring(endingIndex);
100107
}
101108
return resolvedPropertyValue;
102109
}

src/main/java/com/morgan/design/properties/resolver/SubstitutingPropertyResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public boolean requiresFurtherResoltuion(final Object property) {
5151
*/
5252
private boolean propertyRequiresSubstitution(final String property) {
5353
if (null != property) {
54-
return property.startsWith("${") && property.endsWith("}");
54+
return property.contains("${") && property.contains("}") && property.indexOf("${") < property.indexOf("}");
5555
}
5656
return false;
5757
}

src/test/java/com/morgan/design/properties/internal/UpdatingReloadablePropertyPostProcessorIntTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,29 @@ public class UpdatingReloadablePropertyPostProcessorIntTest extends AbstractJUni
3535
public void setUp() throws IOException {
3636
this.loadedProperties = PropertiesLoaderUtils.loadAllProperties(PROPERTIES);
3737
assertThat(this.bean.getStringProperty(), is("Injected String Value"));
38+
assertThat(this.bean.getCompositeStringProperty(), is("Hello, World!"));
3839
}
3940

4041
@After
4142
public void cleanUp() throws Exception {
4243
this.loadedProperties.setProperty("dynamicProperty.stringValue", "Injected String Value");
44+
this.loadedProperties.setProperty("dynamicProperty.baseStringValue", "World");
45+
this.loadedProperties.setProperty("dynamicProperty.compoiteStringValue", "Hello, ${dynamicProperty.baseStringValue}!");
4346

4447
final OutputStream newOutputStream = Files.newOutputStream(new File(DIR + PROPERTIES).toPath(), new OpenOption[] {});
4548
this.loadedProperties.store(newOutputStream, null);
4649

4750
Thread.sleep(500); // this is a hack -> I need to find an alternative
4851

4952
assertThat(this.bean.getStringProperty(), is("Injected String Value"));
53+
assertThat(this.bean.getCompositeStringProperty(), is("Hello, World!"));
5054
}
5155

5256
@Test
5357
public void shouldReloadAlteredStringProperty() throws Exception {
5458
assertThat(this.bean.getStringProperty(), is("Injected String Value"));
5559

56-
this.loadedProperties.setProperty("dynamicProperty.stringValue", "Altered Injected String Value");
60+
this.loadedProperties.setProperty("dynamicProperty.stringValue", "Altered Injected String Value");
5761

5862
final File file = new File(DIR + PROPERTIES);
5963
final OutputStream newOutputStream = Files.newOutputStream(file.toPath(), new OpenOption[] {});
@@ -65,4 +69,21 @@ public void shouldReloadAlteredStringProperty() throws Exception {
6569

6670
assertThat(this.bean.getStringProperty(), is("Altered Injected String Value"));
6771
}
72+
73+
@Test
74+
public void shouldReloadAlteredCompositeStringProperty() throws Exception {
75+
assertThat(this.bean.getCompositeStringProperty(), is("Hello, World!"));
76+
77+
this.loadedProperties.setProperty("dynamicProperty.compoiteStringValue", "Goodbye, ${dynamicProperty.baseStringValue}!");
78+
79+
final File file = new File(DIR + PROPERTIES);
80+
final OutputStream newOutputStream = Files.newOutputStream(file.toPath(), new OpenOption[] {});
81+
this.loadedProperties.store(newOutputStream, null);
82+
newOutputStream.flush();
83+
newOutputStream.close();
84+
85+
Thread.sleep(500); // this is a hack -> I need to find an alternative
86+
87+
assertThat(this.bean.getCompositeStringProperty(), is("Goodbye, World!"));
88+
}
6889
}

src/test/java/com/morgan/design/properties/testBeans/ReloadingAutowiredPropertyBean.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ public class ReloadingAutowiredPropertyBean {
1010
@ReloadableProperty("dynamicProperty.stringValue")
1111
private String stringProperty;
1212

13-
public String getStringProperty() {
13+
@ReloadableProperty("dynamicProperty.compoiteStringValue")
14+
private String compositeStringProperty;
15+
16+
public String getStringProperty() {
1417
return this.stringProperty;
1518
}
19+
20+
public String getCompositeStringProperty() {
21+
return this.compositeStringProperty;
22+
}
1623
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#Sun Jul 15 13:22:10 BST 2012
22
dynamicProperty.stringValue=Injected String Value
3+
dynamicProperty.compoiteStringValue=Hello, World!

0 commit comments

Comments
 (0)