Skip to content

Commit

Permalink
partly revert log changes and load function and tag settings on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 22, 2024
1 parent 3c0237a commit 211fdf5
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 47 deletions.
19 changes: 7 additions & 12 deletions core/src/main/java/lucee/commons/io/log/LogUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
**/
package lucee.commons.io.log;

import java.io.File;
import java.util.Date;

import lucee.aprint;
Expand All @@ -29,12 +30,11 @@
import lucee.commons.lang.ExceptionUtil;
import lucee.commons.lang.StringUtil;
import lucee.commons.lang.SystemOut;
import lucee.loader.engine.CFMLEngineFactory;
import lucee.runtime.PageContext;
import lucee.runtime.PageContextImpl;
import lucee.runtime.PageSource;
import lucee.runtime.config.Config;
import lucee.runtime.config.ConfigPro;
import lucee.runtime.config.ConfigServerImpl;
import lucee.runtime.config.ConfigUtil;
import lucee.runtime.config.ConfigWeb;
import lucee.runtime.engine.ThreadLocalPageContext;
Expand Down Expand Up @@ -208,11 +208,6 @@ public static void log(Config config, int level, String logName, String type, St

}

public static void log(ConfigPro cw, Log log, String type, Exception e) {
if (log != null) log.error(type, e);
else log(cw, type, e);
}

public static void log(PageContext pc, int level, String logName, String type, String msg) {
Log log = ThreadLocalPageContext.getLog(pc, logName);
if (log != null) log.log(level, type, msg);
Expand All @@ -222,15 +217,15 @@ public static void log(PageContext pc, int level, String logName, String type, S
}

public static void logGlobal(Config config, int level, String type, String msg) {
ConfigServerImpl cs = ConfigUtil.getConfigServerImpl(config);
try {
CFMLEngineFactory factory = ConfigUtil.getCFMLEngineFactory(config);
Resource log;
boolean check = false;
if (level > Log.LEVEL_DEBUG) {
if (ERR == null) {
synchronized (cs) {
synchronized (factory) {
if (ERR == null) {
ERR = cs.getConfigDir().getRealResource("logs/err.log");
ERR = ResourceUtil.toResource(new File(factory.getResourceRoot(), "context/logs/err.log"));
check = true;
}
}
Expand All @@ -239,9 +234,9 @@ public static void logGlobal(Config config, int level, String type, String msg)
}
else {
if (OUT == null) {
synchronized (cs) {
synchronized (factory) {
if (OUT == null) {
OUT = cs.getConfigDir().getRealResource("logs/out.log");
OUT = ResourceUtil.toResource(new File(factory.getResourceRoot(), "context/logs/out.log"));
check = true;
}
}
Expand Down
70 changes: 41 additions & 29 deletions core/src/main/java/lucee/runtime/config/ConfigFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,17 @@ public static ConfigServerImpl newInstanceServer(CFMLEngineImpl engine, Map<Stri
boolean hasConfigNew = configFileNew.exists() && configFileNew.length() > 0;

if (!hasConfigNew) {
LogUtil.logGlobal(ThreadLocalPageContext.getConfig(), Log.LEVEL_INFO, ConfigFactoryImpl.class.getName(),
"has no json server context config [" + configFileNew + "]");
LogUtil.logGlobal(null, Log.LEVEL_INFO, ConfigFactoryImpl.class.getName(), "has no json server context config [" + configFileNew + "]");
hasConfigOld = configFileOld.exists() && configFileOld.length() > 0;
LogUtil.logGlobal(ThreadLocalPageContext.getConfig(), Log.LEVEL_INFO, ConfigFactoryImpl.class.getName(),
LogUtil.logGlobal(null, Log.LEVEL_INFO, ConfigFactoryImpl.class.getName(),
"has " + (hasConfigOld ? "" : "no ") + "xml server context config [" + configFileOld + "]");
}
ConfigServerImpl config = existing != null ? existing : new ConfigServerImpl(engine, initContextes, contextes, configDir, configFileNew, ui, essentialOnly, doNew);
ThreadLocalConfigServer.register(config);
// translate to new
if (!hasConfigNew) {
if (hasConfigOld) {
LogUtil.logGlobal(ThreadLocalPageContext.getConfig(), Log.LEVEL_INFO, ConfigFactoryImpl.class.getName(), "convert server context xml config to json");
LogUtil.logGlobal(null, Log.LEVEL_INFO, ConfigFactoryImpl.class.getName(), "convert server context xml config to json");
try {
translateConfigFile(config, configFileOld, configFileNew, "multi", true);
}
Expand Down Expand Up @@ -414,8 +413,6 @@ synchronized static void load(ConfigServerImpl config, Struct root, boolean isRe

config.setLastModified();

_loadFilesystem(config, root, doNew); // load this before execute any code, what for example loadxtension does (json)

if (LOG) log(config, "loaded filesystem");

if (!essentialOnly) {
Expand All @@ -430,7 +427,6 @@ synchronized static void load(ConfigServerImpl config, Struct root, boolean isRe
if (!essentialOnly) {
((CFMLEngineImpl) config.getEngine()).touchMonitor(config);
}
log(config, COMPONENT_EXTENSION);
config.setLoadTime(System.currentTimeMillis());
}

Expand Down Expand Up @@ -2131,55 +2127,38 @@ private static Object toKey(Mapping m) {
* @throws TagLibException
* @throws FunctionLibException
*/
private static void _loadFilesystem(ConfigServerImpl config, Struct root, boolean doNew) {
public static void loadTag(ConfigImpl config, Struct root, boolean doNew) {
try {
Resource configDir = config.getConfigDir();

String strDefaultFLDDirectory = null;
String strDefaultTLDDirectory = null;
String strDefaultFuncDirectory = null;
String strDefaultTagDirectory = null;
String strFuncDirectory = null;
String strTagDirectory = null;

// only read in server context
strDefaultFLDDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.fld", null);
strDefaultTLDDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.tld", null);
strDefaultFuncDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.function", null);
strDefaultTagDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.tag", null);
if (StringUtil.isEmpty(strDefaultFLDDirectory)) strDefaultFLDDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.default.fld", null);
if (StringUtil.isEmpty(strDefaultTLDDirectory)) strDefaultTLDDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.default.tld", null);
if (StringUtil.isEmpty(strDefaultFuncDirectory)) strDefaultFuncDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.default.function", null);
if (StringUtil.isEmpty(strDefaultTagDirectory)) strDefaultTagDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.default.tag", null);
strFuncDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.additional.function", null);
strTagDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.additional.tag", null);

Struct fileSystem = ConfigUtil.getAsStruct("fileSystem", root);

// get library directories
if (fileSystem != null) {
if (StringUtil.isEmpty(strDefaultTLDDirectory)) strDefaultTLDDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "tldDirectory"));
if (StringUtil.isEmpty(strDefaultFLDDirectory)) strDefaultFLDDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "flddirectory"));
if (StringUtil.isEmpty(strDefaultTagDirectory)) strDefaultTagDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "tagDirectory"));
if (StringUtil.isEmpty(strDefaultFuncDirectory)) strDefaultFuncDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "functionDirectory"));
if (StringUtil.isEmpty(strDefaultTLDDirectory)) strDefaultTLDDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "tldDefaultDirectory"));
if (StringUtil.isEmpty(strDefaultFLDDirectory)) strDefaultFLDDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "fldDefaultDirectory"));
if (StringUtil.isEmpty(strDefaultTagDirectory)) strDefaultTagDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "tagDefaultDirectory"));
if (StringUtil.isEmpty(strDefaultFuncDirectory)) strDefaultFuncDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "functionDefaultDirectory"));
if (StringUtil.isEmpty(strTagDirectory)) strTagDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "tagAddionalDirectory"));
if (StringUtil.isEmpty(strFuncDirectory)) strFuncDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "functionAddionalDirectory"));
}

