You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2022/07/29 09:01:08 UTC
[deltaspike] branch master updated: DELTASPIKE-1456 add default methods to ConfigSource
This is an automated email from the ASF dual-hosted git repository.
struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/deltaspike.git
The following commit(s) were added to refs/heads/master by this push:
new 63122947 DELTASPIKE-1456 add default methods to ConfigSource
63122947 is described below
commit 63122947001cdece57ad054a9d5a43a84c5aefc9
Author: Mark Struberg <st...@apache.org>
AuthorDate: Wed Jul 27 17:06:52 2022 +0200
DELTASPIKE-1456 add default methods to ConfigSource
* isScannable() is now a default method which returns true
* getOrdinal() is now a default method which checks "deltaspike_ordinal"
or returns 100.
---
.../deltaspike/core/spi/config/ConfigSource.java | 22 ++++++++++++++++++++--
.../core/api/config/TestConfigSourceProvider.java | 14 ++++----------
2 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigSource.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigSource.java
index bd187723..e1f985bf 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigSource.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigSource.java
@@ -46,6 +46,11 @@ public interface ConfigSource
* in {@link #getOrdinal()}.
*/
String DELTASPIKE_ORDINAL = "deltaspike_ordinal";
+
+ /**
+ * The default value if no special ordinal is defined for this ConfigSource.
+ */
+ int DELTASPIKE_DEFAULT_ORDINAL = 100;
/**
* Lookup order:
@@ -78,9 +83,19 @@ public interface ConfigSource
* /META-INF/apache-deltaspike.properties . Hint: In case of property files every file is handled as independent
* config-source, but all of them have ordinal 400 by default (and can be reordered in a fine-grained manner.</p>
*
+ * <p>This method will only get evaluated once at startup and whenever a new ConfigSource is added.</p>
+ *
* @return the 'importance' aka ordinal of the configured values. The higher, the more important.
*/
- int getOrdinal();
+ default int getOrdinal()
+ {
+ String ordinal = getPropertyValue(DELTASPIKE_ORDINAL);
+ if (ordinal != null && ordinal.length() > 0)
+ {
+ return Integer.valueOf(ordinal);
+ }
+ return DELTASPIKE_DEFAULT_ORDINAL;
+ }
/**
* Return properties contained in this config source.
@@ -107,7 +122,10 @@ public interface ConfigSource
* @return true if this ConfigSource should be scanned for its list of properties,
* false if it should not be scanned.
*/
- boolean isScannable();
+ default boolean isScannable()
+ {
+ return true;
+ }
/**
* This callback should get invoked if an attribute change got detected inside the ConfigSource.
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/TestConfigSourceProvider.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/TestConfigSourceProvider.java
index a2fda5f6..f283f150 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/TestConfigSourceProvider.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/TestConfigSourceProvider.java
@@ -39,12 +39,6 @@ public class TestConfigSourceProvider implements ConfigSourceProvider
private static class TestConfigSource1 implements ConfigSource
{
- @Override
- public int getOrdinal()
- {
- return 1;
- }
-
@Override
public String getPropertyValue(String key)
{
@@ -52,6 +46,10 @@ public class TestConfigSourceProvider implements ConfigSourceProvider
{
return "test1";
}
+ if (ConfigSource.DELTASPIKE_ORDINAL.equals(key))
+ {
+ return "1";
+ }
return null;
}
@@ -69,10 +67,6 @@ public class TestConfigSourceProvider implements ConfigSourceProvider
return TestConfigSourceProvider.class.getName();
}
- @Override
- public boolean isScannable() {
- return true;
- }
}
private static class TestConfigSource2 implements ConfigSource