From 170af02d92a5f5e5442c45d6041cd367e46be3ad Mon Sep 17 00:00:00 2001 From: Arnstein Ressem Date: Mon, 9 Jan 2023 08:25:27 +0100 Subject: Revert "More user friendly class resolution" --- .../com/yahoo/jdisc/application/BsnVersion.java | 21 --------------- .../com/yahoo/jdisc/core/BundleCollisionHook.java | 31 +++++++++++++++++++++- .../yahoo/jdisc/application/BsnVersionTest.java | 24 ----------------- 3 files changed, 30 insertions(+), 46 deletions(-) delete mode 100644 jdisc_core/src/main/java/com/yahoo/jdisc/application/BsnVersion.java delete mode 100644 jdisc_core/src/test/java/com/yahoo/jdisc/application/BsnVersionTest.java (limited to 'jdisc_core/src') 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 deleted file mode 100644 index 40573eee3b2..00000000000 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BsnVersion.java +++ /dev/null @@ -1,21 +0,0 @@ -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 203c2e975e4..3212bb4e6de 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,8 +15,10 @@ 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 @@ -127,4 +129,31 @@ 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 deleted file mode 100644 index 484c4c9fb3c..00000000000 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/application/BsnVersionTest.java +++ /dev/null @@ -1,24 +0,0 @@ -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()); - } -} -- cgit v1.2.3