// set default directories if necessary
if (StringUtil.isEmpty(strDefaultFLDDirectory)) strDefaultFLDDirectory = "{lucee-config}/library/fld/";
if (StringUtil.isEmpty(strDefaultTLDDirectory)) strDefaultTLDDirectory = "{lucee-config}/library/tld/";
if (StringUtil.isEmpty(strDefaultFuncDirectory)) strDefaultFuncDirectory = "{lucee-config}/library/function/";
if (StringUtil.isEmpty(strDefaultTagDirectory)) strDefaultTagDirectory = "{lucee-config}/library/tag/";

// init TLDS
{
ConfigServerImpl cs = config;
config.setTLDs(ConfigUtil.duplicate(new TagLib[] { cs.coreTLDs }, false));
config.setTLDs(ConfigUtil.duplicate(new TagLib[] { ConfigUtil.getConfigServerImpl(config).coreTLDs }, false));
}

// TLD Dir
Expand Down Expand Up @@ -2216,13 +2195,46 @@ private static void _loadFilesystem(ConfigServerImpl config, Struct root, boolea
}
}
config.setTagDirectory(listTags);
}
catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
log(config, t);
}
}

public static void loadFunctions(ConfigImpl config, Struct root, boolean doNew) {
try {
Resource configDir = config.getConfigDir();

// FUNCTIONS
String strDefaultFLDDirectory = null;
String strDefaultFuncDirectory = null;
String strFuncDirectory = null;

// only read in server context
strDefaultFLDDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.fld", null);
strDefaultFuncDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.function", null);
if (StringUtil.isEmpty(strDefaultFLDDirectory)) strDefaultFLDDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.default.fld", null);
if (StringUtil.isEmpty(strDefaultFuncDirectory)) strDefaultFuncDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.default.function", null);
strFuncDirectory = SystemUtil.getSystemPropOrEnvVar("lucee.library.additional.function", null);

Struct fileSystem = ConfigUtil.getAsStruct("fileSystem", root);

// get library directories
if (fileSystem != null) {
if (StringUtil.isEmpty(strDefaultFLDDirectory)) strDefaultFLDDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "flddirectory"));
if (StringUtil.isEmpty(strDefaultFuncDirectory)) strDefaultFuncDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "functionDirectory"));
if (StringUtil.isEmpty(strDefaultFLDDirectory)) strDefaultFLDDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "fldDefaultDirectory"));
if (StringUtil.isEmpty(strDefaultFuncDirectory)) strDefaultFuncDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "functionDefaultDirectory"));
if (StringUtil.isEmpty(strFuncDirectory)) strFuncDirectory = ConfigUtil.translateOldPath(getAttr(fileSystem, "functionAddionalDirectory"));
}

