Skip to content

Commit

Permalink
LDEV-4965 - initial version, need refinement (exception handling, log…
Browse files Browse the repository at this point in the history
…ging ans classloader structure)
  • Loading branch information
michaeloffner committed Jul 17, 2024
1 parent 6672502 commit 7b5a3c2
Show file tree
Hide file tree
Showing 18 changed files with 348 additions and 83 deletions.
18 changes: 18 additions & 0 deletions core/src/main/java/lucee/commons/io/res/util/MavenClassLoader.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lucee.commons.io.res.util;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -9,9 +10,11 @@
public class MavenClassLoader extends ResourceClassLoader {

private static Map<String, MavenClassLoader> instances = new ConcurrentHashMap<>();
private POM pom;

public MavenClassLoader(POM pom, ClassLoader parent) throws IOException {
super(pom.getJars(), parent);
this.pom = pom;
}

public static MavenClassLoader getInstance(POM pom, ClassLoader parent) throws IOException {
Expand All @@ -22,4 +25,19 @@ public static MavenClassLoader getInstance(POM pom, ClassLoader parent) throws I
}
return mcl;
}

public static MavenClassLoader getInstance(POM[] poms, ClassLoader parent) throws IOException {
if (poms == null || poms.length == 0) throw new IOException("you need to define at least one POM.");

Arrays.sort(poms, (pom1, pom2) -> pom1.id().compareTo(pom2.id()));

for (POM pom: poms) {
parent = getInstance(pom, parent);
}
return (MavenClassLoader) parent;
}

public POM getPOM() {
return pom;
}
}
21 changes: 4 additions & 17 deletions core/src/main/java/lucee/runtime/PageContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@
import lucee.commons.io.log.Log;
import lucee.commons.io.log.LogUtil;
import lucee.commons.io.res.Resource;
import lucee.commons.io.res.util.ResourceClassLoader;
import lucee.commons.lang.ClassException;
import lucee.commons.lang.ClassUtil;
import lucee.commons.lang.ExceptionUtil;
import lucee.commons.lang.HTMLEntities;
import lucee.commons.lang.PhysicalClassLoader;
import lucee.commons.lang.StringUtil;
import lucee.commons.lang.mimetype.MimeType;
import lucee.commons.lang.types.RefBoolean;
Expand Down Expand Up @@ -3832,21 +3830,13 @@ public ORMSession getORMSession(boolean create) throws PageException {
}

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

public ClassLoader getClassLoader(Resource[] reses) throws IOException {

ResourceClassLoader rcl = getResourceClassLoader();
return rcl.getCustomResourceClassLoader(reses);
}

private ResourceClassLoader getResourceClassLoader() throws IOException {
JavaSettingsImpl js = (JavaSettingsImpl) getApplicationContext().getJavaSettings();

if (js != null) {
Resource[] jars = js.getResourcesTranslated();
if (jars.length > 0) return config.getResourceClassLoader().getCustomResourceClassLoader(jars);
return js.getResourceClassLoader(reses);
}
return config.getResourceClassLoader();
}
Expand All @@ -3856,12 +3846,9 @@ public ClassLoader getRPCClassLoader(boolean reload) throws IOException {
}

