-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from stuartwdouglas/explicit-config
Add support for explicit configuration
- Loading branch information
Showing
4 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
42 changes: 42 additions & 0 deletions
42
core/runtime/src/main/java/org/jboss/shamrock/runtime/ConfiguredValue.java
This file contains 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,42 @@ | ||
package org.jboss.shamrock.runtime; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
|
||
/** | ||
* Represents a value that can be read from MicroProfile config. It is designed to be passed | ||
* to Template objects, and as such can be configured at both build and run time. | ||
* | ||
* The value is determined as follows: | ||
* | ||
* - If the key is present in MPConfig at runtime, then the runtime value is used | ||
* - If the key is present at deployment time, then the deployment time value is used | ||
* - Otherwise the default value is used, or null if it was not provided | ||
* | ||
* TODO: this is a more explicit alternative to the transparent config option provided by ShamrockConfig. We should probably only have one, this is something to revisit later | ||
* | ||
*/ | ||
public class ConfiguredValue { | ||
|
||
private static final Config config = ConfigProvider.getConfig(); | ||
|
||
private final String key; | ||
private final String defaultValue; | ||
|
||
public ConfiguredValue(String key, String defaultValue) { | ||
this.key = key; | ||
this.defaultValue = defaultValue; | ||
} | ||
|
||
public String getValue() { | ||
return config.getOptionalValue(key, String.class).orElse(defaultValue); | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public String getDefaultValue() { | ||
return defaultValue; | ||
} | ||
} |
This file contains 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 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