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/19 08:30:53 UTC
[sling-org-apache-sling-feature-inventoryprinter] branch r2f
updated: [r2f] updated APIs usage due to r2f APIs update
This is an automated email from the ASF dual-hosted git repository.
simonetripodi pushed a commit to branch r2f
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-inventoryprinter.git
The following commit(s) were added to refs/heads/r2f by this push:
new 5a08903 [r2f] updated APIs usage due to r2f APIs update
5a08903 is described below
commit 5a08903d0646e6104425f036fee05b013c4b3bb9
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Wed Jun 19 10:30:46 2019 +0200
[r2f] updated APIs usage due to r2f APIs update
---
.../impl/AbstractFeatureInventoryPrinter.java | 28 ++++++++--------------
...ractRuntimeEnvironment2FeatureModelPrinter.java | 11 ++-------
.../impl/FeaturesInventoryPrinter.java | 10 ++++----
3 files changed, 16 insertions(+), 33 deletions(-)
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 @@ abstract class AbstractRuntimeEnvironment2FeatureModelPrinter extends AbstractFe
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 @@ package org.apache.sling.feature.inventoryservice.impl;
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 @@ public class FeaturesInventoryPrinter extends AbstractFeatureInventoryPrinter {
}
@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);
}
}