11package com .github .bordertech .config ;
22
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-
173import java .io .BufferedInputStream ;
184import java .io .ByteArrayInputStream ;
195import java .io .ByteArrayOutputStream ;
4329import java .util .Properties ;
4430import java .util .Set ;
4531import 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 ;
4645
4746/**
4847 * <p>
@@ -103,6 +102,7 @@ public class DefaultConfiguration implements Configuration {
103102 public static final String DUMP_FILE = "bordertech.config.parameters.dump.file" ;
104103 /**
105104 * If this parameter is set, it will be used as the environment suffix for each property lookup.
105+ *
106106 * @deprecated Use {@link #PROFILE_PROPERTY} to define the profile property
107107 */
108108 @ Deprecated
@@ -215,8 +215,8 @@ public DefaultConfiguration() {
215215 */
216216 public DefaultConfiguration (final String ... resourceLoadOrder ) {
217217 if (resourceLoadOrder == null || resourceLoadOrder .length == 0 || Arrays
218- .stream (resourceLoadOrder )
219- .anyMatch (StringUtils ::isBlank )) {
218+ .stream (resourceLoadOrder )
219+ .anyMatch (StringUtils ::isBlank )) {
220220 this .resourceLoadOrder = InitHelper .getDefaultResourceLoadOrder ();
221221 } else {
222222 this .resourceLoadOrder = resourceLoadOrder ;
@@ -228,7 +228,7 @@ public DefaultConfiguration(final String... resourceLoadOrder) {
228228 /**
229229 * Copies information from the input stream to the output stream using a specified buffer size.
230230 *
231- * @param in the source stream.
231+ * @param in the source stream.
232232 * @param out the destination stream.
233233 * @throws IOException if there is an error reading or writing to the streams.
234234 */
@@ -244,7 +244,6 @@ private static void copyStream(final InputStream in, final OutputStream out) thr
244244 }
245245
246246 // -----------------------------------------------------------------------------------------------------------------
247-
248247 /**
249248 * Splits the given comma-delimited string into an an array. Leading/trailing spaces in list items will be trimmed.
250249 *
@@ -303,12 +302,9 @@ private void load() {
303302 loadEnvironmentProperties ();
304303 }
305304
306- checkProfileProperty ();
305+ handlePropertySubstitution ();
307306
308- // Now perform variable substitution.
309- for (String key : backing .keySet ()) {
310- substitute (key );
311- }
307+ checkProfileProperty ();
312308
313309 // Dump Header Info
314310 LOG .info (getDumpHeader ());
@@ -715,8 +711,8 @@ private void loadSystemProperties() {
715711 boolean overWriteOnly = getBoolean (USE_SYSTEM_OVERWRITEONLY , false );
716712 List <String > allowedPrefixes = Arrays .asList (getStringArray (USE_SYSTEM_PREFIXES ));
717713 System
718- .getProperties ()
719- .forEach ((key , value ) -> mergeExternalProperty ("System Properties" ,
714+ .getProperties ()
715+ .forEach ((key , value ) -> mergeExternalProperty ("System Properties" ,
720716 (String ) key ,
721717 (String ) value ,
722718 overWriteOnly ,
@@ -729,25 +725,25 @@ private void loadSystemProperties() {
729725 private void loadEnvironmentProperties () {
730726 List <String > allowedPrefixes = Arrays .asList (getStringArray (USE_OSENV_PREFIXES ));
731727 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 ));
734730 }
735731
736732 /**
737733 * Merge the external property.
738734 *
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
743739 * @param allowedPrefixes the list of allowed property prefixes
744740 */
745741 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 ) {
751747
752748 // Check for "include" keys (should not come from System or Environment Properties)
753749 if (INCLUDE .equals (key ) || INCLUDE_AFTER .equals (key )) {
@@ -772,7 +768,7 @@ private void mergeExternalProperty(
772768 * Check allowed prefixes.
773769 *
774770 * @param allowedPrefixes the list of allowed prefixes
775- * @param key the key to check
771+ * @param key the key to check
776772 * @return true if the key is an allowed prefix
777773 */
778774 private boolean isAllowedKeyPrefix (final List <String > allowedPrefixes , final String key ) {
@@ -1270,7 +1266,7 @@ public Configuration subset(final String prefix) {
12701266 /**
12711267 * Returns a sub-set of the parameters contained in this configuration.
12721268 *
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.
12741270 * @param truncate if true, the prefix is truncated in the returned properties.
12751271 * @return the properties sub-set, may be empty.
12761272 */
@@ -1309,7 +1305,7 @@ protected Properties getSubProperties(final String prefix, final boolean truncat
13091305 }
13101306
13111307 /**
1312- * @param key the property key
1308+ * @param key the property key
13131309 * @param defolt the default value if key not available
13141310 * @return the property value or null
13151311 */
@@ -1341,7 +1337,7 @@ protected String get(final String key) {
13411337 /**
13421338 * Add or Modify a property at runtime.
13431339 *
1344- * @param name the property name
1340+ * @param name the property name
13451341 * @param value the property value
13461342 */
13471343 protected void addOrModifyProperty (final String name , final String value ) {
@@ -1367,6 +1363,16 @@ protected void addOrModifyProperty(final String name, final String value) {
13671363 handlePropertiesChanged ();
13681364 }
13691365
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+
13701376 /**
13711377 * Handle a property change.
13721378 */
@@ -1378,8 +1384,8 @@ protected void handlePropertiesChanged() {
13781384 }
13791385
13801386 /**
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
13831389 */
13841390 protected void checkProfileProperty () {
13851391
@@ -1452,8 +1458,9 @@ protected String getEnvironmentKey(final String key) {
14521458 /**
14531459 * A helper class for properties which are being loaded into the {@link DefaultConfiguration}.
14541460 *
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>
14571464 */
14581465 private class IncludeProperties extends Properties {
14591466
@@ -1475,7 +1482,7 @@ private class IncludeProperties extends Properties {
14751482 * Adds a value to the properties set. This has been overridden to support the Configuration extensions (e.g.
14761483 * the "include" directive).
14771484 *
1478- * @param aKey the key to add
1485+ * @param aKey the key to add
14791486 * @param aValue the value to add
14801487 * @return the old value for the key, or null if there was no previously associated value.
14811488 */
0 commit comments