diff options
author | gjoranv <gv@verizonmedia.com> | 2023-01-05 13:05:42 +0100 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2023-01-09 12:59:50 +0100 |
commit | ed9092b7fd04633a4d0f92c6901facf75fbceb79 (patch) | |
tree | e0be30001be24b5501dd5a27e5065b4a5dc65ccb /jdisc_core/src | |
parent | 4566b9710235ee482b36c5abe67166a41555d991 (diff) |
Extract record for BsnVersion for usage outside jdisc_core.
Diffstat (limited to 'jdisc_core/src')
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()); + } +} |