incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r688017 - in /incubator/sling/whiteboard/jcrinstall: pom.xml src/main/java/org/apache/sling/jcr/jcrinstall/JcrInstall.java
Date Fri, 22 Aug 2008 08:28:20 GMT
Author: cziegeler
Date: Fri Aug 22 01:28:20 2008
New Revision: 688017

URL: http://svn.apache.org/viewvc?rev=688017&view=rev
Log:
Add initial support for deployment packages.

Modified:
    incubator/sling/whiteboard/jcrinstall/pom.xml
    incubator/sling/whiteboard/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/JcrInstall.java

Modified: incubator/sling/whiteboard/jcrinstall/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jcrinstall/pom.xml?rev=688017&r1=688016&r2=688017&view=diff
==============================================================================
--- incubator/sling/whiteboard/jcrinstall/pom.xml (original)
+++ incubator/sling/whiteboard/jcrinstall/pom.xml Fri Aug 22 01:28:20 2008
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>1-incubator-SNAPSHOT</version>
+        <version>4-incubator-SNAPSHOT</version>
         <relativePath>../head/parent/pom.xml</relativePath>
     </parent>
 

Modified: incubator/sling/whiteboard/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/JcrInstall.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/JcrInstall.java?rev=688017&r1=688016&r2=688017&view=diff
==============================================================================
--- incubator/sling/whiteboard/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/JcrInstall.java
(original)
+++ incubator/sling/whiteboard/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/JcrInstall.java
Fri Aug 22 01:28:20 2008
@@ -51,6 +51,9 @@
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.component.ComponentContext;
+import org.osgi.service.deploymentadmin.DeploymentAdmin;
+import org.osgi.service.deploymentadmin.DeploymentException;
+import org.osgi.service.deploymentadmin.DeploymentPackage;
 import org.osgi.service.log.LogService;
 import org.osgi.service.packageadmin.PackageAdmin;
 
@@ -106,6 +109,9 @@
 
     private Session session;
 
+    /** @scr.reference cardinality="0..1" policy="dynamic" */
+    private DeploymentAdmin deploymentAdmin;
+
     protected void activate(ComponentContext context)
             throws RepositoryException {
         // System.out.println("FILEINSTALL | aQute (c) 2007 v1.3");
@@ -510,6 +516,76 @@
         getPackageAdmin().refreshPackages(null);
     }
 
+    // ---------- Bundle management --------------------------------------------
+
+    private void doDeploymentPackages(Set<String> added,
+                                      Set<String> updated,
+                                      Set<String> removed) {
+        final DeploymentAdmin dpAdmin = this.deploymentAdmin;
+        if ( dpAdmin == null ) {
+            // TODO What should we do now?
+            return;
+        }
+        boolean refresh = false;
+
+        // update or uninstall deployment packages
+        final DeploymentPackage[] packages = dpAdmin.listDeploymentPackages();
+        for (DeploymentPackage pck : packages) {
+            // TODO Update and remove
+        }
+
+        for (Iterator<String> ai = added.iterator(); ai.hasNext();) {
+            String fileNode = ai.next();
+            if (fileNode.endsWith(".dp")) {
+                refresh |= installDeploymentPackage(dpAdmin, fileNode);
+                ai.remove();
+            }
+        }
+
+        if (refresh) {
+            refresh();
+        }
+    }
+
+    private boolean installDeploymentPackage(DeploymentAdmin dpAdmin, String fileNode) {
+
+        InputStream ins = null;
+        try {
+            ins = getInputStream(fileNode);
+            String location = JCR_INSTALL_PREFIX + fileNode;
+
+            dpAdmin.installDeploymentPackage(ins);
+
+            return true;
+
+        } catch (PathNotFoundException pnfe) {
+            // node or property not found
+            log(LOG_ERROR, "Missing file node or content at " + fileNode, pnfe);
+
+        } catch (ValueFormatException vfe) {
+            // cannot return property as a stream
+            log(LOG_ERROR, "Cannot access stream on file node " + fileNode, vfe);
+
+        } catch (RepositoryException re) {
+            // general Repository issue
+            log(LOG_ERROR, "Generic problem accessing file node " + fileNode, re);
+
+        } catch (DeploymentException be) {
+            // cannot install bundle
+            log(LOG_ERROR, "Failed to install bundle from " + fileNode, be);
+
+        } finally {
+            if (ins != null) {
+                try {
+                    ins.close();
+                } catch (IOException ioe) {
+                }
+            }
+        }
+
+        return false;
+    }
+
     // ---------- General Helper -----------------------------------------------
 
     void log(int level, String message, Throwable t) {



Mime
View raw message