You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:23:35 UTC

[sling-org-apache-sling-tooling-support-install] annotated tag org.apache.sling.tooling.support.install-1.0.0 created (now db8afbf)

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

rombert pushed a change to annotated tag org.apache.sling.tooling.support.install-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tooling-support-install.git.


      at db8afbf  (tag)
 tagging 5a33a436ed10f78f55ea6dc122f0d0ba559e8437 (commit)
      by Robert Munteanu
      on Fri May 2 12:25:15 2014 +0000

- Log -----------------------------------------------------------------
org.apache.sling.tooling.support.install-1.0.0
-----------------------------------------------------------------------

This annotated tag includes the following new commits:

     new 95d0a15  SLING-3019 :  Provide a mechanism to install a bundle based on a directory
     new ddb53ae  SLING-3019 - Provide a mechanism to install a bundle based on a directory
     new 598b744  SLING-3019 - Provide a mechanism to install a bundle based on a directory
     new 3116ce4  SLING-3019 - Provide a mechanism to install a bundle based on a directory
     new c309ada  SLING-3019 - Provide a mechanism to install a bundle based on a directory
     new 030c09e  [maven-release-plugin] prepare release org.apache.sling.tooling.support.install-1.0.0
     new 5a33a43  [maven-release-plugin]  copy for tag org.apache.sling.tooling.support.install-1.0.0

The 7 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.


-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].

[sling-org-apache-sling-tooling-support-install] 01/07: SLING-3019 : Provide a mechanism to install a bundle based on a directory

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.tooling.support.install-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tooling-support-install.git

commit 95d0a15d57639ecdfd4afd69330b968a035d507d
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Aug 15 06:28:01 2013 +0000

    SLING-3019 :  Provide a mechanism to install a bundle based on a directory
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/install@1514171 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  85 ++++++++++
 .../support/install/impl/InstallServlet.java       | 185 +++++++++++++++++++++
 2 files changed, 270 insertions(+)

diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..85e151a
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,85 @@
+<?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>17</version>
+    </parent>
+
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.tooling.support.install</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>Apache Sling Tooling Support Install</name>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/tooling/support/install</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/tooling/support/install</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/tooling/support/install</url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Private-Package>
+                            org.apache.sling.tooling.support.install.impl
+                        </Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
new file mode 100644
index 0000000..3c6f48d
--- /dev/null
+++ b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
@@ -0,0 +1,185 @@
+/*
+ * 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.tooling.support.install.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.JarFile;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.Deflater;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Prototype for installing/updating a bundle from a directory
+ */
+@Component
+@Service(value = Servlet.class)
+@Property(name="alias", value="/system/sling/tooling/install")
+public class InstallServlet extends HttpServlet {
+
+    private static final long serialVersionUID = -8820366266126231409L;
+
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    private static final String DIR = "dir";
+
+    private BundleContext bundleContext;
+
+    @Activate
+    protected void activate(final BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+    }
+
+    @Override
+    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+            throws ServletException, IOException {
+        final String dirPath = req.getParameter(DIR);
+        if ( dirPath == null ) {
+            logger.error("No dir parameter specified : {}", req.getParameterMap());
+            resp.setStatus(500);
+            return;
+        }
+        final File dir = new File(dirPath);
+        if ( dir.exists() && dir.isDirectory() ) {
+            logger.info("Checking dir {} for bundle install", dir);
+            final File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
+            if ( manifestFile.exists() ) {
+                FileInputStream fis = null;
+                try {
+                    fis = new FileInputStream(manifestFile);
+                    final Manifest mf = new Manifest(fis);
+
+                    final String symbolicName = mf.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
+                    if ( symbolicName != null ) {
+                        // search bundle
+                        Bundle found = null;
+                        for(final Bundle b : this.bundleContext.getBundles() ) {
+                            if ( symbolicName.equals(b.getSymbolicName()) ) {
+                                found = b;
+                                break;
+                            }
+                        }
+
+                        final File tempFile = File.createTempFile(dir.getName(), "bundle");
+                        try {
+                            createJar(dir, tempFile, mf);
+
+                            final InputStream in = new FileInputStream(tempFile);
+                            try {
+                                if ( found != null ) {
+                                    // update
+                                    found.update(in);
+                                } else {
+                                    // install
+                                    final Bundle b = bundleContext.installBundle(dir.getAbsolutePath(), in);
+                                    b.start();
+                                }
+                                resp.setStatus(200);
+                                return;
+                            } catch ( final BundleException be ) {
+                                logger.info("Unable to install/update bundle from dir " + dir, be);
+                            }
+                        } finally {
+                            tempFile.delete();
+                        }
+                    } else {
+                        logger.info("Manifest in {} does not have a symbolic name", dir);
+                    }
+                } finally {
+                    if ( fis != null ) {
+                        fis.close();
+                    }
+                }
+            } else {
+                logger.info("Dir {} does not have a manifest", dir);
+            }
+        } else {
+            logger.info("Dir {} does not exist", dir);
+        }
+        resp.setStatus(500);
+    }
+
+    private static void createJar(final File sourceDir, final File jarFile, final Manifest mf)
+    throws IOException {
+        final JarOutputStream zos = new JarOutputStream(new FileOutputStream(jarFile));
+        try {
+            zos.setLevel(Deflater.NO_COMPRESSION);
+            // manifest first
+            final ZipEntry anEntry = new ZipEntry(JarFile.MANIFEST_NAME);
+            zos.putNextEntry(anEntry);
+            mf.write(zos);
+            zos.closeEntry();
+            zipDir(sourceDir, zos, "");
+        } finally {
+            try {
+                zos.close();
+            } catch ( final IOException ignore ) {
+                // ignore
+            }
+        }
+    }
+
+    public static void zipDir(final File sourceDir, final ZipOutputStream zos, final String path)
+    throws IOException {
+        final byte[] readBuffer = new byte[8192];
+        int bytesIn = 0;
+
+        for(final File f : sourceDir.listFiles()) {
+            if (f.isDirectory()) {
+                final String prefix = path + f.getName() + "/";
+                zos.putNextEntry(new ZipEntry(prefix));
+                zipDir(f, zos, prefix);
+            } else {
+                final String entry = path + f.getName();
+                if ( !JarFile.MANIFEST_NAME.equals(entry) ) {
+                    final FileInputStream fis = new FileInputStream(f);
+                    try {
+                        final ZipEntry anEntry = new ZipEntry(entry);
+                        zos.putNextEntry(anEntry);
+                        while ( (bytesIn = fis.read(readBuffer)) != -1) {
+                            zos.write(readBuffer, 0, bytesIn);
+                        }
+                    } finally {
+                        fis.close();
+                    }
+                }
+            }
+        }
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-tooling-support-install] 05/07: SLING-3019 - Provide a mechanism to install a bundle based on a directory

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.tooling.support.install-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tooling-support-install.git

commit c309adaf46836866564c231d5ecf2fcd10f76ec1
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Tue Oct 22 14:31:58 2013 +0000

    SLING-3019 - Provide a mechanism to install a bundle based on a
    directory
    
    Refresh bundles when both installing and updating, to make sure wirings
    are correct.
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/install@1534647 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/tooling/support/install/impl/InstallServlet.java   | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
index dd0239e..ae3e7ac 100644
--- a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
+++ b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
@@ -237,13 +237,15 @@ public class InstallServlet extends HttpServlet {
         if (bundle != null) {
             // update
             bundle.update(in);
-
-            packageAdmin.refreshPackages(new Bundle[] { bundle });
         } else {
             // install
             final Bundle b = bundleContext.installBundle(location, in);
             b.start();
         }
+
+        // take into account added/removed packages for updated bundles and newly satisfied optional package imports
+        // for new installed bundles
+        packageAdmin.refreshPackages(new Bundle[] { bundle });
     }
 
     private Bundle getBundle(final String symbolicName) {

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-tooling-support-install] 06/07: [maven-release-plugin] prepare release org.apache.sling.tooling.support.install-1.0.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.tooling.support.install-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tooling-support-install.git

commit 030c09ea3012d8f0ba412d4e2df903bc32027209
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri May 2 12:23:50 2014 +0000

    [maven-release-plugin] prepare release org.apache.sling.tooling.support.install-1.0.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/install@1591885 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 99d5b37..d424b25 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,15 +28,15 @@
 
     <groupId>org.apache.sling</groupId>
     <artifactId>org.apache.sling.tooling.support.install</artifactId>
-    <version>0.0.1-SNAPSHOT</version>
+    <version>1.0.0</version>
     <packaging>bundle</packaging>
 
     <name>Apache Sling Tooling Support Install</name>
 
     <scm>
-        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/tooling/support/install</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/tooling/support/install</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/trunk/tooling/support/install</url>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.tooling.support.install-1.0.0</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.tooling.support.install-1.0.0</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.tooling.support.install-1.0.0</url>
     </scm>
 
     <build>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-tooling-support-install] 02/07: SLING-3019 - Provide a mechanism to install a bundle based on a directory

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.tooling.support.install-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tooling-support-install.git

