Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2016-02-11 22:29:39 +0000
committerThomas Watson2016-02-11 22:29:39 +0000
commitd2699fce816bd389b5c17cd54aa20a44f63f1473 (patch)
tree1293e1ad1f2d933fa6874b3252bb21e6a131baaa
parenta6b9ae00892db788d5f5d670bfe72414be275791 (diff)
downloadrt.equinox.framework-d2699fce816bd389b5c17cd54aa20a44f63f1473.tar.gz
rt.equinox.framework-d2699fce816bd389b5c17cd54aa20a44f63f1473.tar.xz
rt.equinox.framework-d2699fce816bd389b5c17cd54aa20a44f63f1473.zip
Bug 487696 - ModuleContainer should avoid dynamically resolving packages
that are exported Change-Id: I451d572e659815ed3266261bb643d0b1e6f48e6f Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java31
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainer.java15
2 files changed, 42 insertions, 4 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
index 2a931817d..c1a7acb6f 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
@@ -2151,6 +2151,37 @@ public class TestModuleContainer extends AbstractTest {
}
@Test
+ public void testDynamicWithExport() throws BundleException, IOException {
+ DummyContainerAdaptor adaptor = createDummyAdaptor();
+ ModuleContainer container = adaptor.getContainer();
+
+ // install the system.bundle
+ Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
+ ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
+ Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
+
+ // install an importer
+ Map<String, String> optionalImporterManifest = new HashMap<String, String>();
+ optionalImporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+ optionalImporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "importer");
+ optionalImporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
+ optionalImporterManifest.put(Constants.DYNAMICIMPORT_PACKAGE, "exporter");
+ Module optionalImporterModule = installDummyModule(optionalImporterManifest, "optionalImporter", container);
+
+ // unsatisfied optional and dynamic imports do not fail a resolve.
+ report = container.resolve(Arrays.asList(optionalImporterModule), true);
+ Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
+
+ //dynamic and optional imports are same. Optional import is not satisfied we should only see the dynamic import
+ List<BundleRequirement> importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
+ assertEquals("Wrong number of imports.", 1, importReqsList.size());
+ assertEquals("Import was not dynamic", PackageNamespace.RESOLUTION_DYNAMIC, importReqsList.get(0).getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
+
+ ModuleWire dynamicWire = container.resolveDynamic("exporter", optionalImporterModule.getCurrentRevision());
+ Assert.assertNull("Expected no dynamic wire.", dynamicWire);
+ }
+
+ @Test
public void testSubstitutableExport() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainer.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainer.java
index 2c73e63fe..248d98d61 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainer.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2014 IBM Corporation and others.
+ * Copyright (c) 2012, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,9 +16,7 @@ import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
-import org.eclipse.osgi.container.Module.StartOptions;
-import org.eclipse.osgi.container.Module.State;
-import org.eclipse.osgi.container.Module.StopOptions;
+import org.eclipse.osgi.container.Module.*;
import org.eclipse.osgi.container.ModuleContainerAdaptor.ContainerEvent;
import org.eclipse.osgi.container.ModuleContainerAdaptor.ModuleEvent;
import org.eclipse.osgi.container.ModuleDatabase.Sort;
@@ -746,6 +744,15 @@ public final class ModuleContainer implements DebugOptionsListener {
}
}
+ if (!result.isEmpty()) {
+ // must check that the wiring does not export the package
+ for (ModuleCapability capability : wiring.getModuleCapabilities(PackageNamespace.PACKAGE_NAMESPACE)) {
+ if (dynamicPkgName.equals(capability.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE))) {
+ // the package is exported, must not allow dynamic import
+ return Collections.emptyList();
+ }
+ }
+ }
return result;
}

Back to the top