diff options
3 files changed, 45 insertions, 27 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/BsnVersion.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/BsnVersion.java new file mode 100644 index 00000000000..ee9ecc9fc3e --- /dev/null +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/BsnVersion.java @@ -0,0 +1,21 @@ +package com.yahoo.jdisc.core; + +import org.osgi.framework.Bundle; +import org.osgi.framework.Version; + +/** + * A bundle's symbolic name and version. + * + * @author gjoranv + */ +public record BsnVersion(String symbolicName, Version version) { + + public BsnVersion(Bundle bundle) { + this(bundle.getSymbolicName(), bundle.getVersion()); + } + + public String toReadableString() { + return symbolicName + " version:" + version; + } + +} diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/BundleCollisionHook.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/BundleCollisionHook.java index 3212bb4e6de..e78f3251890 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/BundleCollisionHook.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/BundleCollisionHook.java @@ -129,31 +129,4 @@ public class BundleCollisionHook implements CollisionHook, EventHook, FindHook { } } - - static class BsnVersion { - - private final String symbolicName; - private final Version version; - - BsnVersion(Bundle bundle) { - this.symbolicName = bundle.getSymbolicName(); - this.version = bundle.getVersion(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - BsnVersion that = (BsnVersion) o; - return Objects.equals(symbolicName, that.symbolicName) && - version.equals(that.version); - } - - @Override - public int hashCode() { - return Objects.hash(symbolicName, version); - } - - } - } diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/core/BsnVersionTest.java b/jdisc_core/src/test/java/com/yahoo/jdisc/core/BsnVersionTest.java new file mode 100644 index 00000000000..baeb36d28a8 --- /dev/null +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/core/BsnVersionTest.java @@ -0,0 +1,24 @@ +package com.yahoo.jdisc.core; + +import org.junit.jupiter.api.Test; +import org.osgi.framework.Version; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * @author gjoranv + */ +public class BsnVersionTest { + + @Test + void readable_string_can_be_retrieved() { + BsnVersion bsnVersion = new BsnVersion("com.yahoo.foo", new Version("1.0.0")); + assertEquals("com.yahoo.foo version:1.0.0", bsnVersion.toReadableString()); + } + + @Test + void version_qualifier_can_be_retrieved() { + BsnVersion bsnVersion = new BsnVersion("foo", new Version(1, 2, 3, "SNAPSHOT")); + assertEquals("SNAPSHOT", bsnVersion.version().getQualifier()); + } +} |