diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-01-09 01:26:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 01:26:06 +0100 |
commit | e704b1b4ae95eabfa30f7fc4ea0f44ac4e7ee177 (patch) | |
tree | 8e58757d3d0b2557b332c037d585c4f9b67027e1 /jdisc_core | |
parent | 6cedb4636301e1348d64e58886fe135be8b2b527 (diff) | |
parent | 52cf70ebb4edcae9766af8913faf3da8ffc6e0cd (diff) |
Merge pull request #25443 from vespa-engine/More_user_friendly_class_resolution
More user friendly class resolution
Diffstat (limited to 'jdisc_core')
3 files changed, 46 insertions, 30 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BsnVersion.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BsnVersion.java new file mode 100644 index 00000000000..40573eee3b2 --- /dev/null +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BsnVersion.java @@ -0,0 +1,21 @@ +package com.yahoo.jdisc.application; + +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..203c2e975e4 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 @@ -1,11 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jdisc.core; +import com.yahoo.jdisc.application.BsnVersion; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; import org.osgi.framework.ServiceRegistration; -import org.osgi.framework.Version; import org.osgi.framework.hooks.bundle.CollisionHook; import org.osgi.framework.hooks.bundle.EventHook; import org.osgi.framework.hooks.bundle.FindHook; @@ -15,10 +15,8 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.logging.Logger; -import java.util.stream.Collectors; /** * A bundle {@link CollisionHook} that contains a set of bundles that are allowed to collide with bundles @@ -129,31 +127,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/application/BsnVersionTest.java b/jdisc_core/src/test/java/com/yahoo/jdisc/application/BsnVersionTest.java new file mode 100644 index 00000000000..484c4c9fb3c --- /dev/null +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/application/BsnVersionTest.java @@ -0,0 +1,24 @@ +package com.yahoo.jdisc.application; + +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()); + } +} |