SLING-8083 avoid ClassNotFoundExceptions, take
infoProvider.getInstallationState().getInstalledResources() into account
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.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 @@
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 @@
}
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 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 @@
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 @@
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);
+ }
+ }
}
}
}