1
1
package com .github .bordertech .config ;
2
2
3
- import org .apache .commons .configuration .Configuration ;
4
- import org .apache .commons .configuration .ConversionException ;
5
- import org .apache .commons .configuration .MapConfiguration ;
6
- import org .apache .commons .io .FileUtils ;
7
- import org .apache .commons .lang3 .BooleanUtils ;
8
- import org .apache .commons .lang3 .ObjectUtils ;
9
- import org .apache .commons .lang3 .StringUtils ;
10
- import org .apache .commons .lang3 .SystemUtils ;
11
- import org .apache .commons .lang3 .tuple .ImmutablePair ;
12
- import org .apache .commons .lang3 .tuple .Pair ;
13
- import org .apache .commons .logging .Log ;
14
- import org .apache .commons .logging .impl .SimpleLog ;
15
- import org .apache .commons .text .StringSubstitutor ;
16
-
17
3
import java .io .BufferedInputStream ;
18
4
import java .io .ByteArrayInputStream ;
19
5
import java .io .ByteArrayOutputStream ;
43
29
import java .util .Properties ;
44
30
import java .util .Set ;
45
31
import java .util .TreeSet ;
32
+ import org .apache .commons .configuration .Configuration ;
33
+ import org .apache .commons .configuration .ConversionException ;
34
+ import org .apache .commons .configuration .MapConfiguration ;
35
+ import org .apache .commons .io .FileUtils ;
36
+ import org .apache .commons .lang3 .BooleanUtils ;
37
+ import org .apache .commons .lang3 .ObjectUtils ;
38
+ import org .apache .commons .lang3 .StringUtils ;
39
+ import org .apache .commons .lang3 .SystemUtils ;
40
+ import org .apache .commons .lang3 .tuple .ImmutablePair ;
41
+ import org .apache .commons .lang3 .tuple .Pair ;
42
+ import org .apache .commons .logging .Log ;
43
+ import org .apache .commons .logging .impl .SimpleLog ;
44
+ import org .apache .commons .text .StringSubstitutor ;
46
45
47
46
/**
48
47
* <p>
@@ -103,6 +102,7 @@ public class DefaultConfiguration implements Configuration {
103
102
public static final String DUMP_FILE = "bordertech.config.parameters.dump.file" ;
104
103
/**
105
104
* If this parameter is set, it will be used as the environment suffix for each property lookup.
105
+ *
106
106
* @deprecated Use {@link #PROFILE_PROPERTY} to define the profile property
107
107
*/
108
108
@ Deprecated
@@ -215,8 +215,8 @@ public DefaultConfiguration() {
215
215
*/
216
216
public DefaultConfiguration (final String ... resourceLoadOrder ) {
217
217
if (resourceLoadOrder == null || resourceLoadOrder .length == 0 || Arrays
218
- .stream (resourceLoadOrder )
219
- .anyMatch (StringUtils ::isBlank )) {
218
+ .stream (resourceLoadOrder )
219
+ .anyMatch (StringUtils ::isBlank )) {
220
220
this .resourceLoadOrder = InitHelper .getDefaultResourceLoadOrder ();
221
221
} else {
222
222
this .resourceLoadOrder = resourceLoadOrder ;
@@ -228,7 +228,7 @@ public DefaultConfiguration(final String... resourceLoadOrder) {
228
228
/**
229
229
* Copies information from the input stream to the output stream using a specified buffer size.
230
230
*
231
- * @param in the source stream.
231
+ * @param in the source stream.
232
232
* @param out the destination stream.
233
233
* @throws IOException if there is an error reading or writing to the streams.
234
234
*/
@@ -244,7 +244,6 @@ private static void copyStream(final InputStream in, final OutputStream out) thr
244
244
}
245
245
246
246
// -----------------------------------------------------------------------------------------------------------------
247
-
248
247
/**
249
248
* Splits the given comma-delimited string into an an array. Leading/trailing spaces in list items will be trimmed.
250
249
*
@@ -303,12 +302,9 @@ private void load() {
303
302
loadEnvironmentProperties ();
304
303
}
305
304
306
- checkProfileProperty ();
305
+ handlePropertySubstitution ();
307
306
308
- // Now perform variable substitution.
309
- for (String key : backing .keySet ()) {
310
- substitute (key );
311
- }
307
+ checkProfileProperty ();
312
308
313
309
// Dump Header Info
314
310
LOG .info (getDumpHeader ());
@@ -715,8 +711,8 @@ private void loadSystemProperties() {
715
711
boolean overWriteOnly = getBoolean (USE_SYSTEM_OVERWRITEONLY , false );
716
712
List <String > allowedPrefixes = Arrays .asList (getStringArray (USE_SYSTEM_PREFIXES ));
717
713
System
718
- .getProperties ()
719
- .forEach ((key , value ) -> mergeExternalProperty ("System Properties" ,
714
+ .getProperties ()
715
+ .forEach ((key , value ) -> mergeExternalProperty ("System Properties" ,
720
716
(String ) key ,
721
717
(String ) value ,
722
718
overWriteOnly ,
@@ -729,25 +725,25 @@ private void loadSystemProperties() {
729
725
private void loadEnvironmentProperties () {
730
726
List <String > allowedPrefixes = Arrays .asList (getStringArray (USE_OSENV_PREFIXES ));
731
727
System
732
- .getenv ()
733
- .forEach ((key , value ) -> mergeExternalProperty ("Environment Properties" , key , value , false , allowedPrefixes ));
728
+ .getenv ()
729
+ .forEach ((key , value ) -> mergeExternalProperty ("Environment Properties" , key , value , false , allowedPrefixes ));
734
730
}
735
731
736
732
/**
737
733
* Merge the external property.
738
734
*
739
- * @param location the location of the properties
740
- * @param key the property key
741
- * @param value the property value
742
- * @param overWriteOnly true if only overwrite existing properties
735
+ * @param location the location of the properties
736
+ * @param key the property key
737
+ * @param value the property value
738
+ * @param overWriteOnly true if only overwrite existing properties
743
739
* @param allowedPrefixes the list of allowed property prefixes
744
740
*/
745
741
private void mergeExternalProperty (
746
- final String location ,
747
- final String key ,
748
- final String value ,
749
- final boolean overWriteOnly ,
750
- final List <String > allowedPrefixes ) {
742
+ final String location ,
743
+ final String key ,
744
+ final String value ,
745
+ final boolean overWriteOnly ,
746
+ final List <String > allowedPrefixes ) {
751
747
752
748
// Check for "include" keys (should not come from System or Environment Properties)
753
749
if (INCLUDE .equals (key ) || INCLUDE_AFTER .equals (key )) {
@@ -772,7 +768,7 @@ private void mergeExternalProperty(
772
768
* Check allowed prefixes.
773
769
*
774
770
* @param allowedPrefixes the list of allowed prefixes
775
- * @param key the key to check
771
+ * @param key the key to check
776
772
* @return true if the key is an allowed prefix
777
773
*/
778
774
private boolean isAllowedKeyPrefix (final List <String > allowedPrefixes , final String key ) {
@@ -1270,7 +1266,7 @@ public Configuration subset(final String prefix) {
1270
1266
/**
1271
1267
* Returns a sub-set of the parameters contained in this configuration.
1272
1268
*
1273
- * @param prefix the prefix of the parameter keys which should be included.
1269
+ * @param prefix the prefix of the parameter keys which should be included.
1274
1270
* @param truncate if true, the prefix is truncated in the returned properties.
1275
1271
* @return the properties sub-set, may be empty.
1276
1272
*/
@@ -1309,7 +1305,7 @@ protected Properties getSubProperties(final String prefix, final boolean truncat
1309
1305
}
1310
1306
1311
1307
/**
1312
- * @param key the property key
1308
+ * @param key the property key
1313
1309
* @param defolt the default value if key not available
1314
1310
* @return the property value or null
1315
1311
*/
@@ -1341,7 +1337,7 @@ protected String get(final String key) {
1341
1337
/**
1342
1338
* Add or Modify a property at runtime.
1343
1339
*
1344
- * @param name the property name
1340
+ * @param name the property name
1345
1341
* @param value the property value
1346
1342
*/
1347
1343
protected void addOrModifyProperty (final String name , final String value ) {
@@ -1367,6 +1363,16 @@ protected void addOrModifyProperty(final String name, final String value) {
1367
1363
handlePropertiesChanged ();
1368
1364
}
1369
1365
1366
+ /**
1367
+ * Handle the substitution of property values.
1368
+ */
1369
+ protected void handlePropertySubstitution () {
1370
+ // Now perform variable substitution.
1371
+ for (String key : backing .keySet ()) {
1372
+ substitute (key );
1373
+ }
1374
+ }
1375
+
1370
1376
/**
1371
1377
* Handle a property change.
1372
1378
*/
@@ -1378,8 +1384,8 @@ protected void handlePropertiesChanged() {
1378
1384
}
1379
1385
1380
1386
/**
1381
- * Set the current Profile if it has been set as property. An application defined property overrides,
1382
- * a JVM System property which overrides a OS environment variable
1387
+ * Set the current Profile if it has been set as property. An application defined property overrides, a JVM System
1388
+ * property which overrides a OS environment variable
1383
1389
*/
1384
1390
protected void checkProfileProperty () {
1385
1391
@@ -1452,8 +1458,9 @@ protected String getEnvironmentKey(final String key) {
1452
1458
/**
1453
1459
* A helper class for properties which are being loaded into the {@link DefaultConfiguration}.
1454
1460
*
1455
- * <p>This is used to ensure on the call of put(key, value) is immediately loaded into the
1456
- * {@link DefaultConfiguration} to respect the order hierarchy for the configuration.</p>
1461
+ * <p>
1462
+ * This is used to ensure on the call of put(key, value) is immediately loaded into the {@link DefaultConfiguration}
1463
+ * to respect the order hierarchy for the configuration.</p>
1457
1464
*/
1458
1465
private class IncludeProperties extends Properties {
1459
1466
@@ -1475,7 +1482,7 @@ private class IncludeProperties extends Properties {
1475
1482
* Adds a value to the properties set. This has been overridden to support the Configuration extensions (e.g.
1476
1483
* the "include" directive).
1477
1484
*
1478
- * @param aKey the key to add
1485
+ * @param aKey the key to add
1479
1486
* @param aValue the value to add
1480
1487
* @return the old value for the key, or null if there was no previously associated value.
1481
1488
*/
0 commit comments