You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by si...@apache.org on 2019/06/18 11:45:31 UTC

[sling-whiteboard] 01/05: [r2f] accessing to the base Feature Model via 'sling.feature' framework-property

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

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

commit 6e9daa0fc525f4031ebd384cf93d8c8d3265b18b
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Mon Jun 17 14:28:21 2019 +0200

    [r2f] accessing to the base Feature Model via 'sling.feature'
    framework-property
---
 .../impl/BaseFeature2CurrentRuntimePrinter.java    | 30 +++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/BaseFeature2CurrentRuntimePrinter.java b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/BaseFeature2CurrentRuntimePrinter.java
index a083969..df6312c 100644
--- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/BaseFeature2CurrentRuntimePrinter.java
+++ b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/BaseFeature2CurrentRuntimePrinter.java
@@ -16,6 +16,11 @@
  */
 package org.apache.sling.feature.r2f.impl;
 
+import static org.apache.sling.feature.io.json.FeatureJSONReader.read;
+
+import java.io.IOException;
+import java.io.StringReader;
+
 import static org.apache.sling.feature.diff.FeatureDiff.compareFeatures;
 
 import org.apache.sling.feature.ArtifactId;
@@ -32,8 +37,31 @@ public class BaseFeature2CurrentRuntimePrinter extends AbstractRuntimeEnvironmen
 
     @Override
     protected Feature compute(Feature currentFeature) {
-        // TODO
         Feature previousFeature = null;
+        Object previousFeatureObject = getBundleContext().getProperty("sling.feature");
+
+        if (previousFeatureObject == null) {
+            throw new IllegalStateException("'sling.feature' framework-property is not available");
+        }
+
+        if (previousFeatureObject instanceof String) {
+            String previousFeatureString = (String) previousFeatureObject;
+            try (StringReader reader = new StringReader(previousFeatureString)) {
+                previousFeature = read(reader, "framework-properties.sling.feature");
+            } catch (IOException e) {
+                throw new RuntimeException("An error occurred while reading 'sling.feature' framework-property "
+                                           + previousFeatureObject
+                                           + ", see causing error(s):",
+                                           e);
+            }
+        } else if (previousFeatureObject instanceof Feature) {
+            previousFeature = (Feature) previousFeatureObject;
+        } else {
+            throw new RuntimeException("'sling.feature' framework property "
+                                       + previousFeatureObject
+                                       + " is of unmanagede type "
+                                       + previousFeatureObject.getClass());
+        }
 
         StringBuilder classifier = new StringBuilder()
                                    .append(previousFeature.getId().getVersion())