sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1796079 - in /sling/trunk/bundles/extensions/caconfig/impl: ./ src/main/java/org/apache/sling/caconfig/management/impl/console/ src/main/java/org/apache/sling/caconfig/resource/impl/def/ src/main/java/org/apache/sling/caconfig/resource/imp...
Date Wed, 24 May 2017 16:17:10 GMT
Author: sseifert
Date: Wed May 24 16:17:09 2017
New Revision: 1796079

URL: http://svn.apache.org/viewvc?rev=1796079&view=rev
Log:
SLING-6883 CAConfig: Respect service ranking in ordering context path/config ref proposals

Modified:
    sling/trunk/bundles/extensions/caconfig/impl/pom.xml
    sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java
    sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultContextPathStrategy.java
    sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/resource/impl/util/ResourcePathCollatingIterator.java
    sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ContextResourceTestUtil.java
    sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ResourceEliminateDuplicatesIteratorTest.java
    sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ResourcePathCollatingIteratorTest.java

Modified: sling/trunk/bundles/extensions/caconfig/impl/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/caconfig/impl/pom.xml?rev=1796079&r1=1796078&r2=1796079&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/caconfig/impl/pom.xml (original)
+++ sling/trunk/bundles/extensions/caconfig/impl/pom.xml Wed May 24 16:17:09 2017
@@ -122,7 +122,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.caconfig.spi</artifactId>
-            <version>1.3.0</version>
+            <version>1.3.1-SNAPSHOT</version>
             <scope>compile</scope>
         </dependency>
         <dependency>

Modified: sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java?rev=1796079&r1=1796078&r2=1796079&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java
(original)
+++ sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java
Wed May 24 16:17:09 2017
@@ -170,14 +170,16 @@ public class ConfigurationWebConsolePlug
                 
                 // context paths
                 Iterator<ContextResource> contextResources = contextPathStrategyMultiplexer.findContextResources(contentResource);
-                tableStart(pw, "Context paths", 2);
+                tableStart(pw, "Context paths", 3);
                 pw.println("<th>Context path</th>");
                 pw.println("<th>Config reference</th>");
+                pw.println("<th>Ranking</th>");
                 while (contextResources.hasNext()) {
                     ContextResource contextResource = contextResources.next();
                     tableRows(pw);
                     pw.println("<td>" + xss.encodeForHTML(contextResource.getResource().getPath())
+ "</td>");
                     pw.println("<td>" + xss.encodeForHTML(contextResource.getConfigRef())
+ "</td>");
+                    pw.println("<td>" + contextResource.getServiceRanking() + "</td>");
                 }
                 tableEnd(pw);                
 

Modified: sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultContextPathStrategy.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultContextPathStrategy.java?rev=1796079&r1=1796078&r2=1796079&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultContextPathStrategy.java
(original)
+++ sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultContextPathStrategy.java
Wed May 24 16:17:09 2017
@@ -58,6 +58,10 @@ public class DefaultContextPathStrategy
                 description = "Additional property names to " + PROPERTY_CONFIG_REF + " to
look up a configuration reference. The names are used in the order defined, "
                             + "always starting with " + PROPERTY_CONFIG_REF + ". Once a property
with a value is found, that value is used and the following property names are skipped.")
         String[] configRefPropertyNames();
+
+        @AttributeDefinition(name = "Service Ranking",
+                description = "Priority of persistence strategy (higher = higher priority).")
+            int service_ranking() default 0;
     }
 
     private static final Logger log = LoggerFactory.getLogger(DefaultContextPathStrategy.class);
@@ -121,7 +125,7 @@ public class DefaultContextPathStrategy
                 String configRef = getConfigRef(resource);
                 if (configRef != null) {
                     log.trace("+ Found context path {}, configRef {}", resource.getPath(),
configRef);
-                    return new ContextResource(resource, configRef);
+                    return new ContextResource(resource, configRef, config.service_ranking());
                 }
                 // if getParent() returns null, stop
                 resource = resource.getParent();

Modified: sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/resource/impl/util/ResourcePathCollatingIterator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/resource/impl/util/ResourcePathCollatingIterator.java?rev=1796079&r1=1796078&r2=1796079&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/resource/impl/util/ResourcePathCollatingIterator.java
(original)
+++ sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/resource/impl/util/ResourcePathCollatingIterator.java
Wed May 24 16:17:09 2017
@@ -40,7 +40,12 @@ public class ResourcePathCollatingIterat
             Integer length2 = o2.getResource().getPath().length();
             int result = length2.compareTo(length1);
             if (result == 0) {
-                result = StringUtils.defaultString(o1.getConfigRef()).compareTo(StringUtils.defaultString(o2.getConfigRef()));
+                Integer ranking1 = o1.getServiceRanking();
+                Integer ranking2 = o2.getServiceRanking();
+                result = ranking2.compareTo(ranking1);
+                if (result == 0) {
+                    result = StringUtils.defaultString(o1.getConfigRef()).compareTo(StringUtils.defaultString(o2.getConfigRef()));
+                }
             }
             return result;
         }

