Skip to content

Commit

Permalink
Allow to extend ConfigExtension.
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Jun 17, 2020
1 parent 8347b5b commit d9b362e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions cdi/src/main/java/io/smallrye/config/inject/ConfigExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.smallrye.config.inject;

import java.lang.reflect.ParameterizedType;
Expand Down Expand Up @@ -48,24 +47,23 @@
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2017 Red Hat inc.
*/
public class ConfigExtension implements Extension {

private Set<InjectionPoint> injectionPoints = new HashSet<>();
private final Set<InjectionPoint> injectionPoints = new HashSet<>();

public ConfigExtension() {
}

void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager bm) {
protected void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager bm) {
AnnotatedType<ConfigProducer> configBean = bm.createAnnotatedType(ConfigProducer.class);
bbd.addAnnotatedType(configBean, ConfigProducer.class.getName());
}

void collectConfigPropertyInjectionPoints(@Observes ProcessInjectionPoint<?, ?> pip) {
protected void collectConfigPropertyInjectionPoints(@Observes ProcessInjectionPoint<?, ?> pip) {
if (pip.getInjectionPoint().getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
injectionPoints.add(pip.getInjectionPoint());
}
}

void registerCustomBeans(@Observes AfterBeanDiscovery abd, BeanManager bm) {
protected void registerCustomBeans(@Observes AfterBeanDiscovery abd, BeanManager bm) {
Set<Class<?>> customTypes = new HashSet<>();
for (InjectionPoint ip : injectionPoints) {
Type requiredType = ip.getType();
Expand All @@ -91,8 +89,7 @@ void registerCustomBeans(@Observes AfterBeanDiscovery abd, BeanManager bm) {
}
}

void validate(@Observes AfterDeploymentValidation adv) {

protected void validate(@Observes AfterDeploymentValidation adv) {
Config config = ConfigProvider.getConfig();
for (InjectionPoint injectionPoint : injectionPoints) {
Type type = injectionPoint.getType();
Expand Down Expand Up @@ -131,7 +128,7 @@ void validate(@Observes AfterDeploymentValidation adv) {
}
}

static String getConfigKey(InjectionPoint ip, ConfigProperty configProperty) {
protected static String getConfigKey(InjectionPoint ip, ConfigProperty configProperty) {
String key = configProperty.name();
if (!key.trim().isEmpty()) {
return key;
Expand All @@ -152,6 +149,10 @@ static String getConfigKey(InjectionPoint ip, ConfigProperty configProperty) {
throw InjectionMessages.msg.noConfigPropertyDefaultName(ip);
}

protected Set<InjectionPoint> getInjectionPoints() {
return injectionPoints;
}

private static boolean isClassHandledByConfigProducer(Type requiredType) {
return requiredType == String.class
|| requiredType == Boolean.class
Expand Down

0 comments on commit d9b362e

Please sign in to comment.