[r2f] updated APIs usage due to r2f APIs update
diff --git a/src/main/java/org/apache/sling/feature/inventoryservice/impl/AbstractFeatureInventoryPrinter.java b/src/main/java/org/apache/sling/feature/inventoryservice/impl/AbstractFeatureInventoryPrinter.java
index b3d55eb..56b8f83 100644
--- a/src/main/java/org/apache/sling/feature/inventoryservice/impl/AbstractFeatureInventoryPrinter.java
+++ b/src/main/java/org/apache/sling/feature/inventoryservice/impl/AbstractFeatureInventoryPrinter.java
@@ -18,39 +18,31 @@
*/
package org.apache.sling.feature.inventoryservice.impl;
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.nio.file.Files.newBufferedReader;
-
-import java.io.BufferedReader;
import java.io.PrintWriter;
-import java.net.URI;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import org.apache.felix.inventory.Format;
import org.apache.felix.inventory.InventoryPrinter;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.r2f.RuntimeEnvironment2FeatureModel;
import org.osgi.framework.BundleContext;
abstract class AbstractFeatureInventoryPrinter implements InventoryPrinter {
- private static final String SLING_FEATURE_PROPERTY_NAME = "sling.feature";
-
protected BundleContext bundleContext;
+ protected RuntimeEnvironment2FeatureModel generator;
+
@Override
public final void print(PrintWriter printWriter, Format format, boolean isZip) {
- String featureLocation = bundleContext.getProperty(SLING_FEATURE_PROPERTY_NAME);
- URI previousFeatureURI = URI.create(featureLocation);
- Path previousFeaturePath = Paths.get(previousFeatureURI);
-
- try (BufferedReader reader = newBufferedReader(previousFeaturePath, UTF_8)) {
- onFeature(featureLocation, reader, printWriter);
- } catch (Exception e) {
- e.printStackTrace(printWriter);
+ try {
+ Feature launchFeature = generator.getLaunchFeature(bundleContext);
+ onLaunchFeature(launchFeature, printWriter);
+ } catch (Throwable t) {
+ t.printStackTrace(printWriter);
}
printWriter.println();
}
- protected abstract void onFeature(String featureLocation, BufferedReader reader, PrintWriter printWriter) throws Exception;
+ protected abstract void onLaunchFeature(Feature launchFeature, PrintWriter printWriter) throws Exception;
}
diff --git a/src/main/java/org/apache/sling/feature/inventoryservice/impl/AbstractRuntimeEnvironment2FeatureModelPrinter.java b/src/main/java/org/apache/sling/feature/inventoryservice/impl/AbstractRuntimeEnvironment2FeatureModelPrinter.java
index 9ec7851..bb894af 100644
--- a/src/main/java/org/apache/sling/feature/inventoryservice/impl/AbstractRuntimeEnvironment2FeatureModelPrinter.java
+++ b/src/main/java/org/apache/sling/feature/inventoryservice/impl/AbstractRuntimeEnvironment2FeatureModelPrinter.java
@@ -16,26 +16,19 @@
*/
package org.apache.sling.feature.inventoryservice.impl;
-import static org.apache.sling.feature.io.json.FeatureJSONReader.read;
import static org.apache.sling.feature.io.json.FeatureJSONWriter.write;
-import java.io.BufferedReader;
import java.io.PrintWriter;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Feature;
import org.apache.sling.feature.r2f.ConversionRequest;
import org.apache.sling.feature.r2f.DefaultConversionRequest;
-import org.apache.sling.feature.r2f.RuntimeEnvironment2FeatureModel;
abstract class AbstractRuntimeEnvironment2FeatureModelPrinter extends AbstractFeatureInventoryPrinter {
- protected RuntimeEnvironment2FeatureModel generator;
-
@Override
- protected void onFeature(String featureLocation, BufferedReader reader, PrintWriter printWriter) throws Exception {
- Feature launchFeature = read(reader, featureLocation);
-
+ protected void onLaunchFeature(Feature launchFeature, PrintWriter printWriter) throws Exception {
String groupId = launchFeature.getId().getGroupId();
String artifactId = launchFeature.getId().getArtifactId();
String version = launchFeature.getId().getArtifactId();
@@ -44,7 +37,7 @@
ConversionRequest request = new DefaultConversionRequest()
.setBundleContext(bundleContext)
.setResultId(new ArtifactId(groupId, artifactId, version, classifier, null));
- Feature runtimeFeature = generator.scanAndAssemble(request);
+ Feature runtimeFeature = generator.getRuntimeFeature(request);
Feature computedFeature = compute(launchFeature, runtimeFeature);
diff --git a/src/main/java/org/apache/sling/feature/inventoryservice/impl/FeaturesInventoryPrinter.java b/src/main/java/org/apache/sling/feature/inventoryservice/impl/FeaturesInventoryPrinter.java
index 1118fe8..642d553 100644
--- a/src/main/java/org/apache/sling/feature/inventoryservice/impl/FeaturesInventoryPrinter.java
+++ b/src/main/java/org/apache/sling/feature/inventoryservice/impl/FeaturesInventoryPrinter.java
@@ -21,11 +21,12 @@
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.apache.sling.feature.io.json.FeatureJSONWriter.write;
-import java.io.BufferedReader;
import java.io.PrintWriter;
import org.apache.felix.inventory.InventoryPrinter;
+import org.apache.sling.feature.Feature;
import org.apache.sling.feature.r2f.RuntimeEnvironment2FeatureModel;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
@@ -51,11 +52,8 @@
}
@Override
- protected void onFeature(String featureLocation, BufferedReader reader, PrintWriter printWriter) throws Exception {
- String line = null;
- while ((line = reader.readLine()) != null) {
- printWriter.println(line);
- }
+ protected void onLaunchFeature(Feature launchFeature, PrintWriter printWriter) throws Exception {
+ write(printWriter, launchFeature);
}
}