Skip to content

Commit

Permalink
Fix Marketplace add-on range pattern matching (openhab#3288)
Browse files Browse the repository at this point in the history
* Fix Marketplace add-on range pattern matching

With this fix it will use the correct string for pattern matching add-on version ranges introduced in openhab#2811.

Signed-off-by: Wouter Born <github@maindrain.net>
  • Loading branch information
wborn committed Dec 30, 2022
1 parent 98b4902 commit 5e23b0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class BundleVersion {
public static final Pattern RANGE_PATTERN = Pattern.compile(
"\\[(?<start>\\d+\\.\\d+(?<startmicro>\\.\\d+(\\.\\w+)?)?);(?<end>\\d+\\.\\d+(?<endmicro>\\.\\d+(\\.\\w+)?)?)(?<endtype>[)\\]])");

private final String version;
private final int major;
private final int minor;
private final int micro;
Expand All @@ -39,6 +40,7 @@ public class BundleVersion {
public BundleVersion(String version) {
Matcher matcher = VERSION_PATTERN.matcher(version);
if (matcher.matches()) {
this.version = version;
this.major = Integer.parseInt(matcher.group("major"));
this.minor = Integer.parseInt(matcher.group("minor"));
this.micro = Integer.parseInt(matcher.group("micro"));
Expand Down Expand Up @@ -148,4 +150,9 @@ public int compareTo(BundleVersion other) {
// both versions are milestones, we can compare them
return Long.compare(qualifier, other.qualifier);
}

@Override
public String toString() {
return version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,20 @@ private Addon convertTopicItemToAddon(DiscourseTopicItem topic, List<DiscourseUs

int compatibilityStart = topic.title.lastIndexOf("["); // version range always starts with [
if (topic.title.lastIndexOf(" ") < compatibilityStart) { // check includes [ not present
String potentialRange = topic.title.substring(compatibilityStart + 1);
String potentialRange = topic.title.substring(compatibilityStart);
Matcher matcher = BundleVersion.RANGE_PATTERN.matcher(potentialRange);
if (matcher.matches()) {
try {
compatible = coreVersion.inRange(potentialRange);
title = topic.title.substring(0, compatibilityStart).trim();
logger.debug("{} is {}compatible with core version {}", topic.title, compatible ? "" : "NOT ",
coreVersion);
} catch (IllegalArgumentException e) {
logger.debug("Failed to determine compatibility for addon {}: {}", topic.title, e.getMessage());
compatible = true;
}
} else {
logger.debug("Range pattern does not match '{}'", potentialRange);
}
}

Expand Down

0 comments on commit 5e23b0e

Please sign in to comment.