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/17 00:01:38 UTC

[sling-whiteboard] branch master updated (6b60acf -> 5a4feef)

This is an automated email from the ASF dual-hosted git repository.

simonetripodi pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git.


    from 6b60acf  [feature-diff] comparators moved in a proper package, META-INF informations automatically generated, added comparators service loader test
     new c4a9722  [r2f] RuntimeEnvironment2FeatureModel made as a typical OSGi service
     new 5a4feef  [r2f] added runtime feature generatror InventoryPrinter implementation, DS replaced by a simple bundle activator

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 runtime2feature/pom.xml                            | 30 +++++++++-
 .../r2f/RuntimeEnvironment2FeatureModel.java       | 55 +----------------
 .../{ => impl}/AbstractFeatureElementConsumer.java |  2 +-
 .../r2f/{ => impl}/Bundle2ArtifactMapper.java      |  2 +-
 ...GiConfiguration2FeatureConfigurationMapper.java |  2 +-
 .../RuntimeEnvironment2FeatureModelActivator.java  | 61 +++++++++++++++++++
 .../RuntimeEnvironment2FeatureModelPrinter.java    | 68 ++++++++++++++++++++++
 .../RuntimeEnvironment2FeatureModelService.java}   | 15 ++---
 8 files changed, 166 insertions(+), 69 deletions(-)
 rename runtime2feature/src/main/java/org/apache/sling/feature/r2f/{ => impl}/AbstractFeatureElementConsumer.java (96%)
 rename runtime2feature/src/main/java/org/apache/sling/feature/r2f/{ => impl}/Bundle2ArtifactMapper.java (98%)
 rename runtime2feature/src/main/java/org/apache/sling/feature/r2f/{ => impl}/OSGiConfiguration2FeatureConfigurationMapper.java (97%)
 create mode 100644 runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelActivator.java
 create mode 100644 runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelPrinter.java
 copy runtime2feature/src/main/java/org/apache/sling/feature/r2f/{RuntimeEnvironment2FeatureModel.java => impl/RuntimeEnvironment2FeatureModelService.java} (88%)


[sling-whiteboard] 01/02: [r2f] RuntimeEnvironment2FeatureModel made as a typical OSGi service

Posted by si...@apache.org.
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 c4a9722a123e6b581faea568528eb552178798a7
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Mon Jun 17 01:15:43 2019 +0200

    [r2f] RuntimeEnvironment2FeatureModel made as a typical OSGi service
---
 runtime2feature/pom.xml                            | 18 +++++--
 .../r2f/RuntimeEnvironment2FeatureModel.java       | 55 +---------------------
 .../{ => impl}/AbstractFeatureElementConsumer.java |  2 +-
 .../r2f/{ => impl}/Bundle2ArtifactMapper.java      |  2 +-
 ...GiConfiguration2FeatureConfigurationMapper.java |  2 +-
 .../RuntimeEnvironment2FeatureModelService.java}   | 17 +++----
 6 files changed, 27 insertions(+), 69 deletions(-)

diff --git a/runtime2feature/pom.xml b/runtime2feature/pom.xml
index fac79bc..92ccc31 100644
--- a/runtime2feature/pom.xml
+++ b/runtime2feature/pom.xml
@@ -39,15 +39,18 @@
   </properties>
 
   <dependencies>
-    <!--
-     | Sling Feature Model libraries
-    -->
     <dependency>
       <groupId>org.osgi</groupId>
       <artifactId>osgi.core</artifactId>
       <scope>provided</scope>
     </dependency>
     <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.scr.ds-annotations</artifactId>
+      <version>1.2.10</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
       <groupId>org.osgi</groupId>
       <artifactId>org.osgi.compendium</artifactId>
       <version>5.0.0</version>
@@ -70,4 +73,13 @@
     </dependency>
   </dependencies>
 
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-scr-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+
 </project>
