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 ce4c32a9f369ceffc9840e0b23240ab73ec56fc4 Author: Simo Tripodi <[email protected]> AuthorDate: Tue Jun 18 12:34:35 2019 +0200 [r2f] assemble right ArtifactId for runtime and diff Feature --- ...ractRuntimeEnvironment2FeatureModelPrinter.java | 35 ++++++++++++++++----- .../impl/BaseFeature2CurrentRuntimePrinter.java | 36 ++-------------------- .../RuntimeEnvironment2FeatureModelPrinter.java | 2 +- 3 files changed, 31 insertions(+), 42 deletions(-) diff --git a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/AbstractRuntimeEnvironment2FeatureModelPrinter.java b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/AbstractRuntimeEnvironment2FeatureModelPrinter.java index cb7a1cb..c3df2e4 100644 --- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/AbstractRuntimeEnvironment2FeatureModelPrinter.java +++ b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/AbstractRuntimeEnvironment2FeatureModelPrinter.java @@ -16,10 +16,16 @@ */ package org.apache.sling.feature.r2f.impl; +import static java.nio.file.Files.newBufferedReader; +import static org.apache.sling.feature.io.json.FeatureJSONReader.read; import static org.apache.sling.feature.io.json.FeatureJSONWriter.write; import java.io.IOException; import java.io.PrintWriter; +import java.io.Reader; +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; @@ -32,6 +38,8 @@ import org.osgi.framework.BundleContext; abstract class AbstractRuntimeEnvironment2FeatureModelPrinter implements InventoryPrinter { + private static final String SLING_FEATURE_PROPERTY_NAME = "sling.feature"; + private final RuntimeEnvironment2FeatureModel generator; private final BundleContext bundleContext; @@ -48,18 +56,31 @@ abstract class AbstractRuntimeEnvironment2FeatureModelPrinter implements Invento @Override public final void print(PrintWriter printWriter, Format format, boolean isZip) { - // TODO - String groupId = bundleContext.getProperty(null); - String artifactId = bundleContext.getProperty(null); - String version = bundleContext.getProperty(null); - String classifier = bundleContext.getProperty(null); + String previousFeatureLocation = getBundleContext().getProperty(SLING_FEATURE_PROPERTY_NAME); + URI previousFeatureURI = URI.create(previousFeatureLocation); + Path previousFeaturePath = Paths.get(previousFeatureURI); + Feature previousFeature = null; + + 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); + } + + String groupId = previousFeature.getId().getGroupId(); + String artifactId = previousFeature.getId().getArtifactId(); + String version = previousFeature.getId().getArtifactId(); + String classifier = previousFeature.getId().getArtifactId() + "-RUNTIME"; ConversionRequest request = new DefaultConversionRequest() .setBundleContext(bundleContext) .setResultId(new ArtifactId(groupId, artifactId, version, classifier, null)); Feature currentFeature = generator.scanAndAssemble(request); - Feature computedFeature = compute(currentFeature); + Feature computedFeature = compute(previousFeature, currentFeature); try { write(printWriter, computedFeature); @@ -72,6 +93,6 @@ abstract class AbstractRuntimeEnvironment2FeatureModelPrinter implements Invento } } - protected abstract Feature compute(Feature currentFeature); + protected abstract Feature compute(Feature previousFeature, Feature currentFeature); } 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 9e1fb82..f09e581 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,15 +16,7 @@ */ 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.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; @@ -34,36 +26,12 @@ 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; - - 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() - .append(previousFeature.getId().getVersion()) - .append("-to-") - .append(currentFeature.getId().getVersion()) - .append('-') - .append(currentFeature.getId().getClassifier()) - .append("-upgrade"); - + protected Feature compute(Feature previousFeature, Feature currentFeature) { Feature featureDiff = compareFeatures(new DefaultDiffRequest() .setPrevious(previousFeature) .setCurrent(currentFeature) @@ -72,7 +40,7 @@ public class BaseFeature2CurrentRuntimePrinter extends AbstractRuntimeEnvironmen .setResultId(new ArtifactId(currentFeature.getId().getGroupId(), currentFeature.getId().getArtifactId(), currentFeature.getId().getVersion(), - classifier.toString(), + currentFeature.getId().getClassifier() + "_upgrade", currentFeature.getId().getType()))); return featureDiff; diff --git a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelPrinter.java b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelPrinter.java index 82eec3d..9e53c2e 100644 --- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelPrinter.java +++ b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelPrinter.java @@ -27,7 +27,7 @@ public final class RuntimeEnvironment2FeatureModelPrinter extends AbstractRuntim } @Override - protected Feature compute(Feature currentFeature) { + protected Feature compute(Feature previousFeature, Feature currentFeature) { return currentFeature; }
