-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#59 - Added a ConfigValueConfigSource so it can be combined with inte…
…rceptors and trace the origin of a configuration key.
- Loading branch information
Showing
10 changed files
with
614 additions
and
9 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
39 changes: 39 additions & 0 deletions
39
implementation/src/main/java/io/smallrye/config/ConfigValueConfigSource.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,39 @@ | ||
package io.smallrye.config; | ||
|
||
import static java.util.stream.Collectors.toMap; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
|
||
import org.eclipse.microprofile.config.spi.ConfigSource; | ||
|
||
public interface ConfigValueConfigSource extends ConfigSource { | ||
ConfigValue getConfigValue(String propertyName); | ||
|
||
Map<String, ConfigValue> getConfigValueProperties(); | ||
|
||
@Override | ||
default Map<String, String> getProperties() { | ||
return getConfigValueProperties().entrySet() | ||
.stream() | ||
.collect(toMap(Map.Entry::getKey, | ||
new Function<Map.Entry<String, ConfigValue>, String>() { | ||
@Override | ||
public String apply(final Map.Entry<String, ConfigValue> entry) { | ||
return entry.getValue() != null ? entry.getValue().getValue() : null; | ||
} | ||
})); | ||
} | ||
|
||
@Override | ||
default Set<String> getPropertyNames() { | ||
return getProperties().keySet(); | ||
} | ||
|
||
@Override | ||
default String getValue(String propertyName) { | ||
final ConfigValue value = getConfigValue(propertyName); | ||
return value != null ? value.getValue() : null; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
implementation/src/main/java/io/smallrye/config/ConfigValueConfigSourceInterceptor.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,23 @@ | ||
package io.smallrye.config; | ||
|
||
import javax.annotation.Priority; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
@Priority(100) | ||
public class ConfigValueConfigSourceInterceptor implements ConfigSourceInterceptor { | ||
private static final Logger LOG = Logger.getLogger("io.smallrye.config"); | ||
|
||
@Override | ||
public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) { | ||
final ConfigValue configValue = context.proceed(name); | ||
|
||
LOG.infof("The configuration %s with the value %s was loaded from %s:%d", | ||
configValue.getName(), | ||
configValue.getValue(), | ||
configValue.getConfigSourceName(), | ||
configValue.getLineNumber()); | ||
|
||
return configValue; | ||
} | ||
} |
Oops, something went wrong.