Skip to content

Commit

Permalink
make sure only instance of PageSource is loaded to avoid compiling co…
Browse files Browse the repository at this point in the history
…nflicts
  • Loading branch information
michaeloffner committed Dec 6, 2024
1 parent fb6d998 commit 2272986
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 60 deletions.
30 changes: 23 additions & 7 deletions core/src/main/java/lucee/runtime/MappingImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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!
Expand Down
79 changes: 28 additions & 51 deletions core/src/main/java/lucee/runtime/PageSourceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
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.2.0.182-SNAPSHOT"/>
<property name="version" value="6.2.0.183-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.2.0.182-SNAPSHOT</version>
<version>6.2.0.183-SNAPSHOT</version>
<packaging>jar</packaging>

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

0 comments on commit 2272986

Please sign in to comment.