commit ddb53ae271925e301404f4c3681b395ebe0c6eff
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Tue Oct 22 14:31:34 2013 +0000

    SLING-3019 - Provide a mechanism to install a bundle based on a
    directory
    
    Added JSON rendering of responses.
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/install@1534644 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            | 18 ++++++++
 .../support/install/impl/InstallServlet.java       | 22 ++++++++++
 .../support/install/impl/InstallationResult.java   | 51 ++++++++++++++++++++++
 3 files changed, 91 insertions(+)

diff --git a/pom.xml b/pom.xml
index 85e151a..0ec7b01 100644
--- a/pom.xml
+++ b/pom.xml
@@ -81,5 +81,23 @@
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.compendium</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.json</artifactId>
+            <version>2.0.6</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
index 3c6f48d..765eda7 100644
--- a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
+++ b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
@@ -18,6 +18,7 @@ package org.apache.sling.tooling.support.install.impl;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -73,9 +74,20 @@ public class InstallServlet extends HttpServlet {
         if ( dirPath == null ) {
             logger.error("No dir parameter specified : {}", req.getParameterMap());
             resp.setStatus(500);
+            InstallationResult result = new InstallationResult(false, "No dir parameter specified: "
+                    + req.getParameterMap());
+            result.render(resp.getWriter());
             return;
         }
         final File dir = new File(dirPath);
+        installBasedOnDirectory(resp, dir);
+    }
+
+    private void installBasedOnDirectory(HttpServletResponse resp, final File dir) throws FileNotFoundException,
+            IOException {
+
+        InstallationResult result = null;
+
         if ( dir.exists() && dir.isDirectory() ) {
             logger.info("Checking dir {} for bundle install", dir);
             final File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
@@ -110,16 +122,21 @@ public class InstallServlet extends HttpServlet {
                                     final Bundle b = bundleContext.installBundle(dir.getAbsolutePath(), in);
                                     b.start();
                                 }
+                                result = new InstallationResult(true, null);
                                 resp.setStatus(200);
+                                result.render(resp.getWriter());
                                 return;
                             } catch ( final BundleException be ) {
                                 logger.info("Unable to install/update bundle from dir " + dir, be);
+                                result = new InstallationResult(false,
+                                        "Unable to install/update bundle from dir " + dir);
                             }
                         } finally {
                             tempFile.delete();
                         }
                     } else {
                         logger.info("Manifest in {} does not have a symbolic name", dir);
+                        result = new InstallationResult(false, "Manifest in " + dir + " does not have a symbolic name");
                     }
                 } finally {
                     if ( fis != null ) {
@@ -127,12 +144,17 @@ public class InstallServlet extends HttpServlet {
                     }
                 }
             } else {
+                result = new InstallationResult(false, "Dir " + dir + " does not have a manifest");
                 logger.info("Dir {} does not have a manifest", dir);
             }
         } else {
+            result = new InstallationResult(false, "Dir " + dir + " does not exist");
             logger.info("Dir {} does not exist", dir);
         }
         resp.setStatus(500);
