diff --git a/bundles/org.eclipse.osgi/META-INF/services/org.osgi.framework.connect.FrameworkUtilHelper b/bundles/org.eclipse.osgi/META-INF/services/org.osgi.framework.connect.FrameworkUtilHelper index b95d7c55ff2..aff953ccd7a 100644 --- a/bundles/org.eclipse.osgi/META-INF/services/org.osgi.framework.connect.FrameworkUtilHelper +++ b/bundles/org.eclipse.osgi/META-INF/services/org.osgi.framework.connect.FrameworkUtilHelper @@ -1 +1 @@ -org.eclipse.osgi.launch.EquinoxFactory \ No newline at end of file +org.eclipse.osgi.internal.framework.ConnectFrameworkUtilHelper \ No newline at end of file diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/ConnectFrameworkUtilHelper.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/ConnectFrameworkUtilHelper.java new file mode 100644 index 00000000000..3948a6bb6e5 --- /dev/null +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/ConnectFrameworkUtilHelper.java @@ -0,0 +1,28 @@ +package org.eclipse.osgi.internal.framework; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.WeakHashMap; +import org.osgi.framework.Bundle; +import org.osgi.framework.connect.FrameworkUtilHelper; + +public class ConnectFrameworkUtilHelper implements FrameworkUtilHelper { + static final Set connectHelpers = Collections.newSetFromMap(new WeakHashMap<>()); + + @Override + public Optional getBundle(Class classFromBundle) { + FrameworkUtilHelper[] helpers; + synchronized (connectHelpers) { + helpers = connectHelpers.toArray(FrameworkUtilHelper[]::new); + } + return Arrays.stream(helpers).filter(Objects::nonNull) + .flatMap(helper -> helper.getBundle(classFromBundle).stream()).findFirst(); + } + + public static synchronized void add(FrameworkUtilHelper moduleConnector) { + connectHelpers.add(moduleConnector); + } +} diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java index 0f7beb764c0..27a719be342 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java @@ -57,6 +57,7 @@ import org.osgi.framework.FrameworkUtil; import org.osgi.framework.connect.ConnectContent; import org.osgi.framework.connect.ConnectModule; +import org.osgi.framework.connect.FrameworkUtilHelper; import org.osgi.framework.connect.ModuleConnector; import org.osgi.util.tracker.ServiceTracker; @@ -154,6 +155,11 @@ private static void initConnectFramework(ModuleConnector moduleConnector, Equino final File fwkStore = new File(configUrl.getPath()); @SuppressWarnings({"rawtypes", "unchecked"}) Map config = (Map) equinoxConfig.getInitialConfig(); + if (moduleConnector instanceof FrameworkUtilHelper) { + // TODO when would this ever be removed? But the SPI has the same problem so + // maybe it is okay? + ConnectFrameworkUtilHelper.add((FrameworkUtilHelper) moduleConnector); + } moduleConnector.initialize(fwkStore, Collections.unmodifiableMap(config)); } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/launch/EquinoxFactory.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/launch/EquinoxFactory.java index 9a2be0890d5..fd1ad8a5dd7 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/launch/EquinoxFactory.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/launch/EquinoxFactory.java @@ -14,13 +14,7 @@ package org.eclipse.osgi.launch; import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import org.osgi.framework.Bundle; -import org.osgi.framework.connect.ConnectFramework; import org.osgi.framework.connect.ConnectFrameworkFactory; -import org.osgi.framework.connect.FrameworkUtilHelper; import org.osgi.framework.connect.ModuleConnector; import org.osgi.framework.launch.Framework; import org.osgi.framework.launch.FrameworkFactory; @@ -29,40 +23,15 @@ * The framework factory implementation for the Equinox framework. * @since 3.5 */ -public class EquinoxFactory implements FrameworkFactory, ConnectFrameworkFactory, FrameworkUtilHelper { - - static final Set connectHelpers = ConcurrentHashMap.newKeySet(); +public class EquinoxFactory implements FrameworkFactory, ConnectFrameworkFactory { @Override public Framework newFramework(Map configuration) { - return new Equinox(configuration); + return newFramework(configuration, null); } @Override - public ConnectFramework newFramework(Map configuration, ModuleConnector moduleConnector) { - return new EquinoxConnect(configuration, moduleConnector); - } - - @Override - public Optional getBundle(Class classFromBundle) { - return connectHelpers.stream().flatMap(helper -> helper.getBundle(classFromBundle).stream()).findFirst(); - } - - private static final class EquinoxConnect extends Equinox implements ConnectFramework { - - public EquinoxConnect(Map configuration, ModuleConnector moduleConnector) { - super(configuration, moduleConnector); - } - - @Override - public void addFrameworkUtilHelper(FrameworkUtilHelper helper) { - connectHelpers.add(helper); - } - - @Override - public void removeFrameworkUtilHelper(FrameworkUtilHelper helper) { - connectHelpers.remove(helper); - } - + public Framework newFramework(Map configuration, ModuleConnector moduleConnector) { + return new Equinox(configuration, moduleConnector); } } diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectFramework.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectFramework.java deleted file mode 100644 index 3a93535c69a..00000000000 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectFramework.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.osgi.framework.connect; - -import org.osgi.framework.launch.Framework; - -/** - * A framework created by a {@link ConnectFrameworkFactory} ... this is non - * standard extension - */ -public interface ConnectFramework extends Framework { - - /** - * adds a {@link FrameworkUtilHelper} via this {@link ConnectFramework} - * - * @param helper - */ - void addFrameworkUtilHelper(FrameworkUtilHelper helper); - - /** - * removes a {@link FrameworkUtilHelper} via this {@link ConnectFramework} - * - * @param helper - */ - void removeFrameworkUtilHelper(FrameworkUtilHelper helper); - -} diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectFrameworkFactory.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectFrameworkFactory.java index ed5e6fd713c..fee4e88754b 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectFrameworkFactory.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectFrameworkFactory.java @@ -74,6 +74,6 @@ public interface ConnectFrameworkFactory { * supports permissions. * @see ModuleConnector */ - ConnectFramework newFramework(Map configuration, + Framework newFramework(Map configuration, ModuleConnector moduleConnector); }