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 2019/12/21 08:47:47 UTC

[sling-org-apache-sling-installer-provider-installhook] 02/05: SLING-8948 Ignore Installer Vault Package Install Hook when being used with the feature model

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

ghenzler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-installer-provider-installhook.git

commit ca524dd129ddd13a8f847292d94e009e7f3f49cd
Author: georg.henzler <ge...@netcentric.biz>
AuthorDate: Sat Dec 21 00:26:08 2019 +0100

    SLING-8948 Ignore Installer Vault Package Install Hook when being used
    with the feature model
---
 pom.xml                                            |  2 +-
 src/main/appended-resources/META-INF/MANIFEST.MF   |  2 +-
 .../installhook/OsgiInstallerHookEntry.java        | 58 ++++++++++++++++++++++
 3 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4b62962..48395ba 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
     </parent>
 
     <artifactId>org.apache.sling.installer.provider.installhook</artifactId>
-    <version>1.0.5-SNAPSHOT</version>
+    <version>1.1.0-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <name>Sling Installer Vault Package Install Hook</name>
diff --git a/src/main/appended-resources/META-INF/MANIFEST.MF b/src/main/appended-resources/META-INF/MANIFEST.MF
index 4889165..8f77165 100644
--- a/src/main/appended-resources/META-INF/MANIFEST.MF
+++ b/src/main/appended-resources/META-INF/MANIFEST.MF
@@ -1 +1 @@
-Main-Class: org.apache.sling.installer.provider.installhook.OsgiInstallerHook
+Main-Class: org.apache.sling.installer.provider.installhook.OsgiInstallerHookEntry
diff --git a/src/main/java/org/apache/sling/installer/provider/installhook/OsgiInstallerHookEntry.java b/src/main/java/org/apache/sling/installer/provider/installhook/OsgiInstallerHookEntry.java
new file mode 100644
index 0000000..4b1e1c0
--- /dev/null
+++ b/src/main/java/org/apache/sling/installer/provider/installhook/OsgiInstallerHookEntry.java
@@ -0,0 +1,58 @@
+/*
+    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.installer.provider.installhook;
+
+import org.apache.jackrabbit.vault.packaging.InstallContext;
+import org.apache.jackrabbit.vault.packaging.InstallHook;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OsgiInstallerHookEntry implements InstallHook {
+    private static final Logger LOG = LoggerFactory.getLogger(OsgiInstallerHookEntry.class);
+
+    public static String OSGI_INSTALLER_CLASSNAME = "org.apache.sling.installer.api.OsgiInstaller";
+    public static String HOOK_CLASSNAME = "org.apache.sling.installer.provider.installhook.OsgiInstallerHook";
+
+    @Override
+    public void execute(InstallContext context) throws PackageException {
+
+        try {
+            Class<?> osgiInstallerClass = getClass().getClassLoader().loadClass(OSGI_INSTALLER_CLASSNAME);
+            LOG.debug("Osgi Installer Class found: {}", osgiInstallerClass);
+            loadAndRunInstallHook(context);
+        } catch (ClassNotFoundException e) {
+            LOG.info("Class {} not found, skipping installer hook for package {}", OSGI_INSTALLER_CLASSNAME, context.getPackage().getId());
+        }
+    }
+
+    private void loadAndRunInstallHook(InstallContext context) throws PackageException {
+        InstallHook actualHook = null;
+        try {
+            Class<?> actualHookClass = getClass().getClassLoader().loadClass(HOOK_CLASSNAME);
+            actualHook = (InstallHook) actualHookClass.newInstance();
+        } catch (Exception e) {
+            LOG.error("Could not load/instantiate " + HOOK_CLASSNAME + ": " + e, e);
+            return;
+        }
+
+        actualHook.execute(context);
+    }
+
+}