You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2019/02/12 11:12:04 UTC

[sling-org-apache-sling-feature-extension-apiregions] branch master updated: Ensure the order of the regions in the features.properties

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-extension-apiregions.git


The following commit(s) were added to refs/heads/master by this push:
     new e87cf0f  Ensure the order of the regions in the features.properties
e87cf0f is described below

commit e87cf0f1b578acff858e809b1f4ba9d20ded74d0
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Tue Feb 12 09:46:42 2019 +0000

    Ensure the order of the regions in the features.properties
    
    The regions listed in features.properties should be in the same order as
    the order in which they are declared in the feature file.
---
 .../apiregions/BundleArtifactFeatureHandler.java   |  4 +++-
 .../BundleArtifactFeatureHandlerTest.java          | 26 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/feature/extension/apiregions/BundleArtifactFeatureHandler.java b/src/main/java/org/apache/sling/feature/extension/apiregions/BundleArtifactFeatureHandler.java
index b934837..967e69e 100644
--- a/src/main/java/org/apache/sling/feature/extension/apiregions/BundleArtifactFeatureHandler.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/BundleArtifactFeatureHandler.java
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.io.StringReader;
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Properties;
 import java.util.Set;
@@ -88,7 +89,8 @@ public class BundleArtifactFeatureHandler extends AbstractHandler implements Pos
                     JsonObject jo = (JsonObject) jv;
                     String fid = feature.getId().toMvnId();
 
-                    Set<String> regionSet = new HashSet<>();
+                    // Regions are ordered, so need to use a linked hash set
+                    Set<String> regionSet = new LinkedHashSet<>();
                     String regions = frMap.getProperty(fid);
                     if (regions != null) {
                         regionSet.addAll(Arrays.asList(regions.split(",")));
diff --git a/src/test/java/org/apache/sling/feature/extension/apiregions/BundleArtifactFeatureHandlerTest.java b/src/test/java/org/apache/sling/feature/extension/apiregions/BundleArtifactFeatureHandlerTest.java
index 1561d7a..a4f465e 100644
--- a/src/test/java/org/apache/sling/feature/extension/apiregions/BundleArtifactFeatureHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/extension/apiregions/BundleArtifactFeatureHandlerTest.java
@@ -103,6 +103,32 @@ public class BundleArtifactFeatureHandlerTest {
     }
 
     @Test
+    public void testRegionOrdering() throws Exception {
+        BundleArtifactFeatureHandler bafh = new BundleArtifactFeatureHandler();
+
+        Feature f = new Feature(ArtifactId.fromMvnId("org.sling:somethingelse:1.0.0"));
+        Extension ex = new Extension(ExtensionType.JSON, "api-regions", false);
+        ex.setJSON("[{\"name\":\"global\","
+                + "\"exports\": []},"
+                + "{\"name\":\"internal\","
+                + "\"exports\":[]},"
+                + "{\"name\":\"private\","
+                + "\"exports\":[]},"
+                + "{\"name\":\"forbidden\","
+                + "\"exports\":[]}]");
+
+        bafh.postProcess(new TestHandlerContextImpl(), f, ex);
+
+        String p = System.getProperty("sling.feature.apiregions.resource.features.properties");
+        Properties actual = new Properties();
+        actual.load(new FileReader(p));
+
+        Properties expected = new Properties();
+        expected.put("org.sling:somethingelse:1.0.0", "global,internal,private,forbidden");
+        assertEquals(expected, actual);
+    }
+
+    @Test
     public void testUnrelatedExtension() {
         BundleArtifactFeatureHandler bafh = new BundleArtifactFeatureHandler();
         Extension ex = new Extension(ExtensionType.JSON, "foobar", false);