Permalink
Browse files

make createobject able to force recompilation of cfc components

  • Loading branch information...
brucekirkpatrick committed Jan 6, 2019
1 parent 56ab502 commit cfb5d592e60109b7eb37e7d0dc6e4882c2a4dae4
@@ -98,7 +98,7 @@ public InterfaceImpl(PageContext pc, InterfacePageImpl page, String strExtend, S
while (it.hasNext()) {
str = it.next().trim();
if (str.isEmpty()) continue;
inter = ComponentLoader.searchInterface(pc, loadingLocation, str);
inter = ComponentLoader.searchInterface(pc, loadingLocation, str, false);
extend.add(inter);
}
return extend;
@@ -3177,9 +3177,14 @@ public HttpServlet getServlet() {

@Override
public lucee.runtime.Component loadComponent(String compPath) throws PageException {
return ComponentLoader.searchComponent(this, null, compPath, null, null, false);
return ComponentLoader.searchComponent(this, null, compPath, null, null, false, false);
}

@Override
public lucee.runtime.Component loadComponent(String compPath, Boolean forceReload) throws PageException {
return ComponentLoader.searchComponent(this, null, compPath, null, null, false, forceReload);
}

/**
* @return the base
*/
@@ -78,30 +78,30 @@
* @return
* @throws PageException
*/
public static ComponentImpl searchComponent(PageContext pc, PageSource loadingLocation, String rawPath, Boolean searchLocal, Boolean searchRoot, boolean isExtendedComponent)
public static ComponentImpl searchComponent(PageContext pc, PageSource loadingLocation, String rawPath, Boolean searchLocal, Boolean searchRoot, boolean isExtendedComponent, boolean forceReload)
throws PageException {
return (ComponentImpl) _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, true, RETURN_TYPE_COMPONENT, isExtendedComponent);
return (ComponentImpl) _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, true, RETURN_TYPE_COMPONENT, isExtendedComponent, forceReload);
}

public static ComponentImpl searchComponent(PageContext pc, PageSource loadingLocation, String rawPath, Boolean searchLocal, Boolean searchRoot,
final boolean isExtendedComponent, boolean executeConstr) throws PageException {
return (ComponentImpl) _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, executeConstr, RETURN_TYPE_COMPONENT, isExtendedComponent);
final boolean isExtendedComponent, boolean executeConstr, boolean forceReload) throws PageException {
return (ComponentImpl) _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, executeConstr, RETURN_TYPE_COMPONENT, isExtendedComponent, forceReload);
}

