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 2018/11/07 11:37:24 UTC

[sling-org-apache-sling-feature-extension-apiregions] branch master created (now 7f29b2f)

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

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


      at 7f29b2f  Add .gitignore

This branch includes the following new commits:

     new 952d5d3  SLING-7779 API Region support for the Sling Feature Model
     new 97aca3c  SLING-7779 API Region support for the Sling Feature Model
     new f4b35f0  SLING-7779 API Region support for the Sling Feature Model
     new 627b8b3  SLING-7779 API Region support for the Sling Feature Model
     new 0e0fe63  Rename whitelisting to apiregions
     new 81398c2  Add some sling boilerplate files in preparation for moving out of the whiteboard
     new f478980  Some initial documentation on the apiregions extension.
     new 278857f  Update README.md header
     new 576ceea  Update README.md
     new bbea2ae  Reduce dependencies
     new 40b2497  Handle extension merging with null target
     new cae9ab8  Support inheriting exported packages from regions defined earlier in the feature
     new 7f29b2f  Add .gitignore

The 13 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.



[sling-org-apache-sling-feature-extension-apiregions] 12/13: Support inheriting exported packages from regions defined earlier in the feature

Posted by da...@apache.org.
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

commit cae9ab8e912a489dfe6552ec5ccc0a0c94680fdd
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Tue Nov 6 15:12:07 2018 +0000

    Support inheriting exported packages from regions defined earlier in the feature
    
    When exported packages are defined in a region, these are inherited by
    subsequent regions in the feature file. This is with the exception of
    the global region, which is 'special'.
    So if you have:
    api-regions:JSON|false": [
      {"name": "global",
       "exports": ["com.global"]},
      {"name": "deprecated",
       "exports": ["some.package"]},
      {"name": "internal",
       "exports": ["dont.touch"]}]
    Then the actual packages in the regions are as follows:
    global: com.global
    deprecated: some.package
    internal: dont.touch, some.package
---
 .../apiregions/APIRegionMergeHandler.java          | 50 +++++++++++++++++++---
 .../extension/apiregions/AbstractHandler.java      |  7 +++
 .../apiregions/BundleArtifactFeatureHandler.java   | 12 +++---
 .../extension/apiregions/BundleMappingHandler.java |  2 +-
 .../apiregions/APIRegionMergeHandlerTest.java      | 49 +++++++++++++++++++--
 5 files changed, 105 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java b/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java
index fbd695f..2343c8a 100644
--- a/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java
@@ -23,27 +23,37 @@ import org.apache.sling.feature.builder.MergeHandler;
 
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.json.Json;
 import javax.json.JsonArray;
+import javax.json.JsonArrayBuilder;
 import javax.json.JsonObject;
 import javax.json.JsonReader;
+import javax.json.JsonString;
 import javax.json.JsonValue;
 import javax.json.stream.JsonGenerator;
 
