From 227298629a13d946a0581e3e37c5f49f54b947f4 Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Fri, 6 Dec 2024 20:01:04 +0100 Subject: [PATCH] make sure only instance of PageSource is loaded to avoid compiling conflicts --- .../main/java/lucee/runtime/MappingImpl.java | 30 +++++-- .../java/lucee/runtime/PageSourceImpl.java | 79 +++++++------------ loader/build.xml | 2 +- loader/pom.xml | 2 +- 4 files changed, 53 insertions(+), 60 deletions(-) diff --git a/core/src/main/java/lucee/runtime/MappingImpl.java b/core/src/main/java/lucee/runtime/MappingImpl.java index a9d2a68538..6f97633d48 100755 --- a/core/src/main/java/lucee/runtime/MappingImpl.java +++ b/core/src/main/java/lucee/runtime/MappingImpl.java @@ -34,6 +34,8 @@ import lucee.commons.io.FileUtil; import lucee.commons.io.IOUtil; +import lucee.commons.io.SystemUtil; +import lucee.commons.io.log.Log; import lucee.commons.io.log.LogUtil; import lucee.commons.io.res.Resource; import lucee.commons.lang.ClassUtil; @@ -108,6 +110,8 @@ public final class MappingImpl implements Mapping { private short configInspect; + private Log log; + public MappingImpl(Config config, String virtual, String strPhysical, String strArchive, short inspect, int inspectTemplateAutoIntervalSlow, int inspectTemplateAutoIntervalFast, boolean physicalFirst, boolean hidden, boolean readonly, boolean topLevel, boolean appMapping, boolean ignoreVirtual, ApplicationListener appListener, int listenerMode, int listenerType) { @@ -159,12 +163,17 @@ public MappingImpl(Config config, String virtual, String strPhysical, String str else this.virtual = virtual; this.lcVirtual = this.virtual.toLowerCase(); this.lcVirtualWithSlash = lcVirtual.endsWith("/") ? this.lcVirtual : this.lcVirtual + '/'; + this.log = ThreadLocalPageContext.getLog(config, "application"); } public long getStartTime() { return startTime; } + public Log getLog() { + return log; + } + private void initPhysical() { if (physical == null && strPhysical != null) { synchronized (this) { @@ -466,13 +475,21 @@ else if (realPath.startsWith("./")) { @Override public PageSource getPageSource(String path, boolean isOut) { + if (path.indexOf("//") != -1) { + path = StringUtil.replace(path, "//", "/", false); + } PageSource source = pageSourcePool.getPageSource(path, true); - if (source != null) return source; + if (source == null) { + synchronized (SystemUtil.createToken("MappingImpl", path)) { + source = pageSourcePool.getPageSource(path, true); + if (source == null) { + source = new PageSourceImpl(this, path, isOut); + pageSourcePool.setPage(path, source); - PageSourceImpl newSource = new PageSourceImpl(this, path, isOut); - pageSourcePool.setPage(path, newSource); - - return newSource;// new PageSource(this,path); + } + } + } + return source; } /** @@ -483,8 +500,7 @@ public PageSource getPageSource(String path, boolean isOut) { * @return */ public Resource getResource(String path, boolean isOut) { - // TODO rewrite so PageSourceImpl not need to be loaded - return new PageSourceImpl(this, path, isOut).getResource(); + return getPageSource(path, isOut).getResource(); } // to not delete,used for argus monitor! diff --git a/core/src/main/java/lucee/runtime/PageSourceImpl.java b/core/src/main/java/lucee/runtime/PageSourceImpl.java index 67c39edc99..8b92abdf63 100755 --- a/core/src/main/java/lucee/runtime/PageSourceImpl.java +++ b/core/src/main/java/lucee/runtime/PageSourceImpl.java @@ -94,7 +94,6 @@ public final class PageSourceImpl implements PageSource { private long lastAccess; private RefIntegerSync accessCount = new RefIntegerSync(); private boolean flush = false; - private Log log; private static class PageAndClassName { private Page page; @@ -112,53 +111,11 @@ public void set(Page page) { } - /** - * constructor of the class - * - * @param mapping - * @param realPath - */ - PageSourceImpl(MappingImpl mapping, String realPath, Log log) { - this.mapping = mapping; - this.log = log; - realPath = realPath.replace('\\', '/'); - if (realPath.indexOf("//") != -1) { - realPath = StringUtil.replace(realPath, "//", "/", false); - } - - if (realPath.indexOf('/') != 0) { - if (realPath.startsWith("../")) { - isOutSide = true; - } - else if (realPath.startsWith("./")) { - realPath = realPath.substring(1); - } - else { - realPath = "/" + realPath; - } - } - this.relPath = realPath; - if (logAccessDirectory != null) dump(); - } - - /** - * private constructor of the class - * - * @param mapping - * @param realPath - * @param isOutSide - */ - PageSourceImpl(MappingImpl mapping, String realPath, boolean isOutSide) { - // recompileAlways=mapping.getConfig().getCompileType()==Config.RECOMPILE_ALWAYS; - // recompileAfterStartUp=mapping.getConfig().getCompileType()==Config.RECOMPILE_AFTER_STARTUP || - // recompileAlways; + PageSourceImpl(MappingImpl mapping, String relPath, boolean isOutSide) { this.mapping = mapping; this.isOutSide = isOutSide; - if (realPath.indexOf("//") != -1) { - realPath = StringUtil.replace(realPath, "//", "/", false); - } - this.relPath = realPath; - if (logAccessDirectory != null) dump(); + this.relPath = relPath; + // if (logAccessDirectory != null) dump(); } private void dump() { @@ -207,8 +164,28 @@ public Page getPage() { public PageSource getParent() { if (relPath.equals("/")) return null; - if (StringUtil.endsWith(relPath, '/')) return new PageSourceImpl(mapping, GetDirectoryFromPath.invoke(relPath.substring(0, relPath.length() - 1)), log); - return new PageSourceImpl(mapping, GetDirectoryFromPath.invoke(relPath), log); + if (StringUtil.endsWith(relPath, '/')) return getInstance(mapping, GetDirectoryFromPath.invoke(relPath.substring(0, relPath.length() - 1))); + return getInstance(mapping, GetDirectoryFromPath.invoke(relPath)); + } + + private static PageSource getInstance(MappingImpl mapping, String realPath) { + boolean isOutSide = false; + realPath = realPath.replace('\\', '/'); + if (realPath.indexOf("//") != -1) { + realPath = StringUtil.replace(realPath, "//", "/", false); + } + if (realPath.indexOf('/') != 0) { + if (realPath.startsWith("../")) { + isOutSide = true; + } + else if (realPath.startsWith("./")) { + realPath = realPath.substring(1); + } + else { + realPath = "/" + realPath; + } + } + return mapping.getPageSource(realPath, isOutSide); } @Override @@ -441,7 +418,7 @@ public boolean releaseWhenOutdatted() { synchronized (SystemUtil.createToken("PageSource", getRealpathWithVirtual())) { if (srcLastModified == 0 || srcLastModified != page.getSourceLastModified()) {// || (page instanceof PagePro && ((PagePro) page).getSourceLength() != // srcFile.length()) - if (LogUtil.doesDebug(log)) log.debug("page-source", "release [" + getDisplayPath() + "] from page source pool"); + if (LogUtil.doesDebug(mapping.getLog())) mapping.getLog().debug("page-source", "release [" + getDisplayPath() + "] from page source pool"); resetLoaded(); flush(); return true; @@ -453,7 +430,7 @@ public boolean releaseWhenOutdatted() { } public void flush() { - if (LogUtil.doesDebug(log)) log.debug("page-source", "flush [" + getDisplayPath() + "]"); + if (LogUtil.doesDebug(mapping.getLog())) mapping.getLog().debug("page-source", "flush [" + getDisplayPath() + "]"); pcn.page = null; flush = true; } @@ -1185,7 +1162,7 @@ public boolean executable() { } public void resetLoaded() { - if (LogUtil.doesDebug(log)) log.debug("page-source", "reset loaded [" + getDisplayPath() + "]"); + if (LogUtil.doesDebug(mapping.getLog())) mapping.getLog().debug("page-source", "reset loaded [" + getDisplayPath() + "]"); Page p = pcn.page; if (p != null) p.setLoadType((byte) 0); } diff --git a/loader/build.xml b/loader/build.xml index 06fac8af2a..150731f163 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index 1ad595f3e1..f831215da1 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.2.0.182-SNAPSHOT + 6.2.0.183-SNAPSHOT jar Lucee Loader Build