Skip to content

Commit

Permalink
move RHExetension Metadata in separate class and relove issue with up…
Browse files Browse the repository at this point in the history
…dating regular mappings
  • Loading branch information
michaeloffner committed Nov 26, 2024
1 parent 7351471 commit 5881ec1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 36 deletions.
25 changes: 21 additions & 4 deletions core/src/main/java/lucee/runtime/extension/ExtensionMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import java.util.List;
import java.util.Map;

import lucee.Info;
import lucee.commons.io.log.Log;
import lucee.commons.lang.StringUtil;
import lucee.runtime.osgi.BundleInfo;
import lucee.runtime.osgi.VersionRange;
import lucee.runtime.type.util.ListUtil;

public class ExtensionMetadata {
private static final String[] EMPTY = new String[0];
Expand All @@ -18,10 +21,12 @@ public class ExtensionMetadata {
private String symbolicName;
private String description;
private String type;

private boolean trial;
private String image;
private boolean startBundles;
private BundleInfo[] bundles;
private VersionRange minCoreVersion;

private String[] jars;
private String[] flds;
Expand Down Expand Up @@ -303,8 +308,9 @@ public String getSymbolicName() {
return StringUtil.isEmpty(symbolicName) ? getId() : symbolicName;
}

public void setSymbolicName(String symbolicName) {
this.symbolicName = symbolicName;
public void setSymbolicName(String str) {
str = StringUtil.unwrap(str);
if (!StringUtil.isEmpty(str, true)) symbolicName = str.trim();
}

public int getReleaseType() {
Expand All @@ -331,6 +337,14 @@ public void setTrial(boolean trial) {
this.trial = trial;
}

public VersionRange getMinCoreVersion() {
return minCoreVersion;
}

public void setMinCoreVersion(String str, Info info) {
this.minCoreVersion = StringUtil.isEmpty(str, true) ? null : new VersionRange(str);
}

public String getImage() {
return image;
}
Expand Down Expand Up @@ -371,8 +385,11 @@ public String[] getCategories() {
return categories == null ? EMPTY : categories;
}

public void setCategories(String[] categories) {
this.categories = categories;
public void setCategories(String cat) {
if (!StringUtil.isEmpty(cat, true)) {
this.categories = ListUtil.trimItems(ListUtil.listToStringArray(cat, ","));
}
else this.categories = null;
}

public String[] getWebContexts() {
Expand Down
41 changes: 9 additions & 32 deletions core/src/main/java/lucee/runtime/extension/RHExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ public class RHExtension implements Serializable {

private Resource extensionFile;

private VersionRange minCoreVersion;

private double minLoaderVersion;

public boolean softLoaded = false;
Expand Down Expand Up @@ -516,7 +514,7 @@ private void readManifestConfig(Config config, Manifest manifest, String label,

Attributes attr = manifest.getMainAttributes();

readSymbolicName(label, StringUtil.unwrap(attr.getValue("symbolic-name")));
metadata.setSymbolicName(StringUtil.unwrap(attr.getValue("symbolic-name")));
readName(label, StringUtil.unwrap(attr.getValue("name")));
label = metadata.getName();
readVersion(label, StringUtil.unwrap(attr.getValue("version")));
Expand All @@ -528,8 +526,8 @@ private void readManifestConfig(Config config, Manifest manifest, String label,
metadata.setImage(_img);
String cat = StringUtil.unwrap(attr.getValue("category"));
if (StringUtil.isEmpty(cat, true)) cat = StringUtil.unwrap(attr.getValue("categories"));
readCategories(label, cat);
readCoreVersion(label, StringUtil.unwrap(attr.getValue("lucee-core-version")), info);
metadata.setCategories(cat);
metadata.setMinCoreVersion(StringUtil.unwrap(attr.getValue("lucee-core-version")), info);
readLoaderVersion(label, StringUtil.unwrap(attr.getValue("lucee-loader-version")));
metadata.setStartBundles(Caster.toBooleanValue(StringUtil.unwrap(attr.getValue("start-bundles")), true));

Expand All @@ -554,7 +552,7 @@ private void readManifestConfig(Config config, String id, Struct data, String la
Log logger = ThreadLocalPageContext.getLog(config, "deploy");
Info info = ConfigUtil.getEngine(config).getInfo();

readSymbolicName(label, ConfigFactoryImpl.getAttr(data, "symbolicName", "symbolic-name"));
metadata.setSymbolicName(ConfigFactoryImpl.getAttr(data, "symbolicName", "symbolic-name"));
readName(label, ConfigFactoryImpl.getAttr(data, "name"));
label = getMetadata().getName();
readVersion(label, ConfigFactoryImpl.getAttr(data, "version"));
Expand All @@ -566,8 +564,8 @@ private void readManifestConfig(Config config, String id, Struct data, String la
metadata.setImage(_img);
String cat = ConfigFactoryImpl.getAttr(data, "category");
if (StringUtil.isEmpty(cat, true)) cat = ConfigFactoryImpl.getAttr(data, "categories");
readCategories(label, cat);
readCoreVersion(label, ConfigFactoryImpl.getAttr(data, "luceeCoreVersion", "lucee-core-version"), info);
metadata.setCategories(cat);
metadata.setMinCoreVersion(ConfigFactoryImpl.getAttr(data, "luceeCoreVersion", "lucee-core-version"), info);
readLoaderVersion(label, ConfigFactoryImpl.getAttr(data, "luceeLoaderVersion", "lucee-loader-version"));
metadata.setStartBundles(Caster.toBooleanValue(ConfigFactoryImpl.getAttr(data, "startBundles", "start-bundles"), true));

Expand All @@ -594,23 +592,12 @@ private void readLoaderVersion(String label, String str) {
*/
}

private void readCoreVersion(String label, String str, Info info) {

minCoreVersion = StringUtil.isEmpty(str, true) ? null : new VersionRange(str);
/*
* if (minCoreVersion != null && OSGiUtil.isNewerThan(minCoreVersion, info.getVersion())) { throw
* new InvalidVersion("The Extension [" + label + "] cannot be loaded, " + Constants.NAME +
* " Version must be at least [" + minCoreVersion.toString() + "], version is [" +
* info.getVersion().toString() + "]."); }
*/
}

public void validate(Config config) throws ApplicationException {
validate(ConfigUtil.getEngine(config).getInfo());
}

public void validate(Info info) throws ApplicationException {

VersionRange minCoreVersion = metadata.getMinCoreVersion();
if (minCoreVersion != null && !minCoreVersion.isWithin(info.getVersion())) {
throw new InvalidVersion("The Extension [" + metadata.getName() + "] cannot be loaded, " + Constants.NAME + " Version must be at least [" + minCoreVersion.toString()
+ "], version is [" + info.getVersion().toString() + "].");
Expand All @@ -622,6 +609,7 @@ public void validate(Info info) throws ApplicationException {
}

public boolean isValidFor(Info info) {
VersionRange minCoreVersion = metadata.getMinCoreVersion();
if (minCoreVersion != null && !minCoreVersion.isWithin(info.getVersion())) {
return false;
}
Expand All @@ -631,13 +619,6 @@ public boolean isValidFor(Info info) {
return true;
}

private void readCategories(String label, String cat) {
if (!StringUtil.isEmpty(cat, true)) {
metadata.setCategories(ListUtil.trimItems(ListUtil.listToStringArray(cat, ",")));
}
else metadata.setCategories(null);
}

private void readId(String label, String id) throws ApplicationException {
id = StringUtil.unwrap(id);
if (!Decision.isUUId(id)) {
Expand All @@ -661,11 +642,6 @@ private void readName(String label, String str) throws ApplicationException {
metadata.setName(str.trim());
}

private void readSymbolicName(String label, String str) {
str = StringUtil.unwrap(str);
if (!StringUtil.isEmpty(str, true)) metadata.setSymbolicName(str.trim());
}

public void deployBundles(Config config, boolean load) throws IOException, BundleException {
// no we read the content of the zip
ZipInputStream zis = new ZipInputStream(IOUtil.toBufferedInputStream(extensionFile.getInputStream()));
Expand Down Expand Up @@ -881,6 +857,7 @@ public void populate(Struct el, boolean full) {
else el.removeEL(KeyImpl.init("categories"));

// core version
VersionRange minCoreVersion = metadata.getMinCoreVersion();
if (minCoreVersion != null) el.setEL("luceeCoreVersion", toStringForAttr(minCoreVersion.toString()));
else el.removeEL(KeyImpl.init("luceeCoreVersion"));

Expand Down

0 comments on commit 5881ec1

Please sign in to comment.