You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by gh...@apache.org on 2018/11/08 09:56:48 UTC

[sling-org-apache-sling-installer-provider-installhook] 01/01: SLING-8083 avoid ClassNotFoundExceptions, take infoProvider.getInstallationState().getInstalledResources() into account

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

ghenzler pushed a commit to branch bugfix/SLING-8083-avoid-exceptions-in-log-and-use-installation-state
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-installer-provider-installhook.git

commit b6e00c2b4fec43501263427d5c06bdcae8788aef
Author: georg.henzler <ge...@netcentric.biz>
AuthorDate: Thu Nov 8 10:56:28 2018 +0100

    SLING-8083 avoid ClassNotFoundExceptions, take
    infoProvider.getInstallationState().getInstalledResources() into account
---
 .../provider/installhook/OsgiInstallerHook.java    | 18 +++++++++---
 .../installhook/OsgiInstallerListener.java         | 34 +++++++++++++++++-----
 2 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/sling/installer/provider/installhook/OsgiInstallerHook.java b/src/main/java/org/apache/sling/installer/provider/installhook/OsgiInstallerHook.java
index 2683309..6ca0eec 100644
--- a/src/main/java/org/apache/sling/installer/provider/installhook/OsgiInstallerHook.java
+++ b/src/main/java/org/apache/sling/installer/provider/installhook/OsgiInstallerHook.java
@@ -49,12 +49,14 @@ import org.apache.jackrabbit.vault.packaging.PackageProperties;
 import org.apache.jackrabbit.vault.packaging.VaultPackage;
 import org.apache.sling.installer.api.InstallableResource;
 import org.apache.sling.installer.api.OsgiInstaller;
+import org.apache.sling.installer.api.event.InstallationEvent;
 import org.apache.sling.installer.api.event.InstallationListener;
 import org.apache.sling.installer.api.info.InfoProvider;
 import org.apache.sling.installer.api.info.InstallationState;
 import org.apache.sling.installer.api.info.Resource;
 import org.apache.sling.installer.api.info.ResourceGroup;
 import org.apache.sling.installer.api.tasks.ResourceState;
+import org.apache.sling.installer.api.tasks.TaskResource;
 import org.apache.sling.settings.SlingSettingsService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -101,6 +103,13 @@ public class OsgiInstallerHook implements InstallHook {
 
     InstallHookLogger logger = new InstallHookLogger();
 
+    public OsgiInstallerHook() {
+        LOG.debug("Preloading classes to ensure to not run into a NoClassDefFoundError"
+                + " due to a reloading dynamic classloader: {}, {}, {}, {}",
+                new Object[] { TaskResource.class, InstallationEvent.TYPE.class, ResourceState.class,
+                        InstallerHookOsgiEventListener.class });
+    }
+
     @Override
     public void execute(InstallContext context) throws PackageException {
 
@@ -190,10 +199,13 @@ public class OsgiInstallerHook implements InstallHook {
                     }
                     logger.log("Waiting for " + bundlesLeftToInstall + " bundles / " + configsLeftToInstall + " configs to be installed");
                     Thread.sleep(1000);
+
+                    // the events are not always reliably received, also update listener explicitly with current installation state
+                    hookInstallationListener.updateWith(infoProvider.getInstallationState().getInstalledResources());
                 }
                 if (bundlesLeftToInstall == 0 && configsLeftToInstall == 0) {
                     logger.log("All " + bundlesToInstallByUrl.size() + " bundles / " + configsToInstallByUrl.size()
-                            + " configs have been successfully installed");
+                            + " configs have been successfully installed in " + (System.currentTimeMillis() - startTime) + "ms");
                 }
 
                 int waitForOsgiEventsQuietInSec = getNumericPackageProperty(packageProperties,
@@ -479,10 +491,8 @@ public class OsgiInstallerHook implements InstallHook {
         public void log(Logger logger, String message) {
             if (listener != null) {
                 listener.onMessage(ProgressTrackerListener.Mode.TEXT, message, "");
-                logger.debug(message);
-            } else {
-                logger.info(message);
             }
+            logger.info(message);
         }
     }
 
diff --git a/src/main/java/org/apache/sling/installer/provider/installhook/OsgiInstallerListener.java b/src/main/java/org/apache/sling/installer/provider/installhook/OsgiInstallerListener.java
index 63c64c3..497c90d 100644
--- a/src/main/java/org/apache/sling/installer/provider/installhook/OsgiInstallerListener.java
+++ b/src/main/java/org/apache/sling/installer/provider/installhook/OsgiInstallerListener.java
@@ -20,11 +20,15 @@ package org.apache.sling.installer.provider.installhook;
 
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.sling.installer.api.event.InstallationEvent;
 import org.apache.sling.installer.api.event.InstallationEvent.TYPE;
 import org.apache.sling.installer.api.event.InstallationListener;
+import org.apache.sling.installer.api.info.Resource;
+import org.apache.sling.installer.api.info.ResourceGroup;
+import org.apache.sling.installer.api.tasks.ResourceState;
 import org.apache.sling.installer.api.tasks.TaskResource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,15 +62,31 @@ class OsgiInstallerListener implements InstallationListener {
             String entityId = source.getEntityId();
             String url = source.getURL();
 
-            LOG.trace("Received event about processed entityId={} url={}", entityId, url);
+            LOG.debug("Received event about processed entityId={} url={}", entityId, url);
 
-            if (bundleUrlsToInstall.contains(url)) {
-                LOG.debug("Received event for bundle installed with url={}", url);
-                bundleUrlsToInstall.remove(url);
+            if (bundleUrlsToInstall.remove(url)) {
+                LOG.info("Received bundle installed event url={}", url);
             }
-            if (configUrlsToInstall.contains(url)) {
-                LOG.debug("Received event for config installed with url={}", url);
-                configUrlsToInstall.remove(url);
+            if (configUrlsToInstall.remove(url)) {
+                LOG.info("Received config installed event url={}", url);
+            }
+        }
+    }
+
+    public void updateWith(List<ResourceGroup> installedGroups) {
+        for (ResourceGroup resourceGroup : installedGroups) {
+            List<Resource> resources = resourceGroup.getResources();
+            for (Resource resource : resources) {
+                if (resource.getState() == ResourceState.INSTALLED) {
+                    String url = resource.getURL();
+
+                    if (bundleUrlsToInstall.remove(url)) {
+                        LOG.info("Found bundle in already installed resources url={}", url);
+                    }
+                    if (configUrlsToInstall.remove(url)) {
+                        LOG.info("Found config in already installed resources url={}", url);
+                    }
+                }
             }
         }
     }