From e575006dd92dc7ebbcc4cc742716c04e655d55be Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Mon, 14 Dec 2020 18:23:10 +0000 Subject: [PATCH] Moved CDI related code to its own module. (#465) --- cdi/pom.xml | 110 ++++++++++++++++++ .../config/inject/ConfigException.java | 2 +- .../config/inject/ConfigExtension.java | 0 .../config/inject/ConfigInjectionBean.java | 0 .../inject/ConfigMappingInjectionBean.java | 0 .../config/inject/ConfigProducer.java | 0 .../config/inject/ConfigProducerUtil.java | 0 .../config/inject/InjectionMessages.java | 0 .../config/inject/MetadataInjectionPoint.java | 0 .../config/inject/SecuritySupport.java | 0 .../javax.enterprise.inject.spi.Extension | 0 .../config/inject/ConfigInjectionTest.java | 0 .../inject/ConfigMappingInjectionTest.java | 0 .../InjectedConfigSerializationTest.java | 2 - .../smallrye/config/inject/InjectionTest.java | 4 +- .../inject/InjectionTestConfigFactory.java | 2 +- .../config/inject/KeyValuesConfigSource.java | 69 +++++++++++ .../config/inject/OptionalInjectionTest.java | 0 .../config/inject/SupplierInjectionTest.java | 0 .../config/inject/ValidateInjectionTest.java | 0 implementation/pom.xml | 34 +----- .../config/ConfigMappingInterface.java | 3 +- .../io/smallrye/config/ConfigMessages.java | 4 + pom.xml | 8 +- 24 files changed, 196 insertions(+), 42 deletions(-) create mode 100644 cdi/pom.xml rename {implementation => cdi}/src/main/java/io/smallrye/config/inject/ConfigException.java (99%) rename {implementation => cdi}/src/main/java/io/smallrye/config/inject/ConfigExtension.java (100%) rename {implementation => cdi}/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java (100%) rename {implementation => cdi}/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java (100%) rename {implementation => cdi}/src/main/java/io/smallrye/config/inject/ConfigProducer.java (100%) rename {implementation => cdi}/src/main/java/io/smallrye/config/inject/ConfigProducerUtil.java (100%) rename {implementation => cdi}/src/main/java/io/smallrye/config/inject/InjectionMessages.java (100%) rename {implementation => cdi}/src/main/java/io/smallrye/config/inject/MetadataInjectionPoint.java (100%) rename {implementation => cdi}/src/main/java/io/smallrye/config/inject/SecuritySupport.java (100%) rename {implementation => cdi}/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension (100%) rename {implementation => cdi}/src/test/java/io/smallrye/config/inject/ConfigInjectionTest.java (100%) rename {implementation => cdi}/src/test/java/io/smallrye/config/inject/ConfigMappingInjectionTest.java (100%) rename {implementation => cdi}/src/test/java/io/smallrye/config/inject/InjectedConfigSerializationTest.java (98%) rename {implementation => cdi}/src/test/java/io/smallrye/config/inject/InjectionTest.java (89%) rename {implementation => cdi}/src/test/java/io/smallrye/config/inject/InjectionTestConfigFactory.java (97%) create mode 100644 cdi/src/test/java/io/smallrye/config/inject/KeyValuesConfigSource.java rename {implementation => cdi}/src/test/java/io/smallrye/config/inject/OptionalInjectionTest.java (100%) rename {implementation => cdi}/src/test/java/io/smallrye/config/inject/SupplierInjectionTest.java (100%) rename {implementation => cdi}/src/test/java/io/smallrye/config/inject/ValidateInjectionTest.java (100%) diff --git a/cdi/pom.xml b/cdi/pom.xml new file mode 100644 index 000000000..ddcb6bcbd --- /dev/null +++ b/cdi/pom.xml @@ -0,0 +1,110 @@ + + + + + 4.0.0 + + + io.smallrye.config + smallrye-config-parent + 2.0.0-SNAPSHOT + + + smallrye-config + + SmallRye: MicroProfile Config CDI Implementation + + + + io.smallrye.config + smallrye-config-core + + + jakarta.enterprise + jakarta.enterprise.cdi-api + provided + + + org.jboss.logging + jboss-logging + + + org.jboss.logging + jboss-logging-annotations + + + org.jboss.logging + jboss-logging-processor + + + + + org.junit.jupiter + junit-jupiter + + + org.junit.platform + junit-platform-launcher + test + + + org.junit.platform + junit-platform-testkit + test + + + org.junit.platform + junit-platform-commons + test + + + org.jboss.weld + weld-junit5 + + + javax.enterprise + cdi-api + + + + + + + + coverage + + @{jacocoArgLine} + + + + + org.jacoco + jacoco-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + @{jacocoArgLine} -Xmx512m + + + + + + + + diff --git a/implementation/src/main/java/io/smallrye/config/inject/ConfigException.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigException.java similarity index 99% rename from implementation/src/main/java/io/smallrye/config/inject/ConfigException.java rename to cdi/src/main/java/io/smallrye/config/inject/ConfigException.java index 10ab2b310..9f923d680 100644 --- a/implementation/src/main/java/io/smallrye/config/inject/ConfigException.java +++ b/cdi/src/main/java/io/smallrye/config/inject/ConfigException.java @@ -42,4 +42,4 @@ public String getConfigPropertyName() { return configPropertyName; } -} \ No newline at end of file +} diff --git a/implementation/src/main/java/io/smallrye/config/inject/ConfigExtension.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigExtension.java similarity index 100% rename from implementation/src/main/java/io/smallrye/config/inject/ConfigExtension.java rename to cdi/src/main/java/io/smallrye/config/inject/ConfigExtension.java diff --git a/implementation/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java similarity index 100% rename from implementation/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java rename to cdi/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java diff --git a/implementation/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java similarity index 100% rename from implementation/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java rename to cdi/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java diff --git a/implementation/src/main/java/io/smallrye/config/inject/ConfigProducer.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigProducer.java similarity index 100% rename from implementation/src/main/java/io/smallrye/config/inject/ConfigProducer.java rename to cdi/src/main/java/io/smallrye/config/inject/ConfigProducer.java diff --git a/implementation/src/main/java/io/smallrye/config/inject/ConfigProducerUtil.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigProducerUtil.java similarity index 100% rename from implementation/src/main/java/io/smallrye/config/inject/ConfigProducerUtil.java rename to cdi/src/main/java/io/smallrye/config/inject/ConfigProducerUtil.java diff --git a/implementation/src/main/java/io/smallrye/config/inject/InjectionMessages.java b/cdi/src/main/java/io/smallrye/config/inject/InjectionMessages.java similarity index 100% rename from implementation/src/main/java/io/smallrye/config/inject/InjectionMessages.java rename to cdi/src/main/java/io/smallrye/config/inject/InjectionMessages.java diff --git a/implementation/src/main/java/io/smallrye/config/inject/MetadataInjectionPoint.java b/cdi/src/main/java/io/smallrye/config/inject/MetadataInjectionPoint.java similarity index 100% rename from implementation/src/main/java/io/smallrye/config/inject/MetadataInjectionPoint.java rename to cdi/src/main/java/io/smallrye/config/inject/MetadataInjectionPoint.java diff --git a/implementation/src/main/java/io/smallrye/config/inject/SecuritySupport.java b/cdi/src/main/java/io/smallrye/config/inject/SecuritySupport.java similarity index 100% rename from implementation/src/main/java/io/smallrye/config/inject/SecuritySupport.java rename to cdi/src/main/java/io/smallrye/config/inject/SecuritySupport.java diff --git a/implementation/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension similarity index 100% rename from implementation/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension rename to cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension diff --git a/implementation/src/test/java/io/smallrye/config/inject/ConfigInjectionTest.java b/cdi/src/test/java/io/smallrye/config/inject/ConfigInjectionTest.java similarity index 100% rename from implementation/src/test/java/io/smallrye/config/inject/ConfigInjectionTest.java rename to cdi/src/test/java/io/smallrye/config/inject/ConfigInjectionTest.java diff --git a/implementation/src/test/java/io/smallrye/config/inject/ConfigMappingInjectionTest.java b/cdi/src/test/java/io/smallrye/config/inject/ConfigMappingInjectionTest.java similarity index 100% rename from implementation/src/test/java/io/smallrye/config/inject/ConfigMappingInjectionTest.java rename to cdi/src/test/java/io/smallrye/config/inject/ConfigMappingInjectionTest.java diff --git a/implementation/src/test/java/io/smallrye/config/inject/InjectedConfigSerializationTest.java b/cdi/src/test/java/io/smallrye/config/inject/InjectedConfigSerializationTest.java similarity index 98% rename from implementation/src/test/java/io/smallrye/config/inject/InjectedConfigSerializationTest.java rename to cdi/src/test/java/io/smallrye/config/inject/InjectedConfigSerializationTest.java index f053f1bde..4f2c72ef1 100644 --- a/implementation/src/test/java/io/smallrye/config/inject/InjectedConfigSerializationTest.java +++ b/cdi/src/test/java/io/smallrye/config/inject/InjectedConfigSerializationTest.java @@ -20,8 +20,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import io.smallrye.config.KeyValuesConfigSource; - @ExtendWith(WeldJunit5Extension.class) class InjectedConfigSerializationTest extends InjectionTest { diff --git a/implementation/src/test/java/io/smallrye/config/inject/InjectionTest.java b/cdi/src/test/java/io/smallrye/config/inject/InjectionTest.java similarity index 89% rename from implementation/src/test/java/io/smallrye/config/inject/InjectionTest.java rename to cdi/src/test/java/io/smallrye/config/inject/InjectionTest.java index 4ac2e2ea8..a03e92795 100644 --- a/implementation/src/test/java/io/smallrye/config/inject/InjectionTest.java +++ b/cdi/src/test/java/io/smallrye/config/inject/InjectionTest.java @@ -15,9 +15,7 @@ public abstract class InjectionTest { protected static void beforeClass() throws Exception { final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); final URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { - new URL("memory", null, 0, "/", - new InMemoryStreamHandler( - "io.smallrye.config.inject.InjectionTestConfigFactory")) + new URL("memory", null, 0, "/", new InMemoryStreamHandler(InjectionTestConfigFactory.class.getName())) }, contextClassLoader); Thread.currentThread().setContextClassLoader(urlClassLoader); } diff --git a/implementation/src/test/java/io/smallrye/config/inject/InjectionTestConfigFactory.java b/cdi/src/test/java/io/smallrye/config/inject/InjectionTestConfigFactory.java similarity index 97% rename from implementation/src/test/java/io/smallrye/config/inject/InjectionTestConfigFactory.java rename to cdi/src/test/java/io/smallrye/config/inject/InjectionTestConfigFactory.java index 3ab66edd1..23837db06 100644 --- a/implementation/src/test/java/io/smallrye/config/inject/InjectionTestConfigFactory.java +++ b/cdi/src/test/java/io/smallrye/config/inject/InjectionTestConfigFactory.java @@ -1,6 +1,6 @@ package io.smallrye.config.inject; -import static io.smallrye.config.KeyValuesConfigSource.config; +import static io.smallrye.config.inject.KeyValuesConfigSource.config; import java.util.HashMap; import java.util.HashSet; diff --git a/cdi/src/test/java/io/smallrye/config/inject/KeyValuesConfigSource.java b/cdi/src/test/java/io/smallrye/config/inject/KeyValuesConfigSource.java new file mode 100644 index 000000000..259b58d4d --- /dev/null +++ b/cdi/src/test/java/io/smallrye/config/inject/KeyValuesConfigSource.java @@ -0,0 +1,69 @@ +/* + * Copyright 2017 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.smallrye.config.inject; + +import java.io.Serializable; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.eclipse.microprofile.config.spi.ConfigSource; + +public class KeyValuesConfigSource implements ConfigSource, Serializable { + + private final Map properties = new HashMap<>(); + + private KeyValuesConfigSource(Map properties) { + this.properties.putAll(properties); + } + + @Override + public Map getProperties() { + return Collections.unmodifiableMap(properties); + } + + @Override + public Set getPropertyNames() { + return Collections.unmodifiableSet(properties.keySet()); + } + + @Override + public String getValue(String propertyName) { + return properties.get(propertyName); + } + + @Override + public String getName() { + return "KeyValuesConfigSource"; + } + + public static ConfigSource config(Map properties) { + return new KeyValuesConfigSource(properties); + } + + public static ConfigSource config(String... keyValues) { + if (keyValues.length % 2 != 0) { + throw new IllegalArgumentException("keyValues array must be a multiple of 2"); + } + + Map props = new HashMap<>(); + for (int i = 0; i < keyValues.length; i += 2) { + props.put(keyValues[i], keyValues[i + 1]); + } + return new KeyValuesConfigSource(props); + } +} diff --git a/implementation/src/test/java/io/smallrye/config/inject/OptionalInjectionTest.java b/cdi/src/test/java/io/smallrye/config/inject/OptionalInjectionTest.java similarity index 100% rename from implementation/src/test/java/io/smallrye/config/inject/OptionalInjectionTest.java rename to cdi/src/test/java/io/smallrye/config/inject/OptionalInjectionTest.java diff --git a/implementation/src/test/java/io/smallrye/config/inject/SupplierInjectionTest.java b/cdi/src/test/java/io/smallrye/config/inject/SupplierInjectionTest.java similarity index 100% rename from implementation/src/test/java/io/smallrye/config/inject/SupplierInjectionTest.java rename to cdi/src/test/java/io/smallrye/config/inject/SupplierInjectionTest.java diff --git a/implementation/src/test/java/io/smallrye/config/inject/ValidateInjectionTest.java b/cdi/src/test/java/io/smallrye/config/inject/ValidateInjectionTest.java similarity index 100% rename from implementation/src/test/java/io/smallrye/config/inject/ValidateInjectionTest.java rename to cdi/src/test/java/io/smallrye/config/inject/ValidateInjectionTest.java diff --git a/implementation/pom.xml b/implementation/pom.xml index 5d57ee37c..03924a766 100644 --- a/implementation/pom.xml +++ b/implementation/pom.xml @@ -23,20 +23,15 @@ 2.0.0-SNAPSHOT - smallrye-config + smallrye-config-core - SmallRye: MicroProfile Config Implementation + SmallRye: MicroProfile Config Core Implementation org.eclipse.microprofile.config microprofile-config-api - - jakarta.enterprise - jakarta.enterprise.cdi-api - provided - jakarta.annotation jakarta.annotation-api @@ -83,31 +78,6 @@ org.junit.jupiter junit-jupiter - - org.junit.platform - junit-platform-launcher - test - - - org.junit.platform - junit-platform-testkit - test - - - org.junit.platform - junit-platform-commons - test - - - org.jboss.weld - weld-junit5 - - - javax.enterprise - cdi-api - - - io.smallrye.testing smallrye-testing-utilities diff --git a/implementation/src/main/java/io/smallrye/config/ConfigMappingInterface.java b/implementation/src/main/java/io/smallrye/config/ConfigMappingInterface.java index f6ae8e99c..12a160876 100644 --- a/implementation/src/main/java/io/smallrye/config/ConfigMappingInterface.java +++ b/implementation/src/main/java/io/smallrye/config/ConfigMappingInterface.java @@ -18,7 +18,6 @@ import org.eclipse.microprofile.config.spi.Converter; import io.smallrye.common.constraint.Assert; -import io.smallrye.config.inject.InjectionMessages; /** * Information about a configuration interface. @@ -695,7 +694,7 @@ static Class rawTypeOf(final Type type) { return Object.class; } } else { - throw InjectionMessages.msg.noRawType(type); + throw ConfigMessages.msg.noRawType(type); } } } diff --git a/implementation/src/main/java/io/smallrye/config/ConfigMessages.java b/implementation/src/main/java/io/smallrye/config/ConfigMessages.java index 2f5f65819..045dcacc9 100644 --- a/implementation/src/main/java/io/smallrye/config/ConfigMessages.java +++ b/implementation/src/main/java/io/smallrye/config/ConfigMessages.java @@ -1,6 +1,7 @@ package io.smallrye.config; import java.io.InvalidObjectException; +import java.lang.reflect.Type; import java.util.NoSuchElementException; import java.util.regex.Pattern; @@ -127,4 +128,7 @@ interface ConfigMessages { @Message(id = 37, value = "The Converter API cannot convert a null value") NullPointerException converterNullValue(); + + @Message(id = 38, value = "Type has no raw type class: %s") + IllegalArgumentException noRawType(Type type); } diff --git a/pom.xml b/pom.xml index e536a2539..5ee7650fd 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ SmallRye Config ${project.basedir}/../coverage/target/site/jacoco-aggregate/jacoco.xml - + Apache License, Version 2.0 @@ -67,6 +67,7 @@ common implementation + cdi sources/hocon sources/file-system sources/yaml @@ -126,6 +127,11 @@ smallrye-config-common ${project.version} + + io.smallrye.config + smallrye-config-core + ${project.version} + io.smallrye.config smallrye-config