Modified: sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ContextResourceTestUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ContextResourceTestUtil.java?rev=1796079&r1=1796078&r2=1796079&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ContextResourceTestUtil.java
(original)
+++ sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ContextResourceTestUtil.java
Wed May 24 16:17:09 2017
@@ -57,7 +57,7 @@ public final class ContextResourceTestUt
             @Override
             public Object transform(Object input) {
                 Resource resource = (Resource)input;
-                return new ContextResource(resource, "/conf-test" + resource.getPath());
+                return new ContextResource(resource, "/conf-test" + resource.getPath(), 0);
             }
         });
     }

Modified: sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ResourceEliminateDuplicatesIteratorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ResourceEliminateDuplicatesIteratorTest.java?rev=1796079&r1=1796078&r2=1796079&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ResourceEliminateDuplicatesIteratorTest.java
(original)
+++ sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ResourceEliminateDuplicatesIteratorTest.java
Wed May 24 16:17:09 2017
@@ -49,11 +49,11 @@ public class ResourceEliminateDuplicates
         
         ResourceResolver rr = context.resourceResolver();
         List<ContextResource> list = ImmutableList.of(
-                new ContextResource(rr.getResource("/content/a"), "/conf/a"), 
-                new ContextResource(rr.getResource("/content/a/b"), "/conf/a/b"),
-                new ContextResource(rr.getResource("/content/a"), "/conf/a"),
-                new ContextResource(rr.getResource("/content/a"), null),
-                new ContextResource(rr.getResource("/content/a/b/c"), "/conf/a/b"));
+                new ContextResource(rr.getResource("/content/a"), "/conf/a", 0), 
+                new ContextResource(rr.getResource("/content/a/b"), "/conf/a/b", 0),
+                new ContextResource(rr.getResource("/content/a"), "/conf/a", 0),
+                new ContextResource(rr.getResource("/content/a"), null, 0),
+                new ContextResource(rr.getResource("/content/a/b/c"), "/conf/a/b", 0));
         
         Iterator<Resource> result = toResourceIterator(new ResourceEliminateDuplicatesIterator(list.iterator()));
         assertThat(result, ResourceIteratorMatchers.paths(

Modified: sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ResourcePathCollatingIteratorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ResourcePathCollatingIteratorTest.java?rev=1796079&r1=1796078&r2=1796079&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ResourcePathCollatingIteratorTest.java
(original)
+++ sling/trunk/bundles/extensions/caconfig/impl/src/test/java/org/apache/sling/caconfig/resource/impl/util/ResourcePathCollatingIteratorTest.java
Wed May 24 16:17:09 2017
@@ -81,9 +81,9 @@ public class ResourcePathCollatingIterat
         
         ResourceResolver rr = context.resourceResolver();
         List<ContextResource> list1 = ImmutableList.of(
-                new ContextResource(rr.getResource("/content/a"), "/conf/z"));
+                new ContextResource(rr.getResource("/content/a"), "/conf/z", 0));
         List<ContextResource> list2 = ImmutableList.of(
-                new ContextResource(rr.getResource("/content/a"), "/conf/a"));
+                new ContextResource(rr.getResource("/content/a"), "/conf/a", 0));
         
         Iterator<ContextResource> result = new ResourcePathCollatingIterator(ImmutableList.of(list1.iterator(),
list2.iterator()));
         ContextResource item1 = result.next();
@@ -97,4 +97,31 @@ public class ResourcePathCollatingIterat
         assertEquals("/conf/z", item2.getConfigRef());
     }
 
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testWithConfigRefAndServiceRanking() {
+        context.build()
+            .resource("/content/a")
+            .resource("/content/a/b")
+            .resource("/content/a/b/c")
+            .resource("/content/a/b/c/d");
+        
+        ResourceResolver rr = context.resourceResolver();
+        List<ContextResource> list1 = ImmutableList.of(
+                new ContextResource(rr.getResource("/content/a"), "/conf/z", 500));
+        List<ContextResource> list2 = ImmutableList.of(
+                new ContextResource(rr.getResource("/content/a"), "/conf/a", 100));
+        
+        Iterator<ContextResource> result = new ResourcePathCollatingIterator(ImmutableList.of(list1.iterator(),
list2.iterator()));
+        ContextResource item1 = result.next();
+        ContextResource item2 = result.next();
+        assertFalse(result.hasNext());
+        
+        assertEquals("/content/a", item1.getResource().getPath());
+        assertEquals("/conf/z", item1.getConfigRef());
+
+        assertEquals("/content/a", item2.getResource().getPath());
+        assertEquals("/conf/a", item2.getConfigRef());
+    }
+
 }



Mime
View raw message