Skip to content

Commit

Permalink
move minloaderversion to Metadata class
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Dec 12, 2024
1 parent a72a6b5 commit c618c11
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
10 changes: 10 additions & 0 deletions core/src/main/java/lucee/runtime/extension/ExtensionMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
41 changes: 14 additions & 27 deletions core/src/main/java/lucee/runtime/extension/RHExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,12 @@ public class RHExtension implements Serializable {
private static final ExtensionResourceFilter LEX_FILTER = new ExtensionResourceFilter("lex");

private static Set<String> metadataFilesChecked = new HashSet<>();
private static Map<String, RHExtension> instances = new ConcurrentHashMap<>();

private ExtensionMetadata metadata = new ExtensionMetadata();

private Resource extensionFile;

private double minLoaderVersion;

public boolean softLoaded = false;

private static Map<String, RHExtension> instances = new ConcurrentHashMap<>();

public static RHExtension getInstance(Config config, Resource ext, RHExtension defaultValue) {
RHExtension instance = instances.get(ext.getAbsolutePath());
if (instance == null) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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());
}
Expand All @@ -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.");
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -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
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="7.0.0.71-SNAPSHOT"/>
<property name="version" value="7.0.0.72-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>7.0.0.71-SNAPSHOT</version>
<version>7.0.0.72-SNAPSHOT</version>
<packaging>jar</packaging>

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

0 comments on commit c618c11

Please sign in to comment.