diff options
author | Thomas Watson | 2019-12-16 19:48:40 +0000 |
---|---|---|
committer | Thomas Watson | 2019-12-16 21:55:26 +0000 |
commit | eab8d2faebdbbe56c4244db42115c65b30eb3145 (patch) | |
tree | 5e9716b5264f1eaeec7630511797fbbed27840bc | |
parent | 380fe5e58ace108729431d8e347ec09f913ff0b8 (diff) | |
download | rt.equinox.framework-eab8d2faebdbbe56c4244db42115c65b30eb3145.tar.gz rt.equinox.framework-eab8d2faebdbbe56c4244db42115c65b30eb3145.tar.xz rt.equinox.framework-eab8d2faebdbbe56c4244db42115c65b30eb3145.zip |
Bug 552573 - add tags attribute to osgi.identity for connect
Change-Id: Ida09e6f261d46bef07e282a6c71083e85a0aa30e
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
9 files changed, 83 insertions, 20 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java index 0fbb69861..9e1c7d58c 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java @@ -45,6 +45,7 @@ import java.util.jar.Manifest; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; +import org.eclipse.osgi.container.ModuleContainer; import org.eclipse.osgi.launch.EquinoxFactory; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.eclipse.osgi.tests.bundles.classes.Activator; @@ -60,8 +61,12 @@ import org.osgi.framework.connect.ConnectFramework; import org.osgi.framework.connect.ConnectFrameworkFactory; import org.osgi.framework.connect.ConnectModule; import org.osgi.framework.launch.Framework; +import org.osgi.framework.namespace.IdentityNamespace; +import org.osgi.framework.wiring.BundleCapability; +import org.osgi.framework.wiring.BundleRevision; import org.osgi.framework.wiring.BundleWiring; import org.osgi.framework.wiring.FrameworkWiring; +import org.osgi.resource.Namespace; public class ConnectTests extends AbstractBundleTests { @@ -427,7 +432,9 @@ public class ConnectTests extends AbstractBundleTests { for (String l : locations) { Bundle b = f.getBundleContext().installBundle(l); assertEquals("Wrong symbolic name.", l, b.getSymbolicName()); + checkConnectTag(b); } + checkConnectTags(f, locations); } catch (Throwable t) { sneakyThrow(t); } @@ -442,6 +449,8 @@ public class ConnectTests extends AbstractBundleTests { Bundle b = f.getBundleContext().getBundle(l); assertNotNull("No bundle at location: " + l, b); assertEquals("Wrong symbolic name.", l, b.getSymbolicName()); + checkConnectTag(b); + checkConnectTags(f, locations); } } catch (BundleException e) { sneakyThrow(e); @@ -462,6 +471,7 @@ public class ConnectTests extends AbstractBundleTests { } else { assertNotNull("No bundle at location: " + l, b); assertEquals("Wrong symbolic name.", l, b.getSymbolicName()); + checkConnectTag(b); } } } catch (BundleException e) { @@ -470,6 +480,25 @@ public class ConnectTests extends AbstractBundleTests { }); } + private static void checkConnectTag(Bundle b) { + List<String> tags = (List<String>) b.adapt(BundleRevision.class) // + .getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).stream().findFirst() // + .get().getAttributes().get(IdentityNamespace.CAPABILITY_TAGS_ATTRIBUTE); + assertNotNull("No tags found.", tags); + assertEquals("Wrong number of tags.", 1, tags.size()); + assertTrue("Connect tag not found.", tags.contains(ConnectContent.TAG_OSGI_CONNECT)); + } + + private static void checkConnectTags(Framework f, List<String> locations) { + Collection<BundleCapability> osgiConnectTags = f.adapt(FrameworkWiring.class).findProviders( // + ModuleContainer.createRequirement(IdentityNamespace.IDENTITY_NAMESPACE, // + Collections.singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(tags=osgi.connect)"), // + Collections.emptyMap())); + osgiConnectTags.forEach(c -> { + assertTrue("Unexpected tag on bundle: " + c.getRevision().getBundle(), locations.contains(c.getRevision().getBundle().getLocation())); + }); + } + public void testConnectContentActivatorsWithFrameworkLoaders() { doTestConnectContentActivators(false); } diff --git a/bundles/org.eclipse.osgi/.settings/.api_filters b/bundles/org.eclipse.osgi/.settings/.api_filters index fa3ef9a19..0e63ca1c8 100644 --- a/bundles/org.eclipse.osgi/.settings/.api_filters +++ b/bundles/org.eclipse.osgi/.settings/.api_filters @@ -52,13 +52,6 @@ </message_arguments> </filter> </resource> - <resource path="osgi/src/org/osgi/framework/connect/ConnectFactory.java" type="org.osgi.framework.connect.ConnectFactory"> - <filter comment="Not for OSGi API" id="1110441988"> - <message_arguments> - <message_argument value="org.osgi.framework.connect.ConnectFactory"/> - </message_arguments> - </filter> - </resource> <resource path="osgi/src/org/osgi/framework/connect/ConnectFramework.java" type="org.osgi.framework.connect.ConnectFramework"> <filter comment="Not for OSGi API" id="1110441988"> <message_arguments> @@ -107,4 +100,13 @@ </message_arguments> </filter> </resource> + <resource path="osgi/src/org/osgi/framework/namespace/IdentityNamespace.java" type="org.osgi.framework.namespace.IdentityNamespace"> + <filter comment="Not for OSGi API" id="1141899266"> + <message_arguments> + <message_argument value="1.2"/> + <message_argument value="3.16"/> + <message_argument value="CAPABILITY_TAGS_ATTRIBUTE"/> + </message_arguments> + </filter> + </resource> </component> diff --git a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF index 97cdc8860..30f45f660 100644 --- a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF @@ -61,7 +61,7 @@ Export-Package: org.eclipse.core.runtime.adaptor;x-friends:="org.eclipse.core.ru org.osgi.framework.hooks.service;version="1.1";uses:="org.osgi.framework", org.osgi.framework.hooks.weaving;version="1.1";uses:="org.osgi.framework.wiring", org.osgi.framework.launch;version="1.2";uses:="org.osgi.framework", - org.osgi.framework.namespace;version="1.1";uses:="org.osgi.resource", + org.osgi.framework.namespace;version="1.2";uses:="org.osgi.resource", org.osgi.framework.startlevel;version="1.0";uses:="org.osgi.framework", org.osgi.framework.startlevel.dto;version="1.0";uses:="org.osgi.dto", org.osgi.framework.wiring;version="1.2";uses:="org.osgi.framework,org.osgi.resource", diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/connect/ConnectHookConfigurator.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/connect/ConnectHookConfigurator.java index bbee6b5df..d76f6acbd 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/connect/ConnectHookConfigurator.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/connect/ConnectHookConfigurator.java @@ -21,6 +21,8 @@ import java.io.IOException; import java.io.InputStream; import java.net.URLConnection; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.eclipse.osgi.container.Module; import org.eclipse.osgi.container.ModuleContainerAdaptor.ModuleEvent; @@ -45,6 +47,7 @@ import org.osgi.framework.BundleException; import org.osgi.framework.connect.ConnectContent; import org.osgi.framework.connect.ConnectFramework; import org.osgi.framework.connect.ConnectModule; +import org.osgi.framework.namespace.IdentityNamespace; public class ConnectHookConfigurator implements HookConfigurator { @@ -92,14 +95,32 @@ public class ConnectHookConfigurator implements HookConfigurator { if (m != null) { try { ConnectContent content = m.getContent(); - return content.getHeaders().map((h) -> { + ModuleRevisionBuilder connectBuilder = content.getHeaders().map((h) -> { try { return OSGiManifestBuilderFactory.createBuilder(h); } catch (BundleException e) { sneakyThrow(e); } return null; // should never get here - }).orElse(null); + }).orElse(builder); + connectBuilder.getCapabilities().stream() // + .filter(i -> IdentityNamespace.IDENTITY_NAMESPACE.equals(i.getNamespace())) // + .findFirst().ifPresent((i) -> { + i.getAttributes().compute(IdentityNamespace.CAPABILITY_TAGS_ATTRIBUTE, (k, v) -> { + if (v == null) { + return Collections.singletonList(ConnectContent.TAG_OSGI_CONNECT); + } + if (v instanceof List) { + @SuppressWarnings({"unchecked", "rawtypes"}) + List<String> l = new ArrayList<>((List) v); + l.add(ConnectContent.TAG_OSGI_CONNECT); + return Collections.unmodifiableList(l); + } + // should not get here, but just recover + return Arrays.asList(v, ConnectContent.TAG_OSGI_CONNECT); + }); + }); + return connectBuilder; } catch (IOException e) { sneakyThrow(new BundleException("Error reading bundle.", BundleException.READ_ERROR, e)); //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java index 0c31d9f7b..236ad75d7 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java @@ -16,20 +16,13 @@ package org.osgi.framework; -import static java.lang.invoke.MethodHandles.publicLookup; import static java.util.Objects.requireNonNull; -import java.lang.invoke.MethodHandle; -import java.lang.reflect.AccessibleObject; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Dictionary; import java.util.Enumeration; diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectContent.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectContent.java index a109b609c..ce8ae5d57 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectContent.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectContent.java @@ -23,6 +23,7 @@ import java.util.Optional; import org.osgi.framework.Bundle; import org.osgi.framework.launch.Framework; +import org.osgi.framework.namespace.IdentityNamespace; import org.osgi.framework.wiring.BundleRevisions; /** @@ -40,6 +41,13 @@ import org.osgi.framework.wiring.BundleRevisions; */ public interface ConnectContent { /** + * The {@code osgi.identity} + * {@link IdentityNamespace#CAPABILITY_TAGS_ATTRIBUTE tags} attribute value + * used by the framework to tag connect bundle revisions. + */ + public static final String TAG_OSGI_CONNECT = "osgi.connect"; + + /** * Returns this connect content Manifest headers and values. The * {@link Optional#empty() empty} value is returned if the framework should * handle parsing the Manifest of the content itself. diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/package-info.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/package-info.java index de6a85ca4..861894938 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/package-info.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/package-info.java @@ -22,7 +22,7 @@ * <p> * Example import for consumers using the API in this package: * <p> - * {@code Import-Package: org.osgi.framework; version="[1.0,2.0)"} + * {@code Import-Package: org.osgi.framework.connect; version="[1.0,2.0)"} * * @author $Id$ */ diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/namespace/IdentityNamespace.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/namespace/IdentityNamespace.java index 7bc7a11c4..19e7c5bab 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/namespace/IdentityNamespace.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/namespace/IdentityNamespace.java @@ -105,6 +105,16 @@ public final class IdentityNamespace extends Namespace { public static final String TYPE_UNKNOWN = "unknown"; /** + * The attribute value that contains tags for the resource. A tag is used to + * identify an aspect of the resource that is not otherwise expressed by the + * capabilities of the resource. The value of this attribute must be of type + * {@code List<Version>}. + * + * @since 1.2 + */ + public static final String CAPABILITY_TAGS_ATTRIBUTE = "tags"; + + /** * The capability attribute that contains a human readable copyright notice * for the resource. See the {@code Bundle-Copyright} manifest header. */ diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/namespace/package-info.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/namespace/package-info.java index e89f34a4f..957dd89b5 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/namespace/package-info.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/namespace/package-info.java @@ -15,7 +15,7 @@ */ /** - * Namespace Package Version 1.1. + * Namespace Package Version 1.2. * * <p> * Bundles should not need to import this package at runtime since all @@ -25,7 +25,7 @@ * @author $Id$ */ -@Version("1.1") +@Version("1.2") package org.osgi.framework.namespace; import org.osgi.annotation.versioning.Version; |