You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by th...@apache.org on 2014/06/29 00:03:35 UTC

git commit: Implemented TAP55-2358 : OrderedConfiguration should have consistent ordering

Repository: tapestry-5
Updated Branches:
  refs/heads/master 261c41666 -> a2fac6be8


Implemented TAP55-2358 : OrderedConfiguration should have consistent
ordering

Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/a2fac6be
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/a2fac6be
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/a2fac6be

Branch: refs/heads/master
Commit: a2fac6be8bed9c9406c601409ea4c063a91a832a
Parents: 261c416
Author: Thiago H. de Paula Figueiredo <th...@apache.org>
Authored: Sat Jun 28 19:03:22 2014 -0300
Committer: Thiago H. de Paula Figueiredo <th...@apache.org>
Committed: Sat Jun 28 19:03:22 2014 -0300

----------------------------------------------------------------------
 .../tapestry5/ioc/internal/RegistryImpl.java    | 17 +++++++++-
 .../groovy/ioc/specs/ConfigurationsSpec.groovy  | 16 +++++++++
 .../ioc/specs/PropertyAccessImplSpec.groovy     |  1 -
 .../tapestry5/ioc/ContributionOrderModule.java  | 28 ++++++++++++++++
 .../tapestry5/ioc/ContributionOrderModule2.java | 29 +++++++++++++++++
 .../tapestry5/ioc/ContributionOrderModule3.java | 29 +++++++++++++++++
 .../tapestry5/ioc/ContributionOrderModule4.java | 28 ++++++++++++++++
 .../apache/tapestry5/ioc/OrderedService.java    | 34 ++++++++++++++++++++
 8 files changed, 180 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a2fac6be/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
index 2859a2d..3ef57c6 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
@@ -524,7 +524,12 @@ public class RegistryImpl implements Registry, InternalRegistry, ServiceProxyPro
         Orderer<T> orderer = new Orderer<T>(logger);
         Map<String, OrderedConfigurationOverride<T>> overrides = CollectionFactory.newCaseInsensitiveMap();
 
-        for (Module m : moduleToServiceDefs.keySet())
+        // TAP5-2129. NOTICE: if someday an ordering between modules is added, this should be reverted
+        // or a notice added to the documentation.
+        List<Module> modules = new ArrayList<Module>(moduleToServiceDefs.keySet());
+        Collections.sort(modules, new ModuleComparator());
+        
+        for (Module m : modules)
             addToOrderedConfiguration(orderer, overrides, objectType, serviceDef, m);
 
         // An ugly hack ... perhaps we should introduce a new builtin service so that this can be
@@ -1209,4 +1214,14 @@ public class RegistryImpl implements Registry, InternalRegistry, ServiceProxyPro
     {
         return markerToServiceDef.keySet();
     }
+    
+    final private static class ModuleComparator implements Comparator<Module> {
+
+        @Override
+        public int compare(Module m1, Module m2)
+        {
+            return m1.getModuleBuilder().getClass().getName().compareTo(m2.getModuleBuilder().getClass().getName());
+        }
+        
+    }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a2fac6be/tapestry-ioc/src/test/groovy/ioc/specs/ConfigurationsSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/ConfigurationsSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/ConfigurationsSpec.groovy
index 0594606..c9b2ab8 100644
--- a/tapestry-ioc/src/test/groovy/ioc/specs/ConfigurationsSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/ConfigurationsSpec.groovy
@@ -314,4 +314,20 @@ class ConfigurationsSpec extends AbstractRegistrySpecification {
     then:
     noExceptionThrown()
   }
+  
+  // TAP5-2358
+  def "OrderedConfiguration should have consistent ordering"() {
+
+      when:
+      buildRegistry ContributionOrderModule, ContributionOrderModule2, ContributionOrderModule3, ContributionOrderModule4
+      def configuration1 = getService(OrderedService).getContributions();
+      
+      buildRegistry ContributionOrderModule4, ContributionOrderModule3, ContributionOrderModule2, ContributionOrderModule
+      def configuration2 = getService(OrderedService).getContributions();
+
+      then:
+      configuration1.equals(configuration2)
+          
+  }
+  
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a2fac6be/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy
index 850ed44..c76817f 100644
--- a/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/PropertyAccessImplSpec.groovy
@@ -12,7 +12,6 @@ import org.apache.tapestry5.ioc.internal.util.Pair
 import org.apache.tapestry5.ioc.internal.util.StringLongPair
 import org.apache.tapestry5.ioc.services.ClassPropertyAdapter
 import org.apache.tapestry5.ioc.services.PropertyAccess
-import org.apache.tapestry5.ioc.internal.PropertyAccessImplClasses
 
 import spock.lang.*
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a2fac6be/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule.java
new file mode 100644
index 0000000..4beba21
--- /dev/null
+++ b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule.java
@@ -0,0 +1,28 @@
+// Copyright 2014 The Apache Software Foundation
+//
+// 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.apache.tapestry5.ioc;
+
+
+public class ContributionOrderModule
+{
+    public static void bind(ServiceBinder binder) {
+        binder.bind(OrderedService.class);
+    }
+    
+    public static void contributeOrderedService(OrderedConfiguration<Integer> configuration) 
+    {
+        configuration.add("1", 1);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a2fac6be/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule2.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule2.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule2.java
new file mode 100644
index 0000000..fe838b2
--- /dev/null
+++ b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule2.java
@@ -0,0 +1,29 @@
+// Copyright 2014 The Apache Software Foundation
+//
+// 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.apache.tapestry5.ioc;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class ContributionOrderModule2
+{
+    public static void contributeOrderedService(OrderedConfiguration<Integer> configuration) 
+    {
+        configuration.add("2", 2);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a2fac6be/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule3.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule3.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule3.java
new file mode 100644
index 0000000..07f54b0
--- /dev/null
+++ b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule3.java
@@ -0,0 +1,29 @@
+// Copyright 2014 The Apache Software Foundation
+//
+// 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.apache.tapestry5.ioc;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class ContributionOrderModule3
+{
+    public static void contributeOrderedService(OrderedConfiguration<Integer> configuration) 
+    {
+        configuration.add("3", 3);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a2fac6be/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule4.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule4.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule4.java
new file mode 100644
index 0000000..2181b8a
--- /dev/null
+++ b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ContributionOrderModule4.java
@@ -0,0 +1,28 @@
+// Copyright 2014 The Apache Software Foundation
+//
+// 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.apache.tapestry5.ioc;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class ContributionOrderModule4
+{
+    public static void contributeOrderedService(OrderedConfiguration<Integer> configuration) {
+        configuration.add("4", 4);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a2fac6be/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/OrderedService.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/OrderedService.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/OrderedService.java
new file mode 100644
index 0000000..e908a80
--- /dev/null
+++ b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/OrderedService.java
@@ -0,0 +1,34 @@
+// Copyright 2014 The Apache Software Foundation
+//
+// 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.apache.tapestry5.ioc;
+
+import java.util.List;
+
+public class OrderedService
+{
+    final private List<Integer> contributions;
+    
+
+    public OrderedService(List<Integer> contributions)
+    {
+        super();
+        this.contributions = contributions;
+    }
+
+    public List<Integer> getContributions()
+    {
+        return contributions;
+    }
+
+}