public static InterfaceImpl searchInterface(PageContext pc, PageSource loadingLocation, String rawPath, boolean executeConstr) throws PageException {
return (InterfaceImpl) _search(pc, loadingLocation, rawPath, Boolean.TRUE, Boolean.TRUE, executeConstr, RETURN_TYPE_INTERFACE, false);
public static InterfaceImpl searchInterface(PageContext pc, PageSource loadingLocation, String rawPath, boolean executeConstr, boolean forceReload) throws PageException {
return (InterfaceImpl) _search(pc, loadingLocation, rawPath, Boolean.TRUE, Boolean.TRUE, executeConstr, RETURN_TYPE_INTERFACE, false, forceReload);
}

public static InterfaceImpl searchInterface(PageContext pc, PageSource loadingLocation, String rawPath) throws PageException {
return (InterfaceImpl) _search(pc, loadingLocation, rawPath, Boolean.TRUE, Boolean.TRUE, true, RETURN_TYPE_INTERFACE, false);
public static InterfaceImpl searchInterface(PageContext pc, PageSource loadingLocation, String rawPath, Boolean forceReload) throws PageException {
return (InterfaceImpl) _search(pc, loadingLocation, rawPath, Boolean.TRUE, Boolean.TRUE, true, RETURN_TYPE_INTERFACE, false, forceReload);
}

public static Page searchPage(PageContext pc, PageSource child, String rawPath, Boolean searchLocal, Boolean searchRoot) throws PageException {
return (Page) _search(pc, child, rawPath, searchLocal, searchRoot, false, RETURN_TYPE_PAGE, false);
public static Page searchPage(PageContext pc, PageSource child, String rawPath, Boolean searchLocal, Boolean searchRoot, Boolean forceReload) throws PageException {
return (Page) _search(pc, child, rawPath, searchLocal, searchRoot, false, RETURN_TYPE_PAGE, false, forceReload);
}

private static Object _search(PageContext pc, PageSource loadingLocation, String rawPath, Boolean searchLocal, Boolean searchRoot, boolean executeConstr, short returnType,
final boolean isExtendedComponent) throws PageException {
final boolean isExtendedComponent, boolean forceReload) throws PageException {
PageSource currPS = pc.getCurrentPageSource(null);

ImportDefintion[] importDefintions = null;
@@ -111,14 +111,14 @@ private static Object _search(PageContext pc, PageSource loadingLocation, String
if (cfc instanceof ComponentImpl && currPS.equals(cfc.getPageSource())) {
importDefintions = ((ComponentImpl) cfc)._getImportDefintions();
}
else if ((currP = currPS.loadPage(pc, false, null)) != null) {
else if ((currP = currPS.loadPage(pc, forceReload, null)) != null) {
importDefintions = currP.getImportDefintions();
}
}

// int dialect = currPS == null ? pc.getCurrentTemplateDialect() : currPS.getDialect();
// first try for the current dialect
Object obj = _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, executeConstr, returnType, currPS, importDefintions, CFMLEngine.DIALECT_CFML, isExtendedComponent);
Object obj = _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, executeConstr, returnType, currPS, importDefintions, CFMLEngine.DIALECT_CFML, isExtendedComponent, forceReload);
// then we try the opposite dialect
// if (obj == null && ((ConfigImpl) pc.getConfig()).allowLuceeDialect()) { // only when the lucee dialect is enabled we have to check the opposite
// obj = _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, executeConstr, returnType, currPS, importDefintions,
@@ -131,7 +131,7 @@ else if ((currP = currPS.loadPage(pc, false, null)) != null) {
}

private static Object _search(PageContext pc, PageSource loadingLocation, String rawPath, Boolean searchLocal, Boolean searchRoot, boolean executeConstr, short returnType,
PageSource currPS, ImportDefintion[] importDefintions, int dialect, final boolean isExtendedComponent) throws PageException {
PageSource currPS, ImportDefintion[] importDefintions, int dialect, final boolean isExtendedComponent, boolean forceReload) throws PageException {
ConfigImpl config = (ConfigImpl) pc.getConfig();

//if (dialect == CFMLEngine.DIALECT_LUCEE && !config.allowLuceeDialect()) PageContextImpl.notSupported();
@@ -153,7 +153,7 @@ private static Object _search(PageContext pc, PageSource loadingLocation, String

boolean isRealPath = !StringUtil.startsWith(path, '/');
// PageSource currPS = pc.getCurrentPageSource();
// Page currP=currPS.loadPage(pc,false);
// Page currP=currPS.loadPage(pc,forceReload);
PageSource ps = null;
CIPage page = null;

@@ -167,7 +167,7 @@ private static Object _search(PageContext pc, PageSource loadingLocation, String
for (int y = 0; y < acm.length; y++) {
m = acm[y];
ps = m.getPageSource(pathWithCFC);
page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
page = toCIPage(ps.loadPageThrowTemplateException(pc, forceReload, (Page) null));
if (page != null) {

return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
@@ -220,7 +220,7 @@ private static Object _search(PageContext pc, PageSource loadingLocation, String
if (searchLocal && isRealPath) {
// check realpath
PageSource[] arr = ((PageContextImpl) pc).getRelativePageSources(pathWithCFC);
page = toCIPage(PageSourceImpl.loadPage(pc, arr, null));
page = toCIPage(PageSourceImpl.loadPage(pc, arr, null, forceReload));
if (page != null) {
if (doCache) config.putCachedPageSource(localCacheName, page.getPageSource());
return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
@@ -246,7 +246,7 @@ private static Object _search(PageContext pc, PageSource loadingLocation, String
// search from local first
if (searchLocal) {
arr = ((PageContextImpl) pc).getRelativePageSources(impDef.getPackageAsPath() + pathWithCFC);
page = toCIPage(PageSourceImpl.loadPage(pc, arr, null));
page = toCIPage(PageSourceImpl.loadPage(pc, arr, null, forceReload));
if (page != null) {
if (doCache) config.putCachedPageSource("import:" + impDef.getPackageAsPath() + pathWithCFC, page.getPageSource());
return returnType == RETURN_TYPE_PAGE ? page
@@ -255,7 +255,7 @@ private static Object _search(PageContext pc, PageSource loadingLocation, String
}

// search mappings and webroot
page = toCIPage(PageSourceImpl.loadPage(pc, ((PageContextImpl) pc).getPageSources("/" + impDef.getPackageAsPath() + pathWithCFC), null));
page = toCIPage(PageSourceImpl.loadPage(pc, ((PageContextImpl) pc).getPageSources("/" + impDef.getPackageAsPath() + pathWithCFC), null, forceReload));
if (page != null) {
String key = impDef.getPackageAsPath() + pathWithCFC;
if (doCache && !((MappingImpl) page.getPageSource().getMapping()).isAppMapping()) config.putCachedPageSource("import:" + key, page.getPageSource());
@@ -271,7 +271,7 @@ private static Object _search(PageContext pc, PageSource loadingLocation, String
for (int y = 0; y < mappings.length; y++) {
m = mappings[y];
ps = m.getPageSource(impDef.getPackageAsPath() + pathWithCFC);
page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
page = toCIPage(ps.loadPageThrowTemplateException(pc, forceReload, (Page) null));
if (page != null) {
if (doCache && z > 0) config.putCachedPageSource("import:" + impDef.getPackageAsPath() + pathWithCFC, page.getPageSource());
return returnType == RETURN_TYPE_PAGE ? page
@@ -293,7 +293,7 @@ private static Object _search(PageContext pc, PageSource loadingLocation, String
else p = pathWithCFC;

// search mappings and webroot
page = toCIPage(PageSourceImpl.loadPage(pc, ((PageContextImpl) pc).getPageSources(p), null));
page = toCIPage(PageSourceImpl.loadPage(pc, ((PageContextImpl) pc).getPageSources(p), null, forceReload));
if (page != null) {
String key = pathWithCFC;
if (doCache && !((MappingImpl) page.getPageSource().getMapping()).isAppMapping()) config.putCachedPageSource(key, page.getPageSource());
@@ -308,13 +308,13 @@ private static Object _search(PageContext pc, PageSource loadingLocation, String
for (int i = 0; i < mappings.length; i++) {
m = mappings[i];
ps = m.getPageSource(p);
page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
page = toCIPage(ps.loadPageThrowTemplateException(pc, forceReload, (Page) null));

// recursive search
if (page == null && config.doComponentDeepSearch() && path.indexOf('/') == -1) {
ps = MappingUtil.searchMappingRecursive(m, pathWithCFC, true);
if (ps != null) {
page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
page = toCIPage(ps.loadPageThrowTemplateException(pc, forceReload, (Page) null));
if (page != null) doCache = false;// do not cache this, it could be ambigous
}
}
@@ -338,7 +338,7 @@ private static Object _search(PageContext pc, PageSource loadingLocation, String
if (loadingLocation != null) {
ps = loadingLocation.getRealPage(pathWithCFC);
if (ps != null) {
page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
page = toCIPage(ps.loadPageThrowTemplateException(pc, forceReload, (Page) null));

if (page != null) {
return returnType == RETURN_TYPE_PAGE ? page
@@ -351,7 +351,7 @@ private static Object _search(PageContext pc, PageSource loadingLocation, String
if (StringUtil.startsWithIgnoreCase(rawPath, "cfide.")) {
String rpm = Constants.DEFAULT_PACKAGE + "." + rawPath.substring(6);
try {
return _search(pc, loadingLocation, rpm, searchLocal, searchRoot, executeConstr, returnType, currPS, importDefintions, dialect, false);
return _search(pc, loadingLocation, rpm, searchLocal, searchRoot, executeConstr, returnType, currPS, importDefintions, dialect, false, forceReload);
}
catch (ExpressionException ee) {
return null;
@@ -365,7 +365,7 @@ private static Object _search(PageContext pc, PageSource loadingLocation, String
}

private static String toStringType(short returnType, int dialect) {
if (RETURN_TYPE_COMPONENT == returnType) return "component";//dialect == CFMLEngine.DIALECT_LUCEE ? "class" :
if (RETURN_TYPE_COMPONENT == returnType) return "component";
if (RETURN_TYPE_INTERFACE == returnType) return "interface";
return "component/interface";
}
@@ -36,7 +36,7 @@ public static Component call(PageContext pc, String path) throws PageException {
public static Component call(PageContext pc, String path, Object args) throws PageException {

// first argument is the component itself
Component c = CreateObject.doComponent(pc, path);
Component c = CreateObject.doComponent(pc, path, false);

if (c.get(KeyConstants._init, null) instanceof UDF) {
// no arguments
@@ -25,6 +25,7 @@
import lucee.commons.lang.StringUtil;
import lucee.runtime.Component;
import lucee.runtime.PageContext;
import lucee.runtime.PageContextImpl;
import lucee.runtime.com.COMObject;
import lucee.runtime.config.ConfigImpl;
import lucee.runtime.engine.ThreadLocalPageContext;
@@ -37,23 +38,31 @@
import lucee.runtime.net.proxy.ProxyData;
import lucee.runtime.net.proxy.ProxyDataImpl;
import lucee.runtime.op.Caster;
import lucee.runtime.op.Decision;
import lucee.runtime.security.SecurityManager;
import lucee.runtime.type.Struct;

public final class CreateObject implements Function {
public static Object call(PageContext pc, String cfcName) throws PageException {
return call(pc, "component", cfcName, null, null);
return call(pc, "component", cfcName, null, null, false);
}

public static Object call(PageContext pc, String type, String className) throws PageException {
return call(pc, type, className, null, null);
return call(pc, type, className, null, null, false);
}
public static Object call(PageContext pc, String type, String className, Boolean forceReload) throws PageException {
return call(pc, type, className, null, null, forceReload);
}

public static Object call(PageContext pc, String type, String className, Object context) throws PageException {
return call(pc, type, className, context, null);
if(Decision.isBoolean(context)){
return call(pc, type, className, null, null, Caster.toBoolean(context));
}else {
return call(pc, type, className, context, null, false);
}
}

public static Object call(PageContext pc, String type, String className, Object context, Object serverName) throws PageException {
public static Object call(PageContext pc, String type, String className, Object context, Object serverName, Boolean forceReload) throws PageException {
type = StringUtil.toLowerCase(type);

// JAVA
@@ -67,7 +76,10 @@ public static Object call(PageContext pc, String type, String className, Object
}
// Component
if (type.equals("component") || type.equals("cfc")) {
return doComponent(pc, className);
if(forceReload==null){
forceReload=false;
}
return doComponent(pc, className, forceReload);
}
// Webservice
if (type.equals("webservice") || type.equals("wsdl")) {
@@ -144,8 +156,8 @@ public static Object doCOM(PageContext pc, String className) {
return new COMObject(className);
}

public static Component doComponent(PageContext pc, String className) throws PageException {
return pc.loadComponent(className);
public static Component doComponent(PageContext pc, String className, Boolean forceReload) throws PageException {
return ((PageContextImpl) pc).loadComponent(className, forceReload);
}

public static Object doWebService(PageContext pc, String wsdlUrl) throws PageException {
@@ -39,7 +39,7 @@ public static Object call(PageContext pc, Object[] objArr) throws PageException
String path = Caster.toString(objArr[objArr.length - 1]);
// not store the index to make it faster

Component c = CreateObject.doComponent(pc, path);
Component c = CreateObject.doComponent(pc, path, false);

// no init method
if (!(c.get(KeyConstants._init, null) instanceof UDF)) {
@@ -59,7 +59,7 @@ public Interface searchInterface(PageContext pc, PageSource loadingLocation, Str

@Override
public Page searchPage(PageContext pc, PageSource child, String rawPath, Boolean searchLocal, Boolean searchRoot) throws PageException {
return ComponentLoader.searchPage(pc, child, rawPath, searchLocal, searchRoot);
return ComponentLoader.searchPage(pc, child, rawPath, searchLocal, searchRoot, false);
}

@Override
@@ -1112,6 +1112,8 @@

public abstract Component loadComponent(String compPath) throws PageException;

public abstract Component loadComponent(String compPath, Boolean forceReload) throws PageException;

// public abstract void setActiveComponent(Component component);

/**

0 comments on commit cfb5d59

Please sign in to comment.