+        if (result != null) {
+            result.render(resp.getWriter());
+        }
     }
 
     private static void createJar(final File sourceDir, final File jarFile, final Manifest mf)
diff --git a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java
new file mode 100644
index 0000000..c498d88
--- /dev/null
+++ b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java
@@ -0,0 +1,51 @@
+/*
+ * 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.tooling.support.install.impl;
+
+import java.io.Writer;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.io.JSONWriter;
+
+public class InstallationResult {
+
+    private final boolean status;
+    private final String message;
+
+    public InstallationResult(boolean status, String message) {
+        this.status = status;
+        this.message = message;
+    }
+
+    public void render(Writer out) {
+
+        try {
+            JSONWriter writer = new JSONWriter(out);
+            writer.object();
+            writer.key("status").value(status ? "OK" : "FAILURE");
+            if (!StringUtils.isEmpty(message)) {
+                writer.key("message").value(message);
+            }
+            writer.endObject();
+        } catch (JSONException e) {
+            // never happens
+            throw new RuntimeException(e);
+        }
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-tooling-support-install] 07/07: [maven-release-plugin] copy for tag org.apache.sling.tooling.support.install-1.0.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.tooling.support.install-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tooling-support-install.git

commit 5a33a436ed10f78f55ea6dc122f0d0ba559e8437
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri May 2 12:25:15 2014 +0000

    [maven-release-plugin]  copy for tag org.apache.sling.tooling.support.install-1.0.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.tooling.support.install-1.0.0@1591886 13f79535-47bb-0310-9956-ffa450edef68

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-tooling-support-install] 04/07: SLING-3019 - Provide a mechanism to install a bundle based on a directory

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.tooling.support.install-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tooling-support-install.git

commit 3116ce4519bdc43c262f1c48f16f76d36397decd
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Tue Oct 22 14:31:50 2013 +0000

    SLING-3019 - Provide a mechanism to install a bundle based on a
    directory
    
    Code cleanups:
    
    - Use IOUtils.closeQuietly where applicable
    - Use logAndWriteError consistently
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/install@1534646 13f79535-47bb-0310-9956-ffa450edef68
---
 .../tooling/support/install/impl/InstallServlet.java  | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
index 47b3bc0..dd0239e 100644
--- a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
+++ b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
@@ -212,33 +212,24 @@ public class InstallServlet extends HttpServlet {
                                 result.render(resp.getWriter());
                                 return;
                             } catch ( final BundleException be ) {
-                                logger.info("Unable to install/update bundle from dir " + dir, be);
-                                result = new InstallationResult(false,
-                                        "Unable to install/update bundle from dir " + dir);
+                                logAndWriteError("Unable to install/update bundle from dir " + dir, be, resp);
                             }
                         } finally {
                             tempFile.delete();
                         }
                     } else {
-                        logger.info("Manifest in {} does not have a symbolic name", dir);
-                        result = new InstallationResult(false, "Manifest in " + dir + " does not have a symbolic name");
+                        logAndWriteError("Manifest in " + dir + " does not have a symbolic name", resp);
                     }
                 } finally {
-                    if ( fis != null ) {
-                        fis.close();
-                    }
+                    IOUtils.closeQuietly(fis);
                 }
             } else {
                 result = new InstallationResult(false, "Dir " + dir + " does not have a manifest");
-                logger.info("Dir {} does not have a manifest", dir);
+                logAndWriteError("Dir " + dir + " does have a manifest", resp);
             }
         } else {
             result = new InstallationResult(false, "Dir " + dir + " does not exist");
-            logger.info("Dir {} does not exist", dir);
-        }
-        resp.setStatus(500);
-        if (result != null) {
-            result.render(resp.getWriter());
+            logAndWriteError("Dir " + dir + " does not exist", resp);
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-tooling-support-install] 03/07: SLING-3019 - Provide a mechanism to install a bundle based on a directory

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.tooling.support.install-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tooling-support-install.git

commit 598b744344e4c32d339b0f59055cddf1c911d2ca
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Tue Oct 22 14:31:41 2013 +0000

    SLING-3019 - Provide a mechanism to install a bundle based on a
    directory
    
    Allow updating a bundle from an uploaded jar file.
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/install@1534645 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |   6 +
 .../support/install/impl/InstallServlet.java       | 149 ++++++++++++++++++---
 2 files changed, 135 insertions(+), 20 deletions(-)

diff --git a/pom.xml b/pom.xml
index 0ec7b01..99d5b37 100644
--- a/pom.xml
+++ b/pom.xml
@@ -99,5 +99,11 @@
             <version>2.4</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>commons-fileupload</groupId>
+            <artifactId>commons-fileupload</artifactId>
+            <version>1.2.2</version>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
index 765eda7..47b3bc0 100644
--- a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
+++ b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
@@ -22,7 +22,9 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.List;
 import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 import java.util.zip.Deflater;
@@ -38,13 +40,20 @@ import javax.servlet.http.HttpServletResponse;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
+import org.osgi.service.packageadmin.PackageAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.commons.io.IOUtils;
 
 /**
  * Prototype for installing/updating a bundle from a directory
@@ -60,8 +69,13 @@ public class InstallServlet extends HttpServlet {
 
     private static final String DIR = "dir";
 
+    private static final int UPLOAD_IN_MEMORY_SIZE_THRESHOLD = 512 * 1024 * 1024;
+
     private BundleContext bundleContext;
 
+    @Reference
+    private PackageAdmin packageAdmin;
+
     @Activate
     protected void activate(final BundleContext bundleContext) {
         this.bundleContext = bundleContext;
@@ -71,16 +85,98 @@ public class InstallServlet extends HttpServlet {
     protected void doPost(HttpServletRequest req, HttpServletResponse resp)
             throws ServletException, IOException {
         final String dirPath = req.getParameter(DIR);
-        if ( dirPath == null ) {
-            logger.error("No dir parameter specified : {}", req.getParameterMap());
+
+        boolean isMultipart = ServletFileUpload.isMultipartContent(req);
+
+        if (dirPath == null && !isMultipart) {
+            logger.error("No dir parameter specified : {} and no multipart content found", req.getParameterMap());
             resp.setStatus(500);
             InstallationResult result = new InstallationResult(false, "No dir parameter specified: "
-                    + req.getParameterMap());
+                    + req.getParameterMap() + " and no multipart content found");
             result.render(resp.getWriter());
             return;
         }
-        final File dir = new File(dirPath);
-        installBasedOnDirectory(resp, dir);
+
+        if (isMultipart) {
+            installBasedOnUploadedJar(req, resp);
+        } else {
+            installBasedOnDirectory(resp, new File(dirPath));
+        }
+    }
+
+    private void installBasedOnUploadedJar(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+
+        InstallationResult result = null;
+
+        try {
+            DiskFileItemFactory factory = new DiskFileItemFactory();
+            // try to hold even largish bundles in memory to potentially improve performance
+            factory.setSizeThreshold(UPLOAD_IN_MEMORY_SIZE_THRESHOLD);
+
+            ServletFileUpload upload = new ServletFileUpload();
+            upload.setFileItemFactory(factory);
+
+            @SuppressWarnings("unchecked")
+            List<FileItem> items = upload.parseRequest(req);
+            if (items.size() != 1) {
+                logAndWriteError("Found " + items.size() + " items to process, but only updating 1 bundle is supported", resp);
+                return;
+            }
+
+            FileItem item = items.get(0);
+
+            JarInputStream jar = null;
+            InputStream rawInput = null;
+            try {
+                jar = new JarInputStream(item.getInputStream());
+                Manifest manifest = jar.getManifest();
+                if (manifest == null) {
+                    logAndWriteError("Uploaded jar file does not contain a manifest", resp);
+                    return;
+                }
+
+                final String symbolicName = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
+                if (symbolicName == null) {
+                    logAndWriteError("Manifest does not have a " + Constants.BUNDLE_SYMBOLICNAME, resp);
+                    return;
+                }
+
+                // the JarInputStream is used only for validation, we need a fresh input stream for updating
+                rawInput = item.getInputStream();
+
+                Bundle found = getBundle(symbolicName);
+                try {
+                    installOrUpdateBundle(found, rawInput, null);
+
+                    result = new InstallationResult(true, null);
+                    resp.setStatus(200);
+                    result.render(resp.getWriter());
+                    return;
+                } catch (BundleException e) {
+                    logAndWriteError("Unable to install/update bundle " + symbolicName, e, resp);
+                    return;
+                }
+            } finally {
+                IOUtils.closeQuietly(jar);
+                IOUtils.closeQuietly(rawInput);
+            }
+
+        } catch (FileUploadException e) {
+            logAndWriteError("Failed parsing uploaded bundle", e, resp);
+            return;
+        }
+    }
+
+    private void logAndWriteError(String message, HttpServletResponse resp) throws IOException {
+        logger.info(message);
+        resp.setStatus(500);
+        new InstallationResult(false, message).render(resp.getWriter());
+    }
+
+    private void logAndWriteError(String message, Exception e, HttpServletResponse resp) throws IOException {
+        logger.info(message, e);
+        resp.setStatus(500);
+        new InstallationResult(false, message + " : " + e.getMessage()).render(resp.getWriter());
     }
 
     private void installBasedOnDirectory(HttpServletResponse resp, final File dir) throws FileNotFoundException,
@@ -100,13 +196,7 @@ public class InstallServlet extends HttpServlet {
                     final String symbolicName = mf.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
                     if ( symbolicName != null ) {
                         // search bundle
-                        Bundle found = null;
-                        for(final Bundle b : this.bundleContext.getBundles() ) {
-                            if ( symbolicName.equals(b.getSymbolicName()) ) {
-                                found = b;
-                                break;
-                            }
-                        }
+                        Bundle found = getBundle(symbolicName);
 
                         final File tempFile = File.createTempFile(dir.getName(), "bundle");
                         try {
@@ -114,14 +204,9 @@ public class InstallServlet extends HttpServlet {
 
                             final InputStream in = new FileInputStream(tempFile);
                             try {
-                                if ( found != null ) {
-                                    // update
-                                    found.update(in);
-                                } else {
-                                    // install
-                                    final Bundle b = bundleContext.installBundle(dir.getAbsolutePath(), in);
-                                    b.start();
-                                }
+                                String location = dir.getAbsolutePath();
+
+                                installOrUpdateBundle(found, in, location);
                                 result = new InstallationResult(true, null);
                                 resp.setStatus(200);
                                 result.render(resp.getWriter());
@@ -157,6 +242,30 @@ public class InstallServlet extends HttpServlet {
         }
     }
 
+    private void installOrUpdateBundle(Bundle bundle, final InputStream in, String location) throws BundleException {
+        if (bundle != null) {
+            // update
+            bundle.update(in);
+
+            packageAdmin.refreshPackages(new Bundle[] { bundle });
+        } else {
+            // install
+            final Bundle b = bundleContext.installBundle(location, in);
+            b.start();
+        }
+    }
+
+    private Bundle getBundle(final String symbolicName) {
+        Bundle found = null;
+        for (final Bundle b : this.bundleContext.getBundles()) {
+            if (symbolicName.equals(b.getSymbolicName())) {
+                found = b;
+                break;
+            }
+        }
+        return found;
+    }
+
     private static void createJar(final File sourceDir, final File jarFile, final Manifest mf)
     throws IOException {
         final JarOutputStream zos = new JarOutputStream(new FileOutputStream(jarFile));

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.