diff --git a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/RuntimeEnvironment2FeatureModel.java b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/RuntimeEnvironment2FeatureModel.java
index 5f024e5..e5862a5 100644
--- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/RuntimeEnvironment2FeatureModel.java
+++ b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/RuntimeEnvironment2FeatureModel.java
@@ -16,61 +16,10 @@
  */
 package org.apache.sling.feature.r2f;
 
-import static java.util.Objects.requireNonNull;
-
-import java.util.stream.Stream;
-
-import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.Feature;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-
-public final class RuntimeEnvironment2FeatureModel {
-
-    public static Feature scanAndAssemble(ConversionRequest conversionRequest) {
-        ArtifactId resultId = requireNonNull(conversionRequest.getResultId(), "Impossible to create the Feature with a null id");
-        BundleContext bundleContext = requireNonNull(conversionRequest.getBundleContext(), "Impossible to create the Feature from a null BundleContext");
-
-        Feature targetFeature = new Feature(resultId);
-
-        // collect all bundles
-
-        Bundle[] bundles = bundleContext.getBundles();
-        if (bundles != null) {
-            Bundle2ArtifactMapper mapper = new Bundle2ArtifactMapper(targetFeature);
-
-            Stream.of(bundles).map(mapper).forEach(mapper);
-        }
-
-        // collect all configurations
-
-        ServiceReference<ConfigurationAdmin> configurationAdminReference = bundleContext.getServiceReference(ConfigurationAdmin.class);
-        if (configurationAdminReference != null) {
-            ConfigurationAdmin configurationAdmin = bundleContext.getService(configurationAdminReference);
-            try {
-                Configuration[] configurations = configurationAdmin.listConfigurations(null);
-                if (configurations != null) {
-                    OSGiConfiguration2FeatureConfigurationMapper mapper = new OSGiConfiguration2FeatureConfigurationMapper(targetFeature);
-
-                    Stream.of(configurations).map(mapper).forEach(mapper);
-                }
-            } catch (Exception e) {
-                // that should not happen
-                throw new RuntimeException("Something went wrong while iterating over all available Configurations", e);
-            }
-        }
 
-        return targetFeature;
-    }
+public interface RuntimeEnvironment2FeatureModel {
 
-    /**
-     * This class must not be instantiated from outside.
-     */
-    private RuntimeEnvironment2FeatureModel() {
-        // do nothing
-    }
+    Feature scanAndAssemble(ConversionRequest conversionRequest);
 
 }
diff --git a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/AbstractFeatureElementConsumer.java b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/AbstractFeatureElementConsumer.java
similarity index 96%
rename from runtime2feature/src/main/java/org/apache/sling/feature/r2f/AbstractFeatureElementConsumer.java
rename to runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/AbstractFeatureElementConsumer.java
index d93eb84..f557a8b 100644
--- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/AbstractFeatureElementConsumer.java
+++ b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/AbstractFeatureElementConsumer.java
@@ -14,7 +14,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.sling.feature.r2f;
+package org.apache.sling.feature.r2f.impl;
 
 import java.util.function.Consumer;
 
diff --git a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/Bundle2ArtifactMapper.java b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/Bundle2ArtifactMapper.java
similarity index 98%
rename from runtime2feature/src/main/java/org/apache/sling/feature/r2f/Bundle2ArtifactMapper.java
rename to runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/Bundle2ArtifactMapper.java
index 2167bcc..6779c72 100644
--- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/Bundle2ArtifactMapper.java
+++ b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/Bundle2ArtifactMapper.java
@@ -14,7 +14,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.sling.feature.r2f;
+package org.apache.sling.feature.r2f.impl;
 
 import java.io.IOException;
 import java.io.InputStream;
diff --git a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/OSGiConfiguration2FeatureConfigurationMapper.java b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/OSGiConfiguration2FeatureConfigurationMapper.java
similarity index 97%
rename from runtime2feature/src/main/java/org/apache/sling/feature/r2f/OSGiConfiguration2FeatureConfigurationMapper.java
rename to runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/OSGiConfiguration2FeatureConfigurationMapper.java
index 19dadf9..afe8695 100644
--- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/OSGiConfiguration2FeatureConfigurationMapper.java
+++ b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/OSGiConfiguration2FeatureConfigurationMapper.java
@@ -14,7 +14,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.sling.feature.r2f;
+package org.apache.sling.feature.r2f.impl;
 
 import java.util.Dictionary;
 import java.util.Enumeration;
diff --git a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/RuntimeEnvironment2FeatureModel.java b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelService.java
similarity index 87%
copy from runtime2feature/src/main/java/org/apache/sling/feature/r2f/RuntimeEnvironment2FeatureModel.java
copy to runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelService.java
index 5f024e5..569b339 100644
--- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/RuntimeEnvironment2FeatureModel.java
+++ b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelService.java
@@ -14,7 +14,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.sling.feature.r2f;
+package org.apache.sling.feature.r2f.impl;
 
 import static java.util.Objects.requireNonNull;
 
@@ -22,15 +22,19 @@ import java.util.stream.Stream;
 
 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.RuntimeEnvironment2FeatureModel;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.component.annotations.Component;
 
-public final class RuntimeEnvironment2FeatureModel {
+@Component
+public final class RuntimeEnvironment2FeatureModelService implements RuntimeEnvironment2FeatureModel {
 
-    public static Feature scanAndAssemble(ConversionRequest conversionRequest) {
+    public Feature scanAndAssemble(ConversionRequest conversionRequest) {
         ArtifactId resultId = requireNonNull(conversionRequest.getResultId(), "Impossible to create the Feature with a null id");
         BundleContext bundleContext = requireNonNull(conversionRequest.getBundleContext(), "Impossible to create the Feature from a null BundleContext");
 
@@ -66,11 +70,4 @@ public final class RuntimeEnvironment2FeatureModel {
         return targetFeature;
     }
 
-    /**
-     * This class must not be instantiated from outside.
-     */
-    private RuntimeEnvironment2FeatureModel() {
-        // do nothing
-    }
-
 }


[sling-whiteboard] 02/02: [r2f] added runtime feature generatror InventoryPrinter implementation, DS replaced by a simple bundle activator

Posted by si...@apache.org.
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 5a4feef605da560ce3ed165a1da94b18cc2086cb
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Mon Jun 17 02:01:31 2019 +0200

    [r2f] added runtime feature generatror InventoryPrinter implementation,
    DS replaced by a simple bundle activator
---
 runtime2feature/pom.xml                            | 26 ++++++---
 .../RuntimeEnvironment2FeatureModelActivator.java  | 61 +++++++++++++++++++
 .../RuntimeEnvironment2FeatureModelPrinter.java    | 68 ++++++++++++++++++++++
 .../RuntimeEnvironment2FeatureModelService.java    |  2 -
 4 files changed, 148 insertions(+), 9 deletions(-)

diff --git a/runtime2feature/pom.xml b/runtime2feature/pom.xml
index 92ccc31..1b262a6 100644
--- a/runtime2feature/pom.xml
+++ b/runtime2feature/pom.xml
@@ -45,12 +45,6 @@
       <scope>provided</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.apache.felix.scr.ds-annotations</artifactId>
-      <version>1.2.10</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
       <groupId>org.osgi</groupId>
       <artifactId>org.osgi.compendium</artifactId>
       <version>5.0.0</version>
@@ -62,6 +56,18 @@
       <version>1.0.2</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.feature.io</artifactId>
+      <version>1.0.2</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.inventory</artifactId>
+      <version>1.0.6</version>
+      <scope>provided</scope>
+    </dependency>
 
     <!--
      | Test only dependencies
@@ -77,7 +83,13 @@
     <plugins>
       <plugin>
         <groupId>org.apache.felix</groupId>
-        <artifactId>maven-scr-plugin</artifactId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+              <Bundle-Activator>org.apache.sling.feature.r2f.impl.RuntimeEnvironment2FeatureModelActivator</Bundle-Activator>
+          </instructions>
+        </configuration>
       </plugin>
     </plugins>
   </build>
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
new file mode 100644
index 0000000..9128b54
--- /dev/null
+++ b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelActivator.java
@@ -0,0 +1,61 @@
+/*
+ * 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 java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.inventory.InventoryPrinter;
+import org.apache.sling.feature.r2f.RuntimeEnvironment2FeatureModel;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+public final class RuntimeEnvironment2FeatureModelActivator implements BundleActivator {
+
+    private static final String SERVICE_TITLE = "Apache Sling Runtime Environment to Feature Model converter";
+
+    private static final String SERVICE_NAME = "r2f";
+
+    private ServiceRegistration<RuntimeEnvironment2FeatureModel> converterRegistration;
+
+    private ServiceRegistration<InventoryPrinter> printerRegistration;
+
+    @Override
+    public void start(BundleContext context) throws Exception {
+        final Dictionary<String, Object> properties = new Hashtable<>();
+        properties.put(Constants.SERVICE_VENDOR, context.getBundle().getHeaders(Constants.BUNDLE_VENDOR));
+        properties.put(Constants.SERVICE_DESCRIPTION, SERVICE_TITLE);
+
+        RuntimeEnvironment2FeatureModel converter = new RuntimeEnvironment2FeatureModelService();
+
+        properties.put(InventoryPrinter.NAME, SERVICE_NAME);
+        properties.put(InventoryPrinter.TITLE, SERVICE_TITLE);
+        InventoryPrinter printer = new RuntimeEnvironment2FeatureModelPrinter(converter, context);
+
+        converterRegistration = context.registerService(RuntimeEnvironment2FeatureModel.class, converter, properties);
+        printerRegistration = context.registerService(InventoryPrinter.class, printer, properties);
+    }
+
+    @Override
+    public void stop(BundleContext context) throws Exception {
+        converterRegistration.unregister();
+        printerRegistration.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
new file mode 100644
index 0000000..abf7ca9
--- /dev/null
+++ b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelPrinter.java
@@ -0,0 +1,68 @@
+/*
+ * 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.io.json.FeatureJSONWriter.write;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+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;
+
+public final class RuntimeEnvironment2FeatureModelPrinter implements InventoryPrinter {
+
+    private final RuntimeEnvironment2FeatureModel converter;
+
+    private final BundleContext bundleContext;
+
+    public RuntimeEnvironment2FeatureModelPrinter(RuntimeEnvironment2FeatureModel converter, BundleContext bundleContext) {
+        this.converter = converter;
+        this.bundleContext = bundleContext;
+    }
+
+    @Override
+    public 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);
+
+        ConversionRequest request = new DefaultConversionRequest()
+                                    .setBundleContext(bundleContext)
+                                    .setResultId(new ArtifactId(groupId, artifactId, version, classifier, null));
+        Feature currentFeature = converter.scanAndAssemble(request);
+
+        try {
+            write(printWriter, currentFeature);
+        } catch (IOException e) {
+            printWriter.append("An error occured while searlizing ")
+                       .append(currentFeature.toString())
+                       .append(":\n");
+
+            e.printStackTrace(printWriter);
+        }
+    }
+
+}
diff --git a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelService.java b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelService.java
index 569b339..077969e 100644
--- a/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelService.java
+++ b/runtime2feature/src/main/java/org/apache/sling/feature/r2f/impl/RuntimeEnvironment2FeatureModelService.java
@@ -29,9 +29,7 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.component.annotations.Component;
 
-@Component
 public final class RuntimeEnvironment2FeatureModelService implements RuntimeEnvironment2FeatureModel {
 
     public Feature scanAndAssemble(ConversionRequest conversionRequest) {