You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2018/06/21 12:50:17 UTC

[sling-org-apache-sling-capabilities] branch master updated (e50900f -> a13696f)

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-capabilities.git.


    from e50900f  Initial commit, moving from sling-whiteboard
     new 5efb7a3  Expand README
     new a13696f  Check for duplicate namespaces

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 README.md                                                   |  9 +++++++++
 .../sling/capabilities/internal/JSONCapabilitiesWriter.java | 13 ++++++++++++-
 .../capabilities/internal/JSONCapabilitiesWriterTest.java   | 11 +++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)


[sling-org-apache-sling-capabilities] 01/02: Expand README

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-capabilities.git

commit 5efb7a3e72508d870325c5f96861efff99421107
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Jun 21 14:37:08 2018 +0200

    Expand README
---
 README.md | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/README.md b/README.md
index b84cb65..71df24e 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,12 @@ by aggregating the output of all active `CapabilitiesSource` services.
 This can be easily expanded to multiple sets of Capabilities if needed later on,
 by changing the code to use service properties to group or tag the `CapabilitiesSource` services.
 
+These capabilities are _not_ the same as OSGi capabilities: they can be application-related, indicate
+the availability of external services, etc.
+
+CapabilitiesSource services
+----------------------------
+
 The tests provide simple `CapabilitiesSource` examples, that API is as follows:
 
     @ProviderType
@@ -29,6 +35,9 @@ The tests provide simple `CapabilitiesSource` examples, that API is as follows:
         Map<String, Object> getCapabilities() throws Exception;
     }
 
+CapabilitiesServlet output
+--------------------------
+
 The `CapabilitiesServlet` produces output as in the example below, where two
 `CapabilitiesSource` services are available:
 


[sling-org-apache-sling-capabilities] 02/02: Check for duplicate namespaces

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-capabilities.git

commit a13696f129f8b625b4383c03384c5dc6e1faba89
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Jun 21 14:49:50 2018 +0200

    Check for duplicate namespaces
---
 .../sling/capabilities/internal/JSONCapabilitiesWriter.java | 13 ++++++++++++-
 .../capabilities/internal/JSONCapabilitiesWriterTest.java   | 11 +++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/capabilities/internal/JSONCapabilitiesWriter.java b/src/main/java/org/apache/sling/capabilities/internal/JSONCapabilitiesWriter.java
index 3552941..8a60004 100644
--- a/src/main/java/org/apache/sling/capabilities/internal/JSONCapabilitiesWriter.java
+++ b/src/main/java/org/apache/sling/capabilities/internal/JSONCapabilitiesWriter.java
@@ -22,7 +22,9 @@ import java.io.IOException;
 import java.io.Writer;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 import org.apache.felix.utils.json.JSONWriter;
 import org.apache.sling.capabilities.CapabilitiesSource;
 
@@ -33,6 +35,8 @@ class JSONCapabilitiesWriter {
     
     /** Write JSON to the supplied Writer, using the supplied sources */
     void writeJson(Writer w, Collection<CapabilitiesSource> sources) throws IOException {
+        final Set<String> namespaces = new HashSet<>();
+
         final JSONWriter jw = new JSONWriter(w);
         jw.object();
         jw.key(CAPS_KEY);
@@ -46,7 +50,14 @@ class JSONCapabilitiesWriter {
                 values = new HashMap<>();
                 values.put("_EXCEPTION_", e.getClass().getName() + ":" + e.getMessage());
             }
-            jw.key(s.getNamespace());
+
+            final String namespace = s.getNamespace();
+            if(namespaces.contains(namespace)) {
+              throw new DuplicateNamespaceException(namespace);
+            }
+            namespaces.add(namespace);
+
+            jw.key(namespace);
             jw.object();
             for(Map.Entry<String, Object> e : values.entrySet()) {
                 jw.key(e.getKey());
diff --git a/src/test/java/org/apache/sling/capabilities/internal/JSONCapabilitiesWriterTest.java b/src/test/java/org/apache/sling/capabilities/internal/JSONCapabilitiesWriterTest.java
index dd7227a..3fdb95a 100644
--- a/src/test/java/org/apache/sling/capabilities/internal/JSONCapabilitiesWriterTest.java
+++ b/src/test/java/org/apache/sling/capabilities/internal/JSONCapabilitiesWriterTest.java
@@ -73,4 +73,15 @@ public class JSONCapabilitiesWriterTest {
         
         assertEquals("Expecting 1 key at EXCEPTION", 1, json.getJsonObject("EXCEPTION").keySet().size());
    }
+
+    @Test(expected = DuplicateNamespaceException.class)
+    public void testDuplicateNamespace() throws IOException {
+        final List<CapabilitiesSource> sources = new ArrayList<>();
+        sources.add(new MockSource("duplicate", 1));
+        sources.add(new MockSource("another", 2));
+        sources.add(new MockSource("duplicate", 1));
+
+        final StringWriter w = new StringWriter();
+        new JSONCapabilitiesWriter().writeJson(w, sources);
+    }
 }
\ No newline at end of file