Merge pull request #2 from apache/r2f
SLING-8542 Generate feature model from running AEM instance
diff --git a/pom.xml b/pom.xml
index dbcb125..b1d0ae5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,8 +16,8 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.sling</groupId>
- <artifactId>sling</artifactId>
- <version>34</version>
+ <artifactId>sling-bundle-parent</artifactId>
+ <version>35</version>
<relativePath />
</parent>
@@ -30,7 +30,7 @@
</description>
<properties>
- <sling.java.version>7</sling.java.version>
+ <sling.java.version>8</sling.java.version>
</properties>
<scm>
@@ -40,24 +40,6 @@
<tag>HEAD</tag>
</scm>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>biz.aQute.bnd</groupId>
- <artifactId>bnd-maven-plugin</artifactId>
- <version>4.1.0</version>
- </plugin>
- </plugins>
- </build>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
@@ -67,7 +49,6 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
- <version>1.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -76,5 +57,23 @@
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.feature</artifactId>
+ <version>1.0.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.feature.io</artifactId>
+ <version>1.0.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.feature.r2f</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
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
new file mode 100644
index 0000000..cfa97e7
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/inventoryservice/impl/AbstractFeatureInventoryPrinter.java
@@ -0,0 +1,47 @@
+/*
+ * 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.inventoryservice.impl;
+
+import static org.apache.sling.feature.io.json.FeatureJSONWriter.write;
+
+import java.io.PrintWriter;
+
+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;
+
+abstract class AbstractFeatureInventoryPrinter implements InventoryPrinter {
+
+ protected RuntimeEnvironment2FeatureModel generator;
+
+ @Override
+ public final void print(PrintWriter printWriter, Format format, boolean isZip) {
+ try {
+ Feature computedFeature = getComputedFeature();
+ write(printWriter, computedFeature);
+ } catch (Throwable t) {
+ t.printStackTrace(printWriter);
+ }
+ printWriter.println();
+ }
+
+ protected abstract Feature getComputedFeature();
+
+}
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 ac9710c..c0febd0 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
@@ -18,36 +18,32 @@
*/
package org.apache.sling.feature.inventoryservice.impl;
-import org.apache.felix.inventory.Format;
-import org.apache.felix.inventory.InventoryPrinter;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
+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 java.io.PrintWriter;
-import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import org.apache.felix.inventory.InventoryPrinter;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.r2f.RuntimeEnvironment2FeatureModel;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
@Component(
-property = {InventoryPrinter.NAME + "=launch_feature",
- InventoryPrinter.TITLE + "=Launch Feature",
- InventoryPrinter.FORMAT + "=JSON"})
-public class FeaturesInventoryPrinter implements InventoryPrinter
-{
- @Activate
- BundleContext bc;
+ service = InventoryPrinter.class,
+ property = {
+ NAME + "=feature_launch",
+ TITLE + "=Sling Feature - Launch",
+ FORMAT + "=JSON"
+ },
+ reference = {
+ @Reference(field = "generator", name = "generator", service = RuntimeEnvironment2FeatureModel.class)
+ }
+)
+public class FeaturesInventoryPrinter extends AbstractFeatureInventoryPrinter {
@Override
- public void print(PrintWriter printWriter, Format format, boolean isZip) {
- try {
- Path path = Paths.get(new URI(bc.getProperty("sling.feature")));
- byte[] bytes = Files.readAllBytes(path);
- printWriter.print(new String(bytes));
- } catch (Exception e) {
- e.printStackTrace(printWriter);
- }
- printWriter.println();
+ protected Feature getComputedFeature() {
+ return generator.getLaunchFeature();
}
+
}
diff --git a/src/main/java/org/apache/sling/feature/inventoryservice/impl/Launch2RunningInventoryPrinter.java b/src/main/java/org/apache/sling/feature/inventoryservice/impl/Launch2RunningInventoryPrinter.java
new file mode 100644
index 0000000..a596a6a
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/inventoryservice/impl/Launch2RunningInventoryPrinter.java
@@ -0,0 +1,47 @@
+/*
+ * 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.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 org.apache.felix.inventory.InventoryPrinter;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.r2f.RuntimeEnvironment2FeatureModel;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+@Component(
+ service = InventoryPrinter.class,
+ property = {
+ NAME + "=feature_launch2running",
+ TITLE + "=Sling Feature - Launch 2 Runtime",
+ FORMAT + "=JSON"
+ },
+ reference = {
+ @Reference(field = "generator", name = "generator", service = RuntimeEnvironment2FeatureModel.class)
+ }
+)
+public class Launch2RunningInventoryPrinter extends AbstractFeatureInventoryPrinter {
+
+ @Override
+ protected Feature getComputedFeature() {
+ return generator.getLaunch2RunningUpgradingFeature();
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/feature/inventoryservice/impl/RunningInventoryPrinter.java b/src/main/java/org/apache/sling/feature/inventoryservice/impl/RunningInventoryPrinter.java
new file mode 100644
index 0000000..9340cd4
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/inventoryservice/impl/RunningInventoryPrinter.java
@@ -0,0 +1,47 @@
+/*
+ * 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.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 org.apache.felix.inventory.InventoryPrinter;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.r2f.RuntimeEnvironment2FeatureModel;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+@Component(
+ service = InventoryPrinter.class,
+ property = {
+ NAME + "=feature_running",
+ TITLE + "=Sling Feature - Running",
+ FORMAT + "=JSON"
+ },
+ reference = {
+ @Reference(field = "generator", name = "generator", service = RuntimeEnvironment2FeatureModel.class)
+ }
+)
+public final class RunningInventoryPrinter extends AbstractFeatureInventoryPrinter {
+
+ @Override
+ protected Feature getComputedFeature() {
+ return generator.getRunningFeature();
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/feature/inventoryservice/impl/RuntimeInventoryPrinter.java b/src/main/java/org/apache/sling/feature/inventoryservice/impl/RuntimeInventoryPrinter.java
new file mode 100644
index 0000000..585f9a8
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/inventoryservice/impl/RuntimeInventoryPrinter.java
@@ -0,0 +1,47 @@
+/*
+ * 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.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 org.apache.felix.inventory.InventoryPrinter;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.r2f.RuntimeEnvironment2FeatureModel;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+@Component(
+ service = InventoryPrinter.class,
+ property = {
+ NAME + "=feature_runtime",
+ TITLE + "=Sling Feature - Runtime",
+ FORMAT + "=JSON"
+ },
+ reference = {
+ @Reference(field = "generator", name = "generator", service = RuntimeEnvironment2FeatureModel.class)
+ }
+)
+public final class RuntimeInventoryPrinter extends AbstractFeatureInventoryPrinter {
+
+ @Override
+ protected Feature getComputedFeature() {
+ return generator.getRuntimeFeature();
+ }
+
+}