From c618c1178195e42ae1bff07b0f50fb7ec7435d73 Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Thu, 12 Dec 2024 10:05:50 +0100 Subject: [PATCH] move minloaderversion to Metadata class --- .../runtime/extension/ExtensionMetadata.java | 10 +++++ .../lucee/runtime/extension/RHExtension.java | 41 +++++++------------ loader/build.xml | 2 +- loader/pom.xml | 2 +- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/lucee/runtime/extension/ExtensionMetadata.java b/core/src/main/java/lucee/runtime/extension/ExtensionMetadata.java index 5e31af5731..d063e578a1 100644 --- a/core/src/main/java/lucee/runtime/extension/ExtensionMetadata.java +++ b/core/src/main/java/lucee/runtime/extension/ExtensionMetadata.java @@ -9,6 +9,7 @@ import lucee.commons.lang.StringUtil; import lucee.runtime.mvn.MavenUtil; import lucee.runtime.mvn.MavenUtil.GAVSO; +import lucee.runtime.op.Caster; import lucee.runtime.osgi.BundleInfo; import lucee.runtime.osgi.VersionRange; import lucee.runtime.type.util.ListUtil; @@ -29,6 +30,7 @@ public class ExtensionMetadata { private boolean startBundles; private BundleInfo[] bundles; private VersionRange minCoreVersion; + private double minLoaderVersion; private String[] jars; private String[] flds; @@ -366,6 +368,14 @@ public void setMinCoreVersion(String str, Info info) { this.minCoreVersion = StringUtil.isEmpty(str, true) ? null : new VersionRange(str); } + public double getMinLoaderVersion() { + return minLoaderVersion; + } + + public void setMinLoaderVersion(String str, Info info) { + minLoaderVersion = Caster.toDoubleValue(str, 0); + } + public String getImage() { return image; } diff --git a/core/src/main/java/lucee/runtime/extension/RHExtension.java b/core/src/main/java/lucee/runtime/extension/RHExtension.java index d82689b2b1..1e83aa807a 100644 --- a/core/src/main/java/lucee/runtime/extension/RHExtension.java +++ b/core/src/main/java/lucee/runtime/extension/RHExtension.java @@ -123,17 +123,12 @@ public class RHExtension implements Serializable { private static final ExtensionResourceFilter LEX_FILTER = new ExtensionResourceFilter("lex"); private static Set metadataFilesChecked = new HashSet<>(); + private static Map instances = new ConcurrentHashMap<>(); private ExtensionMetadata metadata = new ExtensionMetadata(); - private Resource extensionFile; - - private double minLoaderVersion; - public boolean softLoaded = false; - private static Map instances = new ConcurrentHashMap<>(); - public static RHExtension getInstance(Config config, Resource ext, RHExtension defaultValue) { RHExtension instance = instances.get(ext.getAbsolutePath()); if (instance == null) { @@ -160,7 +155,9 @@ public static RHExtension getInstance(Config config, Resource ext) throws PageEx } private RHExtension(Config config, Resource ext) throws PageException, IOException, BundleException, ConverterException { - init(config, ext); + this.extensionFile = ext; + + init(config); } public static RHExtension getInstance(Config config, String id, String version) throws PageException, IOException, BundleException, ConverterException { @@ -192,18 +189,17 @@ public RHExtension(Config config, String id, String version) throws PageExceptio } } - init(config, this.extensionFile); + init(config); softLoaded = false; } - private void init(Config config, Resource ext) throws PageException, IOException, BundleException, ConverterException { + private void init(Config config) 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.metadata.setType(config instanceof ConfigWeb ? "web" : "server"); - this.extensionFile = ext; - load(config, ext); + load(config, this.extensionFile); // write metadata to XML Resource mdf = getMetaDataFile(config, getId(), getVersion()); if (!metadataFilesChecked.contains(mdf.getAbsolutePath()) && !mdf.isFile()) { @@ -528,7 +524,7 @@ private void readManifestConfig(Config config, Manifest manifest, String label, if (StringUtil.isEmpty(cat, true)) cat = StringUtil.unwrap(attr.getValue("categories")); metadata.setCategories(cat); metadata.setMinCoreVersion(StringUtil.unwrap(attr.getValue("lucee-core-version")), info); - readLoaderVersion(label, StringUtil.unwrap(attr.getValue("lucee-loader-version"))); + metadata.setMinLoaderVersion(StringUtil.unwrap(attr.getValue("lucee-loader-version")), info); metadata.setStartBundles(Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("start-bundles")), true)); metadata.setAMF(StringUtil.unwrap(attr.getValue("amf")), logger); @@ -567,7 +563,7 @@ private void readManifestConfig(Config config, String id, Struct data, String la if (StringUtil.isEmpty(cat, true)) cat = ConfigFactoryImpl.getAttr(data, "categories"); metadata.setCategories(cat); metadata.setMinCoreVersion(ConfigFactoryImpl.getAttr(data, "luceeCoreVersion", "lucee-core-version"), info); - readLoaderVersion(label, ConfigFactoryImpl.getAttr(data, "luceeLoaderVersion", "lucee-loader-version")); + metadata.setMinLoaderVersion(ConfigFactoryImpl.getAttr(data, "luceeCoreVersion", "lucee-loader-version"), info); metadata.setStartBundles(Caster.toBooleanValue(ConfigFactoryImpl.getAttr(data, "startBundles", "start-bundles"), true)); metadata.setAMF(ConfigFactoryImpl.getAttr(data, "amf"), logger); @@ -585,15 +581,6 @@ private void readManifestConfig(Config config, String id, Struct data, String la metadata.setEventGatewayInstances(ConfigFactoryImpl.getAttr(data, "eventGatewayInstance", "event-gateway-instance"), logger); } - private void readLoaderVersion(String label, String str) { - minLoaderVersion = Caster.toDoubleValue(str, 0); - /* - * if (minLoaderVersion > SystemUtil.getLoaderVersion()) { throw new InvalidVersion( - * "The Extension [" + label + "] cannot be loaded, " + Constants.NAME + - * " Loader Version must be at least [" + str + "], update the Lucee.jar first."); } - */ - } - public void validate(Config config) throws ApplicationException { validate(ConfigUtil.getEngine(config).getInfo()); } @@ -604,9 +591,9 @@ public void validate(Info info) throws ApplicationException { throw new InvalidVersion("The Extension [" + metadata.getName() + "] cannot be loaded, " + Constants.NAME + " Version must be at least [" + minCoreVersion.toString() + "], version is [" + info.getVersion().toString() + "]."); } - if (minLoaderVersion > SystemUtil.getLoaderVersion()) { - throw new InvalidVersion("The Extension [" + metadata.getName() + "] cannot be loaded, " + Constants.NAME + " Loader Version must be at least [" + minLoaderVersion - + "], update the Lucee.jar first."); + if (metadata.getMinLoaderVersion() > SystemUtil.getLoaderVersion()) { + throw new InvalidVersion("The Extension [" + metadata.getName() + "] cannot be loaded, " + Constants.NAME + " Loader Version must be at least [" + + metadata.getMinLoaderVersion() + "], update the Lucee.jar first."); } } @@ -615,7 +602,7 @@ public boolean isValidFor(Info info) { if (minCoreVersion != null && !minCoreVersion.isWithin(info.getVersion())) { return false; } - if (minLoaderVersion > SystemUtil.getLoaderVersion()) { + if (metadata.getMinLoaderVersion() > SystemUtil.getLoaderVersion()) { return false; } return true; @@ -864,7 +851,7 @@ public void populate(Struct el, boolean full) { else el.removeEL(KeyImpl.init("luceeCoreVersion")); // loader version - if (minLoaderVersion > 0) el.setEL("loaderVersion", Caster.toString(minLoaderVersion)); + if (metadata.getMinLoaderVersion() > 0) el.setEL("loaderVersion", Caster.toString(metadata.getMinLoaderVersion())); else el.removeEL(KeyImpl.init("loaderVersion")); // amf diff --git a/loader/build.xml b/loader/build.xml index 9209cbc974..18deaf9013 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index a7457fe490..dcd09d846e 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 7.0.0.71-SNAPSHOT + 7.0.0.72-SNAPSHOT jar Lucee Loader Build