public ClassLoader getRPCClassLoader(boolean reload, ClassLoader[] parents) throws IOException {
ClassLoader cl = ((ConfigPro) config).getRPCClassLoader(reload, parents);
JavaSettingsImpl js = (JavaSettingsImpl) getApplicationContext().getJavaSettings();
ClassLoader cl = config.getRPCClassLoader(reload, parents);
if (js != null) {
Resource[] jars = js.getResourcesTranslated();
if (jars.length > 0) return ((PhysicalClassLoader) cl).getCustomClassLoader(jars, reload);
}
if (js != null) cl = js.getRPCClassLoader(cl, reload);
return cl;
}

Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/lucee/runtime/config/ConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
import lucee.runtime.listener.AppListenerUtil;
import lucee.runtime.listener.ApplicationContext;
import lucee.runtime.listener.ApplicationListener;
import lucee.runtime.listener.JavaSettings;
import lucee.runtime.net.mail.Server;
import lucee.runtime.net.proxy.ProxyData;
import lucee.runtime.net.proxy.ProxyDataImpl;
Expand Down Expand Up @@ -170,6 +171,7 @@ public abstract class ConfigImpl extends ConfigBase implements ConfigPro {

// FUTURE add to interface
public static final short ADMINMODE_SINGLE = 1;

public static final short ADMINMODE_MULTI = 2;
public static final short ADMINMODE_AUTO = 4;

Expand Down Expand Up @@ -435,6 +437,8 @@ public abstract class ConfigImpl extends ConfigBase implements ConfigPro {

private boolean showTest;

private Map<String, JavaSettings> javaSettingsInstances = new ConcurrentHashMap<>();

/**
* @return the allowURLRequestTimeout
*/
Expand Down Expand Up @@ -3987,4 +3991,15 @@ public int getReturnFormat() {
protected void setReturnFormat(int returnFormat) {
this.returnFormat = returnFormat;
}

@Override
public JavaSettings getJavaSettings(String id) {
return javaSettingsInstances.get(id);
}

@Override
public void setJavaSettings(String id, JavaSettings js) {
javaSettingsInstances.put(id, js);
}

}
7 changes: 7 additions & 0 deletions core/src/main/java/lucee/runtime/config/ConfigPro.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import lucee.runtime.extension.ExtensionDefintion;
import lucee.runtime.extension.RHExtension;
import lucee.runtime.extension.RHExtensionProvider;
import lucee.runtime.listener.JavaSettings;
import lucee.runtime.orm.ORMConfiguration;
import lucee.runtime.orm.ORMEngine;
import lucee.runtime.osgi.OSGiUtil.BundleDefinition;
Expand Down Expand Up @@ -386,4 +387,10 @@ public Resource[] getResources(PageContext pc, Mapping[] mappings, String realPa
public boolean getShowMetric();

public boolean getShowTest();

public JavaSettings getJavaSettings(String id);

public void setJavaSettings(String id, JavaSettings js);

public Resource getMavenDir();
}
51 changes: 34 additions & 17 deletions core/src/main/java/lucee/runtime/config/ConfigServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import lucee.commons.io.res.Resource;
import lucee.commons.io.res.ResourcesImpl;
import lucee.commons.io.res.filter.ExtensionResourceFilter;
import lucee.commons.io.res.util.ResourceUtil;
import lucee.commons.lang.ClassUtil;
import lucee.commons.lang.ExceptionUtil;
import lucee.commons.lang.StringUtil;
Expand Down Expand Up @@ -127,6 +128,25 @@ public final class ConfigServerImpl extends ConfigImpl implements ConfigServer {

private final UpdateInfo updateInfo;

private IdentificationServer id;

private String libHash;

private ClassDefinition<AMFEngine> amfEngineCD;

private Map<String, String> amfEngineArgs;

private List<ExtensionDefintion> localExtensions;

private long localExtHash;
private int localExtSize = -1;

private GatewayMap gatewayEntries;

private short adminMode = ADMINMODE_SINGLE;

private Resource mvnDir;

/**
* @param engine
* @param srvConfig
Expand Down Expand Up @@ -632,23 +652,6 @@ public boolean allowRequestTimeout() {
return engine.allowRequestTimeout();
}

private IdentificationServer id;

private String libHash;

private ClassDefinition<AMFEngine> amfEngineCD;

private Map<String, String> amfEngineArgs;

private List<ExtensionDefintion> localExtensions;

private long localExtHash;
private int localExtSize = -1;

private GatewayMap gatewayEntries;

private short adminMode = ADMINMODE_SINGLE;

public String[] getAuthenticationKeys() {
return authKeys == null ? new String[0] : authKeys;
}
Expand Down Expand Up @@ -873,4 +876,18 @@ public void setAdminMode(short adminMode) {
public short getAdminMode() {
return adminMode;
}

@Override
public Resource getMavenDir() {
if (mvnDir == null) {
synchronized (this) {
if (mvnDir == null) {
mvnDir = ResourceUtil.getCanonicalResourceEL(getConfigDir().getRealResource("../mvn/"));

mvnDir.mkdirs();
}
}
}
return mvnDir;
}
}
16 changes: 16 additions & 0 deletions core/src/main/java/lucee/runtime/config/ConfigWebImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lucee.commons.lang.PhysicalClassLoader;
import lucee.runtime.config.gateway.GatewayMap;
import lucee.runtime.exp.PageException;
import lucee.runtime.listener.JavaSettings;
import lucee.runtime.writer.CFMLWriter;

public class ConfigWebImpl implements ConfigWebPro {
Expand Down Expand Up @@ -1921,4 +1922,19 @@ public boolean getFormUrlAsStruct() {
public int getReturnFormat() {
return instance.getReturnFormat();
}

@Override
public JavaSettings getJavaSettings(String id) {
return instance.getJavaSettings(id);
}

@Override
public void setJavaSettings(String id, JavaSettings js) {
instance.setJavaSettings(id, js);
}

@Override
public Resource getMavenDir() {
return instance.getMavenDir();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -610,4 +610,9 @@ public Resource getWebConfigDir() {
public ServletConfig getServletConfig() {
return config;
}

@Override
public Resource getMavenDir() {
return configServer.getMavenDir();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import lucee.runtime.extension.RHExtensionProvider;
import lucee.runtime.gateway.GatewayEngine;
import lucee.runtime.listener.ApplicationListener;
import lucee.runtime.listener.JavaSettings;
import lucee.runtime.lock.LockManager;
import lucee.runtime.monitor.ActionMonitor;
import lucee.runtime.monitor.ActionMonitorCollector;
Expand Down Expand Up @@ -2101,4 +2102,18 @@ public int getReturnFormat() {
return cs.getReturnFormat();
}

@Override
public JavaSettings getJavaSettings(String id) {
return cs.getJavaSettings(id);
}

@Override
public void setJavaSettings(String id, JavaSettings js) {
cs.setJavaSettings(id, js);
}

@Override
public Resource getMavenDir() {
return cs.getMavenDir();
}
}
36 changes: 27 additions & 9 deletions core/src/main/java/lucee/runtime/dump/DumpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package lucee.runtime.dump;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -48,6 +49,7 @@

import lucee.commons.date.TimeZoneUtil;
import lucee.commons.io.res.Resource;
import lucee.commons.io.res.util.MavenClassLoader;
import lucee.commons.lang.CharSet;
import lucee.commons.lang.ExceptionUtil;
import lucee.commons.lang.IDGenerator;
Expand All @@ -60,6 +62,7 @@
import lucee.runtime.functions.international.GetTimeZoneInfo;
import lucee.runtime.functions.system.BundleInfo;
import lucee.runtime.i18n.LocaleFactory;
import lucee.runtime.mvn.POM;
import lucee.runtime.op.Caster;
import lucee.runtime.op.Decision;
import lucee.runtime.osgi.BundleRange;
Expand All @@ -72,11 +75,9 @@
import lucee.runtime.type.Pojo;
import lucee.runtime.type.QueryImpl;
import lucee.runtime.type.Struct;
import lucee.runtime.type.StructImpl;
import lucee.runtime.type.UDF;
import lucee.runtime.type.dt.DateTimeImpl;
import lucee.runtime.type.scope.CookieImpl;
import lucee.runtime.type.util.KeyConstants;
import lucee.runtime.type.util.UDFUtil;

public class DumpUtil {
Expand Down Expand Up @@ -643,14 +644,8 @@ public static DumpData toDumpData(Object o, PageContext pageContext, int maxleve
BundleClassLoader bcl = (BundleClassLoader) cl;
Bundle b = bcl.getBundle();
if (b != null) {
Struct sct = new StructImpl();
sct.setEL(KeyConstants._id, b.getBundleId());
sct.setEL(KeyConstants._name, b.getSymbolicName());
sct.setEL(KeyConstants._location, b.getLocation());
sct.setEL(KeyConstants._version, b.getVersion().toString());

DumpTable bd = new DumpTable("#d6ccc2", "#f5ebe0", "#000000");
bd.setTitle("Bundle Info");
bd.setTitle("OSGi Bundle Info");
bd.appendRow(0, new SimpleDumpData("id: " + b.getBundleId()));
bd.appendRow(0, new SimpleDumpData("symbolic-name: " + b.getSymbolicName()));
bd.appendRow(0, new SimpleDumpData("version: " + b.getVersion().toString()));
Expand All @@ -663,6 +658,29 @@ public static DumpData toDumpData(Object o, PageContext pageContext, int maxleve
}
}

// Maven Info
if (cl instanceof MavenClassLoader) {
try {
MavenClassLoader mcl = (MavenClassLoader) cl;
POM pom = mcl.getPOM();
if (pom != null) {
DumpTable bd = new DumpTable("#d6ccc2", "#f5ebe0", "#000000");
bd.setTitle("Maven Info");
bd.appendRow(0, new SimpleDumpData("groupId: " + pom.getGroupId()));
bd.appendRow(0, new SimpleDumpData("artifactId: " + pom.getArtifactId()));
bd.appendRow(0, new SimpleDumpData("version: " + pom.getVersion()));
try {
bd.appendRow(0, new SimpleDumpData("location: " + pom.getArtifact()));
}
catch (IOException e) {
}
table.appendRow(0, bd);
}
}
catch (NoSuchMethodError e) {
}
}

return setId(id, table);
// }
}
Expand Down
Loading

0 comments on commit 7b5a3c2

Please sign in to comment.