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 14:27:32 UTC
[sling-whiteboard] branch master updated: [r2f] moving
InventoryPrinter implementations to
org.apache.sling.feature.inventoryprinter
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
The following commit(s) were added to refs/heads/master by this push:
new c63a136 [r2f] moving InventoryPrinter implementations to org.apache.sling.feature.inventoryprinter
c63a136 is described below
commit c63a136580bddf5019824c4c78e3dcacda918535
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Tue Jun 18 16:27:25 2019 +0200
[r2f] moving InventoryPrinter implementations to
org.apache.sling.feature.inventoryprinter
---
runtime2feature/pom.xml | 9 --
...ractRuntimeEnvironment2FeatureModelPrinter.java | 98 ----------------------
.../impl/BaseFeature2CurrentRuntimePrinter.java | 49 -----------
.../RuntimeEnvironment2FeatureModelActivator.java | 55 +-----------
.../RuntimeEnvironment2FeatureModelPrinter.java | 34 --------
5 files changed, 4 insertions(+), 241 deletions(-)
diff --git a/runtime2feature/pom.xml b/runtime2feature/pom.xml
index 33c8b90..8ea9c87 100644
--- a/runtime2feature/pom.xml
+++ b/runtime2feature/pom.xml
@@ -74,15 +74,6 @@
<artifactId>org.apache.sling.feature.diff</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
- <!--
- | Apache Felix Inventory Printer
- -->
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.inventory</artifactId>
- <version>1.0.6</version>
- <scope>provided</scope>
- </dependency>
<!--
| Test only dependencies
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
deleted file mode 100644
index c3df2e4..0000000
--- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/AbstractRuntimeEnvironment2FeatureModelPrinter.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-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;
-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;
-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;
-
- public AbstractRuntimeEnvironment2FeatureModelPrinter(RuntimeEnvironment2FeatureModel generator,
- BundleContext bundleContext) {
- this.generator = generator;
- this.bundleContext = bundleContext;
- }
-
- protected final BundleContext getBundleContext() {
- return bundleContext;
- }
-
- @Override
- public final void print(PrintWriter printWriter, Format format, boolean isZip) {
- 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(previousFeature, currentFeature);
-
- try {
- write(printWriter, computedFeature);
- } catch (IOException e) {
- printWriter.append("An error occured while searlizing ")
- .append(computedFeature.toString())
- .append(":\n");
-
- e.printStackTrace(printWriter);
- }
- }
-
- 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
deleted file mode 100644
index f09e581..0000000
--- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/BaseFeature2CurrentRuntimePrinter.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.sling.feature.r2f.impl;
-
-import static org.apache.sling.feature.diff.FeatureDiff.compareFeatures;
-
-import org.apache.sling.feature.ArtifactId;
-import org.apache.sling.feature.Feature;
-import org.apache.sling.feature.diff.DefaultDiffRequest;
-import org.apache.sling.feature.r2f.RuntimeEnvironment2FeatureModel;
-import org.osgi.framework.BundleContext;
-
-public class BaseFeature2CurrentRuntimePrinter extends AbstractRuntimeEnvironment2FeatureModelPrinter {
-
- public BaseFeature2CurrentRuntimePrinter(RuntimeEnvironment2FeatureModel generator, BundleContext bundleContext) {
- super(generator, bundleContext);
- }
-
- @Override
- protected Feature compute(Feature previousFeature, Feature currentFeature) {
- Feature featureDiff = compareFeatures(new DefaultDiffRequest()
- .setPrevious(previousFeature)
- .setCurrent(currentFeature)
- .addIncludeComparator("artifacts")
- .addIncludeComparator("configurations")
- .setResultId(new ArtifactId(currentFeature.getId().getGroupId(),
- currentFeature.getId().getArtifactId(),
- currentFeature.getId().getVersion(),
- currentFeature.getId().getClassifier() + "_upgrade",
- currentFeature.getId().getType())));
-
- return featureDiff;
- }
-
-}
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 0811d94..c34a64b 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,20 +16,13 @@
*/
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;
import static org.osgi.framework.Constants.SERVICE_DESCRIPTION;
import static org.osgi.framework.Constants.SERVICE_VENDOR;
import java.util.Dictionary;
import java.util.Hashtable;
-import java.util.LinkedList;
-import java.util.List;
-import org.apache.felix.inventory.InventoryPrinter;
import org.apache.sling.feature.r2f.RuntimeEnvironment2FeatureModel;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -39,60 +32,20 @@ public final class RuntimeEnvironment2FeatureModelActivator implements BundleAct
private static final String SERVICE_TITLE = "Apache Sling Runtime Environment to Feature Model converter";
- private static final String SERVICE_NAME = "r2f";
-
- private static final String RUNTIME_GENERATOR = " - Runtime Generator";
-
- private static final String BASE_2_RUNTIME_DIFF_GENERATOR = " - Base 2 Runtime diff Generator";
-
- private final List<ServiceRegistration<?>> registrations = new LinkedList<>();
+ private ServiceRegistration<RuntimeEnvironment2FeatureModel> registration;
@Override
public void start(BundleContext bundleContext) throws Exception {
- RuntimeEnvironment2FeatureModel generator = new RuntimeEnvironment2FeatureModelService();
- registerService(bundleContext, RuntimeEnvironment2FeatureModel.class, generator, null);
-
- InventoryPrinter runtimePrinter = new RuntimeEnvironment2FeatureModelPrinter(generator, bundleContext);
- registerService(bundleContext, InventoryPrinter.class, runtimePrinter, RUNTIME_GENERATOR);
-
- InventoryPrinter base2RuntimePrinter = new BaseFeature2CurrentRuntimePrinter(generator, bundleContext);
- registerService(bundleContext, InventoryPrinter.class, base2RuntimePrinter, BASE_2_RUNTIME_DIFF_GENERATOR);
- }
-
- private <S> void registerService(BundleContext bundleContext, Class<S> type, S service, String classifier) {
Dictionary<String, Object> properties = new Hashtable<>();
properties.put(SERVICE_VENDOR, bundleContext.getBundle().getHeaders(BUNDLE_VENDOR));
- putProperty(SERVICE_DESCRIPTION, SERVICE_TITLE, classifier, properties);
- putProperty(SERVICE_DESCRIPTION, SERVICE_TITLE, classifier, properties);
+ properties.put(SERVICE_DESCRIPTION, SERVICE_TITLE);
- 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));
- }
-
- private static void putProperty(String key, String value, String classifier, Dictionary<String, Object> properties) {
- String finalValue;
-
- if (classifier != null && !classifier.isEmpty()) {
- finalValue = value.concat(classifier);
- } else {
- finalValue = value;
- }
-
- properties.put(key, finalValue);
+ registration = bundleContext.registerService(RuntimeEnvironment2FeatureModel.class, new RuntimeEnvironment2FeatureModelService(), properties);
}
@Override
public void stop(BundleContext context) throws Exception {
- for (ServiceRegistration<?> registration : registrations) {
- registration.unregister();
- }
-
- registrations.clear();
+ registration.unregister();
}
}
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
deleted file mode 100644
index 9e53c2e..0000000
--- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelPrinter.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.sling.feature.r2f.impl;
-
-import org.apache.sling.feature.Feature;
-import org.apache.sling.feature.r2f.RuntimeEnvironment2FeatureModel;
-import org.osgi.framework.BundleContext;
-
-public final class RuntimeEnvironment2FeatureModelPrinter extends AbstractRuntimeEnvironment2FeatureModelPrinter {
-
- public RuntimeEnvironment2FeatureModelPrinter(RuntimeEnvironment2FeatureModel converter, BundleContext bundleContext) {
- super(converter, bundleContext);
- }
-
- @Override
- protected Feature compute(Feature previousFeature, Feature currentFeature) {
- return currentFeature;
- }
-
-}