Skip to content

Commit 00d236d

Browse files
committed
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg properties via environment variable and Java system properties
* add documentation
1 parent 1c96f8b commit 00d236d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

xwiki-commons-core/xwiki-commons-configuration/xwiki-commons-configuration-default/src/main/java/org/xwiki/configuration/internal/SystemEnvConfigurationSource.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,23 @@
2727
import jakarta.inject.Singleton;
2828

2929
import org.xwiki.component.annotation.Component;
30+
import org.xwiki.configuration.ConfigurationSource;
3031

3132
/**
3233
* Environment variables based configuration source.
3334
* <p>
34-
* To support all systems, we cannot expect environment variable to allow anything else than [a-zA-Z_]+[a-zA-Z0-9_]* so
35-
* we apply the following encoding:
35+
* Environment variable are expected to be prefixed with XCONF_ to be taken into account by this
36+
* {@link ConfigurationSource}. Also, to support all systems, we cannot expect environment variable to allow anything
37+
* else than [a-zA-Z_]+[a-zA-Z0-9_]* so we apply the following encoding:
3638
* <ul>
3739
* <li>., : and - (don’t hesitate if you think of something else that might be common in a configuration file key) are
3840
* converted to _</li>
3941
* <li>_ remains _</li>
4042
* <li>any other forbidden character is converted to _<UTF8, URL style, code></li>
4143
* </ul>
44+
* <p>
45+
* For example the {@link ConfigurationSource} property key "configuration.1Key@" will lead the the environment variable
46+
* "XCONF_configuration__31Key_40".
4247
*
4348
* @version $Id$
4449
* @since 17.4.0RC1

xwiki-commons-core/xwiki-commons-configuration/xwiki-commons-configuration-default/src/test/java/org/xwiki/configuration/internal/SystemEnvConfigurationSourceTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ void getProperty()
104104

105105
assertEquals("15", this.configuration.getProperty("key1:KEY2_key3.KEY4"));
106106

107-
this.configuration.getenv().put(SystemEnvConfigurationSource.PREFIX + "_31Key_40", "value");
107+
this.configuration.getenv().put(SystemEnvConfigurationSource.PREFIX + "_31Key__40", "value");
108108

109-
assertEquals("value", this.configuration.getProperty("1Key@"));
109+
assertEquals("value", this.configuration.getProperty("1Key.@"));
110110
}
111111

112112
@Test

0 commit comments

Comments
 (0)