From c2ce1a68a6c87d57db2bbbdaeec344ce07684f0d Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Tue, 2 Aug 2022 13:06:23 +0300 Subject: [PATCH] Added Helidon 3.0 support --- redisson-helidon/pom.xml | 114 +--------------- redisson-helidon/redisson-helidon-20/pom.xml | 125 ++++++++++++++++++ .../redisson/helidon/RedissonExtension.java | 0 .../src/main/resources/META-INF/beans.xml | 0 .../javax.enterprise.inject.spi.Extension | 0 .../org/redisson/RedissonExtensionTest.java | 0 .../src/test/resources/META-INF/beans.xml | 0 .../META-INF/microprofile-config.properties | 0 redisson-helidon/redisson-helidon-30/pom.xml | 125 ++++++++++++++++++ .../redisson/helidon/RedissonExtension.java | 90 +++++++++++++ .../src/main/resources/META-INF/beans.xml | 7 + .../jakarta.enterprise.inject.spi.Extension | 1 + .../org/redisson/RedissonExtensionTest.java | 50 +++++++ .../src/test/resources/META-INF/beans.xml | 7 + .../META-INF/microprofile-config.properties | 2 + 15 files changed, 412 insertions(+), 109 deletions(-) create mode 100644 redisson-helidon/redisson-helidon-20/pom.xml rename redisson-helidon/{ => redisson-helidon-20}/src/main/java/org/redisson/helidon/RedissonExtension.java (100%) rename redisson-helidon/{ => redisson-helidon-20}/src/main/resources/META-INF/beans.xml (100%) rename redisson-helidon/{ => redisson-helidon-20}/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension (100%) rename redisson-helidon/{ => redisson-helidon-20}/src/test/java/org/redisson/RedissonExtensionTest.java (100%) rename redisson-helidon/{ => redisson-helidon-20}/src/test/resources/META-INF/beans.xml (100%) rename redisson-helidon/{ => redisson-helidon-20}/src/test/resources/META-INF/microprofile-config.properties (100%) create mode 100644 redisson-helidon/redisson-helidon-30/pom.xml create mode 100644 redisson-helidon/redisson-helidon-30/src/main/java/org/redisson/helidon/RedissonExtension.java create mode 100644 redisson-helidon/redisson-helidon-30/src/main/resources/META-INF/beans.xml create mode 100644 redisson-helidon/redisson-helidon-30/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension create mode 100644 redisson-helidon/redisson-helidon-30/src/test/java/org/redisson/RedissonExtensionTest.java create mode 100644 redisson-helidon/redisson-helidon-30/src/test/resources/META-INF/beans.xml create mode 100644 redisson-helidon/redisson-helidon-30/src/test/resources/META-INF/microprofile-config.properties diff --git a/redisson-helidon/pom.xml b/redisson-helidon/pom.xml index e55b9131e..bbab40c25 100644 --- a/redisson-helidon/pom.xml +++ b/redisson-helidon/pom.xml @@ -9,117 +9,13 @@ redisson-helidon - jar + pom Redisson/Helidon integration - - - - com.mycila - license-maven-plugin - 3.0 - - ${basedir} -
${basedir}/../header.txt
- false - true - false - - src/main/java/org/redisson/ - - - target/** - - true - - JAVADOC_STYLE - - true - true - UTF-8 -
- - - - check - - - -
- - - maven-javadoc-plugin - - - - maven-compiler-plugin - -
-
- - - - org.redisson - redisson - ${project.version} - - - - jakarta.enterprise - jakarta.enterprise.cdi-api - 2.0.2 - provided - - - - org.jboss - jandex - 2.3.0.Final - runtime - true - - - io.helidon.microprofile.config - helidon-microprofile-config - [1.4.0,) - runtime - true - - - - org.eclipse.microprofile.config - microprofile-config-api - 1.4 - compile - - - - io.helidon.microprofile.cdi - helidon-microprofile-cdi - [1.4.0,) - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.junit.jupiter - junit-jupiter-params - test - - - ch.qos.logback - logback-classic - test - - - org.assertj - assertj-core - test - - + + redisson-helidon-20 + redisson-helidon-30 + diff --git a/redisson-helidon/redisson-helidon-20/pom.xml b/redisson-helidon/redisson-helidon-20/pom.xml new file mode 100644 index 000000000..04baccf23 --- /dev/null +++ b/redisson-helidon/redisson-helidon-20/pom.xml @@ -0,0 +1,125 @@ + + 4.0.0 + + + org.redisson + redisson-helidon + 3.17.6-SNAPSHOT + ../ + + + redisson-helidon-20 + jar + + Redisson/Helidon integration + + + + + com.mycila + license-maven-plugin + 3.0 + + ${basedir} +
${basedir}/../../header.txt
+ false + true + false + + src/main/java/org/redisson/ + + + target/** + + true + + JAVADOC_STYLE + + true + true + UTF-8 +
+ + + + check + + + +
+ + + maven-javadoc-plugin + + + + maven-compiler-plugin + +
+
+ + + + org.redisson + redisson + ${project.version} + + + + jakarta.enterprise + jakarta.enterprise.cdi-api + 2.0.2 + provided + + + + org.jboss + jandex + 2.3.0.Final + runtime + true + + + io.helidon.microprofile.config + helidon-microprofile-config + 2.5.1 + runtime + true + + + + org.eclipse.microprofile.config + microprofile-config-api + 1.4 + compile + + + + io.helidon.microprofile.cdi + helidon-microprofile-cdi + 2.5.1 + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test + + + ch.qos.logback + logback-classic + test + + + org.assertj + assertj-core + test + + + +
diff --git a/redisson-helidon/src/main/java/org/redisson/helidon/RedissonExtension.java b/redisson-helidon/redisson-helidon-20/src/main/java/org/redisson/helidon/RedissonExtension.java similarity index 100% rename from redisson-helidon/src/main/java/org/redisson/helidon/RedissonExtension.java rename to redisson-helidon/redisson-helidon-20/src/main/java/org/redisson/helidon/RedissonExtension.java diff --git a/redisson-helidon/src/main/resources/META-INF/beans.xml b/redisson-helidon/redisson-helidon-20/src/main/resources/META-INF/beans.xml similarity index 100% rename from redisson-helidon/src/main/resources/META-INF/beans.xml rename to redisson-helidon/redisson-helidon-20/src/main/resources/META-INF/beans.xml diff --git a/redisson-helidon/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/redisson-helidon/redisson-helidon-20/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension similarity index 100% rename from redisson-helidon/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension rename to redisson-helidon/redisson-helidon-20/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension diff --git a/redisson-helidon/src/test/java/org/redisson/RedissonExtensionTest.java b/redisson-helidon/redisson-helidon-20/src/test/java/org/redisson/RedissonExtensionTest.java similarity index 100% rename from redisson-helidon/src/test/java/org/redisson/RedissonExtensionTest.java rename to redisson-helidon/redisson-helidon-20/src/test/java/org/redisson/RedissonExtensionTest.java diff --git a/redisson-helidon/src/test/resources/META-INF/beans.xml b/redisson-helidon/redisson-helidon-20/src/test/resources/META-INF/beans.xml similarity index 100% rename from redisson-helidon/src/test/resources/META-INF/beans.xml rename to redisson-helidon/redisson-helidon-20/src/test/resources/META-INF/beans.xml diff --git a/redisson-helidon/src/test/resources/META-INF/microprofile-config.properties b/redisson-helidon/redisson-helidon-20/src/test/resources/META-INF/microprofile-config.properties similarity index 100% rename from redisson-helidon/src/test/resources/META-INF/microprofile-config.properties rename to redisson-helidon/redisson-helidon-20/src/test/resources/META-INF/microprofile-config.properties diff --git a/redisson-helidon/redisson-helidon-30/pom.xml b/redisson-helidon/redisson-helidon-30/pom.xml new file mode 100644 index 000000000..9d0852909 --- /dev/null +++ b/redisson-helidon/redisson-helidon-30/pom.xml @@ -0,0 +1,125 @@ + + 4.0.0 + + + org.redisson + redisson-helidon + 3.17.6-SNAPSHOT + ../ + + + redisson-helidon-30 + jar + + Redisson/Helidon integration + + + + + com.mycila + license-maven-plugin + 3.0 + + ${basedir} +
${basedir}/../../header.txt
+ false + true + false + + src/main/java/org/redisson/ + + + target/** + + true + + JAVADOC_STYLE + + true + true + UTF-8 +
+ + + + check + + + +
+ + + maven-javadoc-plugin + + + + maven-compiler-plugin + +
+
+ + + + org.redisson + redisson + ${project.version} + + + + jakarta.enterprise + jakarta.enterprise.cdi-api + 3.0.1 + provided + + + + org.jboss + jandex + 2.4.3.Final + runtime + true + + + io.helidon.microprofile.config + helidon-microprofile-config + 3.0.0 + runtime + true + + + + org.eclipse.microprofile.config + microprofile-config-api + 3.0.1 + compile + + + + io.helidon.microprofile.cdi + helidon-microprofile-cdi + 3.0.0 + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test + + + ch.qos.logback + logback-classic + test + + + org.assertj + assertj-core + test + + + +
diff --git a/redisson-helidon/redisson-helidon-30/src/main/java/org/redisson/helidon/RedissonExtension.java b/redisson-helidon/redisson-helidon-30/src/main/java/org/redisson/helidon/RedissonExtension.java new file mode 100644 index 000000000..6ec3fc166 --- /dev/null +++ b/redisson-helidon/redisson-helidon-30/src/main/java/org/redisson/helidon/RedissonExtension.java @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2013-2021 Nikita Koksharov + * + * 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 org.redisson.helidon; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.event.Observes; +import jakarta.enterprise.inject.spi.*; +import jakarta.inject.Named; +import org.eclipse.microprofile.config.Config; +import org.redisson.Redisson; +import org.redisson.api.RedissonClient; +import org.redisson.config.PropertiesConvertor; + +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * + * @author Nikita Koksharov + * + */ +public class RedissonExtension implements Extension { + + private final Set qualifiers = new HashSet<>(); + + private void processRedissonInjectionPoint(@Observes ProcessInjectionPoint point) { + if (point == null) { + return; + } + InjectionPoint injectionPoint = point.getInjectionPoint(); + if (injectionPoint == null) { + return; + } + + qualifiers.addAll(injectionPoint.getQualifiers()); + } + + private void addBeans(@Observes AfterBeanDiscovery discovery, BeanManager beanManager) { + if (discovery == null || beanManager == null) { + return; + } + + for (Annotation qualifier : qualifiers) { + Set qualifiers = Collections.singleton(qualifier); + + discovery.addBean() + .scope(ApplicationScoped.class) + .addQualifiers(qualifiers) + .addTransitiveTypeClosure(RedissonClient.class) + .produceWith((instance) -> { + + String instanceName = "default"; + if (qualifier instanceof Named) { + instanceName = ((Named) qualifier).value(); + } + + Config cfg = instance.select(Config.class).get(); + String yamlConfig = PropertiesConvertor.toYaml(Redisson.class.getName() + "." + instanceName + ".", + cfg.getPropertyNames(), prop -> { + return cfg.getValue(prop, String.class); + }, true); + + try { + org.redisson.config.Config config = org.redisson.config.Config.fromYAML(yamlConfig); + return Redisson.create(config); + } catch (IOException e) { + throw new IllegalStateException(e); + } + }); + } + } + + +} diff --git a/redisson-helidon/redisson-helidon-30/src/main/resources/META-INF/beans.xml b/redisson-helidon/redisson-helidon-30/src/main/resources/META-INF/beans.xml new file mode 100644 index 000000000..8aaaeade9 --- /dev/null +++ b/redisson-helidon/redisson-helidon-30/src/main/resources/META-INF/beans.xml @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/redisson-helidon/redisson-helidon-30/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension b/redisson-helidon/redisson-helidon-30/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension new file mode 100644 index 000000000..0caad7871 --- /dev/null +++ b/redisson-helidon/redisson-helidon-30/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension @@ -0,0 +1 @@ +org.redisson.helidon.RedissonExtension \ No newline at end of file diff --git a/redisson-helidon/redisson-helidon-30/src/test/java/org/redisson/RedissonExtensionTest.java b/redisson-helidon/redisson-helidon-30/src/test/java/org/redisson/RedissonExtensionTest.java new file mode 100644 index 000000000..7bdf44ecc --- /dev/null +++ b/redisson-helidon/redisson-helidon-30/src/test/java/org/redisson/RedissonExtensionTest.java @@ -0,0 +1,50 @@ +package org.redisson; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.Initialized; +import jakarta.enterprise.event.Observes; +import jakarta.enterprise.inject.Instance; +import jakarta.enterprise.inject.literal.NamedLiteral; +import jakarta.enterprise.inject.se.SeContainerInitializer; +import jakarta.enterprise.inject.spi.CDI; +import jakarta.inject.Named; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.redisson.api.RBucket; +import org.redisson.api.RedissonClient; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * + * @author Nikita Koksharov + * + */ +@ApplicationScoped +public class RedissonExtensionTest { + + @BeforeEach + void startCdiContainer() { + System.setProperty("org.redisson.Redisson.simple.singleServerConfig.address", "redis://127.0.0.1:6379"); + SeContainerInitializer initializer = SeContainerInitializer.newInstance(); + initializer.initialize(); + } + + private void onInit(@Observes @Initialized(ApplicationScoped.class) Object event, + @Named("simple") RedissonClient client) { + assertThat(client).isNotNull(); + } + + @Test + public void test() { + Instance instance = CDI.current().select(RedissonClient.class, NamedLiteral.of("simple")); + RedissonClient redissonClient = instance.get(); + + RBucket b = redissonClient.getBucket("test"); + b.set("1"); + assertThat(b.get()).isEqualTo("1"); + assertThat(b.delete()).isTrue(); + } + + +} diff --git a/redisson-helidon/redisson-helidon-30/src/test/resources/META-INF/beans.xml b/redisson-helidon/redisson-helidon-30/src/test/resources/META-INF/beans.xml new file mode 100644 index 000000000..8aaaeade9 --- /dev/null +++ b/redisson-helidon/redisson-helidon-30/src/test/resources/META-INF/beans.xml @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/redisson-helidon/redisson-helidon-30/src/test/resources/META-INF/microprofile-config.properties b/redisson-helidon/redisson-helidon-30/src/test/resources/META-INF/microprofile-config.properties new file mode 100644 index 000000000..3ff53e1b5 --- /dev/null +++ b/redisson-helidon/redisson-helidon-30/src/test/resources/META-INF/microprofile-config.properties @@ -0,0 +1,2 @@ +mp.initializer.allow=true +mp.initializer.no-warn=true \ No newline at end of file