// set default directories if necessary
if (StringUtil.isEmpty(strDefaultFLDDirectory)) strDefaultFLDDirectory = "{lucee-config}/library/fld/";
if (StringUtil.isEmpty(strDefaultFuncDirectory)) strDefaultFuncDirectory = "{lucee-config}/library/function/";

// Init flds
{
ConfigServerImpl cs = config;
config.setFLDs(cs.coreFLDs.duplicate(false));
config.setFLDs(ConfigUtil.getConfigServerImpl(config).coreFLDs.duplicate(false));

}

Expand Down
45 changes: 43 additions & 2 deletions core/src/main/java/lucee/runtime/config/ConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,28 @@ public ConfigImpl resetScopeCascadingType() {
*/
@Override
public TagLib[] getTLDs() {
if (cfmlTlds == null) {
synchronized (SystemUtil.createToken("ConfigImpl", "getTLDs")) {
if (cfmlTlds == null) {
ConfigFactoryImpl.loadTag(this, root, newVersion());
}
}
}
return cfmlTlds;
}

public ConfigImpl resetTLDs() {
if (cfmlTlds != null) {
synchronized (SystemUtil.createToken("ConfigImpl", "getTLDs")) {
if (cfmlTlds != null) {
cfmlTlds = null;
tldFile = null;
}
}
}
return this;
}

@Override
public TagLib getCoreTagLib() {
TagLib[] tlds = getTLDs();
Expand Down Expand Up @@ -1688,7 +1707,7 @@ public void setPassword(Password password) {
this.password = password;
}

protected void addTag(String nameSpace, String nameSpaceSeperator, String name, ClassDefinition cd) {
protected void addTagXXX(String nameSpace, String nameSpaceSeperator, String name, ClassDefinition cd) {

TagLib[] tlds = cfmlTlds;
for (int i = 0; i < tlds.length; i++) {
Expand Down Expand Up @@ -1944,13 +1963,32 @@ protected void setFLDs(FunctionLib flds) {
*/
@Override
public FunctionLib getFLDs() {
if (cfmlFlds == null) {
synchronized (SystemUtil.createToken("ConfigImpl", "getFLDs")) {
if (cfmlFlds == null) {
ConfigFactoryImpl.loadFunctions(this, root, newVersion());
}
}
}
return cfmlFlds;
}

public ConfigImpl resetFLDs() {
if (cfmlFlds != null) {
synchronized (SystemUtil.createToken("ConfigImpl", "getFLDs")) {
if (cfmlFlds != null) {
cfmlFlds = null;
fldFile = null;
}
}
}
return this;
}

@Override
@Deprecated
public FunctionLib[] getFLDs(int dialect) { // used in the image extension
return new FunctionLib[] { cfmlFlds };
return new FunctionLib[] { getFLDs() };
}

protected void setFldFile(Resource fileFld) throws FunctionLibException {
Expand Down Expand Up @@ -1982,6 +2020,8 @@ protected void setFldFile(Resource fileFld) throws FunctionLibException {

@Override
public Resource getFldFile() {
getFLDs(); // will trigger the load of this variable

return fldFile;
}

Expand Down Expand Up @@ -2770,6 +2810,7 @@ public ConfigImpl resetResourceCharSet() {// = SystemUtil.getCharSet()

@Override
public Resource getTldFile() {
getTLDs();
return tldFile;
}

Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/lucee/runtime/tag/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4711,6 +4711,7 @@ private void doUpdateFilesystem() throws PageException {
throw Caster.toPageException(e);
}
store();
ConfigUtil.getConfigServerImpl(config).resetTLDs().resetFLDs();
((ConfigWebPro) pageContext.getConfig()).resetServerFunctionMappings();
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/tag/TagUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ else if (value instanceof Map) {
* @param cs
* @param config
*/
public static void addTagMetaData(ConfigWebPro cw, lucee.commons.io.log.Log log) {
public static void addTagMetaData(ConfigWebPro cw) {

PageContextImpl pc = null;
try {
Expand All @@ -260,7 +260,7 @@ public static void addTagMetaData(ConfigWebPro cw, lucee.commons.io.log.Log log)

}
catch (Exception e) {
LogUtil.log(cw, log, "tag", e);
LogUtil.log(cw, "tag", e);
}
finally {
pc.getConfig().getFactory().releaseLuceePageContext(pc, true);
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="7.0.0.60-SNAPSHOT"/>
<property name="version" value="7.0.0.61-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>7.0.0.60-SNAPSHOT</version>
<version>7.0.0.61-SNAPSHOT</version>
<packaging>jar</packaging>

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

0 comments on commit 211fdf5

Please sign in to comment.