tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [2/2] incubator-tamaya git commit: Fixed registration issue with converters. Improved toString formatting.
Date Mon, 12 Dec 2016 16:14:54 GMT
Fixed registration issue with converters.
Improved toString formatting.


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

Branch: refs/heads/master
Commit: 77850ea316369b3d259ffd174cc80bac3c47dedd
Parents: 05b6514
Author: anatole <anatole@apache.org>
Authored: Mon Dec 12 17:06:22 2016 +0100
Committer: anatole <anatole@apache.org>
Committed: Mon Dec 12 17:14:15 2016 +0100

----------------------------------------------------------------------
 buildconfigurations/pom.xml                     |   2 +-
 .../core/internal/DefaultConfiguration.java     |   7 ++
 .../internal/DefaultConfigurationContext.java   | 103 ++++++++-----------
 .../DefaultConfigurationContextBuilder.java     |   4 +-
 .../internal/DefaultConfigurationProvider.java  |   3 +-
 .../core/internal/PropertyConverterManager.java |   2 +-
 .../core/ConfigurationContextBuilderTest.java   |   8 +-
 .../DefaultConfigurationContextBuilderTest.java |   4 +-
 .../internal/PropertyConverterManagerTest.java  |  15 +--
 9 files changed, 72 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/77850ea3/buildconfigurations/pom.xml
----------------------------------------------------------------------
diff --git a/buildconfigurations/pom.xml b/buildconfigurations/pom.xml
index 3973395..c53d8df 100644
--- a/buildconfigurations/pom.xml
+++ b/buildconfigurations/pom.xml
@@ -47,5 +47,5 @@ under the License.
         </url>
       <tag>vote02-tamaya-0.2-incubating</tag>
   </scm>