-public class APIRegionMergeHandler implements MergeHandler {
+import static org.apache.sling.feature.extension.apiregions.AbstractHandler.API_REGIONS_NAME;
+import static org.apache.sling.feature.extension.apiregions.AbstractHandler.EXPORTS_KEY;
+import static org.apache.sling.feature.extension.apiregions.AbstractHandler.GLOBAL_NAME;
+import static org.apache.sling.feature.extension.apiregions.AbstractHandler.NAME_KEY;
+import static org.apache.sling.feature.extension.apiregions.AbstractHandler.ORG_FEATURE_KEY;
 
+public class APIRegionMergeHandler implements MergeHandler {
     @Override
     public boolean canMerge(Extension extension) {
-        return "api-regions".equals(extension.getName());
+        return API_REGIONS_NAME.equals(extension.getName());
     }
 
     @Override
     public void merge(HandlerContext context, Feature target, Feature source, Extension targetEx, Extension sourceEx) {
-        if (!sourceEx.getName().equals("api-regions"))
+        if (!sourceEx.getName().equals(API_REGIONS_NAME))
             return;
-        if (targetEx != null && !targetEx.getName().equals("api-regions"))
+        if (targetEx != null && !targetEx.getName().equals(API_REGIONS_NAME))
             return;
 
         JsonReader srcJR = Json.createReader(new StringReader(sourceEx.getJSON()));
@@ -67,13 +77,43 @@ public class APIRegionMergeHandler implements MergeHandler {
             gen.write(jv);
         }
 
+        Map<String, List<String>> inheritedPackages = new LinkedHashMap<>(); // keep the insertion order
         for (int i=0; i < srcJA.size(); i++) {
             gen.writeStartObject();
             JsonObject jo = srcJA.getJsonObject(i);
+            boolean exportsWritten = false;
+            if (!jo.containsKey(ORG_FEATURE_KEY)) {
+                gen.write(ORG_FEATURE_KEY, source.getId().toMvnId());
+
+                List<String> exports = new ArrayList<>();
+                if (jo.containsKey(EXPORTS_KEY)) {
+                    JsonArray ja = jo.getJsonArray(EXPORTS_KEY);
+                    for (JsonValue jv : ja) {
+                        if (jv instanceof JsonString) {
+                            exports.add(((JsonString) jv).getString());
+                        }
+                    }
+                }
+
+                String name = jo.getString(NAME_KEY);
+                if (!GLOBAL_NAME.equals(name)) {
+                    ArrayList<String> localExports = new ArrayList<>(exports);
+                    for (Map.Entry<String, List<String>> entry : inheritedPackages.entrySet()) {
+                        entry.getValue().stream().filter(p -> !exports.contains(p)).forEach(exports::add);
+                    }
+                    inheritedPackages.put(name, localExports);
+
+                    JsonArrayBuilder eab = Json.createArrayBuilder();
+                    exports.stream().forEach(e -> eab.add(e));
+                    gen.write(EXPORTS_KEY, eab.build());
+                    exportsWritten = true;
+                }
+            }
             for (Map.Entry<String, JsonValue> entry : jo.entrySet()) {
+                if (EXPORTS_KEY.equals(entry.getKey()) && exportsWritten)
+                    continue;
                 gen.write(entry.getKey(), entry.getValue());
             }
-            gen.write("org-feature", source.getId().toMvnId());
             gen.writeEnd();
         }
 
diff --git a/src/main/java/org/apache/sling/feature/extension/apiregions/AbstractHandler.java b/src/main/java/org/apache/sling/feature/extension/apiregions/AbstractHandler.java
index 32321a2..bc19632 100644
--- a/src/main/java/org/apache/sling/feature/extension/apiregions/AbstractHandler.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/AbstractHandler.java
@@ -29,6 +29,13 @@ import java.util.Date;
 import java.util.Properties;
 
 class AbstractHandler {
+    static final String API_REGIONS_NAME = "api-regions";
+    static final String GLOBAL_NAME = "global";
+
+    static final String NAME_KEY = "name";
+    static final String EXPORTS_KEY = "exports";
+    static final String ORG_FEATURE_KEY = "org-feature";
+
     private static final String FILE_PREFIX = "apiregions.";
 
     protected File getDataFile(String name) throws IOException {
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 0b04c4f..014315c 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
@@ -41,7 +41,7 @@ import javax.json.JsonValue;
 public class BundleArtifactFeatureHandler extends AbstractHandler implements PostProcessHandler {
     @Override
     public void postProcess(HandlerContext context, Feature feature, Extension extension) {
-        if (!"api-regions".equals(extension.getName()))
+        if (!API_REGIONS_NAME.equals(extension.getName()))
             return;
 
         try {
@@ -59,7 +59,7 @@ public class BundleArtifactFeatureHandler extends AbstractHandler implements Pos
         for (Artifact b : feature.getBundles()) {
             String id = b.getId().toMvnId().trim();
 
-            String fid = b.getMetadata().get("org-feature");
+            String fid = b.getMetadata().get(ORG_FEATURE_KEY);
             if (fid == null)
                 fid = feature.getId().toMvnId().trim();
 
@@ -90,8 +90,8 @@ public class BundleArtifactFeatureHandler extends AbstractHandler implements Pos
             if (jv instanceof JsonObject) {
                 JsonObject jo = (JsonObject) jv;
                 String fid = null;
-                if (jo.containsKey("org-feature"))
-                    fid = jo.getString("org-feature");
+                if (jo.containsKey(ORG_FEATURE_KEY))
+                    fid = jo.getString(ORG_FEATURE_KEY);
                 if (fid == null)
                     fid = feature.getId().toMvnId();
 
@@ -100,7 +100,7 @@ public class BundleArtifactFeatureHandler extends AbstractHandler implements Pos
                 if (regions != null) {
                     regionSet.addAll(Arrays.asList(regions.split(",")));
                 }
-                String region = jo.getString("name");
+                String region = jo.getString(NAME_KEY);
                 regionSet.add(region);
 
                 frMap.put(fid, regionSet.stream().collect(Collectors.joining(",")));
@@ -110,7 +110,7 @@ public class BundleArtifactFeatureHandler extends AbstractHandler implements Pos
                 if (packages != null) {
                     packageSet.addAll(Arrays.asList(packages.split(",")));
                 }
-                JsonArray eja = jo.getJsonArray("exports");
+                JsonArray eja = jo.getJsonArray(EXPORTS_KEY);
                 for (int i=0; i < eja.size(); i++) {
                     packageSet.add(eja.getString(i));
                 }
diff --git a/src/main/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandler.java b/src/main/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandler.java
index 38896e1..00a9c0a 100644
--- a/src/main/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandler.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandler.java
@@ -31,7 +31,7 @@ import java.util.jar.JarFile;
 public class BundleMappingHandler extends AbstractHandler implements PostProcessHandler {
     @Override
     public void postProcess(HandlerContext context, Feature feature, Extension extension) {
-        if (!"api-regions".equals(extension.getName()))
+        if (!API_REGIONS_NAME.equals(extension.getName()))
             return;
 
         try {
diff --git a/src/test/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandlerTest.java b/src/test/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandlerTest.java
index db9bcd0..9fd6860 100644
--- a/src/test/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandlerTest.java
@@ -43,7 +43,7 @@ public class APIRegionMergeHandlerTest {
     }
 
     @Test
-    public void testAPIRegionMergeHandler() {
+    public void testAPIRegionMerging() {
         APIRegionMergeHandler armh = new APIRegionMergeHandler();
 
         Feature tf = new Feature(ArtifactId.fromMvnId("x:t:1"));
@@ -58,7 +58,10 @@ public class APIRegionMergeHandlerTest {
 
         Extension srEx = new Extension(ExtensionType.JSON, "api-regions", false);
         srEx.setJSON("[{\"name\":\"global\","
-                + "\"exports\": [\"test\"]}]");
+                + "\"exports\": [\"test\"]},"
+                + "{\"name\":\"something\","
+                + "\"exports\": [\"a.ha\"],"
+                + "\"org-feature\": \"different:feature:1\"}]");
 
         armh.merge(null, tf, sf, tgEx, srEx);
 
@@ -69,7 +72,47 @@ public class APIRegionMergeHandlerTest {
                 + "\"org-feature\":\"some:feature:1\"},"
                 + "{\"name\":\"global\","
                 + "\"org-feature\":\"y:s:2\","
-                + "\"exports\": [\"test\"]}]";
+                + "\"exports\": [\"test\"]},"
+                + "{\"name\":\"something\","
+                + "\"exports\": [\"a.ha\"],"
+                + "\"org-feature\": \"different:feature:1\"}]";
+        JsonReader er = Json.createReader(new StringReader(expectedJSON));
+        JsonReader ar = Json.createReader(new StringReader(tgEx.getJSON()));
+        JsonArray ea = er.readArray();
+        JsonArray aa = ar.readArray();
+
+        assertEquals(ea, aa);
+    }
+
+    @Test
+    public void testRegionExportsInheritance() throws Exception {
+        APIRegionMergeHandler armh = new APIRegionMergeHandler();
+
+        Feature tf = new Feature(ArtifactId.fromMvnId("x:t:1"));
+        Feature sf = new Feature(ArtifactId.fromMvnId("y:s:2"));
+
+        Extension srEx = new Extension(ExtensionType.JSON, "api-regions", false);
+        srEx.setJSON("[{\"name\":\"global\","
+                + "\"exports\": [\"a.b.c\",\"d.e.f\"]},"
+                + "{\"name\":\"deprecated\","
+                + "\"exports\":[\"klm\",\"qrs\"]},"
+                + "{\"name\":\"internal\","
+                + "\"exports\":[\"xyz\"]},"
+                + "{\"name\":\"forbidden\","
+                + "\"exports\":[\"abc\",\"klm\"]},"
+                + "{\"name\":\"internal\","
+                + "\"exports\":[\"test\"],"
+                + "\"org-feature\":\"an.other:feature:123\"}]");
+
+        armh.merge(null, tf, sf, null, srEx);
+
+        Extension tgEx = tf.getExtensions().iterator().next();
+
+        String expectedJSON = "[{\"name\":\"global\",\"org-feature\":\"y:s:2\",\"exports\":[\"a.b.c\",\"d.e.f\"]},"
+                + "{\"name\":\"deprecated\",\"org-feature\":\"y:s:2\",\"exports\":[\"klm\",\"qrs\"]},"
+                + "{\"name\":\"internal\",\"org-feature\":\"y:s:2\",\"exports\":[\"xyz\",\"klm\",\"qrs\"]},"
+                + "{\"name\":\"forbidden\",\"org-feature\":\"y:s:2\",\"exports\":[\"abc\",\"klm\",\"qrs\",\"xyz\"]},"
+                + "{\"name\":\"internal\",\"org-feature\":\"an.other:feature:123\",\"exports\":[\"test\"]}]";
         JsonReader er = Json.createReader(new StringReader(expectedJSON));
         JsonReader ar = Json.createReader(new StringReader(tgEx.getJSON()));
         JsonArray ea = er.readArray();


[sling-org-apache-sling-feature-extension-apiregions] 13/13: Add .gitignore

Posted by da...@apache.org.
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

commit 7f29b2fe0f16d6d536f18dedca8a8afdb0806183
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Wed Nov 7 11:24:35 2018 +0000

    Add .gitignore
---
 .gitignore | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5b783ed
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,17 @@
+/target
+.idea
+.classpath
+.metadata
+.project
+.settings
+.externalToolBuilders
+maven-eclipse.xml
+*.swp
+*.iml
+*.ipr
+*.iws
+*.bak
+.vlt
+.DS_Store
+jcr.log
+atlassian-ide-plugin.xml


[sling-org-apache-sling-feature-extension-apiregions] 01/13: SLING-7779 API Region support for the Sling Feature Model

Posted by da...@apache.org.
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

commit 952d5d3f49f978d4e5eddf29330df4cb0d50c280
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Wed Oct 31 12:34:45 2018 +0000

    SLING-7779 API Region support for the Sling Feature Model
    
    Initial commit for the apiregions extension, which transforms region in
    formation in feature models into runtime-accessed resources.
---
 pom.xml                                            |  61 ++++++++++
 .../whitelisting/extensions/APIRegionHandler.java  |  75 +++++++++++++
 .../whitelisting/extensions/AbstractHandler.java   |  58 ++++++++++
 .../extensions/BundleArtifactFeatureHandler.java   | 123 +++++++++++++++++++++
 .../extensions/BundleMappingHandler.java           |  63 +++++++++++
 .../org.apache.sling.feature.builder.MergeHandler  |   1 +
 ...apache.sling.feature.builder.PostProcessHandler |   2 +
 7 files changed, 383 insertions(+)

diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..0fb4d4b
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0"?><!-- Licensed to the Apache Software Foundation (ASF) 
+    under one or more contributor license agreements. See the NOTICE file distributed 
+    with this work for additional information regarding copyright ownership. 
+    The ASF licenses this file to You 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>34</version>
+        <relativePath />
+    </parent>
+
+    <artifactId>org.apache.sling.feature.extension.apiregions</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>Sling Featuremodel - API Regions Exension</name>
+
+    <properties>
+        <jdk.version>8</jdk.version>
+    </properties>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <exclude>src/main/resources/META-INF/services/**</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-json_1.0_spec</artifactId>
+            <version>1.0-alpha-1</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.feature</artifactId>
+            <version>0.1.3-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/feature/whitelisting/extensions/APIRegionHandler.java b/src/main/java/org/apache/sling/feature/whitelisting/extensions/APIRegionHandler.java
new file mode 100644
index 0000000..1756412
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/whitelisting/extensions/APIRegionHandler.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.feature.whitelisting.extensions;
+
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.builder.HandlerContext;
+import org.apache.sling.feature.builder.MergeHandler;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Map;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonValue;
+import javax.json.stream.JsonGenerator;
+
+public class APIRegionHandler implements MergeHandler {
+
+    @Override
+    public boolean canMerge(Extension extension) {
+        return "api-regions".equals(extension.getName());
+    }
+
+    @Override
+    public void merge(HandlerContext context, Feature target, Feature source, Extension targetEx, Extension sourceEx) {
+        if (!targetEx.getName().equals("api-regions") || !sourceEx.getName().equals("api-regions"))
+            return;
+
+        JsonReader srcJR = Json.createReader(new StringReader(sourceEx.getJSON()));
+        JsonArray srcJA = srcJR.readArray();
+
+        JsonReader tgtJR = Json.createReader(new StringReader(targetEx.getJSON()));
+        JsonArray tgtJA = tgtJR.readArray();
+
+        StringWriter sw = new StringWriter();
+        JsonGenerator gen = Json.createGenerator(sw);
+        gen.writeStartArray();
+        for (JsonValue jv : tgtJA) {
+            gen.write(jv);
+        }
+
+        for (int i=0; i < srcJA.size(); i++) {
+            gen.writeStartObject();
+            JsonObject jo = srcJA.getJsonObject(i);
+            for (Map.Entry<String, JsonValue> entry : jo.entrySet()) {
+                gen.write(entry.getKey(), entry.getValue());
+            }
+            gen.write("org-feature", source.getId().toMvnId());
+            gen.writeEnd();
+        }
+
+        gen.writeEnd();
+        gen.close();
+
+        targetEx.setJSON(sw.toString());
+    }
+}
diff --git a/src/main/java/org/apache/sling/feature/whitelisting/extensions/AbstractHandler.java b/src/main/java/org/apache/sling/feature/whitelisting/extensions/AbstractHandler.java
new file mode 100644
index 0000000..ddc2d5e
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/whitelisting/extensions/AbstractHandler.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.feature.whitelisting.extensions;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Date;
+import java.util.Properties;
+
+class AbstractHandler {
+    private static final String FILE_PREFIX = "whitelisting.";
+
+    protected File getDataFile(String name) throws IOException {
+        Path p = Files.createTempFile(FILE_PREFIX, name);
+        File f = p.toFile();
+        f.deleteOnExit();
+
+        System.setProperty(FILE_PREFIX + name, f.getCanonicalPath());
+        return f;
+    }
+
+    protected Properties loadProperties(File file) throws IOException, FileNotFoundException {
+        Properties map = new Properties();
+        if (file.exists()) {
+            try (InputStream is = new FileInputStream(file)) {
+                map.load(is);
+            }
+        }
+        return map;
+    }
+
+    protected void storeProperties(Properties properties, File file) throws IOException, FileNotFoundException {
+        try (OutputStream os = new FileOutputStream(file)) {
+            properties.store(os, "Generated at " + new Date());
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleArtifactFeatureHandler.java b/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleArtifactFeatureHandler.java
new file mode 100644
index 0000000..79558c4
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleArtifactFeatureHandler.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.feature.whitelisting.extensions;
+
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.builder.HandlerContext;
+import org.apache.sling.feature.builder.PostProcessHandler;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonValue;
+
+public class BundleArtifactFeatureHandler extends AbstractHandler implements PostProcessHandler {
+    @Override
+    public void postProcess(HandlerContext context, Feature feature, Extension extension) {
+        if (!"api-regions".equals(extension.getName()))
+            return;
+
+        try {
+            writeBundleToFeatureMap(feature);
+            writeFeatureToRegionAndPackageMap(feature, extension);
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    private void writeBundleToFeatureMap(Feature feature) throws IOException {
+        File bundlesFile = getDataFile("bundles.properties");
+        Properties map = loadProperties(bundlesFile);
+
+        for (Artifact b : feature.getBundles()) {
+            String id = b.getId().toMvnId().trim();
+
+            String fid = b.getMetadata().get("org-feature");
+            if (fid == null)
+                fid = feature.getId().toMvnId().trim();
+
+            String m = map.getProperty(id);
+            if (m != null) {
+                List<String> l = Arrays.asList(m.split(","));
+                if (!l.contains(fid))
+                    m = m.trim() + "," + fid;
+            } else {
+                m = fid;
+            }
+            map.put(id, m);
+        }
+
+        storeProperties(map, bundlesFile);
+    }
+
+    private void writeFeatureToRegionAndPackageMap(Feature feature, Extension extension) throws IOException {
+        JsonReader jr = Json.createReader(new StringReader(extension.getJSON()));
+        JsonArray ja = jr.readArray();
+
+        File featuresFile = getDataFile("features.properties");
+        File regionsFile = getDataFile("regions.properties");
+        Properties frMap = loadProperties(featuresFile);
+        Properties rpMap = loadProperties(regionsFile);
+
+        for (JsonValue jv : ja) {
+            if (jv instanceof JsonObject) {
+                JsonObject jo = (JsonObject) jv;
+                String fid = jo.getString("org-feature");
+                if (fid == null)
+                    fid = feature.getId().toMvnId();
+
+                Set<String> regionSet = new HashSet<>();
+                String regions = frMap.getProperty(fid);
+                if (regions != null) {
+                    regionSet.addAll(Arrays.asList(regions.split(",")));
+                }
+                String region = jo.getString("name");
+                regionSet.add(region);
+
+                frMap.put(fid, regionSet.stream().collect(Collectors.joining(",")));
+
+                Set<String> packageSet = new HashSet<>();
+                String packages = rpMap.getProperty(region);
+                if (packages != null) {
+                    packageSet.addAll(Arrays.asList(packages.split(",")));
+                }
+                JsonArray eja = jo.getJsonArray("exports");
+                for (int i=0; i < eja.size(); i++) {
+                    packageSet.add(eja.getString(i));
+                }
+                rpMap.put(region, packageSet.stream().collect(Collectors.joining(",")));
+            }
+        }
+
+        storeProperties(frMap, featuresFile);
+        storeProperties(rpMap, regionsFile);
+    }
+}
diff --git a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java b/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
new file mode 100644
index 0000000..1338e88
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.feature.whitelisting.extensions;
+
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.builder.HandlerContext;
+import org.apache.sling.feature.builder.PostProcessHandler;
+import org.osgi.framework.Constants;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.jar.JarFile;
+
+public class BundleMappingHandler extends AbstractHandler implements PostProcessHandler {
+    @Override
+    public void postProcess(HandlerContext context, Feature feature, Extension extension) {
+        if (!"api-regions".equals(extension.getName()))
+            return;
+
+
+        try {
+            File idBSNFile = getDataFile("idbsnver.properties");
+            Properties map = loadProperties(idBSNFile);
+
+            for (Artifact b : feature.getBundles()) {
+                File f = context.getArtifactProvider().provide(b.getId());
+
+                try (JarFile jf = new JarFile(f)) {
+                    String bsn = jf.getManifest().getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
+                    if (bsn == null)
+                        continue;
+
+                    String ver = jf.getManifest().getMainAttributes().getValue(Constants.BUNDLE_VERSION);
+                    if (ver == null)
+                        ver = "0.0.0";
+
+                    map.put(b.getId().toMvnId(), bsn.trim() + "~" + ver.trim());
+                }
+            }
+
+            storeProperties(map, idBSNFile);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+}
diff --git a/src/main/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler b/src/main/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler
new file mode 100644
index 0000000..359d2fa
--- /dev/null
+++ b/src/main/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler
@@ -0,0 +1 @@
+org.apache.sling.feature.whitelisting.extensions.APIRegionHandler
diff --git a/src/main/resources/META-INF/services/org.apache.sling.feature.builder.PostProcessHandler b/src/main/resources/META-INF/services/org.apache.sling.feature.builder.PostProcessHandler
new file mode 100644
index 0000000..22b67f7
--- /dev/null
+++ b/src/main/resources/META-INF/services/org.apache.sling.feature.builder.PostProcessHandler
@@ -0,0 +1,2 @@
+org.apache.sling.feature.whitelisting.extensions.BundleMappingHandler
+org.apache.sling.feature.whitelisting.extensions.BundleArtifactFeatureHandler


[sling-org-apache-sling-feature-extension-apiregions] 07/13: Some initial documentation on the apiregions extension.

Posted by da...@apache.org.
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

commit f4789803e9d0541103e7d8ff9c2ddc687246772c
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Nov 5 14:02:35 2018 +0000

    Some initial documentation on the apiregions extension.
---
 README.md | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..714dbc9
--- /dev/null
+++ b/README.md
@@ -0,0 +1,24 @@
+[<img src="http://sling.apache.org/res/logos/sling.png"/>](http://sling.apache.org)
+
+ [![Build Status](https://builds.apache.org/buildStatus/icon?job=sling-slingfeature-maven-plugin-1.8)](https://builds.apache.org/view/S-Z/view/Sling/job/sling-slingfeature-maven-plugin-1.8) [![Test Status](https://img.shields.io/jenkins/t/https/builds.apache.org/view/S-Z/view/Sling/job/sling-slingfeature-maven-plugin-1.8.svg)](https://builds.apache.org/view/S-Z/view/Sling/job/sling-slingfeature-maven-plugin-1.8/test_results_analyzer/) [![License](https://img.shields.io/badge/License-Apac [...]
+
+# Apache Sling API Regions extension
+
+This component contains extensions relating to the API Regions component.
+The following extensions are registered via the ServiceLoader mechanism:
+
+## `org.apache.sling.feature.builder.MergeHandler`
+Merge handlers are called when features are merged during the aggregation process.
+
+`APIRegionMergeHandler` - This handler knows how to merge API Regions extensions and adds the `org-feature` key to the `api-regions` sections to record what feature this section originally belonged.
+
+
+## `org.apache.sling.feature.builder.PostProcessHandler`
+PostProcessHandlers are called when a feature contains an `api-regions` section.
+
+`BundleMappingHandler` - This handler creates a mapping file `idbsnver.properties` that maps the Artifact ID to a bundle symbolic name and version. A tilde `~` is used in the value of the map to separate BSN and version. 
+
+`BundleArtifactFeatureHandler` - This handler creates 3 mapping files:
+    `bundles.properties`: maps bundles to the original feature they were in. A bundle could be from more then one feature.
+    `features.properties`: maps features to regions. A feature can be in more than one region.
+    `regions.properties`: maps regions to packages. A region can expose more than one package.
\ No newline at end of file


[sling-org-apache-sling-feature-extension-apiregions] 05/13: Rename whitelisting to apiregions

Posted by da...@apache.org.
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

commit 0e0fe632aa4506be14888cab76e564566b1918ca
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Nov 5 11:01:44 2018 +0000

    Rename whitelisting to apiregions
---
 .../apache/sling/feature/extension/apiregions/AbstractHandler.java  | 2 +-
 .../META-INF/services/org.apache.sling.feature.builder.MergeHandler | 2 +-
 .../services/org.apache.sling.feature.builder.PostProcessHandler    | 4 ++--
 .../extension/apiregions/BundleArtifactFeatureHandlerTest.java      | 6 +++---
 .../feature/extension/apiregions/BundleMappingHandlerTest.java      | 3 +--
 5 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/extension/apiregions/AbstractHandler.java b/src/main/java/org/apache/sling/feature/extension/apiregions/AbstractHandler.java
index 122c22b..32321a2 100644
--- a/src/main/java/org/apache/sling/feature/extension/apiregions/AbstractHandler.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/AbstractHandler.java
@@ -29,7 +29,7 @@ import java.util.Date;
 import java.util.Properties;
 
 class AbstractHandler {
-    private static final String FILE_PREFIX = "whitelisting.";
+    private static final String FILE_PREFIX = "apiregions.";
 
     protected File getDataFile(String name) throws IOException {
         Path p = Files.createTempFile(FILE_PREFIX, name);
diff --git a/src/main/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler b/src/main/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler
index 359d2fa..ec6db93 100644
--- a/src/main/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler
+++ b/src/main/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler
@@ -1 +1 @@
-org.apache.sling.feature.whitelisting.extensions.APIRegionHandler
+org.apache.sling.feature.extension.apiregions.APIRegionMergeHandler
diff --git a/src/main/resources/META-INF/services/org.apache.sling.feature.builder.PostProcessHandler b/src/main/resources/META-INF/services/org.apache.sling.feature.builder.PostProcessHandler
index 22b67f7..1bf6138 100644
--- a/src/main/resources/META-INF/services/org.apache.sling.feature.builder.PostProcessHandler
+++ b/src/main/resources/META-INF/services/org.apache.sling.feature.builder.PostProcessHandler
@@ -1,2 +1,2 @@
-org.apache.sling.feature.whitelisting.extensions.BundleMappingHandler
-org.apache.sling.feature.whitelisting.extensions.BundleArtifactFeatureHandler
+org.apache.sling.feature.extension.apiregions.BundleMappingHandler
+org.apache.sling.feature.extension.apiregions.BundleArtifactFeatureHandler
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 3cff17f..e8b5ca9 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
@@ -47,7 +47,7 @@ public class BundleArtifactFeatureHandlerTest {
         ex.setJSON("[]");
         bafh.postProcess(null, f, ex);
 
-        String p = System.getProperty("whitelisting.bundles.properties");
+        String p = System.getProperty("apiregions.bundles.properties");
         Properties actual = new Properties();
         actual.load(new FileReader(p));
 
@@ -74,7 +74,7 @@ public class BundleArtifactFeatureHandlerTest {
 
         bafh.postProcess(null, f, ex);
 
-        String p = System.getProperty("whitelisting.features.properties");
+        String p = System.getProperty("apiregions.features.properties");
         Properties actual = new Properties();
         actual.load(new FileReader(p));
 
@@ -87,7 +87,7 @@ public class BundleArtifactFeatureHandlerTest {
         assertEquals(new HashSet<>(Arrays.asList(el)), new HashSet<>(Arrays.asList(al)));
         assertEquals(expected, actual);
 
-        String p2 = System.getProperty("whitelisting.regions.properties");
+        String p2 = System.getProperty("apiregions.regions.properties");
         Properties actual2 = new Properties();
         actual2.load(new FileReader(p2));
 
diff --git a/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java b/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java
index b65764f..899302a 100644
--- a/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java
@@ -22,7 +22,6 @@ import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.builder.ArtifactProvider;
-import org.apache.sling.feature.extension.apiregions.BundleMappingHandler;
 import org.junit.Test;
 
 import java.io.File;
@@ -62,7 +61,7 @@ public class BundleMappingHandlerTest {
         f.getBundles().add(b3);
         bmh.postProcess(() -> ap, f, ex);
 
-        String p = System.getProperty("whitelisting.idbsnver.properties");
+        String p = System.getProperty("apiregions.idbsnver.properties");
         Properties actual = new Properties();
         actual.load(new FileReader(p));
 


[sling-org-apache-sling-feature-extension-apiregions] 11/13: Handle extension merging with null target

Posted by da...@apache.org.
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

commit 40b24975d6604dcec9d1711ef2771ea34ad95c2f
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Tue Nov 6 13:58:43 2018 +0000

    Handle extension merging with null target
---
 .../extension/apiregions/APIRegionMergeHandler.java      | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java b/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java
index f1c0d52..fbd695f 100644
--- a/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java
@@ -41,14 +41,24 @@ public class APIRegionMergeHandler implements MergeHandler {
 
     @Override
     public void merge(HandlerContext context, Feature target, Feature source, Extension targetEx, Extension sourceEx) {
-        if (!targetEx.getName().equals("api-regions") || !sourceEx.getName().equals("api-regions"))
+        if (!sourceEx.getName().equals("api-regions"))
+            return;
+        if (targetEx != null && !targetEx.getName().equals("api-regions"))
             return;
 
         JsonReader srcJR = Json.createReader(new StringReader(sourceEx.getJSON()));
         JsonArray srcJA = srcJR.readArray();
 
-        JsonReader tgtJR = Json.createReader(new StringReader(targetEx.getJSON()));
-        JsonArray tgtJA = tgtJR.readArray();
+        JsonArray tgtJA;
+        if (targetEx != null) {
+            JsonReader tgtJR = Json.createReader(new StringReader(targetEx.getJSON()));
+            tgtJA = tgtJR.readArray();
+        } else {
+            targetEx = new Extension(sourceEx.getType(), sourceEx.getName(), sourceEx.isRequired());
+            target.getExtensions().add(targetEx);
+
+            tgtJA = Json.createArrayBuilder().build();
+        }
 
         StringWriter sw = new StringWriter();
         JsonGenerator gen = Json.createGenerator(sw);


[sling-org-apache-sling-feature-extension-apiregions] 09/13: Update README.md

Posted by da...@apache.org.
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

commit 576ceeafc0bde826db7225d58cb81b087376d799
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Nov 5 14:12:57 2018 +0000

    Update README.md
---
 README.md | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 98f055f..fe9e9ea 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,10 @@ PostProcessHandlers are called when a feature contains an `api-regions` section.
 `BundleMappingHandler` - This handler creates a mapping file `idbsnver.properties` that maps the Artifact ID to a bundle symbolic name and version. A tilde `~` is used in the value of the map to separate BSN and version. 
 
 `BundleArtifactFeatureHandler` - This handler creates 3 mapping files:
-    `bundles.properties`: maps bundles to the original feature they were in. A bundle could be from more then one feature.
-    `features.properties`: maps features to regions. A feature can be in more than one region.
-    `regions.properties`: maps regions to packages. A region can expose more than one package.
\ No newline at end of file
+* `bundles.properties`: maps bundles to the original feature they were in. A bundle could be from more then one feature.
+* `features.properties`: maps features to regions. A feature can be in more than one region.
+* `regions.properties`: maps regions to packages. A region can expose more than one package.
+
+The location of the files created by the `BundleArtifactFeatureHandler` handler is stored in a system property with name `apiregions.` + filename. So to obtain the file name of the `bundles.properties` file, make the following call:
+
+    System.getProperty("apiregions.bundles.properties")
\ No newline at end of file


[sling-org-apache-sling-feature-extension-apiregions] 02/13: SLING-7779 API Region support for the Sling Feature Model

Posted by da...@apache.org.
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

commit 97aca3cc663f178cd84e0db615fcfafa09d3d4b3
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Wed Oct 31 16:58:46 2018 +0000

    SLING-7779 API Region support for the Sling Feature Model
    
    Unit tests for the BundleMappingHandler
---
 pom.xml                                            |   8 ++
 .../extensions/BundleMappingHandler.java           |   1 -
 .../apiregions/BundleMappingHandlerTest.java       |  86 +++++++++++++++++++++
 src/test/resources/b1/MANIFEST.MF                  |   3 +
 src/test/resources/b1/b1.jar                       | Bin 0 -> 371 bytes
 src/test/resources/b2/MANIFEST.MF                  |   3 +
 src/test/resources/b2/b2.jar                       | Bin 0 -> 374 bytes
 src/test/resources/b3/MANIFEST.MF                  |   2 +
 src/test/resources/b3/b3.jar                       | Bin 0 -> 358 bytes
 9 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 0fb4d4b..857060f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,6 +34,7 @@
                 <configuration>
                     <excludes>
                         <exclude>src/main/resources/META-INF/services/**</exclude>
+                        <exclude>src/test/resources/**</exclude>
                     </excludes>
                 </configuration>
             </plugin>
@@ -57,5 +58,12 @@
             <artifactId>osgi.core</artifactId>
             <scope>provided</scope>
         </dependency>
+
+        <!-- Testing -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java b/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
index 1338e88..bf68d02 100644
--- a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
+++ b/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
@@ -34,7 +34,6 @@ public class BundleMappingHandler extends AbstractHandler implements PostProcess
         if (!"api-regions".equals(extension.getName()))
             return;
 
-
         try {
             File idBSNFile = getDataFile("idbsnver.properties");
             Properties map = loadProperties(idBSNFile);
diff --git a/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java b/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java
new file mode 100644
index 0000000..1b24f9f
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.feature.extension.apiregions;
+
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.ExtensionType;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.builder.ArtifactProvider;
+import org.apache.sling.feature.whitelisting.extensions.BundleMappingHandler;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+
+public class BundleMappingHandlerTest {
+    @Test
+    public void testHandler() throws IOException {
+        ArtifactProvider ap = new ArtifactProvider() {
+            @Override
+            public File provide(ArtifactId id) {
+                switch(id.toMvnId()) {
+                case "g:b1:1":
+                    return getResourceFile("b1/b1.jar");
+                case "g:b2:1.2.3":
+                    return getResourceFile("b2/b2.jar");
+                case "g:b3:0":
+                    return getResourceFile("b3/b3.jar");
+                default: return null;
+                }
+            }
+        };
+
+        BundleMappingHandler bmh = new BundleMappingHandler();
+
+        Extension ex = new Extension(ExtensionType.JSON, "api-regions", false);
+        Feature f = new Feature(ArtifactId.fromMvnId("foo:bar:123"));
+        Artifact b1 = new Artifact(ArtifactId.fromMvnId("g:b1:1"));
+        f.getBundles().add(b1);
+        Artifact b2 = new Artifact(ArtifactId.fromMvnId("g:b2:1.2.3"));
+        f.getBundles().add(b2);
+        Artifact b3 = new Artifact(ArtifactId.fromMvnId("g:b3:0"));
+        f.getBundles().add(b3);
+        bmh.postProcess(() -> ap, f, ex);
+
+        String p = System.getProperty("whitelisting.idbsnver.properties");
+        Properties actual = new Properties();
+        actual.load(new FileReader(p));
+
+        Properties expected = new Properties();
+        expected.put("g:b1:1", "b1~1.0.0");
+        expected.put("g:b2:1.2.3", "b2~1.2.3");
+        assertEquals(expected, actual);
+    }
+
+    @Test
+    public void testUnrelatedExtension() {
+        BundleMappingHandler bmh = new BundleMappingHandler();
+        Extension ex = new Extension(ExtensionType.JSON, "foobar", false);
+        bmh.postProcess(null, null, ex);
+        // Should not do anything and definitely not throw an exception
+    }
+
+    private File getResourceFile(String filename) {
+        return new File(getClass().getClassLoader().getResource(filename).getFile());
+    }
+}
diff --git a/src/test/resources/b1/MANIFEST.MF b/src/test/resources/b1/MANIFEST.MF
new file mode 100644
index 0000000..28bba7a
--- /dev/null
+++ b/src/test/resources/b1/MANIFEST.MF
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: b1
+Bundle-Version: 1.0.0
+
diff --git a/src/test/resources/b1/b1.jar b/src/test/resources/b1/b1.jar
new file mode 100644
index 0000000..6798c5e
Binary files /dev/null and b/src/test/resources/b1/b1.jar differ
diff --git a/src/test/resources/b2/MANIFEST.MF b/src/test/resources/b2/MANIFEST.MF
new file mode 100644
index 0000000..653d2b0
--- /dev/null
+++ b/src/test/resources/b2/MANIFEST.MF
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: b2
+Bundle-Version: 1.2.3
+
diff --git a/src/test/resources/b2/b2.jar b/src/test/resources/b2/b2.jar
new file mode 100644
index 0000000..c9cfb6b
Binary files /dev/null and b/src/test/resources/b2/b2.jar differ
diff --git a/src/test/resources/b3/MANIFEST.MF b/src/test/resources/b3/MANIFEST.MF
new file mode 100644
index 0000000..bf91437
--- /dev/null
+++ b/src/test/resources/b3/MANIFEST.MF
@@ -0,0 +1,2 @@
+NotABundle: me
+
diff --git a/src/test/resources/b3/b3.jar b/src/test/resources/b3/b3.jar
new file mode 100644
index 0000000..bca1724
Binary files /dev/null and b/src/test/resources/b3/b3.jar differ


[sling-org-apache-sling-feature-extension-apiregions] 03/13: SLING-7779 API Region support for the Sling Feature Model

Posted by da...@apache.org.
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

commit f4b35f05a78396c251b791f2df43e03087d0fe8b
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Fri Nov 2 13:23:49 2018 +0000

    SLING-7779 API Region support for the Sling Feature Model
    
    Unit tests for the BundleArtifactFeatureHandler
---
 pom.xml                                            |   6 ++
 .../extensions/BundleArtifactFeatureHandler.java   |   7 +-
 .../extensions/BundleMappingHandler.java           |   2 +-
 .../BundleArtifactFeatureHandlerTest.java          | 112 +++++++++++++++++++++
 4 files changed, 123 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 857060f..ee8416f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,5 +65,11 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.johnzon</groupId>
+            <artifactId>johnzon-core</artifactId>
+            <version>1.0.0</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleArtifactFeatureHandler.java b/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleArtifactFeatureHandler.java
index 79558c4..786ed77 100644
--- a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleArtifactFeatureHandler.java
+++ b/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleArtifactFeatureHandler.java
@@ -48,8 +48,7 @@ public class BundleArtifactFeatureHandler extends AbstractHandler implements Pos
             writeBundleToFeatureMap(feature);
             writeFeatureToRegionAndPackageMap(feature, extension);
         } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            throw new RuntimeException(e);
         }
     }
 
@@ -90,7 +89,9 @@ public class BundleArtifactFeatureHandler extends AbstractHandler implements Pos
         for (JsonValue jv : ja) {
             if (jv instanceof JsonObject) {
                 JsonObject jo = (JsonObject) jv;
-                String fid = jo.getString("org-feature");
+                String fid = null;
+                if (jo.containsKey("org-feature"))
+                    fid = jo.getString("org-feature");
                 if (fid == null)
                     fid = feature.getId().toMvnId();
 
diff --git a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java b/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
index bf68d02..02ab958 100644
--- a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
+++ b/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
@@ -56,7 +56,7 @@ public class BundleMappingHandler extends AbstractHandler implements PostProcess
 
             storeProperties(map, idBSNFile);
         } catch (IOException e) {
-            e.printStackTrace();
+            throw new RuntimeException(e);
         }
     }
 }
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
new file mode 100644
index 0000000..06942ea
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/extension/apiregions/BundleArtifactFeatureHandlerTest.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.feature.extension.apiregions;
+
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.ExtensionType;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.whitelisting.extensions.BundleArtifactFeatureHandler;
+import org.junit.Test;
+
+import java.io.FileReader;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+
+public class BundleArtifactFeatureHandlerTest {
+    @Test
+    public void testBundleToFeatureMap() throws Exception {
+        BundleArtifactFeatureHandler bafh = new BundleArtifactFeatureHandler();
+
+        Feature f = new Feature(ArtifactId.fromMvnId("org.sling:something:1.2.3:slingosgifeature:myclassifier"));
+        Artifact b1 = new Artifact(ArtifactId.fromMvnId("org.sling:b1:1"));
+        Artifact b2 = new Artifact(ArtifactId.fromMvnId("org.sling:b2:1"));
+        Artifact b3a = new Artifact(ArtifactId.fromMvnId("org.sling:b3:1"));
+        b3a.getMetadata().put("org-feature", "some.other:feature:123");
+        Artifact b3b = new Artifact(ArtifactId.fromMvnId("org.sling:b3:1"));
+        f.getBundles().addAll(Arrays.asList(b1, b2, b3a, b3b));
+
+        Extension ex = new Extension(ExtensionType.JSON, "api-regions", false);
+        ex.setJSON("[]");
+        bafh.postProcess(null, f, ex);
+
+        String p = System.getProperty("whitelisting.bundles.properties");
+        Properties actual = new Properties();
+        actual.load(new FileReader(p));
+
+        Properties expected = new Properties();
+        expected.put("org.sling:b1:1", "org.sling:something:1.2.3:slingosgifeature:myclassifier");
+        expected.put("org.sling:b2:1", "org.sling:something:1.2.3:slingosgifeature:myclassifier");
+        expected.put("org.sling:b3:1", "some.other:feature:123,org.sling:something:1.2.3:slingosgifeature:myclassifier");
+        assertEquals(expected, actual);
+    }
+
+    @Test
+    public void testFeatureToRegionMap() throws Exception {
+        BundleArtifactFeatureHandler bafh = new BundleArtifactFeatureHandler();
+
+        Feature f = new Feature(ArtifactId.fromMvnId("org.sling:something:1.2.3"));
+        Extension ex = new Extension(ExtensionType.JSON, "api-regions", false);
+        ex.setJSON("[{\"name\":\"global\","
+                + "\"exports\": [\"a.b.c\",\"d.e.f\"]},"
+                + "{\"name\":\"internal\","
+                + "\"exports\":[\"xyz\"]},"
+                + "{\"name\":\"global\","
+                + "\"exports\":[\"test\"],"
+                + "\"org-feature\":\"an.other:feature:123\"}]");
+
+        bafh.postProcess(null, f, ex);
+
+        String p = System.getProperty("whitelisting.features.properties");
+        Properties actual = new Properties();
+        actual.load(new FileReader(p));
+
+        Properties expected = new Properties();
+        expected.put("an.other:feature:123", "global");
+        expected.put("org.sling:something:1.2.3", "internal,global");
+
+        String[] al = ((String) actual.remove("org.sling:something:1.2.3")).split(",");
+        String[] el = ((String) expected.remove("org.sling:something:1.2.3")).split(",");
+        assertEquals(new HashSet<>(Arrays.asList(el)), new HashSet<>(Arrays.asList(al)));
+        assertEquals(expected, actual);
+
+        String p2 = System.getProperty("whitelisting.regions.properties");
+        Properties actual2 = new Properties();
+        actual2.load(new FileReader(p2));
+
+        Properties expected2 = new Properties();
+        expected2.put("internal", "xyz");
+        expected2.put("global", "test,a.b.c,d.e.f");
+
+        String[] agl2 = ((String) actual2.remove("global")).split(",");
+        String[] egl2 = ((String) expected2.remove("global")).split(",");
+        assertEquals(new HashSet<>(Arrays.asList(egl2)), new HashSet<>(Arrays.asList(agl2)));
+        assertEquals(expected2, actual2);
+    }
+
+    @Test
+    public void testUnrelatedExtension() {
+        BundleArtifactFeatureHandler bafh = new BundleArtifactFeatureHandler();
+        Extension ex = new Extension(ExtensionType.JSON, "foobar", false);
+        bafh.postProcess(null, null, ex);
+        // Should not do anything and definitely not throw an exception
+    }
+}


[sling-org-apache-sling-feature-extension-apiregions] 04/13: SLING-7779 API Region support for the Sling Feature Model

Posted by da...@apache.org.
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

commit 627b8b3a6efee14d783bc1654a474d1b2b9717a5
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Fri Nov 2 16:28:58 2018 +0000

    SLING-7779 API Region support for the Sling Feature Model
    
    Unit tests for the APIRegionHandler and renamed package.
---
 .../apiregions/APIRegionMergeHandler.java}         |  4 +-
 .../apiregions}/AbstractHandler.java               |  2 +-
 .../apiregions}/BundleArtifactFeatureHandler.java  |  2 +-
 .../apiregions}/BundleMappingHandler.java          |  2 +-
 .../apiregions/APIRegionMergeHandlerTest.java      | 80 ++++++++++++++++++++++
 .../BundleArtifactFeatureHandlerTest.java          |  1 -
 .../apiregions/BundleMappingHandlerTest.java       |  2 +-
 7 files changed, 86 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/whitelisting/extensions/APIRegionHandler.java b/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java
similarity index 95%
rename from src/main/java/org/apache/sling/feature/whitelisting/extensions/APIRegionHandler.java
rename to src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java
index 1756412..f1c0d52 100644
--- a/src/main/java/org/apache/sling/feature/whitelisting/extensions/APIRegionHandler.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.feature.whitelisting.extensions;
+package org.apache.sling.feature.extension.apiregions;
 
 import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.Feature;
@@ -32,7 +32,7 @@ import javax.json.JsonReader;
 import javax.json.JsonValue;
 import javax.json.stream.JsonGenerator;
 
-public class APIRegionHandler implements MergeHandler {
+public class APIRegionMergeHandler implements MergeHandler {
 
     @Override
     public boolean canMerge(Extension extension) {
diff --git a/src/main/java/org/apache/sling/feature/whitelisting/extensions/AbstractHandler.java b/src/main/java/org/apache/sling/feature/extension/apiregions/AbstractHandler.java
similarity index 97%
rename from src/main/java/org/apache/sling/feature/whitelisting/extensions/AbstractHandler.java
rename to src/main/java/org/apache/sling/feature/extension/apiregions/AbstractHandler.java
index ddc2d5e..122c22b 100644
--- a/src/main/java/org/apache/sling/feature/whitelisting/extensions/AbstractHandler.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/AbstractHandler.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.feature.whitelisting.extensions;
+package org.apache.sling.feature.extension.apiregions;
 
 import java.io.File;
 import java.io.FileInputStream;
diff --git a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleArtifactFeatureHandler.java b/src/main/java/org/apache/sling/feature/extension/apiregions/BundleArtifactFeatureHandler.java
similarity index 98%
rename from src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleArtifactFeatureHandler.java
rename to src/main/java/org/apache/sling/feature/extension/apiregions/BundleArtifactFeatureHandler.java
index 786ed77..0b04c4f 100644
--- a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleArtifactFeatureHandler.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/BundleArtifactFeatureHandler.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.feature.whitelisting.extensions;
+package org.apache.sling.feature.extension.apiregions;
 
 import org.apache.sling.feature.Artifact;
 import org.apache.sling.feature.Extension;
diff --git a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java b/src/main/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandler.java
similarity index 97%
rename from src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
rename to src/main/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandler.java
index 02ab958..38896e1 100644
--- a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandler.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.feature.whitelisting.extensions;
+package org.apache.sling.feature.extension.apiregions;
 
 import org.apache.sling.feature.Artifact;
 import org.apache.sling.feature.Extension;
diff --git a/src/test/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandlerTest.java b/src/test/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandlerTest.java
new file mode 100644
index 0000000..db9bcd0
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandlerTest.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.feature.extension.apiregions;
+
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.ExtensionType;
+import org.apache.sling.feature.Feature;
+import org.junit.Test;
+
+import java.io.StringReader;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonReader;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class APIRegionMergeHandlerTest {
+    @Test
+    public void testCanMerge() {
+        APIRegionMergeHandler armh = new APIRegionMergeHandler();
+
+        Extension ex = new Extension(ExtensionType.JSON, "api-regions", false);
+        assertTrue(armh.canMerge(ex));
+        assertFalse(armh.canMerge(new Extension(ExtensionType.JSON, "foo", false)));
+    }
+
+    @Test
+    public void testAPIRegionMergeHandler() {
+        APIRegionMergeHandler armh = new APIRegionMergeHandler();
+
+        Feature tf = new Feature(ArtifactId.fromMvnId("x:t:1"));
+        Feature sf = new Feature(ArtifactId.fromMvnId("y:s:2"));
+
+        Extension tgEx = new Extension(ExtensionType.JSON, "api-regions", false);
+        tgEx.setJSON("[{\"name\":\"global\","
+                + "\"exports\": [\"a.b.c\",\"d.e.f\"]},"
+                + "{\"name\":\"internal\","
+                + "\"exports\":[\"xyz\"],"
+                + "\"org-feature\":\"some:feature:1\"}]");
+
+        Extension srEx = new Extension(ExtensionType.JSON, "api-regions", false);
+        srEx.setJSON("[{\"name\":\"global\","
+                + "\"exports\": [\"test\"]}]");
+
+        armh.merge(null, tf, sf, tgEx, srEx);
+
+        String expectedJSON = "[{\"name\":\"global\","
+                + "\"exports\": [\"a.b.c\",\"d.e.f\"]},"
+                + "{\"name\":\"internal\","
+                + "\"exports\":[\"xyz\"],"
+                + "\"org-feature\":\"some:feature:1\"},"
+                + "{\"name\":\"global\","
+                + "\"org-feature\":\"y:s:2\","
+                + "\"exports\": [\"test\"]}]";
+        JsonReader er = Json.createReader(new StringReader(expectedJSON));
+        JsonReader ar = Json.createReader(new StringReader(tgEx.getJSON()));
+        JsonArray ea = er.readArray();
+        JsonArray aa = ar.readArray();
+
+        assertEquals(ea, aa);
+    }
+}
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 06942ea..3cff17f 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
@@ -21,7 +21,6 @@ import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.Feature;
-import org.apache.sling.feature.whitelisting.extensions.BundleArtifactFeatureHandler;
 import org.junit.Test;
 
 import java.io.FileReader;
diff --git a/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java b/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java
index 1b24f9f..b65764f 100644
--- a/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java
@@ -22,7 +22,7 @@ import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.builder.ArtifactProvider;
-import org.apache.sling.feature.whitelisting.extensions.BundleMappingHandler;
+import org.apache.sling.feature.extension.apiregions.BundleMappingHandler;
 import org.junit.Test;
 
 import java.io.File;


[sling-org-apache-sling-feature-extension-apiregions] 10/13: Reduce dependencies

Posted by da...@apache.org.
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

commit bbea2ae426a7b132f9d56e685e0c6580b8276ec4
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Tue Nov 6 13:03:13 2018 +0000

    Reduce dependencies
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index ee8416f..0461ce0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,7 +50,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.feature</artifactId>
-            <version>0.1.3-SNAPSHOT</version>
+            <version>0.2.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>


[sling-org-apache-sling-feature-extension-apiregions] 06/13: Add some sling boilerplate files in preparation for moving out of the whiteboard

Posted by da...@apache.org.
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

commit 81398c270263b7d30bce75eb252b67935a1f02bc
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Nov 5 14:02:00 2018 +0000

    Add some sling boilerplate files in preparation for moving out of the whiteboard
---
 CODE_OF_CONDUCT.md |  22 ++++++
 CONTRIBUTING.md    |  24 +++++++
 LICENSE            | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 248 insertions(+)

diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 0000000..0fa18e5
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,22 @@
+<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you 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.
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
+Apache Software Foundation Code of Conduct
+====
+
+Being an Apache project, Apache Sling adheres to the Apache Software Foundation's [Code of Conduct](https://www.apache.org/foundation/policies/conduct.html).
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..ac82a1a
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,24 @@
+<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you 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.
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
+Contributing
+====
+
+Thanks for choosing to contribute!
+
+You will find all the necessary details about how you can do this at https://sling.apache.org/contributing.html.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   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.


[sling-org-apache-sling-feature-extension-apiregions] 08/13: Update README.md header

Posted by da...@apache.org.
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

commit 278857f5a2292afd6c39c578b330dcc42c3b8200
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Nov 5 14:04:48 2018 +0000

    Update README.md header
---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 714dbc9..98f055f 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 [<img src="http://sling.apache.org/res/logos/sling.png"/>](http://sling.apache.org)
 
- [![Build Status](https://builds.apache.org/buildStatus/icon?job=sling-slingfeature-maven-plugin-1.8)](https://builds.apache.org/view/S-Z/view/Sling/job/sling-slingfeature-maven-plugin-1.8) [![Test Status](https://img.shields.io/jenkins/t/https/builds.apache.org/view/S-Z/view/Sling/job/sling-slingfeature-maven-plugin-1.8.svg)](https://builds.apache.org/view/S-Z/view/Sling/job/sling-slingfeature-maven-plugin-1.8/test_results_analyzer/) [![License](https://img.shields.io/badge/License-Apac [...]
+[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
 
 # Apache Sling API Regions extension