sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [sling-whiteboard] branch master updated: A simple feature model launcher extension providing a launcher that can be used to run on felix connect.
Date Thu, 02 May 2019 13:56:00 GMT
This is an automated email from the ASF dual-hosted git repository.

pauls 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 aff1da5  A simple feature model launcher extension providing a launcher that can
be used to run on felix connect.
aff1da5 is described below

commit aff1da5a3ea60dd250a2fa90052455d3c98a60d4
Author: Karl Pauls <karlpauls@gmail.com>
AuthorDate: Thu May 2 15:55:51 2019 +0200

    A simple feature model launcher extension providing a launcher that can be used to run
on felix connect.
---
 connectfeaturelauncher/pom.xml                     | 114 +++++++++++++++++++
 .../extensions/connect/impl/PojoSRLauncher.java    | 124 +++++++++++++++++++++
 .../extensions/connect/impl/PojoSRRunner.java      |  40 +++++++
 .../org.apache.sling.feature.launcher.spi.Launcher |   1 +
 4 files changed, 279 insertions(+)

diff --git a/connectfeaturelauncher/pom.xml b/connectfeaturelauncher/pom.xml
new file mode 100644
index 0000000..4330b02
--- /dev/null
+++ b/connectfeaturelauncher/pom.xml
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+    <!--
+        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.
+    -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>34</version>
+        <relativePath />
+    </parent>
+
+    <artifactId>org.apache.sling.feature.launcher.extensions.connect</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <name>Apache Sling Feature Launcher Connect Extension</name>
+    <description>
+        An Apache Sling Feature Launcher extensions using Apache Felix Connect as a framework
+    </description>
+
+    <properties>
+        <sling.java.version>8</sling.java.version>
+    </properties>
+
+    <scm>
+        <connection>scm:git:git@github.com:apache/sling-whiteboard.git</connection>
+        <developerConnection>scm:git:git@github.com:apache/sling-whiteboard.git</developerConnection>
+        <url>https://github.com/apache/sling-whiteboard</url>
+        <tag>HEAD</tag>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-jar-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <exclude>readme.md</exclude>
+                        <exclude>src/main/resources/META-INF/services/**</exclude>
+                        <exclude>**/*.properties</exclude>
+                        <exclude>launcher/**</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <version>7.0.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.feature.launcher</artifactId>
+            <version>1.0.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.feature</artifactId>
+            <version>1.0.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.connect</artifactId>
+            <version>0.2.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <!-- Testing dependencies -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>2.8.9</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/connectfeaturelauncher/src/main/java/org/apache/sling/feature/launcher/extensions/connect/impl/PojoSRLauncher.java
b/connectfeaturelauncher/src/main/java/org/apache/sling/feature/launcher/extensions/connect/impl/PojoSRLauncher.java
new file mode 100644
index 0000000..a01c97f
--- /dev/null
+++ b/connectfeaturelauncher/src/main/java/org/apache/sling/feature/launcher/extensions/connect/impl/PojoSRLauncher.java
@@ -0,0 +1,124 @@
+/*
+ * 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.launcher.extensions.connect.impl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.launcher.impl.launchers.FrameworkLauncher;
+import org.apache.sling.feature.launcher.spi.LauncherPrepareContext;
+import org.osgi.framework.Constants;
+
+public class PojoSRLauncher extends FrameworkLauncher
+{
+    @Override
+    public void prepare(LauncherPrepareContext context, ArtifactId frameworkId, Feature app)
throws Exception
+    {
+        super.prepare(context, frameworkId, app);
+
+        String filter = "";
+        if (frameworkId.getArtifactId().equals("org.apache.felix.connect"))
+        {
+            for (List<Artifact> bundles : app.getBundles().getBundlesByStartOrder().values())
+            {
+                for (Artifact artifact : bundles)
+                {
+                    File file = context.getArtifactFile(artifact.getId());
+
+                    try (JarFile jar = new JarFile(file, false)) {
+                        Manifest mf = jar.getManifest();
+                        String bsn = mf.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
+                        if (bsn != null)
+                        {
+                            String cp = mf.getMainAttributes().getValue(Constants.BUNDLE_CLASSPATH);
+                            if (cp != null)
+                            {
+                                for (String entry : cp.split(","))
+                                {
+                                    int idx = entry.indexOf(';');
+                                    if (idx != -1)
+                                    {
+                                        entry = entry.substring(0, idx);
+                                    }
+                                    entry = entry.trim();
+                                    if (!entry.isEmpty() && !entry.equals("."))
+                                    {
+                                        JarEntry content = jar.getJarEntry(entry);
+                                        if (content != null && !content.isDirectory())
+                                        {
+                                            File target = File.createTempFile(entry, ".jar");
+                                            try
+                                            {
+                                                try (InputStream input = jar.getInputStream(content))
+                                                {
+                                                    try (FileOutputStream output = new FileOutputStream(target))
+                                                    {
+                                                        byte[] buffer = new byte[64 * 1024];
+                                                        for (int i = input.read(buffer);
i != -1; i = input.read(buffer))
+                                                        {
+                                                            output.write(buffer, 0, i);
+                                                        }
+                                                    }
+                                                    context.addAppJar(target);
+                                                }
+                                            }
+                                            catch (Exception ex)
+                                            {
+                                                ex.printStackTrace();
+                                            }
+                                        }
+                                    }
+                                    else
+                                    {
+                                        context.addAppJar(file);
+                                        filter += "(" + Constants.BUNDLE_SYMBOLICNAME + "="
+  bsn + ")";
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                context.addAppJar(file);
+                                filter += "(" + Constants.BUNDLE_SYMBOLICNAME + "=" +  bsn
+ ")";
+                            }
+                        }
+
+                    } catch (Exception ex) {
+                        ex.printStackTrace();
+                    }
+                }
+            }
+            if (!filter.isEmpty()) {
+                filter = "(|" + filter + ")";
+                app.getFrameworkProperties().put("pojosr.filter", filter);
+            }
+        }
+    }
+
+    @Override
+    protected String getFrameworkRunnerClass()
+    {
+        return PojoSRRunner.class.getName();
+    }
+}
diff --git a/connectfeaturelauncher/src/main/java/org/apache/sling/feature/launcher/extensions/connect/impl/PojoSRRunner.java
b/connectfeaturelauncher/src/main/java/org/apache/sling/feature/launcher/extensions/connect/impl/PojoSRRunner.java
new file mode 100644
index 0000000..5a170ee
--- /dev/null
+++ b/connectfeaturelauncher/src/main/java/org/apache/sling/feature/launcher/extensions/connect/impl/PojoSRRunner.java
@@ -0,0 +1,40 @@
+/*
+ * 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.launcher.extensions.connect.impl;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.sling.feature.launcher.impl.launchers.FrameworkRunner;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.launch.Framework;
+
+public class PojoSRRunner extends FrameworkRunner
+{
+    public PojoSRRunner(Map<String, String> frameworkProperties, Map<Integer, List<File>>
bundlesMap, List<Object[]> configurations, List<File> installables) throws Exception
+    {
+        super(frameworkProperties, bundlesMap, configurations, installables);
+    }
+
+    @Override
+    protected void setupFramework(Framework framework, Map<Integer, List<File>>
bundlesMap) throws BundleException
+    {
+        super.setupFramework(framework, framework.getSymbolicName().equals("org.apache.felix.connect")
? Collections.emptyMap() : bundlesMap);
+    }
+}
diff --git a/connectfeaturelauncher/src/main/resources/META-INF/services/org.apache.sling.feature.launcher.spi.Launcher
b/connectfeaturelauncher/src/main/resources/META-INF/services/org.apache.sling.feature.launcher.spi.Launcher
new file mode 100644
index 0000000..2dad0f8
--- /dev/null
+++ b/connectfeaturelauncher/src/main/resources/META-INF/services/org.apache.sling.feature.launcher.spi.Launcher
@@ -0,0 +1 @@
+org.apache.sling.feature.launcher.extensions.connect.impl.PojoSRLauncher
\ No newline at end of file


Mime
View raw message