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:39 UTC
[sling-whiteboard] 01/02: [r2f] RuntimeEnvironment2FeatureModel
made as a typical OSGi service
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
- }
-
}