Skip to content

Commit

Permalink
add default javasettings and show maven info in GetApplicationSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jul 17, 2024
1 parent e7e322c commit 0425eb6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package lucee.runtime.functions.system;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

Expand Down Expand Up @@ -50,9 +51,11 @@
import lucee.runtime.listener.ApplicationContextSupport;
import lucee.runtime.listener.ClassicApplicationContext;
import lucee.runtime.listener.JavaSettings;
import lucee.runtime.listener.JavaSettingsImpl;
import lucee.runtime.listener.ModernApplicationContext;
import lucee.runtime.listener.SessionCookieData;
import lucee.runtime.listener.SessionCookieDataImpl;
import lucee.runtime.mvn.POM;
import lucee.runtime.net.mail.Server;
import lucee.runtime.net.mail.ServerImpl;
import lucee.runtime.net.proxy.ProxyData;
Expand Down Expand Up @@ -412,6 +415,26 @@ public static Struct call(PageContext pc, boolean suppressFunctions, boolean onl
sb.append(reses[i].getAbsolutePath());
}
jsSct.put("loadCFMLClassPath", sb.toString());

// maven
if (js instanceof JavaSettingsImpl) {
JavaSettingsImpl jsi = (JavaSettingsImpl) js;
List<POM> poms = jsi.getPoms();
if (poms != null) {
Array arr = new ArrayImpl();
Struct s;
for (POM pom: poms) {
s = new StructImpl();
// TODO add more columns
s.set(KeyConstants._groupId, pom.getGroupId());
s.set(KeyConstants._artifactId, pom.getArtifactId());
s.set(KeyConstants._version, pom.getVersion());
arr.append(s);
}
jsSct.put("maven", arr);
}
}

