Skip to content

Commit

Permalink
LDEV-5033 - add argument "javacast"
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jul 22, 2024
1 parent 0c1af7b commit 58eef07
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 84 deletions.
18 changes: 9 additions & 9 deletions core/src/main/java/lucee/runtime/PageContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
public final class PageContextImpl extends PageContext {

private static final RefBoolean DUMMY_BOOL = new RefBooleanImpl(false);
private static final boolean JAVA_SETTING_CLASSIC_MODE = true;
private static final boolean JAVA_SETTING_CLASSIC_MODE = false;
private static int counter = 0;

/**
Expand Down Expand Up @@ -3835,23 +3835,23 @@ public ORMSession getORMSession(boolean create) throws PageException {
return ormSession;
}

public ClassLoader getClassLoader() throws IOException {
return getClassLoader(null);
}
/*
* public ClassLoader getClassLoader() throws IOException { return getClassLoader(null); }
*/

public JavaSettings getJavaSettings() {
return getApplicationContext().getJavaSettings();
}

public ClassLoader getClassLoader(Resource[] reses) throws IOException {
public ClassLoader getClassLoader() throws IOException {
JavaSettingsImpl js = (JavaSettingsImpl) getJavaSettings();
if (js != null) {
// TODO FUTURE 7 we do this to avoid any kind of regression, in Lucee 7 remove this
if (!JAVA_SETTING_CLASSIC_MODE && !js.hasPoms() && !js.hasOSGis()) {
if (JAVA_SETTING_CLASSIC_MODE && !js.hasPoms() && !js.hasOSGis()) {
Resource[] jars = js.getResourcesTranslated();
if (jars.length > 0) return config.getResourceClassLoader().getCustomResourceClassLoader(jars);
}
return js.getResourceClassLoader(reses);
return js.getClassLoader(null, false);

}
return config.getResourceClassLoader();
Expand All @@ -3866,12 +3866,12 @@ public ClassLoader getRPCClassLoader(boolean reload, ClassLoader[] parents) thro
JavaSettingsImpl js = (JavaSettingsImpl) getJavaSettings();
if (js != null) {
// TODO FUTURE 7 we do this to avoid any kind of regression, in Lucee 7 remove this
if (!JAVA_SETTING_CLASSIC_MODE && !js.hasPoms() && !js.hasOSGis()) {
if (JAVA_SETTING_CLASSIC_MODE && !js.hasPoms() && !js.hasOSGis()) {
Resource[] jars = js.getResourcesTranslated();
if (jars.length > 0) return ((PhysicalClassLoader) cl).getCustomClassLoader(jars, reload);
}
else {
java.util.Collection<Resource> jars = js.getAllResources(null);
java.util.Collection<Resource> jars = js.getAllResources(cl);
if (jars.size() > 0) return ((PhysicalClassLoader) cl).getCustomClassLoader(jars.toArray(new Resource[jars.size()]), reload);
}

Expand Down
12 changes: 8 additions & 4 deletions core/src/main/java/lucee/runtime/functions/other/JavaProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package lucee.runtime.functions.other;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

Expand Down Expand Up @@ -128,12 +129,11 @@ public static Class<?> loadClass(PageContext pc, String className, Object pathOr
else if (Decision.isStruct(pathOrName)) {
JavaSettingsImpl js = (JavaSettingsImpl) JavaSettingsImpl.getInstance(pc.getConfig(), Caster.toStruct(pathOrName));
try {
return js.getResourceClassLoader(null).loadClass(className);
return ClassUtil.loadClass(js.getClassLoader(((PageContextImpl) pc).getClassLoader(), false), className);
}
catch (Exception e) {
catch (IOException e) {
throw Caster.toPageException(e);
}

}

return loadClassByPath(pc, className, ListUtil.toStringArray(Caster.toArray(pathOrName)));
Expand Down Expand Up @@ -172,7 +172,11 @@ private static Class<?> loadClassByPath(PageContext pc, String className, String
// load class
try {

ClassLoader cl = resources.isEmpty() ? pci.getClassLoader() : pci.getClassLoader(resources.toArray(new Resource[resources.size()]));
ClassLoader cl = pci.getClassLoader();
if (!resources.isEmpty()) {
JavaSettingsImpl js = (JavaSettingsImpl) JavaSettingsImpl.getInstance(pc.getConfig(), resources);
cl = js.getClassLoader(cl, false);
}

Class clazz = null;
try {
Expand Down
20 changes: 8 additions & 12 deletions core/src/main/java/lucee/runtime/functions/string/JavaCast.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
*/
package lucee.runtime.functions.string;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;

import lucee.commons.lang.ClassException;
import lucee.commons.lang.ClassUtil;
import lucee.commons.lang.StringUtil;
import lucee.runtime.PageContext;
import lucee.runtime.PageContextImpl;
import lucee.runtime.exp.ExpressionException;
import lucee.runtime.exp.PageException;
import lucee.runtime.ext.function.Function;
Expand Down Expand Up @@ -112,20 +113,15 @@ private static Class<?> toClass(PageContext pc, String lcType, String type, Stru
if (lcType.equals("bigdecimal")) {
return BigDecimal.class;
}
if (javaSettings != null) {
JavaSettingsImpl js = (JavaSettingsImpl) JavaSettingsImpl.getInstance(pc.getConfig(), Caster.toStruct(javaSettings));
try {
return js.getResourceClassLoader(null).loadClass(type);
}
catch (Exception e) {
throw Caster.toPageException(e);
}
}
try {

try {
if (javaSettings != null) {
JavaSettingsImpl js = (JavaSettingsImpl) JavaSettingsImpl.getInstance(pc.getConfig(), Caster.toStruct(javaSettings));
return ClassUtil.loadClass(js.getClassLoader(((PageContextImpl) pc).getClassLoader(), false), type);
}
return ClassUtil.loadClass(pc, type);
}
catch (ClassException e) {
catch (IOException e) {
throw Caster.toPageException(e);
}
}
Expand Down
Loading

0 comments on commit 58eef07

Please sign in to comment.