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

dklco 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 780b3b6  Latest state of the upgrade code
780b3b6 is described below

commit 780b3b6e0c51fb5bb7e2966e9c206d722bd89053
Author: Dan Klco <dk...@apache.org>
AuthorDate: Thu Jan 17 08:49:46 2019 -0500

    Latest state of the upgrade code
---
 upgrade/pom.xml                                    |  6 ++
 .../apache/sling/upgrade/EntryHandlerFactory.java  | 10 +++-
 .../apache/sling/upgrade/UpgradeResultEntry.java   | 70 ++++++++++++++++++++++
 .../sling/upgrade/impl/BundleEntryFactory.java     | 42 +++++++++++++
 4 files changed, 127 insertions(+), 1 deletion(-)

diff --git a/upgrade/pom.xml b/upgrade/pom.xml
index 5e74b99..8a57995 100644
--- a/upgrade/pom.xml
+++ b/upgrade/pom.xml
@@ -132,6 +132,12 @@
             <version>1.3.10</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.installer.core</artifactId>
+            <version>3.9.0</version>
+            <scope>provided</scope>
+        </dependency>
 
         <!-- Test Dependencies -->
         <dependency>
diff --git 
a/upgrade/src/main/java/org/apache/sling/upgrade/EntryHandlerFactory.java 
b/upgrade/src/main/java/org/apache/sling/upgrade/EntryHandlerFactory.java
index 6ac5114..a0e8383 100644
--- a/upgrade/src/main/java/org/apache/sling/upgrade/EntryHandlerFactory.java
+++ b/upgrade/src/main/java/org/apache/sling/upgrade/EntryHandlerFactory.java
@@ -41,7 +41,15 @@ public interface EntryHandlerFactory<E extends UpgradeEntry> 
{
      * @param entry the entry to to load the upgrade entry from
      * @param is    the input stream to load the entry contents from
      * @return the upgrade entry
-     * @throws IOException 
+     * @throws IOException
      */
     E loadEntry(JarEntry entry, InputStream is) throws IOException;
+
+    /**
+     * Process a single upgrade entry and return the result of processing the 
entry.
+     * 
+     * @param entry the entry to process
+     * @return the result of processing the entry
+     */
+    UpgradeResultEntry<E> processEntry(E entry);
 }
diff --git 
a/upgrade/src/main/java/org/apache/sling/upgrade/UpgradeResultEntry.java 
b/upgrade/src/main/java/org/apache/sling/upgrade/UpgradeResultEntry.java
new file mode 100644
index 0000000..cdef7b2
--- /dev/null
+++ b/upgrade/src/main/java/org/apache/sling/upgrade/UpgradeResultEntry.java
@@ -0,0 +1,70 @@
+/*
+ * 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.upgrade;
+
+public class UpgradeResultEntry<E extends UpgradeEntry> {
+
+    public enum RESULT {
+        FAILED, NO_OPERATION, SUCCEEDED
+    };
+
+    private final Throwable cause;
+
+    private final E entry;
+
+    private final RESULT result;
+
+    public UpgradeResultEntry(E entry) {
+        this.entry = entry;
+        this.cause = null;
+        this.result = RESULT.SUCCEEDED;
+    }
+
+    public UpgradeResultEntry(E entry, Throwable cause) {
+        this.cause = cause;
+        this.entry = entry;
+        this.result = RESULT.FAILED;
+    }
+
+    public UpgradeResultEntry(E entry, Throwable cause, RESULT result) {
+        this.cause = cause;
+        this.entry = entry;
+        this.result = result;
+        ;
+    }
+
+    /**
+     * @return the cause
+     */
+    public Throwable getCause() {
+        return cause;
+    }
+
+    /**
+     * @return the entry
+     */
+    public E getEntry() {
+        return entry;
+    }
+
+    /**
+     * @return the result
+     */
+    public RESULT getResult() {
+        return result;
+    }
+}
diff --git 
a/upgrade/src/main/java/org/apache/sling/upgrade/impl/BundleEntryFactory.java 
b/upgrade/src/main/java/org/apache/sling/upgrade/impl/BundleEntryFactory.java
index 12a306e..1f92da1 100644
--- 
a/upgrade/src/main/java/org/apache/sling/upgrade/impl/BundleEntryFactory.java
+++ 
b/upgrade/src/main/java/org/apache/sling/upgrade/impl/BundleEntryFactory.java
@@ -16,27 +16,47 @@
  */
 package org.apache.sling.upgrade.impl;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.regex.Pattern;
+import java.util.stream.Stream;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.sling.installer.api.OsgiInstaller;
+import org.apache.sling.installer.api.info.InfoProvider;
+import org.apache.sling.installer.api.info.Resource;
 import org.apache.sling.settings.SlingSettingsService;
 import org.apache.sling.upgrade.BundleEntry;
 import org.apache.sling.upgrade.EntryHandlerFactory;
+import org.apache.sling.upgrade.UpgradeResultEntry;
+import org.apache.sling.upgrade.UpgradeResultEntry.RESULT;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 @Component(service = { EntryHandlerFactory.class }, immediate = true)
 public class BundleEntryFactory implements EntryHandlerFactory<BundleEntry> {
 
+    private static final Logger log = 
LoggerFactory.getLogger(BundleEntryFactory.class);
+
     @Reference
     private SlingSettingsService settingsService;
 
+    @Reference
+    private InfoProvider infoProvider;
+
+    @Reference
+    private OsgiInstaller installer;
+
     private static final Pattern ENTRY_PATTERN = Pattern
             
.compile("resources\\/install(.[a-z_]+)?\\/\\d{1,2}\\/[\\w\\-\\.]+\\.jar");
     private BundleContext bundleContext;
@@ -61,4 +81,26 @@ public class BundleEntryFactory implements 
EntryHandlerFactory<BundleEntry> {
         return new BundleEntry(entry, is, bundleContext);
     }
 
+    @Override
+    public UpgradeResultEntry<BundleEntry> processEntry(BundleEntry entry) {
+        UpgradeResultEntry<BundleEntry> result = null;
+        if (!entry.isInstalled() || entry.isUpdated()) {
+            try {
+                log.debug("Installing bundle {}", entry.getOriginalName());
+                Bundle bundle = bundleContext.installBundle("launchpad:" + 
entry.getOriginalName(),
+                        new ByteArrayInputStream(entry.getContents()));
+                bundle.start();
+                log.debug("Bundle installed correctly!");
+                result = new UpgradeResultEntry<>(entry);
+
+            } catch (Exception e) {
+                log.error("Exception installing bundle", e);
+                result = new UpgradeResultEntry<>(entry, e);
+            }
+        } else {
+            result = new UpgradeResultEntry<>(entry, null, 
RESULT.NO_OPERATION);
+        }
+        return result;
+    }
+
 }

Reply via email to