sct.put("javaSettings", jsSct);
// REST Settings
// MUST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ public ClassicApplicationContext(ConfigWeb config, String name, boolean isDefaul
this.source = source;
this.triggerComponentDataMember = config.getTriggerComponentDataMember();
this.restSettings = config.getRestSetting();
this.javaSettings = new JavaSettingsImpl();
this.wstype = WS_TYPE_AXIS1;
cgiScopeReadonly = cp.getCGIScopeReadonly();
this.antiSamyPolicy = ((ConfigPro) config).getAntiSamyPolicy();
Expand Down Expand Up @@ -879,6 +878,7 @@ public Resource[] getRestCFCLocations() {

@Override
public JavaSettings getJavaSettings() {
if (javaSettings == null) javaSettings = ModernApplicationContext.getDefaultJavaSettings(config);
return javaSettings;
}

Expand Down
44 changes: 19 additions & 25 deletions core/src/main/java/lucee/runtime/listener/JavaSettingsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
import lucee.runtime.type.util.ArrayUtil;
import lucee.runtime.type.util.KeyConstants;
import lucee.runtime.type.util.ListUtil;
import lucee.transformer.bytecode.util.SystemExitScanner;

public class JavaSettingsImpl implements JavaSettings {

private static final int DEFAULT_WATCH_INTERVAL = 60;

private List<POM> poms;
private List<BD> osgis;
private final Resource[] resources;
Expand All @@ -67,37 +67,31 @@ public class JavaSettingsImpl implements JavaSettings {
private Map<String, ResourceClassLoader> classLoaders = new ConcurrentHashMap<String, ResourceClassLoader>();
private Config config;

public JavaSettingsImpl() {
this.config = ThreadLocalPageContext.getConfig();
this.resources = new Resource[0];
this.bundles = new Resource[0];
this.loadCFMLClassPath = false;
this.reloadOnChange = false;
this.watchInterval = DEFAULT_WATCH_INTERVAL;
this.watchedExtensions = new String[] { "jar", "class" };
public JavaSettingsImpl(Config config, List<POM> poms, List<BD> osgis, Resource[] resources, Resource[] bundles, Boolean loadCFMLClassPath, boolean reloadOnChange,
int watchInterval, String[] watchedExtensions) {
this.config = config == null ? ThreadLocalPageContext.getConfig() : config;
this.poms = poms;
this.osgis = osgis;
this.resources = resources == null ? new Resource[0] : resources;
this.bundles = bundles == null ? new Resource[0] : bundles;
this.loadCFMLClassPath = Boolean.TRUE.equals(loadCFMLClassPath);
this.reloadOnChange = reloadOnChange;
this.watchInterval = watchInterval;
this.watchedExtensions = watchedExtensions == null ? new String[] { "jar", "class" } : watchedExtensions;

// TODO needed? SystemExitScanner.validate(resources);
}

public boolean hasPoms() {
return poms != null && poms.size() > 0;
}

public boolean hasOSGis() {
return osgis != null && osgis.size() > 0;
public List<POM> getPoms() {
return poms;
}

public JavaSettingsImpl(Config config, List<POM> poms, List<BD> osgis, Resource[] resources, Resource[] bundles, Boolean loadCFMLClassPath, boolean reloadOnChange,
int watchInterval, String[] watchedExtensions) throws PageException {
this.config = config;
this.poms = poms;
this.osgis = osgis;
this.resources = resources;
this.bundles = bundles;
this.loadCFMLClassPath = Boolean.TRUE.equals(loadCFMLClassPath);
this.reloadOnChange = reloadOnChange;
this.watchInterval = watchInterval;
this.watchedExtensions = watchedExtensions;
SystemExitScanner.validate(resources);

public boolean hasOSGis() {
return osgis != null && osgis.size() > 0;
}

public ClassLoader getRPCClassLoader(ClassLoader parent, boolean reload) throws IOException {
Expand Down Expand Up @@ -226,7 +220,7 @@ public String[] watchedExtensions() {
return watchedExtensions;
}

public static JavaSettings getInstance(Config config, Struct sct) throws PageException {
public static JavaSettings getInstance(Config config, Struct sct) {
// TODO faster hash?
String id = HashUtil.create64BitHashAsString(sct.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import lucee.commons.lang.CharSet;
import lucee.commons.lang.ExceptionUtil;
import lucee.commons.lang.Pair;
import lucee.commons.lang.SerializableObject;
import lucee.commons.lang.StringUtil;
import lucee.commons.lang.types.RefBoolean;
import lucee.runtime.Component;
Expand All @@ -54,6 +55,7 @@
import lucee.runtime.component.Member;
import lucee.runtime.config.Config;
import lucee.runtime.config.ConfigPro;
import lucee.runtime.config.ConfigWeb;
import lucee.runtime.config.ConfigWebUtil;
import lucee.runtime.db.ClassDefinition;
import lucee.runtime.db.DataSource;
Expand Down Expand Up @@ -164,6 +166,8 @@ public class ModernApplicationContext extends ApplicationContextSupport {
private static final Key USE_JAVA_AS_REGEX_ENGINE = KeyConstants._useJavaAsRegexEngine;

private static Map<String, CacheConnection> initCacheConnections = new ConcurrentHashMap<String, CacheConnection>();
private static Object token = new SerializableObject();
private static JavaSettings defaultJavaSettings;

private Component component;

Expand Down Expand Up @@ -1802,18 +1806,26 @@ private void initJava() {
if (!initJavaSettings) {
Object o = get(component, JAVA_SETTING, null);
if (o != null && Decision.isStruct(o)) {
try {
javaSettings = JavaSettingsImpl.getInstance(config, Caster.toStruct(o, null));
}
catch (PageException e) {
throw new PageRuntimeException(e);
}

javaSettings = JavaSettingsImpl.getInstance(config, Caster.toStruct(o, null));
}
if (javaSettings == null) {
javaSettings = getDefaultJavaSettings(config);
}
initJavaSettings = true;
}
}

public static JavaSettings getDefaultJavaSettings(ConfigWeb config) {
if (defaultJavaSettings == null) {
synchronized (token) {
if (defaultJavaSettings == null) {
defaultJavaSettings = JavaSettingsImpl.getInstance(config, new StructImpl());
}
}
}
return defaultJavaSettings;
}

@Override
public Map<Collection.Key, Object> getTagAttributeDefaultValues(PageContext pc, String tagClassName) {
if (!initDefaultAttributeValues) {
Expand Down

0 comments on commit 0425eb6

Please sign in to comment.