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:32 UTC
[sling-whiteboard] 02/05: [r2f] correctly retrieved the
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 518881bc053e0b7dcad16e8f128a7b6f50a37672
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Tue Jun 18 12:23:05 2019 +0200
[r2f] correctly retrieved the sling.feature framework property
---
.../impl/BaseFeature2CurrentRuntimePrinter.java | 43 +++++++++-------------
.../RuntimeEnvironment2FeatureModelActivator.java | 10 ++++-
2 files changed, 26 insertions(+), 27 deletions(-)
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 df6312c..9e1fb82 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,12 +16,15 @@
*/
package org.apache.sling.feature.r2f.impl;
+import static java.nio.file.Files.newBufferedReader;
+import static org.apache.sling.feature.diff.FeatureDiff.compareFeatures;
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 java.io.Reader;
+import java.net.URI;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Feature;
@@ -31,36 +34,26 @@ import org.osgi.framework.BundleContext;
public class BaseFeature2CurrentRuntimePrinter extends AbstractRuntimeEnvironment2FeatureModelPrinter {
+ private static final String SLING_FEATURE_PROPERTY_NAME = "sling.feature";
+
public BaseFeature2CurrentRuntimePrinter(RuntimeEnvironment2FeatureModel generator, BundleContext bundleContext) {
super(generator, bundleContext);
}
@Override
protected Feature compute(Feature currentFeature) {
+ String previousFeatureLocation = getBundleContext().getProperty(SLING_FEATURE_PROPERTY_NAME);
+ URI previousFeatureURI = URI.create(previousFeatureLocation);
+ Path previousFeaturePath = Paths.get(previousFeatureURI);
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());
+ try (Reader reader = newBufferedReader(previousFeaturePath)) {
+ previousFeature = read(reader, previousFeatureLocation);
+ } catch (IOException e) {
+ throw new RuntimeException("An error occurred while reading 'sling.feature' framework-property "
+ + previousFeatureLocation
+ + ", see causing error(s):",
+ e);
}
StringBuilder classifier = new StringBuilder()
diff --git a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelActivator.java b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelActivator.java
index 6e26d76..0811d94 100644
--- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelActivator.java
+++ b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelActivator.java
@@ -16,6 +16,8 @@
*/
package org.apache.sling.feature.r2f.impl;
+import static org.apache.felix.inventory.Format.JSON;
+import static org.apache.felix.inventory.InventoryPrinter.FORMAT;
import static org.apache.felix.inventory.InventoryPrinter.NAME;
import static org.apache.felix.inventory.InventoryPrinter.TITLE;
import static org.osgi.framework.Constants.BUNDLE_VENDOR;
@@ -62,8 +64,12 @@ public final class RuntimeEnvironment2FeatureModelActivator implements BundleAct
properties.put(SERVICE_VENDOR, bundleContext.getBundle().getHeaders(BUNDLE_VENDOR));
putProperty(SERVICE_DESCRIPTION, SERVICE_TITLE, classifier, properties);
putProperty(SERVICE_DESCRIPTION, SERVICE_TITLE, classifier, properties);
- putProperty(NAME, SERVICE_NAME, classifier, properties);
- putProperty(TITLE, SERVICE_TITLE, classifier, properties);
+
+ if (InventoryPrinter.class.isAssignableFrom(type)) {
+ putProperty(NAME, SERVICE_NAME, classifier, properties);
+ putProperty(TITLE, SERVICE_TITLE, classifier, properties);
+ putProperty(FORMAT, JSON.toString(), classifier, properties);
+ }
registrations.add(bundleContext.registerService(type, service, properties));
}