You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2017/10/03 17:22:27 UTC

incubator-tamaya-sandbox git commit: TAMAYA-260 Fixed failing microprofile tests.

Repository: incubator-tamaya-sandbox
Updated Branches:
  refs/heads/master 9788f0028 -> 6e5b58376


TAMAYA-260 Fixed failing microprofile tests.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/6e5b5837
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/6e5b5837
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/6e5b5837

Branch: refs/heads/master
Commit: 6e5b58376e76c7721ce06071448d2683507851d4
Parents: 9788f00
Author: Anatole Tresch <an...@apache.org>
Authored: Tue Oct 3 19:22:17 2017 +0200
Committer: Anatole Tresch <an...@apache.org>
Committed: Tue Oct 3 19:22:17 2017 +0200

----------------------------------------------------------------------
 .../microprofile/TamayaConfiguration.java       | 10 ++--
 .../cdi/MicroprofileCDIExtension.java           | 14 ++++-
 .../cdi/MicroprofileConfigurationProducer.java  |  7 +++
 .../converter/ProviderConverter.java            | 61 ++++++++++++++++++++
 .../org.apache.tamaya.spi.PropertyConverter     |  3 +-
 5 files changed, 88 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/6e5b5837/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java
index 72b902b..7b5a73c 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java
@@ -18,10 +18,7 @@
  */
 package org.apache.tamaya.microprofile;
 
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.ConfigQuery;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.*;
 import org.apache.tamaya.spi.ConfigurationContext;
 import org.eclipse.microprofile.config.Config;
 
@@ -75,6 +72,11 @@ public class TamayaConfiguration implements Configuration{
     }
 
     @Override
+    public <T> T getFromValue(String value, TypeLiteral<T> targetType) {
+        return ConfigurationProvider.getConfiguration().getFromValue(value, targetType);
+    }
+
+    @Override
     public Map<String, String> getProperties() {
         return null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/6e5b5837/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java
index 7a819fc..550b9e0 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileCDIExtension.java
@@ -19,7 +19,9 @@ package org.apache.tamaya.microprofile.cdi;
 import org.eclipse.microprofile.config.inject.ConfigProperty;
 
 import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.spi.*;
+import javax.inject.Provider;
 import java.lang.reflect.Field;
 import java.lang.reflect.Member;
 import java.lang.reflect.Method;
@@ -66,9 +68,17 @@ public class MicroprofileCDIExtension implements Extension {
                 String key = !annotation.name().isEmpty()?annotation.name():MicroprofileConfigurationProducer.getDefaultKey(injectionPoint);
                 Member member = injectionPoint.getMember();
                 if(member instanceof Field) {
-                    types.add(((Field) member).getType());
+                    Field f = (Field)member;
+                    if(!Instance.class.equals(f.getType()) &&
+                            !Provider.class.equals(f.getType())){
+                        types.add(f.getType());
+                    }
                 }else if(member instanceof Method){
-                    types.add(((Method) member).getParameterTypes()[0]);
+                    Method m = (Method)member;
+                    if(!Instance.class.equals(m.getParameterTypes()[0]) &&
+                            !Provider.class.equals(m.getParameterTypes()[0])){
+                        types.add(m.getParameterTypes()[0]);
+                    }
                 }else{
                     continue;
                 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/6e5b5837/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
index eb1ac61..e3eae2c 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
@@ -33,6 +33,7 @@ import javax.enterprise.inject.*;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.inject.Provider;
 import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.List;
 import java.util.logging.Level;
@@ -91,6 +92,12 @@ public class MicroprofileConfigurationProducer {
         if (injectionPoint.getMember() instanceof AnnotatedElement) {
             builder.setAnnotatedElement((AnnotatedElement) injectionPoint.getMember());
         }
+        if(targetType instanceof ParameterizedType){
+            ParameterizedType pt = (ParameterizedType)targetType;
+            if(pt.getRawType().equals(Provider.class)) {
+                builder.setTargetType(TypeLiteral.of(pt.getActualTypeArguments()[0]));
+            }
+        }
         return builder.build();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/6e5b5837/microprofile/src/main/java/org/apache/tamaya/microprofile/converter/ProviderConverter.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/converter/ProviderConverter.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/converter/ProviderConverter.java
new file mode 100644
index 0000000..1983e3d
--- /dev/null
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/converter/ProviderConverter.java
@@ -0,0 +1,61 @@
+/*
+ * 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.tamaya.microprofile.converter;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import javax.annotation.Priority;
+import javax.inject.Provider;
+import java.lang.reflect.Type;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to Boolean for 1 = true, otherwise false.
+ */
+@Priority(-1)
+public class ProviderConverter implements PropertyConverter<Provider> {
+
+    private final Logger LOG = Logger.getLogger(getClass().getName());
+
+    @Override
+    public Provider convert(String value, ConversionContext context) {
+        return () -> {
+            try{
+                Type targetType = context.getTargetType().getType();
+                return context.getConfiguration().getFromValue(value, TypeLiteral.of(targetType));
+            }catch(Exception e){
+                throw new ConfigException("Error evaluating config value.", e);
+            }
+        };
+    }
+
+    @Override
+    public boolean equals(Object o){
+        return getClass().equals(o.getClass());
+    }
+
+    @Override
+    public int hashCode(){
+        return getClass().hashCode();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/6e5b5837/microprofile/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
----------------------------------------------------------------------
diff --git a/microprofile/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/microprofile/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
index 51051e6..2205fa2 100644
--- a/microprofile/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
+++ b/microprofile/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
@@ -17,4 +17,5 @@
 #  under the License.
 #
 
-org.apache.tamaya.microprofile.converter.BooleanAsIntegerConverterFix
\ No newline at end of file
+org.apache.tamaya.microprofile.converter.BooleanAsIntegerConverterFix
+org.apache.tamaya.microprofile.converter.ProviderConverter
\ No newline at end of file