deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [5/5] deltaspike git commit: adding prefix to @Configuration
Date Wed, 09 Nov 2016 11:52:34 GMT
adding prefix to @Configuration


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/8e6fa365
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/8e6fa365
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/8e6fa365

Branch: refs/heads/master
Commit: 8e6fa365a3e8f52f1262320408457fa95d40cf00
Parents: b81d498
Author: rmannibucau <rmannibucau@apache.org>
Authored: Mon Nov 7 12:51:31 2016 +0100
Committer: rmannibucau <rmannibucau@apache.org>
Committed: Mon Nov 7 12:51:31 2016 +0100

----------------------------------------------------------------------
 .../core/api/config/Configuration.java          |  5 +++
 .../config/ProxyConfigurationLifecycle.java     |  9 ++++--
 .../InjectableConfigPropertyTest.java           |  7 +++++
 .../config/injectable/PrefixedConfigBean.java   | 32 ++++++++++++++++++++
 .../META-INF/apache-deltaspike.properties       |  2 ++
 5 files changed, 52 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/8e6fa365/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Configuration.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Configuration.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Configuration.java
index 5c3e33d..d2fa689 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Configuration.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Configuration.java
@@ -47,4 +47,9 @@ public @interface Configuration
      * @return the duration unit for {@see cacheFor()}.
      */
     TimeUnit cacheUnit() default SECONDS;
+
+    /**
+     * @return the key prefix to apply to all methods.
+     */
+    String prefix() default "";
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/8e6fa365/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ProxyConfigurationLifecycle.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ProxyConfigurationLifecycle.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ProxyConfigurationLifecycle.java
index 645e227..13c687e 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ProxyConfigurationLifecycle.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ProxyConfigurationLifecycle.java
@@ -56,7 +56,8 @@ class ProxyConfigurationLifecycle implements ContextualLifecycle
         final long cacheFor = configuration.cacheFor();
         return Proxy.newProxyInstance(
                 Thread.currentThread().getContextClassLoader(), api,
-                new ConfigurationHandler(cacheFor <= 0 ? -1 : configuration.cacheUnit().toMillis(cacheFor)));
+                new ConfigurationHandler(
+                        cacheFor <= 0 ? -1 : configuration.cacheUnit().toMillis(cacheFor),
configuration.prefix()));
     }
 
     @Override
@@ -74,10 +75,12 @@ class ProxyConfigurationLifecycle implements ContextualLifecycle
         private final ConcurrentMap<Method, ConfigResolver.TypedResolver<?>>
resolvers =
                 new ConcurrentHashMap<Method, ConfigResolver.TypedResolver<?>>();
         private final long cacheMs;
+        private final String prefix;
 
-        private ConfigurationHandler(final long cacheMs)
+        private ConfigurationHandler(final long cacheMs, final String prefix)
         {
             this.cacheMs = cacheMs;
+            this.prefix = prefix;
         }
 
         @Override
@@ -137,7 +140,7 @@ class ProxyConfigurationLifecycle implements ContextualLifecycle
                 }
 
                 typedResolver = delegate.asResolver(
-                        annotation.name(), annotation.defaultValue(), returnType,
+                        prefix + annotation.name(), annotation.defaultValue(), returnType,
                         annotation.converter(), annotation.parameterizedBy(),
                         annotation.projectStageAware(), annotation.evaluateVariables());
                 if (cacheMs > 0)

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/8e6fa365/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/InjectableConfigPropertyTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/InjectableConfigPropertyTest.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/InjectableConfigPropertyTest.java
index bb1e573..5009949 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/InjectableConfigPropertyTest.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/InjectableConfigPropertyTest.java
@@ -149,4 +149,11 @@ public class InjectableConfigPropertyTest
         assertEquals(singletonList(new URL("http://127.0.0.2")), settingsBean.urlListFromProperties());
         assertEquals("value", settingsBean.customSourceValue());
     }
+
+    @Test
+    public void proxyPrefix() throws MalformedURLException
+    {
+        PrefixedConfigBean settingsBean = BeanProvider.getContextualReference(PrefixedConfigBean.class);
+        assertEquals("done", settingsBean.value());
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/8e6fa365/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/PrefixedConfigBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/PrefixedConfigBean.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/PrefixedConfigBean.java
new file mode 100644
index 0000000..46dbd49
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/PrefixedConfigBean.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.test.core.api.config.injectable;
+
+import org.apache.deltaspike.core.api.config.ConfigProperty;
+import org.apache.deltaspike.core.api.config.Configuration;
+
+import java.net.URL;
+import java.util.List;
+
+@Configuration(prefix = "prefix.")
+public interface PrefixedConfigBean
+{
+    @ConfigProperty(name = "suffix")
+    String value();
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/8e6fa365/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
b/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
index 61a86bf..c4a11c1 100644
--- a/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
+++ b/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
@@ -50,3 +50,5 @@ my.very.secret=onlyIDoKnowIt
 deactivate.org.apache.deltaspike.test.core.impl.activation.DeactivatedClass=true
 
 urlListFromProperties = http://127.0.0.2
+
+prefix.suffix = done


Mime
View raw message