Skip to content

Commit

Permalink
improve extension loading
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed May 6, 2024
1 parent 1ba758b commit a57ea82
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/lucee/runtime/config/ConfigAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 22 additions & 3 deletions core/src/main/java/lucee/runtime/config/ConfigWebFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4806,14 +4806,16 @@ 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) {
if (md5.equals(config.getExtensionsMD5())) {
return;
}
}

boolean firstLoad = config.getExtensionsMD5() == null;

try {
RHExtension.removeDuplicates(children);
}
Expand All @@ -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);
Expand All @@ -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());
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/lucee/runtime/extension/RHExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -271,7 +272,18 @@ private static void _getFunctionMembers(final Class clazz, Map<String, FunctionM
final String classPath = clazz.getName().replace('.', '/') + ".class";
final ClassLoader cl = getClassLoader(clazz);
final RefInteger classAccess = new RefIntegerImpl();
ClassReader classReader = new ClassReader(cl.getResourceAsStream(classPath));
ClassReader classReader;
try {
classReader = new ClassReader(cl.getResourceAsStream(classPath));
}
catch (IOException ioe) {
if ("Class not found".equals(ioe.getMessage())) {
IOException tmp = new IOException("unable to load class path [" + classPath + "]");
ExceptionUtil.initCauseEL(tmp, ioe);
ioe = tmp;
}
throw ioe;
}

// Create a ClassVisitor to visit the methods
ClassVisitor visitor = new ClassVisitor(Opcodes.ASM9) {
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.1.0.132-SNAPSHOT"/>
<property name="version" value="6.1.0.133-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.1.0.132-SNAPSHOT</version>
<version>6.1.0.133-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit a57ea82

Please sign in to comment.