From 9f876e1402abcc3cacb9164ddeda420406425ab3 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Thu, 27 Aug 2026 22:56:44 +0100 Subject: [PATCH] Remove CDI config-source-injection and config-events modules --- coverage/pom.xml | 12 -- documentation/mkdocs.yaml | 2 - .../src/main/docs/extensions/config-events.md | 150 ------------------ .../extensions/config-source-injection.md | 39 ----- pom.xml | 2 - utils/cdi-provider/build-test-java17 | 0 utils/cdi-provider/build-test-java21 | 0 utils/cdi-provider/build-test-java25 | 0 utils/cdi-provider/pom.xml | 77 --------- .../util/injection/ConfigSourceMap.java | 19 --- .../util/injection/ConfigSourceProvider.java | 71 --------- .../smallrye/config/util/injection/Name.java | 22 --- .../src/main/java/module-info.java | 9 -- .../src/main/resources/META-INF/beans.xml | 5 - .../test/ConfigSourceProviderTest.java | 86 ---------- .../util/injection/test/InjectionTest.java | 57 ------- .../test/InjectionTestConfigFactory.java | 24 --- .../src/test/java/module-info.java | 14 -- utils/events/build-test-java17 | 0 utils/events/build-test-java21 | 0 utils/events/build-test-java25 | 0 utils/events/pom.xml | 70 -------- .../smallrye/config/events/ChangeEvent.java | 52 ------ .../config/events/ChangeEventNotifier.java | 96 ----------- .../io/smallrye/config/events/KeyFilter.java | 36 ----- .../smallrye/config/events/SourceFilter.java | 36 ----- .../java/io/smallrye/config/events/Type.java | 7 - .../io/smallrye/config/events/TypeFilter.java | 36 ----- .../smallrye/config/events/regex/Field.java | 13 -- .../config/events/regex/RegexFilter.java | 27 ---- .../events/regex/RegexFilterInterceptor.java | 71 --------- .../config/events/regex/RegexLogging.java | 22 --- utils/events/src/main/java/module-info.java | 12 -- .../src/main/resources/META-INF/beans.xml | 5 - .../events/ChangeEventNotifierTest.java | 105 ------------ 35 files changed, 1177 deletions(-) delete mode 100644 documentation/src/main/docs/extensions/config-events.md delete mode 100644 documentation/src/main/docs/extensions/config-source-injection.md delete mode 100644 utils/cdi-provider/build-test-java17 delete mode 100644 utils/cdi-provider/build-test-java21 delete mode 100644 utils/cdi-provider/build-test-java25 delete mode 100644 utils/cdi-provider/pom.xml delete mode 100644 utils/cdi-provider/src/main/java/io/smallrye/config/util/injection/ConfigSourceMap.java delete mode 100644 utils/cdi-provider/src/main/java/io/smallrye/config/util/injection/ConfigSourceProvider.java delete mode 100644 utils/cdi-provider/src/main/java/io/smallrye/config/util/injection/Name.java delete mode 100644 utils/cdi-provider/src/main/java/module-info.java delete mode 100644 utils/cdi-provider/src/main/resources/META-INF/beans.xml delete mode 100644 utils/cdi-provider/src/test/java/io/smallrye/config/util/injection/test/ConfigSourceProviderTest.java delete mode 100644 utils/cdi-provider/src/test/java/io/smallrye/config/util/injection/test/InjectionTest.java delete mode 100644 utils/cdi-provider/src/test/java/io/smallrye/config/util/injection/test/InjectionTestConfigFactory.java delete mode 100644 utils/cdi-provider/src/test/java/module-info.java delete mode 100644 utils/events/build-test-java17 delete mode 100644 utils/events/build-test-java21 delete mode 100644 utils/events/build-test-java25 delete mode 100644 utils/events/pom.xml delete mode 100644 utils/events/src/main/java/io/smallrye/config/events/ChangeEvent.java delete mode 100644 utils/events/src/main/java/io/smallrye/config/events/ChangeEventNotifier.java delete mode 100644 utils/events/src/main/java/io/smallrye/config/events/KeyFilter.java delete mode 100644 utils/events/src/main/java/io/smallrye/config/events/SourceFilter.java delete mode 100644 utils/events/src/main/java/io/smallrye/config/events/Type.java delete mode 100644 utils/events/src/main/java/io/smallrye/config/events/TypeFilter.java delete mode 100644 utils/events/src/main/java/io/smallrye/config/events/regex/Field.java delete mode 100644 utils/events/src/main/java/io/smallrye/config/events/regex/RegexFilter.java delete mode 100644 utils/events/src/main/java/io/smallrye/config/events/regex/RegexFilterInterceptor.java delete mode 100644 utils/events/src/main/java/io/smallrye/config/events/regex/RegexLogging.java delete mode 100644 utils/events/src/main/java/module-info.java delete mode 100644 utils/events/src/main/resources/META-INF/beans.xml delete mode 100644 utils/events/src/test/java/io/smallrye/config/events/ChangeEventNotifierTest.java diff --git a/coverage/pom.xml b/coverage/pom.xml index ec77f550e..ace4a0ebb 100644 --- a/coverage/pom.xml +++ b/coverage/pom.xml @@ -70,18 +70,6 @@ smallrye-config-crypto ${project.version} - - - io.smallrye.config - smallrye-config-events - ${project.version} - - - io.smallrye.config - smallrye-config-source-injection - ${project.version} - - io.smallrye.config diff --git a/documentation/mkdocs.yaml b/documentation/mkdocs.yaml index 312a7396d..bbdfe8908 100644 --- a/documentation/mkdocs.yaml +++ b/documentation/mkdocs.yaml @@ -37,8 +37,6 @@ nav: - 'Fallback': extensions/fallback.md - 'Relocate': extensions/relocate.md - 'Logging': extensions/logging.md - - 'Events': extensions/config-events.md - - 'Config Source Injection': extensions/config-source-injection.md plugins: - search diff --git a/documentation/src/main/docs/extensions/config-events.md b/documentation/src/main/docs/extensions/config-events.md deleted file mode 100644 index f778acbca..000000000 --- a/documentation/src/main/docs/extensions/config-events.md +++ /dev/null @@ -1,150 +0,0 @@ -# Config Events - -The Config Events extension allows you to fire change events on Config Sources. - -## Usage - -To use the Config Events, add the following to your Maven `pom.xml`: - -```xml - - io.smallrye.config - smallrye-config-events - {{attributes['version']}} - -``` - -## Events - -The CDI Event is a `ChangeEvent` and contains the following fields: - -- String key -- Optional\ oldValue -- String newValue -- Type type -- String fromSource - -The `ChangeEvent` can be of any of the following types: - -- NEW - When you create a new key and value (i.e. the key does not exist anywhere in any config source) -- UPDATE - When you update a value of an existing key (i.e. the key and value exist somewhere in a config source) -- REMOVE - When you remove the value from the source (and that changed the overall config) - -### Observing Events - -You can listen to all or some of these events, filtering by `type` and/or `key` and/or `source`, example: - -```java -// Getting all config event -public void all(@Observes ChangeEvent changeEvent){ - log.log(Level.SEVERE, "ALL: Received a config change event: {0}", changeEvent); -} - -// Get only new values -public void newValue(@Observes @TypeFilter(Type.NEW) ChangeEvent changeEvent){ - log.log(Level.SEVERE, "NEW: Received a config change event: {0}", changeEvent); -} - -// Get only override values -public void overrideValue(@Observes @TypeFilter(Type.UPDATE) ChangeEvent changeEvent){ - log.log(Level.SEVERE, "UPDATE: Received a config change event: {0}", changeEvent); -} - -// Get only revert values -public void revertValue(@Observes @TypeFilter(Type.REMOVE) ChangeEvent changeEvent){ - log.log(Level.SEVERE, "REMOVE: Received a config change event: {0}", changeEvent); -} - -// Getting all config event when key is some.key -public void allForKey(@Observes @KeyFilter("some.key") ChangeEvent changeEvent){ - log.log(Level.SEVERE, "ALL for key [some.key]: Received a config change event: {0}", changeEvent); -} - -// Getting all config event when key is some.key for new events -public void newForKey(@Observes @TypeFilter(Type.NEW) @KeyFilter("some.key") ChangeEvent changeEvent){ - log.log(Level.SEVERE, "NEW for key [some.key]: Received a config change event: {0}", changeEvent); -} - -// Getting all config event when key is some.key for override events -public void overrideForKey(@Observes @TypeFilter(Type.UPDATE) @KeyFilter("some.key") ChangeEvent changeEvent){ - log.log(Level.SEVERE, "UPDATE for key [some.key]: Received a config change event: {0}", changeEvent); -} - -// Getting all config event when key is some.key for revert events -public void revertForKey(@Observes @TypeFilter(Type.REMOVE) @KeyFilter("some.key") ChangeEvent changeEvent){ - log.log(Level.SEVERE, "REMOVE for key [some.key]: Received a config change event: {0}", changeEvent); -} - -// Getting all config events for a certain source -public void allForSource(@Observes @SourceFilter("MemoryConfigSource") ChangeEvent changeEvent){ - log.log(Level.SEVERE, "ALL for source [MemoryConfigSource]: Received a config change event: {0}", changeEvent); -} - -// Getting all config events for a certain source -public void allForSourceAndKey(@Observes @SourceFilter("MemoryConfigSource") @KeyFilter("some.key") ChangeEvent changeEvent){ - log.log(Level.SEVERE, "ALL for source [MemoryConfigSource] and for key [some.key]: Received a config change event: {0}", changeEvent); -} - -// Getting all config events for a certain source -public void overrideForSourceAndKey(@Observes @TypeFilter(Type.UPDATE) @SourceFilter("MemoryConfigSource") @KeyFilter("some.key") ChangeEvent changeEvent){ - log.log(Level.SEVERE, "UPDATE for source [MemoryConfigSource] and for key [some.key]: Received a config change event: {0}", changeEvent); -} -``` - -Note: You can filter by including the `@TypeFilter` and/or the `@KeyFilter` and/or the `@SourceFilter`. - -### Pattern matching on field. - -You might want to listen for fields that match a certain regex. - -Example, listen to all keys that starts with `some.`: - -```java -@RegexFilter("^some\\..+") -public void allForPatternMatchOnKey(@Observes ChangeEvent changeEvent){ - log.log(Level.SEVERE, "Pattern match on key: Received a config change event: {0}", changeEvent); -} -``` - -By default, it will match on `key`, however you also listen on another field, for example, listen to all `oldValue` -that starts with `some.`: - -```java -@RegexFilter(onField = Field.oldValue, value = "^some\\..+") -public void allForPatternMatchOnOldValue(@Observes ChangeEvent changeEvent){ - log.log(Level.SEVERE, "Pattern match on old value: Received a config change event: {0}", changeEvent); -} -``` - -You can Match on the following fields of the `ChangeEvent` object: - -- key -- oldValue -- newValue -- fromSource - -## Implementing Events in a ConfigSource - -The `ChangeEventNotifier` allows you to detect changes and fire the appropriate events. - -To use it in your own source: - -- Get a snapshot of the properties before the change. -- Get a snapshot of the properties after the change. -- Call `detectChangesAndFire` method: - -Example: - -```java -Map before = new HashMap<>(configSource.getProperties()); -memoryConfigSource.getProperties().remove(key); -Map after = new HashMap<>(configSource.getProperties()); -ChangeEventNotifier.getInstance().detectChangesAndFire(before, after,configSource.getName()); -``` - -or if you know the change and do not need detection: - -```java -configSource.getProperties().remove(key); -ChangeEventNotifier.getInstance().fire(new ChangeEvent(Type.REMOVE,key,getOptionalOldValue(oldValue),null,configSource.getName())); -``` diff --git a/documentation/src/main/docs/extensions/config-source-injection.md b/documentation/src/main/docs/extensions/config-source-injection.md deleted file mode 100644 index 4f2fb8aa4..000000000 --- a/documentation/src/main/docs/extensions/config-source-injection.md +++ /dev/null @@ -1,39 +0,0 @@ -# Config Source Injection - -The Config Source Injection extension allows you to use CDI injection to inject a ConfigSource by name in your CDI -aware beans, or by looking it up programatically in the CDI `BeanManager`. - -## Usage - -To use the Config Source Injection, add the following to your Maven `pom.xml`: - -```xml - - io.smallrye.config - smallrye-config-source-injection - {{attributes['version']}} - -``` - -### Injecting Sources - -You can inject a `ConfigSource` by referencing it by name: - -```java -@Inject -@Name("MemoryConfigSource") -private ConfigSource memoryConfigSource; - -@Inject -@Name("SysPropConfigSource") -private ConfigSource systemPropertiesConfigSource; -``` - -You can also get a Map of all config sources. The map key holds the `ConfigSource` name and the map value the -`ConfigSource`: - -```java -@Inject -@ConfigSourceMap -private Map configSourceMap; -``` diff --git a/pom.xml b/pom.xml index 905054f4a..391ea2572 100644 --- a/pom.xml +++ b/pom.xml @@ -78,8 +78,6 @@ sources/yaml sources/zookeeper sources/keystore - utils/events - utils/cdi-provider utils/crypto documentation diff --git a/utils/cdi-provider/build-test-java17 b/utils/cdi-provider/build-test-java17 deleted file mode 100644 index e69de29bb..000000000 diff --git a/utils/cdi-provider/build-test-java21 b/utils/cdi-provider/build-test-java21 deleted file mode 100644 index e69de29bb..000000000 diff --git a/utils/cdi-provider/build-test-java25 b/utils/cdi-provider/build-test-java25 deleted file mode 100644 index e69de29bb..000000000 diff --git a/utils/cdi-provider/pom.xml b/utils/cdi-provider/pom.xml deleted file mode 100644 index 931ab59aa..000000000 --- a/utils/cdi-provider/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - 4.0.0 - - - io.smallrye.config - smallrye-config-parent - 4.0.0-SNAPSHOT - ../../ - - - smallrye-config-source-injection - - SmallRye Config: CDI ConfigSource Injection - - - - jakarta.enterprise - jakarta.enterprise.cdi-api - provided - - - - org.eclipse.microprofile.config - microprofile-config-api - provided - - - - - org.junit.jupiter - junit-jupiter - - - - org.jboss.weld - weld-junit5 - - - - io.smallrye.config - smallrye-config - test - - - io.smallrye.config - smallrye-config-core - test - - - - - - - maven-compiler-plugin - - - default-testCompile - - - --add-modules=io.smallrye.config - --add-reads=io.smallrye.config.util.injection=io.smallrye.config.inject,io.smallrye.config - - - - - - - maven-surefire-plugin - - - false - - - - - diff --git a/utils/cdi-provider/src/main/java/io/smallrye/config/util/injection/ConfigSourceMap.java b/utils/cdi-provider/src/main/java/io/smallrye/config/util/injection/ConfigSourceMap.java deleted file mode 100644 index 82901427e..000000000 --- a/utils/cdi-provider/src/main/java/io/smallrye/config/util/injection/ConfigSourceMap.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.smallrye.config.util.injection; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import jakarta.inject.Qualifier; - -/** - * Mark a map that contains the config sources - * - * @author Phillip Kruger - */ -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.METHOD, ElementType.FIELD }) -public @interface ConfigSourceMap { -} diff --git a/utils/cdi-provider/src/main/java/io/smallrye/config/util/injection/ConfigSourceProvider.java b/utils/cdi-provider/src/main/java/io/smallrye/config/util/injection/ConfigSourceProvider.java deleted file mode 100644 index a6eee7e02..000000000 --- a/utils/cdi-provider/src/main/java/io/smallrye/config/util/injection/ConfigSourceProvider.java +++ /dev/null @@ -1,71 +0,0 @@ -package io.smallrye.config.util.injection; - -import java.lang.annotation.Annotation; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -import jakarta.annotation.PostConstruct; -import jakarta.enterprise.context.Dependent; -import jakarta.enterprise.inject.Produces; -import jakarta.enterprise.inject.spi.InjectionPoint; -import jakarta.inject.Inject; -import jakarta.inject.Provider; - -import org.eclipse.microprofile.config.Config; -import org.eclipse.microprofile.config.spi.ConfigSource; - -/** - * Making the Config sources available via CDI - * - * @author Phillip Kruger - */ -@Dependent -public class ConfigSourceProvider { - @Inject - private Provider configProvider; - - private final Map configSourceMap = new HashMap() { - @Override - public Collection values() { - return StreamSupport.stream(configProvider.get().getConfigSources().spliterator(), false) - .collect(Collectors.toList()); - } - }; - - @PostConstruct - public void init() { - if (this.configSourceMap.isEmpty()) { - for (ConfigSource configSource : configProvider.get().getConfigSources()) { - this.configSourceMap.put(configSource.getName(), configSource); - } - } - } - - @Produces - @ConfigSourceMap - public Map produceConfigSourceMap() { - return this.configSourceMap; - } - - @Produces - @Name("") - public ConfigSource produceConfigSource(final InjectionPoint injectionPoint) { - Set qualifiers = injectionPoint.getQualifiers(); - String name = getName(qualifiers); - return configSourceMap.get(name); - } - - private String getName(Set qualifiers) { - for (Annotation qualifier : qualifiers) { - if (qualifier.annotationType().equals(Name.class)) { - Name name = (Name) qualifier; - return name.value(); - } - } - return ""; - } -} diff --git a/utils/cdi-provider/src/main/java/io/smallrye/config/util/injection/Name.java b/utils/cdi-provider/src/main/java/io/smallrye/config/util/injection/Name.java deleted file mode 100644 index 58408c7e2..000000000 --- a/utils/cdi-provider/src/main/java/io/smallrye/config/util/injection/Name.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.smallrye.config.util.injection; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import jakarta.enterprise.util.Nonbinding; -import jakarta.inject.Qualifier; - -/** - * The define the name of a config source - * - * @author Phillip Kruger - */ -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.METHOD, ElementType.FIELD }) -public @interface Name { - @Nonbinding - String value(); -} diff --git a/utils/cdi-provider/src/main/java/module-info.java b/utils/cdi-provider/src/main/java/module-info.java deleted file mode 100644 index 9c698e35a..000000000 --- a/utils/cdi-provider/src/main/java/module-info.java +++ /dev/null @@ -1,9 +0,0 @@ -module io.smallrye.config.util.injection { - requires jakarta.annotation; - requires jakarta.cdi; - requires jakarta.inject; - - requires transitive org.eclipse.microprofile.config; - - exports io.smallrye.config.util.injection; -} \ No newline at end of file diff --git a/utils/cdi-provider/src/main/resources/META-INF/beans.xml b/utils/cdi-provider/src/main/resources/META-INF/beans.xml deleted file mode 100644 index ad2a3b6ec..000000000 --- a/utils/cdi-provider/src/main/resources/META-INF/beans.xml +++ /dev/null @@ -1,5 +0,0 @@ - - diff --git a/utils/cdi-provider/src/test/java/io/smallrye/config/util/injection/test/ConfigSourceProviderTest.java b/utils/cdi-provider/src/test/java/io/smallrye/config/util/injection/test/ConfigSourceProviderTest.java deleted file mode 100644 index 0d040d7a0..000000000 --- a/utils/cdi-provider/src/test/java/io/smallrye/config/util/injection/test/ConfigSourceProviderTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package io.smallrye.config.util.injection.test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.util.Iterator; -import java.util.Map; - -import jakarta.inject.Inject; - -import org.eclipse.microprofile.config.Config; -import org.eclipse.microprofile.config.spi.ConfigSource; -import org.jboss.weld.junit5.WeldInitiator; -import org.jboss.weld.junit5.WeldJunit5Extension; -import org.jboss.weld.junit5.WeldSetup; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import io.smallrye.config.inject.ConfigExtension; -import io.smallrye.config.util.injection.ConfigSourceMap; -import io.smallrye.config.util.injection.ConfigSourceProvider; -import io.smallrye.config.util.injection.Name; - -/** - * Testing the injection of a Config source name and the Config Source Map - * - * @author Phillip Kruger - */ -@ExtendWith(WeldJunit5Extension.class) -class ConfigSourceProviderTest extends InjectionTest { - @WeldSetup - WeldInitiator weld = WeldInitiator.from(ConfigExtension.class, ConfigSourceProvider.class) - .addBeans() - .inject(this) - .build(); - - @Inject - @Name("SysPropConfigSource") - ConfigSource systemPropertiesConfigSource; - - @Inject - @Name("PropertiesConfigSource[source=memory]") - ConfigSource propertiesConfigSource; - - @Inject - @ConfigSourceMap - Map configSourceMap; - - @Inject - Config config; - - @Test - void injectionByName() { - assertNotNull(systemPropertiesConfigSource); - assertFalse(systemPropertiesConfigSource.getProperties().isEmpty()); - } - - @Test - void injectOfPropertiesFile() { - assertNotNull(propertiesConfigSource); - assertFalse(propertiesConfigSource.getProperties().isEmpty()); - Map properties = propertiesConfigSource.getProperties(); - assertNotNull(properties); - assertEquals(1, properties.size()); - assertEquals("testvalue", properties.get("testkey")); - } - - @Test - void injectionOfMap() { - assertNotNull(configSourceMap); - assertFalse(configSourceMap.isEmpty()); - } - - @Test - void sourcesOrder() { - Iterator sources = config.getConfigSources().iterator(); - Iterator mapSources = configSourceMap.values().iterator(); - - while (sources.hasNext()) { - assertEquals(sources.next(), mapSources.next()); - } - - assertFalse(mapSources.hasNext()); - } -} diff --git a/utils/cdi-provider/src/test/java/io/smallrye/config/util/injection/test/InjectionTest.java b/utils/cdi-provider/src/test/java/io/smallrye/config/util/injection/test/InjectionTest.java deleted file mode 100644 index 1803ad22d..000000000 --- a/utils/cdi-provider/src/test/java/io/smallrye/config/util/injection/test/InjectionTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package io.smallrye.config.util.injection.test; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLClassLoader; -import java.net.URLConnection; -import java.net.URLStreamHandler; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; - -public abstract class InjectionTest { - @BeforeAll - public 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.util.injection.test.InjectionTestConfigFactory")) - }, contextClassLoader); - Thread.currentThread().setContextClassLoader(urlClassLoader); - } - - @AfterAll - public static void afterClass() { - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(contextClassLoader.getParent()); - } - - public static class InMemoryStreamHandler extends URLStreamHandler { - final byte[] contents; - - public InMemoryStreamHandler(final String contents) { - this.contents = contents.getBytes(); - } - - @Override - protected URLConnection openConnection(final URL u) throws IOException { - if (!u.getFile().endsWith("SmallRyeConfigFactory")) { - return null; - } - - return new URLConnection(u) { - @Override - public void connect() throws IOException { - } - - @Override - public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream(contents); - } - }; - } - } -} diff --git a/utils/cdi-provider/src/test/java/io/smallrye/config/util/injection/test/InjectionTestConfigFactory.java b/utils/cdi-provider/src/test/java/io/smallrye/config/util/injection/test/InjectionTestConfigFactory.java deleted file mode 100644 index c3fcf2d66..000000000 --- a/utils/cdi-provider/src/test/java/io/smallrye/config/util/injection/test/InjectionTestConfigFactory.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.smallrye.config.util.injection.test; - -import java.util.HashMap; - -import io.smallrye.config.PropertiesConfigSource; -import io.smallrye.config.SmallRyeConfig; -import io.smallrye.config.SmallRyeConfigFactory; -import io.smallrye.config.SmallRyeConfigProviderResolver; - -public class InjectionTestConfigFactory extends SmallRyeConfigFactory { - @Override - public SmallRyeConfig getConfigFor( - final SmallRyeConfigProviderResolver configProviderResolver, final ClassLoader classLoader) { - return configProviderResolver.getBuilder().forClassLoader(classLoader) - .addDefaultSources() - .withSources(new PropertiesConfigSource(new HashMap() { - { - put("testkey", "testvalue"); - } - }, "memory", 0)) - .addDefaultInterceptors() - .build(); - } -} diff --git a/utils/cdi-provider/src/test/java/module-info.java b/utils/cdi-provider/src/test/java/module-info.java deleted file mode 100644 index 179d3f0fb..000000000 --- a/utils/cdi-provider/src/test/java/module-info.java +++ /dev/null @@ -1,14 +0,0 @@ -open module io.smallrye.config.source.injection.test { - requires io.smallrye.config; - requires io.smallrye.config.inject; - requires io.smallrye.config.util.injection; - - requires jakarta.inject; - requires jakarta.cdi; - - requires org.eclipse.microprofile.config; - requires org.junit.jupiter.api; - - // even though we can't run in module mode, we still need to build this way - requires weld.junit5; -} \ No newline at end of file diff --git a/utils/events/build-test-java17 b/utils/events/build-test-java17 deleted file mode 100644 index e69de29bb..000000000 diff --git a/utils/events/build-test-java21 b/utils/events/build-test-java21 deleted file mode 100644 index e69de29bb..000000000 diff --git a/utils/events/build-test-java25 b/utils/events/build-test-java25 deleted file mode 100644 index e69de29bb..000000000 diff --git a/utils/events/pom.xml b/utils/events/pom.xml deleted file mode 100644 index 82b924c0f..000000000 --- a/utils/events/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - 4.0.0 - - - io.smallrye.config - smallrye-config-parent - 4.0.0-SNAPSHOT - ../../ - - - smallrye-config-events - - SmallRye Config: CDI Events - - - - jakarta.enterprise - jakarta.enterprise.cdi-api - provided - - - jakarta.annotation - jakarta.annotation-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.jboss.weld - weld-junit5 - - - - io.smallrye.config - smallrye-config - test - - - - - - - maven-surefire-plugin - - - false - - - - - diff --git a/utils/events/src/main/java/io/smallrye/config/events/ChangeEvent.java b/utils/events/src/main/java/io/smallrye/config/events/ChangeEvent.java deleted file mode 100644 index cdba1ae2b..000000000 --- a/utils/events/src/main/java/io/smallrye/config/events/ChangeEvent.java +++ /dev/null @@ -1,52 +0,0 @@ -package io.smallrye.config.events; - -import java.io.Serializable; -import java.util.Optional; - -/** - * an Event on a config element - * - * @author Phillip Kruger - */ -public class ChangeEvent implements Serializable { - - private final Type type; - private final String key; - private final Optional oldValue; - private final String newValue; - private final String fromSource; - - public ChangeEvent(Type type, String key, Optional oldValue, String newValue, String fromSource) { - this.type = type; - this.key = key; - this.oldValue = oldValue; - this.newValue = newValue; - this.fromSource = fromSource; - } - - public Type getType() { - return type; - } - - public String getKey() { - return key; - } - - public Optional getOldValue() { - return oldValue; - } - - public String getNewValue() { - return newValue; - } - - public String getFromSource() { - return fromSource; - } - - @Override - public String toString() { - return "ChangeEvent{" + "type=" + type + ", key=" + key + ", oldValue=" + oldValue + ", newValue=" + newValue - + ", fromSource=" + fromSource + '}'; - } -} diff --git a/utils/events/src/main/java/io/smallrye/config/events/ChangeEventNotifier.java b/utils/events/src/main/java/io/smallrye/config/events/ChangeEventNotifier.java deleted file mode 100644 index 5f3faa108..000000000 --- a/utils/events/src/main/java/io/smallrye/config/events/ChangeEventNotifier.java +++ /dev/null @@ -1,96 +0,0 @@ -package io.smallrye.config.events; - -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.enterprise.context.Initialized; -import jakarta.enterprise.event.Event; -import jakarta.enterprise.event.Observes; -import jakarta.inject.Inject; - -/** - * Easy way to fire a change event - * - * @author Phillip Kruger - * - * This gets used from Config sources that is not in the CDI Context. So we can not @Inject a bean. - * For some reason, CDI.current() is only working on Payara, and not on Thorntail and OpenLiberty, so this ugly footwork - * is to - * get around that. - */ -@ApplicationScoped -public class ChangeEventNotifier { - - @Inject - private Event broadcaster; - - private static ChangeEventNotifier INSTANCE; - - public void init(@Observes @Initialized(ApplicationScoped.class) Object init) { - INSTANCE = this; - } - - public static ChangeEventNotifier getInstance() { - // return CDI.current().select(ChangeEventNotifier.class).get(); - return INSTANCE; - } - - public void detectChangesAndFire(Map before, Map after, String fromSource) { - List changes = new ArrayList<>(); - if (!before.equals(after)) { - Set> beforeEntries = before.entrySet(); - for (Map.Entry beforeEntry : beforeEntries) { - String key = beforeEntry.getKey(); - String oldValue = beforeEntry.getValue(); - if (after.containsKey(key)) { - String newValue = after.get(key); - // Value can be null ! - if ((oldValue != null && newValue == null) || - (newValue != null && oldValue == null) || - (newValue != null && oldValue != null && !newValue.equals(oldValue))) { - // Update - changes.add(new ChangeEvent(Type.UPDATE, key, getOptionalOldValue(oldValue), newValue, fromSource)); - } - after.remove(key); - } else { - // Removed. - changes.add(new ChangeEvent(Type.REMOVE, key, getOptionalOldValue(oldValue), null, fromSource)); - } - } - Set> newEntries = after.entrySet(); - for (Map.Entry newEntry : newEntries) { - // New - changes.add(new ChangeEvent(Type.NEW, newEntry.getKey(), Optional.empty(), newEntry.getValue(), fromSource)); - } - } - if (!changes.isEmpty()) - fire(changes); - } - - public void fire(ChangeEvent changeEvent) { - List annotationList = new ArrayList<>(); - annotationList.add(new TypeFilter.TypeFilterLiteral(changeEvent.getType())); - annotationList.add(new KeyFilter.KeyFilterLiteral(changeEvent.getKey())); - annotationList.add(new SourceFilter.SourceFilterLiteral(changeEvent.getFromSource())); - - broadcaster.select(annotationList.toArray(new Annotation[annotationList.size()])).fire(changeEvent); - } - - public void fire(List changeEvents) { - for (ChangeEvent changeEvent : changeEvents) { - fire(changeEvent); - } - } - - public Optional getOptionalOldValue(String oldValue) { - if (oldValue == null || oldValue.isEmpty()) - return Optional.empty(); - return Optional.of(oldValue); - } - -} diff --git a/utils/events/src/main/java/io/smallrye/config/events/KeyFilter.java b/utils/events/src/main/java/io/smallrye/config/events/KeyFilter.java deleted file mode 100644 index 6c4d554ab..000000000 --- a/utils/events/src/main/java/io/smallrye/config/events/KeyFilter.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.smallrye.config.events; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import jakarta.enterprise.util.AnnotationLiteral; -import jakarta.inject.Qualifier; - -/** - * Filter the event on the key - * - * @author Phillip Kruger - */ -@Qualifier -@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD }) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface KeyFilter { - String value(); - - class KeyFilterLiteral extends AnnotationLiteral implements KeyFilter { - private final String key; - - KeyFilterLiteral(String key) { - this.key = key; - } - - @Override - public String value() { - return this.key; - } - } -} diff --git a/utils/events/src/main/java/io/smallrye/config/events/SourceFilter.java b/utils/events/src/main/java/io/smallrye/config/events/SourceFilter.java deleted file mode 100644 index f854111de..000000000 --- a/utils/events/src/main/java/io/smallrye/config/events/SourceFilter.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.smallrye.config.events; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import jakarta.enterprise.util.AnnotationLiteral; -import jakarta.inject.Qualifier; - -/** - * Filter by a config source - * - * @author Phillip Kruger - */ -@Qualifier -@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD }) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface SourceFilter { - String value(); - - class SourceFilterLiteral extends AnnotationLiteral implements SourceFilter { - private final String name; - - SourceFilterLiteral(String name) { - this.name = name; - } - - @Override - public String value() { - return this.name; - } - } -} diff --git a/utils/events/src/main/java/io/smallrye/config/events/Type.java b/utils/events/src/main/java/io/smallrye/config/events/Type.java deleted file mode 100644 index 6e886ab16..000000000 --- a/utils/events/src/main/java/io/smallrye/config/events/Type.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.smallrye.config.events; - -public enum Type { - NEW, - REMOVE, - UPDATE -} \ No newline at end of file diff --git a/utils/events/src/main/java/io/smallrye/config/events/TypeFilter.java b/utils/events/src/main/java/io/smallrye/config/events/TypeFilter.java deleted file mode 100644 index b6ca942fa..000000000 --- a/utils/events/src/main/java/io/smallrye/config/events/TypeFilter.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.smallrye.config.events; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import jakarta.enterprise.util.AnnotationLiteral; -import jakarta.inject.Qualifier; - -/** - * filter by change type - * - * @author Phillip Kruger - */ -@Qualifier -@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD }) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface TypeFilter { - Type value(); - - class TypeFilterLiteral extends AnnotationLiteral implements TypeFilter { - private final Type type; - - TypeFilterLiteral(Type type) { - this.type = type; - } - - @Override - public Type value() { - return this.type; - } - } -} diff --git a/utils/events/src/main/java/io/smallrye/config/events/regex/Field.java b/utils/events/src/main/java/io/smallrye/config/events/regex/Field.java deleted file mode 100644 index 1fc1965c7..000000000 --- a/utils/events/src/main/java/io/smallrye/config/events/regex/Field.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.smallrye.config.events.regex; - -/** - * a field to apply a regex on - * - * @author Phillip Kruger - */ -public enum Field { - key, - oldValue, - newValue, - fromSource -} diff --git a/utils/events/src/main/java/io/smallrye/config/events/regex/RegexFilter.java b/utils/events/src/main/java/io/smallrye/config/events/regex/RegexFilter.java deleted file mode 100644 index 60cda2222..000000000 --- a/utils/events/src/main/java/io/smallrye/config/events/regex/RegexFilter.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.smallrye.config.events.regex; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import jakarta.enterprise.util.Nonbinding; -import jakarta.interceptor.InterceptorBinding; - -/** - * an interceptor that match the value to a regular expression - * - * @author Phillip Kruger - */ -@Inherited -@InterceptorBinding -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.METHOD, ElementType.TYPE }) -public @interface RegexFilter { - @Nonbinding - String value(); - - @Nonbinding - Field onField() default Field.key; -} diff --git a/utils/events/src/main/java/io/smallrye/config/events/regex/RegexFilterInterceptor.java b/utils/events/src/main/java/io/smallrye/config/events/regex/RegexFilterInterceptor.java deleted file mode 100644 index a0e82f3de..000000000 --- a/utils/events/src/main/java/io/smallrye/config/events/regex/RegexFilterInterceptor.java +++ /dev/null @@ -1,71 +0,0 @@ -package io.smallrye.config.events.regex; - -import java.util.Optional; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import jakarta.annotation.Priority; -import jakarta.interceptor.AroundInvoke; -import jakarta.interceptor.Interceptor; -import jakarta.interceptor.InvocationContext; - -import io.smallrye.config.events.ChangeEvent; - -@RegexFilter(value = "") -@Interceptor -@Priority(100) -public class RegexFilterInterceptor { - @AroundInvoke - public Object observer(InvocationContext ctx) throws Exception { - - RegexFilter regexFilterAnnotation = ctx.getMethod().getAnnotation(RegexFilter.class); - Field onField = regexFilterAnnotation.onField(); - String regex = regexFilterAnnotation.value(); - - Optional posibleChangeEvent = getChangeEvent(ctx); - - if (posibleChangeEvent.isPresent()) { - ChangeEvent changeEvent = posibleChangeEvent.get(); - String value = getValueToApplyRegexOn(changeEvent, onField); - Pattern pattern = Pattern.compile(regex); - Matcher matcher = pattern.matcher(value); - boolean b = matcher.matches(); - if (!b) - return null; - } else { - RegexLogging.log.changeEventParameterMissing(ctx.getMethod().getName()); - } - return ctx.proceed(); - } - - private String getValueToApplyRegexOn(ChangeEvent changeEvent, Field onField) { - String value = null; - switch (onField) { - case key: - value = changeEvent.getKey(); - break; - case fromSource: - value = changeEvent.getFromSource(); - break; - case newValue: - value = changeEvent.getNewValue(); - break; - case oldValue: - value = changeEvent.getOldValue().orElse(""); - } - - return value; - } - - private Optional getChangeEvent(InvocationContext ctx) { - Object[] parameters = ctx.getParameters(); - - for (Object parameter : parameters) { - if (parameter.getClass().equals(ChangeEvent.class)) { - ChangeEvent changeEvent = (ChangeEvent) parameter; - return Optional.of(changeEvent); - } - } - return Optional.empty(); - } -} diff --git a/utils/events/src/main/java/io/smallrye/config/events/regex/RegexLogging.java b/utils/events/src/main/java/io/smallrye/config/events/regex/RegexLogging.java deleted file mode 100644 index 5ef490afa..000000000 --- a/utils/events/src/main/java/io/smallrye/config/events/regex/RegexLogging.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.smallrye.config.events.regex; - -import java.lang.invoke.MethodHandles; -import java.util.Locale; - -import org.jboss.logging.BasicLogger; -import org.jboss.logging.Logger; -import org.jboss.logging.annotations.LogMessage; -import org.jboss.logging.annotations.Message; -import org.jboss.logging.annotations.MessageLogger; - -@MessageLogger(projectCode = "SRCFG", length = 5) -interface RegexLogging extends BasicLogger { - - // if we add message localization one day, we must drop the Locale.ROOT argument - RegexLogging log = Logger.getMessageLogger(MethodHandles.lookup(), RegexLogging.class, - RegexLogging.class.getPackage().getName(), Locale.ROOT); - - @LogMessage(level = Logger.Level.WARN) - @Message(id = 5000, value = "Can not find ChangeEvent parameter for method %s. @RegexFilter is being ignored") - void changeEventParameterMissing(String methodName); -} diff --git a/utils/events/src/main/java/module-info.java b/utils/events/src/main/java/module-info.java deleted file mode 100644 index cb0d389a2..000000000 --- a/utils/events/src/main/java/module-info.java +++ /dev/null @@ -1,12 +0,0 @@ -module io.smallrye.config.events { - requires jakarta.annotation; - requires jakarta.cdi; - requires jakarta.inject; - requires jakarta.interceptor; - - requires org.jboss.logging; - requires org.jboss.logging.annotations; - - exports io.smallrye.config.events; - exports io.smallrye.config.events.regex; -} \ No newline at end of file diff --git a/utils/events/src/main/resources/META-INF/beans.xml b/utils/events/src/main/resources/META-INF/beans.xml deleted file mode 100644 index ad2a3b6ec..000000000 --- a/utils/events/src/main/resources/META-INF/beans.xml +++ /dev/null @@ -1,5 +0,0 @@ - - diff --git a/utils/events/src/test/java/io/smallrye/config/events/ChangeEventNotifierTest.java b/utils/events/src/test/java/io/smallrye/config/events/ChangeEventNotifierTest.java deleted file mode 100644 index c3d805508..000000000 --- a/utils/events/src/test/java/io/smallrye/config/events/ChangeEventNotifierTest.java +++ /dev/null @@ -1,105 +0,0 @@ -package io.smallrye.config.events; - -import java.util.Optional; - -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.enterprise.event.Observes; - -import org.jboss.weld.junit5.WeldInitiator; -import org.jboss.weld.junit5.WeldJunit5Extension; -import org.jboss.weld.junit5.WeldSetup; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import io.smallrye.config.events.regex.RegexFilter; -import io.smallrye.config.inject.ConfigExtension; - -/** - * Testing that the events fire correctly - * - * @author Phillip Kruger - */ -@ExtendWith(WeldJunit5Extension.class) -class ChangeEventNotifierTest { - @WeldSetup - WeldInitiator weld = WeldInitiator.from(ConfigExtension.class, ChangeEventNotifier.class) - .addBeans() - .activate(ApplicationScoped.class) - .inject(this) - .build(); - - @Test - void testNewType() { - ChangeEvent changeEvent = new ChangeEvent(Type.NEW, "test.key", Optional.empty(), "test value", "TestCase"); - ChangeEventNotifier.getInstance().fire(changeEvent); - } - - @Test - void testUpdateType() { - ChangeEvent changeEvent = new ChangeEvent(Type.UPDATE, "test.key", Optional.of("old value"), "test value", "TestCase"); - ChangeEventNotifier.getInstance().fire(changeEvent); - } - - @Test - void testRemoveType() { - ChangeEvent changeEvent = new ChangeEvent(Type.REMOVE, "test.key", Optional.of("old value"), null, "TestCase"); - ChangeEventNotifier.getInstance().fire(changeEvent); - } - - @Test - void testCertainKey() { - ChangeEvent changeEvent = new ChangeEvent(Type.UPDATE, "some.key", Optional.of("old value"), "test value", "TestCase"); - ChangeEventNotifier.getInstance().fire(changeEvent); - } - - @Test - void testCertainKeyAndUpdate() { - ChangeEvent changeEvent = new ChangeEvent(Type.UPDATE, "some.key", Optional.of("old value"), "test value", "TestCase"); - ChangeEventNotifier.getInstance().fire(changeEvent); - } - - @Test - void testCertainSource() { - ChangeEvent changeEvent = new ChangeEvent(Type.UPDATE, "some.key", Optional.of("old value"), "test value", - "SomeConfigSource"); - ChangeEventNotifier.getInstance().fire(changeEvent); - } - - @Test - void testRegex() { - ChangeEvent changeEvent = new ChangeEvent(Type.NEW, "testcase.key", Optional.empty(), "test value", "TestCase"); - ChangeEventNotifier.getInstance().fire(changeEvent); - } - - public void listenForNew(@Observes @TypeFilter(Type.NEW) ChangeEvent changeEvent) { - Assertions.assertEquals(Type.NEW, changeEvent.getType(), "Expecting new type"); - } - - public void listenForUpdate(@Observes @TypeFilter(Type.UPDATE) ChangeEvent changeEvent) { - Assertions.assertEquals(Type.UPDATE, changeEvent.getType(), "Expecting update type"); - } - - public void listenForRemove(@Observes @TypeFilter(Type.REMOVE) ChangeEvent changeEvent) { - Assertions.assertEquals(Type.REMOVE, changeEvent.getType(), "Expecting remove type"); - } - - public void listenForCertainKey(@Observes @KeyFilter("some.key") ChangeEvent changeEvent) { - Assertions.assertEquals("Expecting certain key", "some.key", changeEvent.getKey()); - } - - public void listenForCertainKeyAndUpdate( - @Observes @TypeFilter(Type.UPDATE) @KeyFilter("some.key") ChangeEvent changeEvent) { - Assertions.assertEquals("Expecting certain key", "some.key", changeEvent.getKey()); - Assertions.assertEquals(Type.UPDATE, changeEvent.getType(), "Expecting update type"); - } - - public void listenForCertainSource(@Observes @SourceFilter("SomeConfigSource") ChangeEvent changeEvent) { - Assertions.assertEquals("Expecting certain config source", "SomeConfigSource", changeEvent.getFromSource()); - } - - @RegexFilter("^testcase\\..+") - public void listenForKeyPattern(@Observes ChangeEvent changeEvent) { - Assertions.assertTrue(changeEvent.getKey().startsWith("testcase"), "Expecting key to start with certain value"); - } -}