SLING-8976: revert the work done in SLING-8815
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/AbstractResolverHookFactory.java b/src/main/java/org/apache/sling/feature/apiregions/impl/AbstractResolverHookFactory.java
deleted file mode 100644
index 9042090..0000000
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/AbstractResolverHookFactory.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.feature.apiregions.impl;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Version;
-import org.osgi.framework.hooks.resolver.ResolverHookFactory;
-
-abstract class AbstractResolverHookFactory<K, V> implements ResolverHookFactory {
-
- static final String CLASSLOADER_PSEUDO_PROTOCOL = "classloader://";
-
- static final String PROPERTIES_RESOURCE_PREFIX = "sling.feature.apiregions.resource.";
-
- static final String PROPERTIES_FILE_LOCATION = "sling.feature.apiregions.location";
-
- static final String IDBSNVER_FILENAME = "idbsnver.properties";
-
- protected final URI getDataFileURI(BundleContext ctx, String name) throws IOException, URISyntaxException {
- String fn = ctx.getProperty(PROPERTIES_RESOURCE_PREFIX + name);
- if (fn == null) {
- String loc = ctx.getProperty(PROPERTIES_FILE_LOCATION);
- if (loc != null) {
- fn = loc + "/" + name;
- }
- }
-
- if (fn == null) {
- throw new IOException("API Region Enforcement enabled, but no configuration found to find "
- + "region definition resource: " + name);
- }
-
- if (fn.contains(":")) {
- if (fn.startsWith(CLASSLOADER_PSEUDO_PROTOCOL)) {
- // It's using the 'classloader:' protocol looks up the location from the classloader
- String loc = fn.substring(CLASSLOADER_PSEUDO_PROTOCOL.length());
- if (!loc.startsWith("/")) {
- loc = "/" + loc;
- }
- fn = getClass().getResource(loc).toString();
- }
- // It's already a URL
- return new URI(fn);
- }
-
- // It's a file location
- return new File(fn).toURI();
- }
-
- protected final Map<K, V> readBsnVerMap(BundleContext context) throws IOException, URISyntaxException {
- final Map<K, V> bsnVerMap = new HashMap<>();
-
- URI idbsnverFile = getDataFileURI(context, IDBSNVER_FILENAME);
-
- Properties properties = new Properties();
- try (InputStream is = idbsnverFile.toURL().openStream()) {
- properties.load(is);
- }
-
- for (String artifactId : properties.stringPropertyNames()) {
- String value = properties.getProperty(artifactId);
- if (value != null && !value.isEmpty()) { // it shouldn't happen, but...
- int splitIndex = value.indexOf('~');
- if (splitIndex != -1) { // again, it shouldn't happen...
- String bundleSymbolicName = value.substring(0, splitIndex);
- String bundleVersion = value.substring(splitIndex + 1);
- Version version = Version.valueOf(bundleVersion);
-
- addBsnVerArtifact(bsnVerMap, artifactId, bundleSymbolicName, version);
- }
- }
- }
-
- return bsnVerMap;
- }
-
- protected abstract void addBsnVerArtifact(Map<K, V> bsnVerMap,
- String artifactId,
- String bundleSymbolicName,
- Version bundleVersion);
-
-}
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java b/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
index 39b5a0e..190e29b 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
@@ -49,16 +49,12 @@
BundleContext bundleContext;
ServiceRegistration<ResolverHookFactory> hookRegistration;
- ServiceRegistration<ResolverHookFactory> platformIsolationRegistration;
-
@Override
public synchronized void start(BundleContext context) throws Exception {
bundleContext = context;
registerHook();
- registerPlatformIsolationEnforcer();
-
context.addFrameworkListener(this);
}
@@ -84,29 +80,11 @@
}
}
- synchronized void registerPlatformIsolationEnforcer() {
- if (platformIsolationRegistration != null) {
- return;
+ synchronized void unregisterHook() {
+ if (hookRegistration != null) {
+ hookRegistration.unregister();
+ hookRegistration = null;
}
-
- try {
- PlatformIsolationEnforcer enforcer = new PlatformIsolationEnforcer(bundleContext);
- platformIsolationRegistration = bundleContext.registerService(ResolverHookFactory.class, enforcer, new Hashtable<>());
- } catch (Exception e) {
- RegionEnforcer.LOG.log(Level.SEVERE, "Problem activating Platform Isolation runtime enforcement component", e);
- }
- }
-
- synchronized void unregisterHooks() {
- hookRegistration = unregisterService(hookRegistration);
- platformIsolationRegistration = unregisterService(platformIsolationRegistration);
- }
-
- private <S> ServiceRegistration<S> unregisterService(ServiceRegistration<S> serviceRegistration) {
- if (serviceRegistration != null) {
- serviceRegistration.unregister();
- }
- return null;
}
@Override
@@ -155,10 +133,9 @@
Dictionary<?,?> props = (Dictionary<?,?>) args[0];
Object disabled = props.get("disable");
if ("true".equals(disabled)) {
- unregisterHooks();
+ unregisterHook();
} else {
registerHook();
- registerPlatformIsolationEnforcer();
}
}
}
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/PlatformIsolationEnforcer.java b/src/main/java/org/apache/sling/feature/apiregions/impl/PlatformIsolationEnforcer.java
deleted file mode 100644
index 200d1e3..0000000
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/PlatformIsolationEnforcer.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.feature.apiregions.impl;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Version;
-import org.osgi.framework.hooks.resolver.ResolverHook;
-import org.osgi.framework.wiring.BundleRevision;
-
-public class PlatformIsolationEnforcer extends AbstractResolverHookFactory<String, Version> {
-
- final Map<String, Version> bsnVerMap;
-
- PlatformIsolationEnforcer(BundleContext context) throws IOException, URISyntaxException {
- Map<String, Version> bsnVerMap = readBsnVerMap(context);
- this.bsnVerMap = Collections.unmodifiableMap(bsnVerMap);
- }
-
- @Override
- protected void addBsnVerArtifact(Map<String, Version> bsnVerMap,
- String artifactId,
- String bundleSymbolicName,
- Version bundleVersion) {
- bsnVerMap.put(bundleSymbolicName, bundleVersion);
- }
-
- @Override
- public ResolverHook begin(Collection<BundleRevision> triggers) {
- return new PlatformIsolationHook(bsnVerMap);
- }
-
-}
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/PlatformIsolationHook.java b/src/main/java/org/apache/sling/feature/apiregions/impl/PlatformIsolationHook.java
deleted file mode 100644
index 47ea7ce..0000000
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/PlatformIsolationHook.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.feature.apiregions.impl;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.osgi.framework.Version;
-import org.osgi.framework.hooks.resolver.ResolverHook;
-import org.osgi.framework.wiring.BundleCapability;
-import org.osgi.framework.wiring.BundleRequirement;
-import org.osgi.framework.wiring.BundleRevision;
-
-public class PlatformIsolationHook implements ResolverHook {
-
- protected static final String OSGI_WIRING_PACKAGE_NAMESPACE = "osgi.wiring.package";
-
- static final Logger LOG = Logger.getLogger(PlatformIsolationHook.class.getName());
-
- private final Map<String, Version> bsnVerMap;
-
- PlatformIsolationHook(Map<String, Version> bsnVerMap) {
- this.bsnVerMap = bsnVerMap;
- }
-
- @Override
- public void filterResolvable(Collection<BundleRevision> candidates) {
- // not used in this version
- }
-
- @Override
- public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
- // not used in this version
- }
-
- @Override
- public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
- for (Iterator<BundleCapability> it = candidates.iterator(); it.hasNext();) {
- BundleCapability candidate = it.next();
-
- BundleRevision rev = candidate.getRevision();
-
- // bundle is allowed to wire to itself
- if (requirement.getRevision().getBundle().getBundleId() == rev.getBundle().getBundleId()) {
- continue;
- }
-
- LOG.log(Level.FINE, "Checking if "
- + requirement
- + " can resolve from "
- + candidate
- + "...");
-
- // is it a restricted bundle?
- if (filter(requirement, candidate)) {
- it.remove();
- LOG.log(Level.INFO, "Prevented "
- + requirement
- + " from resolving to "
- + candidate);
- } else if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, "Check OK:"
- + requirement
- + " can resolve to "
- + candidate
- + "...");
- }
- }
- }
-
- boolean filter(BundleRequirement requirement, BundleCapability candidate) {
- String requirementNamespace = requirement.getNamespace();
- String candidateNamespace = candidate.getNamespace();
- if (!OSGI_WIRING_PACKAGE_NAMESPACE.equals(requirementNamespace)
- || !requirementNamespace.equals(candidateNamespace)) {
- return false; // checking wiring packages only
- }
-
- BundleRevision candidateRevision = candidate.getRevision();
- String candidateSymbolicName = candidateRevision.getSymbolicName();
- Version candidateVersion = candidateRevision.getVersion();
-
- Version expectedVersion = bsnVerMap.get(candidateSymbolicName);
-
- return expectedVersion != null && !expectedVersion.equals(candidateVersion);
- }
-
- @Override
- public void end() {
- // not used in this version
- }
-
-}
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
index f2aa3d9..a2dd9f8 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
@@ -18,6 +18,13 @@
*/
package org.apache.sling.feature.apiregions.impl;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
+import org.osgi.framework.hooks.resolver.ResolverHook;
+import org.osgi.framework.hooks.resolver.ResolverHookFactory;
+import org.osgi.framework.wiring.BundleRevision;
+
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
@@ -38,17 +45,15 @@
import java.util.Set;
import java.util.logging.Logger;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Version;
-import org.osgi.framework.hooks.resolver.ResolverHook;
-import org.osgi.framework.wiring.BundleRevision;
-
-class RegionEnforcer extends AbstractResolverHookFactory<Map.Entry<String, Version>, List<String>> {
+class RegionEnforcer implements ResolverHookFactory {
public static final String GLOBAL_REGION = "global";
+ static final String CLASSLOADER_PSEUDO_PROTOCOL = "classloader://";
static final String APIREGIONS_JOINGLOBAL = "sling.feature.apiregions.joinglobal";
+ static final String PROPERTIES_RESOURCE_PREFIX = "sling.feature.apiregions.resource.";
+ static final String PROPERTIES_FILE_LOCATION = "sling.feature.apiregions.location";
-
+ static final String IDBSNVER_FILENAME = "idbsnver.properties";
static final String BUNDLE_FEATURE_FILENAME = "bundles.properties";
static final String FEATURE_REGION_FILENAME = "features.properties";
static final String REGION_PACKAGE_FILENAME = "regions.properties";
@@ -66,7 +71,7 @@
URI idbsnverFile = getDataFileURI(context, IDBSNVER_FILENAME);
// Register the location as a service property for diagnostic purposes
regProps.put(IDBSNVER_FILENAME, idbsnverFile.toString());
- Map<Entry<String, Version>, List<String>> bvm = readBsnVerMap(context);
+ Map<Entry<String, Version>, List<String>> bvm = populateBSNVerMap(idbsnverFile);
URI bundlesFile = getDataFileURI(context, BUNDLE_FEATURE_FILENAME);
// Register the location as a service property for diagnostic purposes
@@ -123,12 +128,28 @@
}
}
- @Override
- protected void addBsnVerArtifact(Map<Entry<String, Version>, List<String>> bsnVerMap,
- String artifactId,
- String bundleSymbolicName,
- Version bundleVersion) {
- Map.Entry<String, Version> bsnVer = new AbstractMap.SimpleEntry<>(bundleSymbolicName, bundleVersion);
+ private static Map<Map.Entry<String, Version>, List<String>> populateBSNVerMap(URI idbsnverFile) throws IOException {
+ Map<Map.Entry<String, Version>, List<String>> m = new HashMap<>();
+
+ Properties p = new Properties();
+ try (InputStream is = idbsnverFile.toURL().openStream()) {
+ p.load(is);
+ }
+
+ for (String n : p.stringPropertyNames()) {
+ String[] bsnver = p.getProperty(n).split("~");
+ addBsnVerArtifact(m, bsnver[0], bsnver[1], n);
+ }
+
+ return m;
+ }
+
+ private static void addBsnVerArtifact(
+ Map<Map.Entry<String, Version>, List<String>> bsnVerMap,
+ String bundleSymbolicName, String bundleVersion,
+ String artifactId) {
+ Version version = Version.valueOf(bundleVersion);
+ Map.Entry<String, Version> bsnVer = new AbstractMap.SimpleEntry<>(bundleSymbolicName, version);
List<String> l = bsnVerMap.get(bsnVer);
if (l == null) {
l = new ArrayList<>();
@@ -178,6 +199,35 @@
bf.addAll(values);
}
+ private URI getDataFileURI(BundleContext ctx, String name) throws IOException, URISyntaxException {
+ String fn = ctx.getProperty(PROPERTIES_RESOURCE_PREFIX + name);
+ if (fn == null) {
+ String loc = ctx.getProperty(PROPERTIES_FILE_LOCATION);
+ if (loc != null) {
+ fn = loc + "/" + name;
+ }
+ }
+
+ if (fn == null)
+ throw new IOException("API Region Enforcement enabled, but no configuration found to find "
+ + "region definition resource: " + name);
+
+ if (fn.contains(":")) {
+ if (fn.startsWith(CLASSLOADER_PSEUDO_PROTOCOL)) {
+ // It's using the 'classloader:' protocol looks up the location from the classloader
+ String loc = fn.substring(CLASSLOADER_PSEUDO_PROTOCOL.length());
+ if (!loc.startsWith("/"))
+ loc = "/" + loc;
+ fn = getClass().getResource(loc).toString();
+ }
+ // It's already a URL
+ return new URI(fn);
+ } else {
+ // It's a file location
+ return new File(fn).toURI();
+ }
+ }
+
@Override
public ResolverHook begin(Collection<BundleRevision> triggers) {
if (enabledRegions.isEmpty())
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
index faf1098..7deb0ea 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
@@ -133,7 +133,7 @@
@Test
public void testUnregisterHook() {
Activator a = new Activator();
- a.unregisterHooks(); // Should not throw an exception
+ a.unregisterHook(); // Should not throw an exception
assertNull(a.hookRegistration);
}
@@ -145,7 +145,7 @@
Activator a = new Activator();
a.hookRegistration = reg;
- a.unregisterHooks();
+ a.unregisterHook();
Mockito.verify(reg).unregister();
assertNull(a.hookRegistration);
}
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/PlatformIsolationEnforcerTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/PlatformIsolationEnforcerTest.java
deleted file mode 100644
index 13d1339..0000000
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/PlatformIsolationEnforcerTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.feature.apiregions.impl;
-
-import static org.junit.Assert.*;
-import static org.apache.sling.feature.apiregions.impl.AbstractResolverHookFactory.IDBSNVER_FILENAME;
-import static org.apache.sling.feature.apiregions.impl.AbstractResolverHookFactory.PROPERTIES_RESOURCE_PREFIX;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Version;
-
-public class PlatformIsolationEnforcerTest {
-
- @Test
- public void testLoadBSNVerMap() throws Exception {
- String propertiesFile = getClass().getResource("/idbsnver1.properties").getFile();
-
- BundleContext context = mock(BundleContext.class);
- when(context.getProperty(PROPERTIES_RESOURCE_PREFIX + IDBSNVER_FILENAME)).thenReturn(propertiesFile);
-
- PlatformIsolationEnforcer enforcer = new PlatformIsolationEnforcer(context);
-
- assertFalse(enforcer.bsnVerMap.isEmpty());
- assertEquals(2, enforcer.bsnVerMap.size());
-
- Map<String, Version> expected = new HashMap<>();
- expected.put("b2", new Version(1, 2, 3));
- expected.put("b1", new Version(1, 0, 0));
-
- assertEquals(expected, enforcer.bsnVerMap);
- }
-
-}
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/PlatformIsolationHookTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/PlatformIsolationHookTest.java
deleted file mode 100644
index f495ede..0000000
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/PlatformIsolationHookTest.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.feature.apiregions.impl;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
-import org.osgi.framework.Version;
-import org.osgi.framework.wiring.BundleCapability;
-import org.osgi.framework.wiring.BundleRequirement;
-import org.osgi.framework.wiring.BundleRevision;
-
-public class PlatformIsolationHookTest {
-
- @Test
- public void doNotFilterRequirementWithDifferentNamespace() {
- BundleRequirement requirement = mock(BundleRequirement.class);
- when(requirement.getNamespace()).thenReturn("something.irrilevant");
-
- // won't be touched
- BundleCapability candidate = newBundleCapability();
-
- PlatformIsolationHook hook = new PlatformIsolationHook(new HashMap<String, Version>());
- assertFalse(hook.filter(requirement, candidate));
- }
-
- @Test
- public void doNotFilterCandidateWithDifferentNamespace() {
- BundleRequirement requirement = newRequirement();
-
- BundleCapability candidate = mock(BundleCapability.class);
- when(candidate.getNamespace()).thenReturn("something.irrilevant");
-
- PlatformIsolationHook hook = new PlatformIsolationHook(new HashMap<String, Version>());
- assertFalse(hook.filter(requirement, candidate));
- }
-
- @Test
- public void letUnownBundleBeResolved() {
- Map<String, Version> bsnVerMap = new HashMap<>();
- bsnVerMap.put("b2", new Version(1, 2, 3));
- bsnVerMap.put("b1", new Version(1, 0, 0));
- PlatformIsolationHook hook = new PlatformIsolationHook(bsnVerMap);
-
- BundleRequirement requirement = newRequirement();
-
- BundleCapability candidate = newBundleCapability();
- BundleRevision revision = newBundleRevision("asd", "1.0.0.CUSTOM");
- when(candidate.getRevision()).thenReturn(revision);
-
- assertFalse(hook.filter(requirement, candidate));
- }
-
- @Test
- public void letKnownBundleBeResolved() {
- Map<String, Version> bsnVerMap = new HashMap<>();
- bsnVerMap.put("b2", new Version(1, 2, 3));
- bsnVerMap.put("b1", new Version(1, 0, 0));
- PlatformIsolationHook hook = new PlatformIsolationHook(bsnVerMap);
-
- BundleRequirement requirement = newRequirement();
-
- BundleCapability candidate = newBundleCapability();
- BundleRevision revision = newBundleRevision("b1", "1.0.0");
- when(candidate.getRevision()).thenReturn(revision);
-
- assertFalse(hook.filter(requirement, candidate));
- }
-
- @Test
- public void upatedBundleFilteredOut() {
- Map<String, Version> bsnVerMap = new HashMap<>();
- bsnVerMap.put("b2", new Version(1, 2, 3));
- bsnVerMap.put("b1", new Version(1, 0, 0));
- PlatformIsolationHook hook = new PlatformIsolationHook(bsnVerMap);
-
- BundleRequirement requirement = newRequirement();
-
- BundleCapability candidate = newBundleCapability();
- BundleRevision revision = newBundleRevision("b1", "1.0.0.CUSTOM");
- when(candidate.getRevision()).thenReturn(revision);
-
- assertTrue(hook.filter(requirement, candidate));
- }
-
- private static BundleRequirement newRequirement() {
- BundleRequirement requirement = mock(BundleRequirement.class);
- when(requirement.getNamespace()).thenReturn(PlatformIsolationHook.OSGI_WIRING_PACKAGE_NAMESPACE);
- return requirement;
- }
-
- private static BundleCapability newBundleCapability() {
- BundleCapability candidate = mock(BundleCapability.class);
- when(candidate.getNamespace()).thenReturn(PlatformIsolationHook.OSGI_WIRING_PACKAGE_NAMESPACE);
- return candidate;
- }
-
- private static BundleRevision newBundleRevision(String symbolicName, String version) {
- BundleRevision revision = mock(BundleRevision.class);
- when(revision.getSymbolicName()).thenReturn(symbolicName);
- when(revision.getVersion()).thenReturn(Version.valueOf(version));
- return revision;
- }
-
-}