From a57ea8278f8d29a6744e58df1e93f5bbf23b9991 Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Mon, 6 May 2024 19:57:26 +0200 Subject: [PATCH] improve extension loading --- .../lucee/runtime/config/ConfigAdmin.java | 3 ++- .../runtime/config/ConfigWebFactory.java | 25 ++++++++++++++++--- .../lucee/runtime/extension/RHExtension.java | 5 +++- .../lucee/transformer/dynamic/meta/Clazz.java | 2 +- .../dynamic/meta/dynamic/ClazzDynamic.java | 14 ++++++++++- loader/build.xml | 2 +- loader/pom.xml | 2 +- 7 files changed, 44 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/lucee/runtime/config/ConfigAdmin.java b/core/src/main/java/lucee/runtime/config/ConfigAdmin.java index 89e740d68f..94b738ea6d 100755 --- a/core/src/main/java/lucee/runtime/config/ConfigAdmin.java +++ b/core/src/main/java/lucee/runtime/config/ConfigAdmin.java @@ -4749,7 +4749,8 @@ public void updateRHExtension(Config config, RHExtension rhext, boolean reload, // load the bundles if (rhext.getStartBundles()) { - rhext.deployBundles(ci); + rhext.deployBundles(ci, true); + BundleInfo[] bfs = rhext.getBundles(); if (bfs != null) { for (BundleInfo bf: bfs) { diff --git a/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java b/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java index 793210c1fc..8aa9a6e8aa 100644 --- a/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java +++ b/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java @@ -4806,7 +4806,6 @@ private static void _loadExtensionBundles(ConfigServerImpl cs, ConfigImpl config if (config instanceof ConfigServer) { changed = ConfigFactory.modeChange(config.getConfigDir(), config.getAdminMode() == ConfigImpl.ADMINMODE_MULTI ? "multi" : "single", false); } - Array children = ConfigWebUtil.getAsArray("extensions", root); String md5 = CollectionUtil.md5(children); if (!changed) { @@ -4814,6 +4813,9 @@ private static void _loadExtensionBundles(ConfigServerImpl cs, ConfigImpl config return; } } + + boolean firstLoad = config.getExtensionsMD5() == null; + try { RHExtension.removeDuplicates(children); } @@ -4837,7 +4839,6 @@ private static void _loadExtensionBundles(ConfigServerImpl cs, ConfigImpl config child = Caster.toStruct(it.next(), null); if (child == null) continue; id = Caster.toString(child.get(KeyConstants._id, null), null); - BundleInfo[] bfsq; try { String res = Caster.toString(child.get(KeyConstants._resource, null), null); @@ -4849,7 +4850,25 @@ private static void _loadExtensionBundles(ConfigServerImpl cs, ConfigImpl config // we force a new installation if we have switched from single to multi mode, because extension can // act completely different if that is the case rhe = RHExtension.installExtension(config, id, Caster.toString(child.get(KeyConstants._version, null), null), res, changed); - if (rhe.getStartBundles()) rhe.deployBundles(config); + if (rhe.getStartBundles()) { + if (!firstLoad) { + rhe.deployBundles(config, true); + } + else { + try { + BundleInfo[] bundles = rhe.getBundles(); + if (bundles != null) { + for (BundleInfo bi: bundles) { + OSGiUtil.loadBundleFromLocal(bi.getSymbolicName(), bi.getVersion(), null, false, null); + } + } + } + catch (Exception ex) { + rhe.deployBundles(config, true); + } + } + } + extensions.add(rhe); installedFiles.add(rhe.getExtensionFile()); installedIds.add(rhe.getId()); diff --git a/core/src/main/java/lucee/runtime/extension/RHExtension.java b/core/src/main/java/lucee/runtime/extension/RHExtension.java index 67f82a8bd5..92d98f8866 100644 --- a/core/src/main/java/lucee/runtime/extension/RHExtension.java +++ b/core/src/main/java/lucee/runtime/extension/RHExtension.java @@ -816,7 +816,7 @@ private void readSymbolicName(String label, String str) { if (!StringUtil.isEmpty(str, true)) symbolicName = str.trim(); } - public void deployBundles(Config config) throws IOException, BundleException { + public void deployBundles(Config config, boolean load) throws IOException, BundleException { // no we read the content of the zip ZipInputStream zis = new ZipInputStream(IOUtil.toBufferedInputStream(extensionFile.getInputStream())); ZipEntry entry; @@ -838,6 +838,9 @@ public void deployBundles(Config config) throws IOException, BundleException { tmp.moveTo(tmpJar); ConfigAdmin.updateJar(config, tmpJar, false); } + else if (load) { + OSGiUtil.loadBundle((BundleFile) obj); + } } zis.closeEntry(); diff --git a/core/src/main/java/lucee/transformer/dynamic/meta/Clazz.java b/core/src/main/java/lucee/transformer/dynamic/meta/Clazz.java index 3f8a34583a..62c2946eb2 100644 --- a/core/src/main/java/lucee/transformer/dynamic/meta/Clazz.java +++ b/core/src/main/java/lucee/transformer/dynamic/meta/Clazz.java @@ -57,7 +57,7 @@ public abstract class Clazz implements Serializable { public static boolean allowReflection() { if (allowReflection == null) { - allowReflection = Caster.toBooleanValue(SystemUtil.getSystemPropOrEnvVar("lucee.allow.reflection", null), false); + allowReflection = Caster.toBooleanValue(SystemUtil.getSystemPropOrEnvVar("lucee.allow.reflection", null), true); } return allowReflection; } diff --git a/core/src/main/java/lucee/transformer/dynamic/meta/dynamic/ClazzDynamic.java b/core/src/main/java/lucee/transformer/dynamic/meta/dynamic/ClazzDynamic.java index 2d0b5c88ea..736fddef3a 100644 --- a/core/src/main/java/lucee/transformer/dynamic/meta/dynamic/ClazzDynamic.java +++ b/core/src/main/java/lucee/transformer/dynamic/meta/dynamic/ClazzDynamic.java @@ -27,6 +27,7 @@ import lucee.commons.io.IOUtil; import lucee.commons.io.log.Log; import lucee.commons.io.res.Resource; +import lucee.commons.lang.ExceptionUtil; import lucee.commons.lang.PhysicalClassLoader; import lucee.commons.lang.types.RefInteger; import lucee.commons.lang.types.RefIntegerImpl; @@ -271,7 +272,18 @@ private static void _getFunctionMembers(final Class clazz, Map - + diff --git a/loader/pom.xml b/loader/pom.xml index cb00b55f89..2019be6739 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.1.0.132-SNAPSHOT + 6.1.0.133-SNAPSHOT jar Lucee Loader Build