-    
+
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/77850ea3/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index 1b37233..268d825 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -222,4 +222,11 @@ public class DefaultConfiguration implements Configuration {
     public ConfigurationContext getConfigurationContext() {
         return configurationContext;
     }
+
+    @Override
+    public String toString() {
+        return "Configuration{\n " +
+                configurationContext +
+                '}';
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/77850ea3/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
index 280793a..c3031f0 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
@@ -81,33 +81,10 @@ public class DefaultConfigurationContext implements ConfigurationContext
{
         propertySources.addAll(builder.propertySources);
         // now sort them according to their ordinal values
         immutablePropertySources = Collections.unmodifiableList(propertySources);
-        StringBuilder b= new StringBuilder();
-        b.append("Registered " + immutablePropertySources.size() + " property sources: \n");
-        b.append("   NAME [TYPE]\n");
-        b.append("   ---------------------------------------------------\n");
-        for(PropertySource ps: immutablePropertySources){
-            b.append("   ").append(ps.getName()).append("  [").append(ps.getClass().getSimpleName()).append("],\n");
-        }
-        if(b.length()>0) {
-            b.setLength(b.length() - 2);
-        }
-        LOG.info(b.toString());
-        b.setLength(0);
 
         // as next step we pick up the PropertyFilters pretty much the same way
         List<PropertyFilter> propertyFilters = new ArrayList<>(builder.getPropertyFilters());
         immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
-        b.append("Registered " + immutablePropertyFilters.size() + " property filters: \n");
-        b.append("   TYPE\n");
-        b.append("   ----------------------------------------------------------\n");
-        for(PropertyFilter pf: immutablePropertyFilters){
-            b.append("   ").append(pf.getClass().getName()).append(",\n");
-        }
-        if(b.length()>0) {
-            b.setLength(b.length() - 2);
-        }
-        LOG.info(b.toString());
-        b.setLength(0);
 
         // Finally add the converters
         for(Map.Entry<TypeLiteral<?>, Collection<PropertyConverter<?>>>
en:builder.getPropertyConverter().entrySet()) {
@@ -115,21 +92,6 @@ public class DefaultConfigurationContext implements ConfigurationContext
{
                 this.propertyConverterManager.register(en.getKey(), converter);
             }
         }
-        b.append("Registered " + propertyConverterManager.getPropertyConverters().size()
+ " property converters:\n");
-        b.append("   TYPE\n");
-        b.append("   ----------------------------------------------------------\n");
-        for(Map.Entry<TypeLiteral<?>,List<PropertyConverter<?>>>
list: propertyConverterManager.getPropertyConverters().entrySet()){
-            b.append("   ").append(list.getKey().getRawType().getName()).append(" -> \n");
-            for(PropertyConverter<?> conv:list.getValue()) {
-                b.append("     ").append(conv.toString()).append(",\n");
-            }
-        }
-        if(b.length()>0) {
-            b.setLength(b.length() - 2);
-        }
-        LOG.info(b.toString());
-        b.setLength(0);
-
         propertyValueCombinationPolicy = builder.combinationPolicy;
         if(propertyValueCombinationPolicy==null){
             propertyValueCombinationPolicy = ServiceContextManager.getServiceContext().getService(PropertyValueCombinationPolicy.class);
@@ -137,7 +99,6 @@ public class DefaultConfigurationContext implements ConfigurationContext
{
         if(propertyValueCombinationPolicy==null){
             propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
         }
-        LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
     }
 
 
@@ -185,34 +146,54 @@ public class DefaultConfigurationContext implements ConfigurationContext
{
         StringBuilder b = new StringBuilder("ConfigurationContext{\n");
         b.append("  Property Sources\n");
         b.append("  ----------------\n");
-        b.append("  CLASS                         NAME                                  
                               ORDINAL SCANNABLE SIZE\n");
-        for(PropertySource ps:getPropertySources()){
-            b.append("  ");
-            appendFormatted(b, ps.getClass().getSimpleName(), 30);
-            appendFormatted(b, ps.getName(), 70);
-            appendFormatted(b, String.valueOf(ps.getOrdinal()), 8);
-            appendFormatted(b, String.valueOf(ps.isScannable()), 10);
-            if(ps.isScannable()) {
-                appendFormatted(b, String.valueOf(ps.getProperties().size()), 8);
-            }else{
-                appendFormatted(b, "-", 8);
+        if(immutablePropertySources.isEmpty()){
+            b.append("  No property sources loaded.\n\n");
+        }else {
+            b.append("  CLASS                         NAME                              
                                   ORDINAL SCANNABLE SIZE    STATE     ERROR\n\n");
+            for (PropertySource ps : immutablePropertySources) {
+                b.append("  ");
+                appendFormatted(b, ps.getClass().getSimpleName(), 30);
+                appendFormatted(b, ps.getName(), 70);
+                appendFormatted(b, String.valueOf(ps.getOrdinal()), 8);
+                appendFormatted(b, String.valueOf(ps.isScannable()), 10);
+                if (ps.isScannable()) {
+                    appendFormatted(b, String.valueOf(ps.getProperties().size()), 8);
+                } else {
+                    appendFormatted(b, "-", 8);
+                }
+                PropertyValue state = ps.get("_state");
+                if(state==null){
+                    appendFormatted(b, "OK", 10);
+                }else {
+                    appendFormatted(b, state.getValue(), 10);
+                    if("ERROR".equals(state.getValue())){
+                        PropertyValue val = ps.get("_exception");
+                        if(val!=null) {
+                            appendFormatted(b, val.getValue(), 30);
+                        }
+                    }
+                }
+                b.append('\n');
             }
-            b.append('\n');
+            b.append("\n");
         }
-        b.append("\n");
         b.append("  Property Filters\n");
         b.append("  ----------------\n");
-        b.append("  CLASS                         INFO\n");
-        for(PropertyFilter filter:getPropertyFilters()){
-            b.append("  ");
-            appendFormatted(b, filter.getClass().getSimpleName(), 30);
-            b.append(removeNewLines(filter.toString()));
-            b.append('\n');
+        if(immutablePropertyFilters.isEmpty()){
+            b.append("  No property filters loaded.\n\n");
+        }else {
+            b.append("  CLASS                         INFO\n\n");
+            for (PropertyFilter filter : getPropertyFilters()) {
+                b.append("  ");
+                appendFormatted(b, filter.getClass().getSimpleName(), 30);
+                b.append(removeNewLines(filter.toString()));
+                b.append('\n');
+            }
+            b.append("\n\n");
         }
-        b.append("\n\n");
         b.append("  Property Converters\n");
         b.append("  -------------------\n");
-        b.append("  CLASS                         TYPE                          INFO\n");
+        b.append("  CLASS                         TYPE                          INFO\n\n");
         for(Map.Entry<TypeLiteral<?>, List<PropertyConverter<?>>>
converterEntry:getPropertyConverters().entrySet()){
             for(PropertyConverter converter: converterEntry.getValue()){
                 b.append("  ");
@@ -222,6 +203,8 @@ public class DefaultConfigurationContext implements ConfigurationContext
{
                 b.append('\n');
             }
         }
+        b.append("\n\n");
+        b.append("  PropertyValueCombinationPolicy: " + getPropertyValueCombinationPolicy().getClass().getName()).append('\n');
         b.append('}');
         return b.toString();
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/77850ea3/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
index d9ee63b..b3dcc82 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
@@ -29,6 +29,7 @@ import org.apache.tamaya.spi.PropertySourceProvider;
 import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
 import org.apache.tamaya.spi.ServiceContextManager;
 
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -364,7 +365,8 @@ public class DefaultConfigurationContextBuilder implements ConfigurationContextB
         Map<TypeLiteral, Collection<PropertyConverter>> result = new HashMap<>();
         for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices(
                 PropertyConverter.class)) {
-            TypeLiteral target = TypeLiteral.of(TypeLiteral.of(conv.getClass()).getType());
+            Type type = TypeLiteral.getGenericInterfaceTypeParameters(conv.getClass(), PropertyConverter.class)[0];
+            TypeLiteral target = TypeLiteral.of(type);
             Collection<PropertyConverter> convList = result.get(target);
             if (convList == null) {
                 convList = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/77850ea3/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
index bcc9eae..4b02472 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
@@ -35,7 +35,8 @@ public class DefaultConfigurationProvider implements ConfigurationProviderSpi
{
     ConfigurationContext context = new DefaultConfigurationContextBuilder()
             .addDefaultPropertyConverters()
             .addDefaultPropertyFilters()
-            .addDefaultPropertySources().build();
+            .addDefaultPropertySources()
+            .build();
 
     private Configuration config = new DefaultConfiguration(context);
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/77850ea3/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
index ab35b90..1e9586a 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
@@ -80,7 +80,7 @@ public class PropertyConverterManager {
      * Constructor.
      */
     public PropertyConverterManager() {
-        this(true);
+        this(false);
     }
 
     public PropertyConverterManager(boolean init) {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/77850ea3/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
index f6f7316..9a1dd6f 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
@@ -250,11 +250,11 @@ public class ConfigurationContextBuilderTest {
                 .addPropertyConverters(TypeLiteral.of(String.class), converter);
         ConfigurationContext ctx = b.build();
         assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
-        assertEquals(ctx.getPropertyConverters().size(), 19);
+        assertEquals(ctx.getPropertyConverters().size(), 1);
         b = ConfigurationProvider.getConfigurationContextBuilder()
                 .addPropertyConverters(TypeLiteral.of(String.class), converter);
         b.addPropertyConverters(TypeLiteral.of(String.class), converter);
-        assertEquals(ctx.getPropertyConverters().size(), 19);
+        assertEquals(ctx.getPropertyConverters().size(), 1);
     }
 
     @Test
@@ -271,12 +271,12 @@ public class ConfigurationContextBuilderTest {
                         Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter}));
         ConfigurationContext ctx = b.build();
         assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
-        assertEquals(ctx.getPropertyConverters().size(), 19);
+        assertEquals(ctx.getPropertyConverters().size(), 1);
         b = ConfigurationProvider.getConfigurationContextBuilder()
                 .addPropertyConverters(TypeLiteral.of(String.class),
                         Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter}));
         b.addPropertyConverters(TypeLiteral.of(String.class), converter);
-        assertEquals(ctx.getPropertyConverters().size(), 19);
+        assertEquals(ctx.getPropertyConverters().size(), 1);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/77850ea3/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java
b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java
index 1075fcc..bbb9d14 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java
@@ -140,11 +140,11 @@ public class DefaultConfigurationContextBuilderTest {
                 .addPropertyConverters(TypeLiteral.of(String.class), converter);
         ConfigurationContext ctx = b.build();
         assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
-        assertEquals(ctx.getPropertyConverters().size(), 19);
+        assertEquals(ctx.getPropertyConverters().size(), 1);
         b = new DefaultConfigurationContextBuilder()
                 .addPropertyConverters(TypeLiteral.of(String.class), converter);
         b.addPropertyConverters(TypeLiteral.of(String.class), converter);
-        assertEquals(ctx.getPropertyConverters().size(), 19);
+        assertEquals(ctx.getPropertyConverters().size(), 1);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/77850ea3/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
b/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
index ec420f8..09701fb 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
@@ -79,7 +79,7 @@ public class PropertyConverterManagerTest {
 
     @Test
     public void testDirectSuperclassConverterMapping(){
-        PropertyConverterManager manager = new PropertyConverterManager();
+        PropertyConverterManager manager = new PropertyConverterManager(true);
         List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
         assertThat(converters, hasSize(1));
         converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
@@ -97,15 +97,18 @@ public class PropertyConverterManagerTest {
     public void testMultipleConverterLoad(){
         PropertyConverterManager manager = new PropertyConverterManager();
         List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
-        assertThat(converters, hasSize(1));
+        assertThat(converters, hasSize(0));
         manager = new PropertyConverterManager();
         converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
+        assertThat(converters, hasSize(0));
+        manager.initConverters();
+        converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
         assertThat(converters, hasSize(1));
     }
 
     @Test
     public void testTransitiveSuperclassConverterMapping(){
-        PropertyConverterManager manager = new PropertyConverterManager();
+        PropertyConverterManager manager = new PropertyConverterManager(true);
         List<PropertyConverter<A>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(A.class)));
         assertThat(converters, hasSize(1));
 
@@ -119,7 +122,7 @@ public class PropertyConverterManagerTest {
 
     @Test
     public void testDirectInterfaceMapping(){
-        PropertyConverterManager manager = new PropertyConverterManager();
+        PropertyConverterManager manager = new PropertyConverterManager(true);
         List<PropertyConverter<Readable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Readable.class)));
         assertThat(converters, hasSize(1));
 
@@ -133,7 +136,7 @@ public class PropertyConverterManagerTest {
 
     @Test
     public void testTransitiveInterfaceMapping1(){
-        PropertyConverterManager manager = new PropertyConverterManager();
+        PropertyConverterManager manager = new PropertyConverterManager(true);
         List<PropertyConverter<Runnable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Runnable.class)));
         assertThat(converters, hasSize(1));
 
@@ -147,7 +150,7 @@ public class PropertyConverterManagerTest {
 
     @Test
     public void testTransitiveInterfaceMapping2(){
-        PropertyConverterManager manager = new PropertyConverterManager();
+        PropertyConverterManager manager = new PropertyConverterManager(true);
         List<PropertyConverter<AutoCloseable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(AutoCloseable.class)));
         assertThat(converters, hasSize(1));
 


Mime
View raw message