geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1832036 - in /geronimo/components/config/trunk/impl/src: main/java/org/apache/geronimo/config/cdi/ConfigurationHandler.java test/java/org/apache/geronimo/config/test/internal/ProxyTest.java
Date Tue, 22 May 2018 15:38:08 GMT
Author: rmannibucau
Date: Tue May 22 15:38:08 2018
New Revision: 1832036

URL: http://svn.apache.org/viewvc?rev=1832036&view=rev
Log:
Thanks Mark to have pointed out @ConfigProperty can be put on a TYPE so we can use it to handle
prefixes in our proxies

Modified:
    geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigurationHandler.java
    geronimo/components/config/trunk/impl/src/test/java/org/apache/geronimo/config/test/internal/ProxyTest.java

Modified: geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigurationHandler.java
URL: http://svn.apache.org/viewvc/geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigurationHandler.java?rev=1832036&r1=1832035&r2=1832036&view=diff
==============================================================================
--- geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigurationHandler.java
(original)
+++ geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigurationHandler.java
Tue May 22 15:38:08 2018
@@ -16,6 +16,7 @@
  */
 package org.apache.geronimo.config.cdi;
 
+import static java.util.Optional.ofNullable;
 import static java.util.function.Function.identity;
 import static java.util.stream.Collectors.toList;
 import static java.util.stream.Collectors.toMap;
@@ -44,9 +45,13 @@ public class ConfigurationHandler implem
 
     ConfigurationHandler(final Config config, final Class<?> api) {
         this.config = config;
+
+        final String prefix = ofNullable(api.getAnnotation(ConfigProperty.class))
+                .map(ConfigProperty::name)
+                .orElse("");
         this.methodMetas = Stream.of(api.getMethods())
             .filter(m -> m.isAnnotationPresent(ConfigProperty.class))
-            .collect(toMap(identity(), MethodMeta::new));
+            .collect(toMap(identity(), e -> new MethodMeta(e, prefix)));
     }
 
     @Override
@@ -75,7 +80,7 @@ public class ConfigurationHandler implem
 
         private final boolean optional;
 
-        private MethodMeta(final Method m) {
+        private MethodMeta(final Method m, final String prefix) {
             final ConfigProperty annotation = m.getAnnotation(ConfigProperty.class);
             optional = Optional.class == m.getReturnType();
             final Type type = optional ?
@@ -109,7 +114,7 @@ public class ConfigurationHandler implem
                 throw new IllegalArgumentException("Unsupported type: " + type);
             }
 
-            key = annotation.name().isEmpty() ? m.getDeclaringClass().getName() + "." + m.getName()
: annotation.name();
+            key = prefix + (annotation.name().isEmpty() ? m.getDeclaringClass().getName()
+ "." + m.getName() : annotation.name());
             final boolean hasDefault = !annotation.defaultValue().equals(ConfigProperty.UNCONFIGURED_VALUE);
             if (lookupType == long.class || lookupType == Long.class) {
                 defaultValue = hasDefault ? Long.parseLong(annotation.defaultValue()) : 0L;

Modified: geronimo/components/config/trunk/impl/src/test/java/org/apache/geronimo/config/test/internal/ProxyTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/config/trunk/impl/src/test/java/org/apache/geronimo/config/test/internal/ProxyTest.java?rev=1832036&r1=1832035&r2=1832036&view=diff
==============================================================================
--- geronimo/components/config/trunk/impl/src/test/java/org/apache/geronimo/config/test/internal/ProxyTest.java
(original)
+++ geronimo/components/config/trunk/impl/src/test/java/org/apache/geronimo/config/test/internal/ProxyTest.java
Tue May 22 15:38:08 2018
@@ -39,12 +39,13 @@ public class ProxyTest extends Arquillia
 
     @Deployment
     public static WebArchive deploy() {
+        System.setProperty("prefix.val", "yes");
         System.setProperty(LIST_KEY, "a,b,1");
         System.setProperty(SOME_KEY, "yeah");
         System.setProperty(SOME_OTHER_KEY, "123");
         JavaArchive testJar = ShrinkWrap
                 .create(JavaArchive.class, "PoxyTest.jar")
-                .addClasses(ProxyTest.class, SomeProxy.class)
+                .addClasses(ProxyTest.class, SomeProxy.class, PrefixedSomeProxy.class)
                 .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
 
         return ShrinkWrap
@@ -53,6 +54,9 @@ public class ProxyTest extends Arquillia
     }
 
     @Inject
+    private PrefixedSomeProxy prefixed;
+
+    @Inject
     private SomeProxy proxy;
 
     @Test
@@ -65,6 +69,17 @@ public class ProxyTest extends Arquillia
         assertEquals(proxy.listDefaults(), asList(1, 2, 1));
     }
 
+    @Test
+    public void prefix() {
+        assertEquals(prefixed.val(), "yes");
+    }
+
+    @ConfigProperty(name = "prefix.")
+    public interface PrefixedSomeProxy {
+        @ConfigProperty(name = "val")
+        String val();
+    }
+
     public interface SomeProxy {
         @ConfigProperty
         int key2();



Mime
View raw message