diff --git a/core/src/main/java/lucee/runtime/config/ConfigAdmin.java b/core/src/main/java/lucee/runtime/config/ConfigAdmin.java index f04bbd17d3..b5b308e5fc 100755 --- a/core/src/main/java/lucee/runtime/config/ConfigAdmin.java +++ b/core/src/main/java/lucee/runtime/config/ConfigAdmin.java @@ -4001,7 +4001,7 @@ public void updateUpdateAdminMode(String mode, boolean merge, boolean keep) thro for (ConfigWeb cw: webs) { try { for (RHExtension ext: ((ConfigPro) cw).getRHExtensions()) { - ext.addToAvailable(); + ext.addToAvailable(cw); } } catch (Exception e) { @@ -4412,7 +4412,7 @@ public void removeRHExtension(String id) throws PageException { if (child == null) continue; try { - rhe = new RHExtension(config, Caster.toString(child.get(KeyConstants._id), null), Caster.toString(child.get(KeyConstants._version), null)); + rhe = RHExtension.getInstance(config, Caster.toString(child.get(KeyConstants._id), null), Caster.toString(child.get(KeyConstants._version), null)); } catch (Throwable t) { ExceptionUtil.rethrowIfNecessary(t); @@ -4571,10 +4571,10 @@ public static RHExtension _updateRHExtension(ConfigPro config, Resource ext, boo public RHExtension updateRHExtension(Config config, Resource ext, boolean reload, boolean force, short action) throws PageException { RHExtension rhext; try { - rhext = new RHExtension(config, ext); - if (RHExtension.ACTION_COPY == action) rhext.copyToInstalled(); - else if (RHExtension.ACTION_MOVE == action) rhext.moveToInstalled(); - rhext.validate(); + rhext = RHExtension.getInstance(config, ext); + if (RHExtension.ACTION_COPY == action) rhext.copyToInstalled(config); + else if (RHExtension.ACTION_MOVE == action) rhext.moveToInstalled(config); + rhext.validate(config); } catch (Throwable t) { ExceptionUtil.rethrowIfNecessary(t); @@ -6370,7 +6370,7 @@ public BundleDefinition[] _updateExtension(ConfigPro config, RHExtension ext) th Resource r; if (!StringUtil.isEmpty(res) && (r = ResourceUtil.toResourceExisting(config, res, null)) != null) { try { - RHExtension _ext = new RHExtension(config, r);// TODO not load it again! + RHExtension _ext = RHExtension.getInstance(config, r);// TODO not load it again! if (_ext != null && _ext.getId().equalsIgnoreCase(ext.getId())) { old = RHExtension.toBundleDefinitions(ConfigWebUtil.getAsString("bundles", el, null)); // get existing bundles before populate new ones ext.populate(el, false); @@ -6426,7 +6426,7 @@ private RHExtension getRHExtension(final ConfigPro config, final String id, fina if (!id.equals(_id)) continue; try { - return new RHExtension(config, _id, Caster.toString(tmp.get(KeyConstants._version), null)); + return RHExtension.getInstance(config, _id, Caster.toString(tmp.get(KeyConstants._version), null)); } catch (Exception e) { return defaultValue; @@ -6465,7 +6465,7 @@ private RHExtension _hasRHExtensionInstalled(ConfigPro config, ExtensionDefintio v = Caster.toString(sct.get(KeyConstants._version, null), null); if (!RHExtension.isInstalled(config, id, v)) continue; - if (ed.equals(new ExtensionDefintion(id, v))) return new RHExtension(config, id, v); + if (ed.equals(new ExtensionDefintion(id, v))) return RHExtension.getInstance(config, id, v); } return null; } diff --git a/core/src/main/java/lucee/runtime/config/ConfigServerImpl.java b/core/src/main/java/lucee/runtime/config/ConfigServerImpl.java index d6951d1db9..332400a158 100644 --- a/core/src/main/java/lucee/runtime/config/ConfigServerImpl.java +++ b/core/src/main/java/lucee/runtime/config/ConfigServerImpl.java @@ -808,7 +808,7 @@ public List loadLocalExtensions(boolean validate) { } if (ed == null) { try { - ext = new RHExtension(this, locReses[i]); + ext = RHExtension.getInstance(this, locReses[i]); ed = new ExtensionDefintion(ext.getId(), ext.getVersion()); ed.setSource(ext); diff --git a/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java b/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java index b452e7fdaf..9c41e88269 100644 --- a/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java +++ b/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java @@ -4982,7 +4982,7 @@ private static void _loadExtensionBundles(ConfigServerImpl cs, ConfigImpl config if (!installedFiles.contains(r)) { // is maybe a diff version installed? - RHExtension ext = new RHExtension(config, r); + RHExtension ext = RHExtension.getInstance(config, r); if (!installedIds.contains(ext.getId())) { if (log != null) log.info("extension", "Found the extension [" + ext + "] in the installed folder that is not present in the configuration in any version, so we will uninstall it"); diff --git a/core/src/main/java/lucee/runtime/engine/CFMLEngineImpl.java b/core/src/main/java/lucee/runtime/engine/CFMLEngineImpl.java index bcefd86e24..15c4a24167 100644 --- a/core/src/main/java/lucee/runtime/engine/CFMLEngineImpl.java +++ b/core/src/main/java/lucee/runtime/engine/CFMLEngineImpl.java @@ -628,8 +628,8 @@ private int deployBundledExtension(ConfigServerImpl cs, boolean validate) { log.info("extract-extension", "Copy extension [" + name + "] to temp directory [" + temp + "]"); ResourceUtil.touch(temp); Util.copy(is, temp.getOutputStream(), false, true); - rhe = new RHExtension(cs, temp); - rhe.validate(); + rhe = RHExtension.getInstance(cs, temp); + rhe.validate(cs); ExtensionDefintion alreadyExists = null; it = existing.iterator(); while (it.hasNext()) { diff --git a/core/src/main/java/lucee/runtime/extension/ExtensionDefintion.java b/core/src/main/java/lucee/runtime/extension/ExtensionDefintion.java index 0307f0cdbe..f838a8ac3a 100644 --- a/core/src/main/java/lucee/runtime/extension/ExtensionDefintion.java +++ b/core/src/main/java/lucee/runtime/extension/ExtensionDefintion.java @@ -134,7 +134,7 @@ public RHExtension toRHExtension() throws PageException, IOException, BundleExce // MUST try to load the Extension throw new ApplicationException("ExtensionDefinition does not contain the necessary data to create the requested object."); } - rhe = new RHExtension(config, source); + rhe = RHExtension.getInstance(config, source); return rhe; } diff --git a/core/src/main/java/lucee/runtime/extension/RHExtension.java b/core/src/main/java/lucee/runtime/extension/RHExtension.java index 4ef21c570e..20894eceba 100644 --- a/core/src/main/java/lucee/runtime/extension/RHExtension.java +++ b/core/src/main/java/lucee/runtime/extension/RHExtension.java @@ -34,6 +34,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.jar.Attributes; import java.util.jar.Manifest; import java.util.zip.ZipEntry; @@ -200,24 +201,45 @@ public class RHExtension implements Serializable { private boolean loaded; - private final Config config; + // private final Config config; public boolean softLoaded = false; - public RHExtension(Config config, Resource ext) throws PageException, IOException, BundleException, ConverterException { - this.config = config; - init(ext); + private static Map instances = new ConcurrentHashMap<>(); + + public static RHExtension getInstance(Config config, Resource ext) throws PageException, IOException, BundleException, ConverterException { + RHExtension instance = instances.get(ext.getAbsolutePath()); + if (instance == null) { + instance = new RHExtension(config, ext); + instances.put(instance.getId() + ":" + instance.getVersion(), instance); + instances.put(ext.getAbsolutePath(), instance); + } + return instance; + } + + private RHExtension(Config config, Resource ext) throws PageException, IOException, BundleException, ConverterException { + init(config, ext); + } + + public static RHExtension getInstance(Config config, String id, String version) throws PageException, IOException, BundleException, ConverterException { + RHExtension instance = instances.get(id + ":" + version); + if (instance == null) { + instance = new RHExtension(config, id, version); + instances.put(instance.getId() + ":" + instance.getVersion(), instance); + instances.put(instance.extensionFile.getAbsolutePath(), instance); + } + return instance; } - public RHExtension(Config config, String id, String version) throws PageException, IOException, BundleException, ConverterException { - this.config = config; + private RHExtension(Config config, String id, String version) throws PageException, IOException, BundleException, ConverterException { + // this.config = config; Struct data = getMetaData(config, id, version, (Struct) null); this.extensionFile = getExtensionInstalledFile(config, id, version, false); // do we have usefull meta data? if (data != null && data.containsKey("startBundles")) { try { - readManifestConfig(id, data, extensionFile.getAbsolutePath(), null); + readManifestConfig(config, id, data, extensionFile.getAbsolutePath(), null); softLoaded = true; return; } @@ -228,18 +250,18 @@ public RHExtension(Config config, String id, String version) throws PageExceptio } } - init(this.extensionFile); + init(config, this.extensionFile); softLoaded = false; } - private void init(Resource ext) throws PageException, IOException, BundleException, ConverterException { + private void init(Config config, Resource ext) throws PageException, IOException, BundleException, ConverterException { // make sure the config is registerd with the thread if (ThreadLocalPageContext.getConfig() == null) ThreadLocalConfig.register(config); // is it a web or server context? this.type = config instanceof ConfigWeb ? "web" : "server"; this.extensionFile = ext; - load(ext); + load(config, ext); // write metadata to XML Resource mdf = getMetaDataFile(config, id, version); if (!metadataFilesChecked.contains(mdf.getAbsolutePath()) && !mdf.isFile()) { @@ -289,12 +311,12 @@ public static boolean isInstalled(Config config, String id, String version) thro * @throws ConverterException * @throws IOException */ - public Resource copyToInstalled() throws PageException, ConverterException, IOException { + public Resource copyToInstalled(Config config) throws PageException, ConverterException, IOException { if (extensionFile == null) throw new IOException("no extension file defined"); if (!extensionFile.isFile()) throw new IOException("given extension file [" + extensionFile + "] does not exist"); - addToAvailable(extensionFile); - return act(extensionFile, RHExtension.ACTION_COPY); + addToAvailable(config, extensionFile); + return act(config, extensionFile, RHExtension.ACTION_COPY); } /** @@ -306,12 +328,12 @@ public Resource copyToInstalled() throws PageException, ConverterException, IOEx * @throws ConverterException * @throws IOException */ - public Resource moveToInstalled() throws PageException, ConverterException, IOException { + public Resource moveToInstalled(Config config) throws PageException, ConverterException, IOException { if (extensionFile == null) throw new IOException("no extension file defined"); if (!extensionFile.isFile()) throw new IOException("given extension file [" + extensionFile + "] does not exist"); - addToAvailable(extensionFile); - return act(extensionFile, RHExtension.ACTION_MOVE); + addToAvailable(config, extensionFile); + return act(config, extensionFile, RHExtension.ACTION_MOVE); } public static void storeMetaData(Config config, String id, String version, Struct data) throws ConverterException, IOException { @@ -327,7 +349,7 @@ private static void storeMetaData(Resource file, Struct data) throws ConverterEx } // copy the file to extension dir if it is not already there - private Resource act(Resource ext, short action) throws PageException { + private Resource act(Config config, Resource ext, short action) throws PageException { Resource trg; Resource trgDir; try { @@ -351,14 +373,14 @@ else if (action == ACTION_MOVE) { return trg; } - public void addToAvailable() { - addToAvailable(getExtensionFile()); + public void addToAvailable(Config config) { + addToAvailable(config, getExtensionFile()); } - private void addToAvailable(Resource ext) { + private void addToAvailable(Config config, Resource ext) { if (id == null) { try { - load(ext); + load(config, ext); } catch (Exception e) { LogUtil.log("deploy", "extension", e); @@ -423,7 +445,7 @@ public static Manifest getManifestFromFile(Config config, Resource file) throws } - private void load(Resource ext) throws IOException, BundleException, ApplicationException { + private void load(Config config, Resource ext) throws IOException, BundleException, ApplicationException { // print.ds(ext.getAbsolutePath()); loaded = true; // no we read the content of the zip @@ -524,7 +546,7 @@ else if (!entry.isDirectory() && (startsWith(path, type, "web.applications") || // read the manifest if (manifest == null) throw new ApplicationException("The Extension [" + ext + "] is invalid,no Manifest file was found at [META-INF/MANIFEST.MF]."); - readManifestConfig(manifest, ext.getAbsolutePath(), _img); + readManifestConfig(config, manifest, ext.getAbsolutePath(), _img); this.jars = jars.toArray(new String[jars.size()]); this.flds = flds.toArray(new String[flds.size()]); @@ -544,7 +566,7 @@ else if (!entry.isDirectory() && (startsWith(path, type, "web.applications") || } - private void readManifestConfig(Manifest manifest, String label, String _img) throws ApplicationException { + private void readManifestConfig(Config config, Manifest manifest, String label, String _img) throws ApplicationException { boolean isWeb = config instanceof ConfigWeb; type = isWeb ? "web" : "server"; Log logger = ThreadLocalPageContext.getLog(config, "deploy"); @@ -558,7 +580,7 @@ private void readManifestConfig(Manifest manifest, String label, String _img) th readVersion(label, StringUtil.unwrap(attr.getValue("version"))); label += " : " + version; readId(label, StringUtil.unwrap(attr.getValue("id"))); - readReleaseType(label, StringUtil.unwrap(attr.getValue("release-type")), isWeb); + readReleaseType(config, label, StringUtil.unwrap(attr.getValue("release-type")), isWeb); description = StringUtil.unwrap(attr.getValue("description")); trial = Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("trial")), false); if (_img == null) _img = StringUtil.unwrap(attr.getValue("image")); @@ -584,7 +606,7 @@ private void readManifestConfig(Manifest manifest, String label, String _img) th readEventGatewayInstances(label, StringUtil.unwrap(attr.getValue("event-gateway-instance")), logger); } - private void readManifestConfig(String id, Struct data, String label, String _img) throws ApplicationException { + private void readManifestConfig(Config config, String id, Struct data, String label, String _img) throws ApplicationException { boolean isWeb = config instanceof ConfigWeb; type = isWeb ? "web" : "server"; @@ -597,7 +619,7 @@ private void readManifestConfig(String id, Struct data, String label, String _im readVersion(label, ConfigWebFactory.getAttr(data, "version")); label += " : " + version; readId(label, StringUtil.isEmpty(id) ? ConfigWebFactory.getAttr(data, "id") : id); - readReleaseType(label, ConfigWebFactory.getAttr(data, "releaseType", "release-type"), isWeb); + readReleaseType(config, label, ConfigWebFactory.getAttr(data, "releaseType", "release-type"), isWeb); description = ConfigWebFactory.getAttr(data, "description"); trial = Caster.toBooleanValue(ConfigWebFactory.getAttr(data, "trial"), false); if (_img == null) _img = ConfigWebFactory.getAttr(data, "image"); @@ -739,7 +761,7 @@ private void readCoreVersion(String label, String str, Info info) { */ } - public void validate() throws ApplicationException { + public void validate(Config config) throws ApplicationException { validate(ConfigWebUtil.getEngine(config).getInfo()); } @@ -772,7 +794,7 @@ private void readCategories(String label, String cat) { else categories = null; } - private void readReleaseType(String label, String str, boolean isWeb) throws ApplicationException { + private void readReleaseType(Config config, String label, String str, boolean isWeb) throws ApplicationException { if (((ConfigPro) ThreadLocalPageContext.getConfig(config)).getAdminMode() == ConfigImpl.ADMINMODE_SINGLE) return; // release type int rt = RELEASE_TYPE_ALL; @@ -1137,7 +1159,7 @@ private static Query createQuery() throws DatabaseException { 0, "Extensions"); } - private void populate(Query qry) throws PageException, IOException, BundleException { + private void populate(Query qry) throws PageException { int row = qry.addRow(); qry.setAt(KeyConstants._id, row, getId()); qry.setAt(KeyConstants._name, row, getName()); @@ -1364,85 +1386,63 @@ public int getReleaseType() { return releaseType; } - public BundleInfo[] getBundles() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public BundleInfo[] getBundles() { return bundles; } public BundleInfo[] getBundles(BundleInfo[] defaultValue) { - if (!loaded) { - try { - load(extensionFile); - } - catch (Exception e) { - return defaultValue; - } - } return bundles; } - public String[] getFlds() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getFlds() { return flds == null ? EMPTY : flds; } - public String[] getJars() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getJars() { return jars == null ? EMPTY : jars; } - public String[] getTlds() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getTlds() { return tlds == null ? EMPTY : tlds; } - public String[] getFunctions() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getFunctions() { return functions == null ? EMPTY : functions; } - public String[] getArchives() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getArchives() { return archives == null ? EMPTY : archives; } - public String[] getTags() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getTags() { return tags == null ? EMPTY : tags; } - public String[] getEventGateways() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getEventGateways() { return gateways == null ? EMPTY : gateways; } - public String[] getApplications() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getApplications() { return applications == null ? EMPTY : applications; } - public String[] getComponents() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getComponents() { return components == null ? EMPTY : components; } - public String[] getPlugins() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getPlugins() { return plugins == null ? EMPTY : plugins; } - public String[] getContexts() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getContexts() { return contexts == null ? EMPTY : contexts; } - public String[] getConfigs() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getConfigs() { return configs == null ? EMPTY : configs; } - public String[] getWebContexts() throws ApplicationException, IOException, BundleException { - if (!loaded) load(extensionFile); + public String[] getWebContexts() { return webContexts == null ? EMPTY : webContexts; } diff --git a/core/src/main/java/lucee/runtime/listener/JavaSettingsImpl.java b/core/src/main/java/lucee/runtime/listener/JavaSettingsImpl.java index a0c1ea5ea1..08852b0dd6 100644 --- a/core/src/main/java/lucee/runtime/listener/JavaSettingsImpl.java +++ b/core/src/main/java/lucee/runtime/listener/JavaSettingsImpl.java @@ -28,7 +28,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import lucee.print; import lucee.commons.digest.HashUtil; import lucee.commons.io.log.Log; import lucee.commons.io.log.LogUtil; @@ -113,10 +112,6 @@ private ClassLoader getClassLoader(ClassLoader parent, Resource[] resources, boo String key = hash(resources) + ":" + parent.getName(); ResourceClassLoader classLoader = reload ? null : classLoaders.get(key); - print.e("----- getClassLoader -----" + key); - print.e("key:" + key); - print.e("reload:" + reload); - if (classLoader == null) { Collection allResources = getAllResources(resources); if (allResources.size() > 0) { @@ -169,9 +164,6 @@ private ClassLoader getClassLoaderOld(ClassLoader parent, Resource[] resources, String key = hash(resources) + ":" + parent.getName(); ResourceClassLoader classLoader = reload ? null : classLoaders.get(key); ResourceClassLoader modified = null; - print.e("----- getClassLoader -----" + key); - print.e("key:" + key); - print.e("reload:" + reload); if (classLoader == null) { // maven if (poms != null) { diff --git a/loader/build.xml b/loader/build.xml index 284707553a..c72564311d 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index d8fe7395ae..c138c2f525 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.2.0.21-SNAPSHOT + 6.2.0.22-SNAPSHOT jar Lucee Loader Build