-
Notifications
You must be signed in to change notification settings - Fork 136
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg properties via environment variable and Java system properties #1315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ce50a05
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg prop…
tmortagne 896c7d5
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg prop…
tmortagne 04e951f
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg prop…
tmortagne 511c0a2
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg prop…
tmortagne 1a43ede
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg prop…
tmortagne c41ca5e
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg prop…
tmortagne 8ab0a06
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg prop…
tmortagne 62957bd
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg prop…
tmortagne 49a940a
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg prop…
tmortagne 2b09034
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg prop…
tmortagne 5615fd0
XCOMMONS-3289: Allow overwritting xwiki.properties and xwiki.cfg prop…
tmortagne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
.../src/main/java/org/xwiki/configuration/internal/AbstractCompositeConfigurationSource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.configuration.internal; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.xwiki.configuration.ConfigurationSource; | ||
|
||
/** | ||
* Base class for composing (aka chaining) several Configuration Sources. The order of sources is important. Sources | ||
* located before other sources take priority. | ||
* | ||
* @version $Id$ | ||
* @since 7.4M1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The version may look a bit strange, but it's actually a move from platform. |
||
*/ | ||
public abstract class AbstractCompositeConfigurationSource extends AbstractConfigurationSource | ||
implements Iterable<ConfigurationSource> | ||
{ | ||
@Override | ||
public boolean containsKey(String key) | ||
{ | ||
boolean result = false; | ||
|
||
for (ConfigurationSource source : this) { | ||
if (source.containsKey(key)) { | ||
result = true; | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
public <T> T getProperty(String key) | ||
{ | ||
T result = null; | ||
|
||
for (ConfigurationSource source : this) { | ||
if (source.containsKey(key)) { | ||
result = source.<T>getProperty(key); | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
public <T> T getProperty(String key, Class<T> valueClass) | ||
{ | ||
T result = null; | ||
|
||
for (ConfigurationSource source : this) { | ||
if (source.containsKey(key)) { | ||
result = source.getProperty(key, valueClass); | ||
break; | ||
} | ||
} | ||
|
||
// List and Properties must return empty collections and not null values. | ||
if (result == null) { | ||
result = getDefault(valueClass); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
public <T> T getProperty(String key, T defaultValue) | ||
{ | ||
T result = null; | ||
|
||
for (ConfigurationSource source : this) { | ||
if (source.containsKey(key)) { | ||
result = source.<T>getProperty(key, defaultValue); | ||
break; | ||
} | ||
} | ||
|
||
if (result == null) { | ||
result = defaultValue; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
public List<String> getKeys() | ||
{ | ||
// We use a linked hash set in order to keep the keys in the order in which they were defined in the sources. | ||
Set<String> keys = new LinkedHashSet<>(); | ||
|
||
for (ConfigurationSource source : this) { | ||
keys.addAll(source.getKeys()); | ||
} | ||
|
||
return new ArrayList<>(keys); | ||
} | ||
|
||
@Override | ||
public List<String> getKeys(String prefix) | ||
{ | ||
// We use a linked hash set in order to keep the keys in the order in which they were defined in the sources. | ||
Set<String> keys = new LinkedHashSet<>(); | ||
|
||
for (ConfigurationSource source : this) { | ||
keys.addAll(source.getKeys(prefix)); | ||
} | ||
|
||
return new ArrayList<>(keys); | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() | ||
{ | ||
for (ConfigurationSource source : this) { | ||
if (!source.isEmpty()) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty(String prefix) | ||
{ | ||
for (ConfigurationSource source : this) { | ||
if (!source.isEmpty(prefix)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...tion-api/src/main/java/org/xwiki/configuration/internal/CompositeConfigurationSource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.configuration.internal; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import org.xwiki.configuration.ConfigurationSource; | ||
|
||
/** | ||
* Allows composing (aka chaining) several Configuration Sources. The order of sources is important. Sources located | ||
* before other sources take priority. | ||
* | ||
* @version $Id$ | ||
* @since 2.0M1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The version may look a bit strange, but it's actually a move from platform. |
||
*/ | ||
public class CompositeConfigurationSource extends AbstractCompositeConfigurationSource | ||
{ | ||
/** | ||
* The order of sources is important. Sources located before other sources take priority. | ||
*/ | ||
protected List<ConfigurationSource> sources = new ArrayList<>(); | ||
|
||
/** | ||
* @param source the source to add to the list of sources | ||
*/ | ||
public void addConfigurationSource(ConfigurationSource source) | ||
{ | ||
this.sources.add(source); | ||
} | ||
|
||
@Override | ||
public Iterator<ConfigurationSource> iterator() | ||
{ | ||
return this.sources.iterator(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.