You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jw...@apache.org on 2015/10/21 17:00:29 UTC
svn commit: r1709860 - in /aries/trunk/subsystem:
subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/WovenClassListener.java
subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1435Test.java
Author: jwross
Date: Wed Oct 21 15:00:28 2015
New Revision: 1709860
URL: http://svn.apache.org/viewvc?rev=1709860&view=rev
Log:
ARIES-1435 Sharing policy updates for dynamic imports, if necessary, should proceed up the subsystem region tree.
Whether or not a sharing policy already allows a matching capability for a dynamic import is not a sufficient condition for terminating the walk up the region tree. It may only be used
for the purposes of avoiding an unnecessary update to a particular sharing policy in the path.
Add test.
Modified:
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/WovenClassListener.java
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1435Test.java
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/WovenClassListener.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/WovenClassListener.java?rev=1709860&r1=1709859&r2=1709860&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/WovenClassListener.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/WovenClassListener.java Wed Oct 21 15:00:28 2015
@@ -22,7 +22,6 @@ import java.security.AccessController;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Deque;
import java.util.EnumSet;
import java.util.HashMap;
@@ -178,9 +177,15 @@ public class WovenClassListener implemen
// Do nothing.
return;
}
+ BasicSubsystem subsystem = deque.pop();
+ if (filter.isAllowed(providers.iterator().next())) {
+ // The sharing policy already allows the dynamic import
+ // so no update is necessary.
+ return;
+ }
// Add the subsystem to the list indicating a sharing policy
// update is required.
- subsystems.add(deque.pop());
+ subsystems.add(subsystem);
}
@Override
@@ -191,15 +196,6 @@ public class WovenClassListener implemen
// Do not visit the head region of this filter connection.
return false;
}
- String dynamicImport = requirement.getPackageName();
- if (!"*".equals(dynamicImport)
- && !dynamicImport.endsWith(".*")
- && filter.isAllowed(providers.iterator().next())) {
- // The dynamic import does not contain a wildcard and the
- // sharing policy already allows the import.
- // Do not visit the head region of this filter connection.
- return false;
- }
// Visit the head region of this filter connection
return true;
}
@@ -230,31 +226,27 @@ public class WovenClassListener implemen
BundleRevision br = provider.getResource();
if (region.contains(br.getBundle()) && !requirement.getPackageName().contains("*")) {
// The subsystem contains the provider so there is no
- // need to update it's sharing policy. It must be added
- // to the list, however, to serve as a head.
- subsystems.add(deque.pop());
+ // need to update it's sharing policy. Remove it from
+ // the list.
+ deque.pop();
// Do not traverse the edges of this region.
return false;
}
}
if (region.getEdges().isEmpty()) {
// We want to traverse the edges but it has none. This means
- // we will miss a call to postEdgeTraverse resulting in a
- // needed subsystem not being added. Add it here.
- subsystems.add(deque.pop());
+ // there is no sharing policy to update. Remove it from the
+ // list.
+ deque.pop();
}
// Traverse the edges of this region.
return true;
}
});
- // The reversal is necessary because the postEdgeTraverse calls in the
- // visitor act as a LIFO queue. We want the order to be tail, head/tail,
- // head/tail, ..., head. In other words, index i is the tail and index
- // i + 1 is the head.
- Collections.reverse(subsystems);
- for (int i = 0; i < subsystems.size()-1; i++) {
- Region tail = subsystems.get(i).getRegion();
- Region head = subsystems.get(i+1).getRegion();
+ // Collect the information for the necessary sharing policy updates.
+ for (BasicSubsystem subsystem : subsystems) {
+ Region tail = subsystem.getRegion();
+ Region head = scopedParent(subsystem).getRegion();
RegionUpdaterInfo info = updates.get(tail);
if (info == null) {
info = new RegionUpdaterInfo(tail, head);
Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1435Test.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1435Test.java?rev=1709860&r1=1709859&r2=1709860&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1435Test.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1435Test.java Wed Oct 21 15:00:28 2015
@@ -18,15 +18,19 @@
*/
package org.apache.aries.subsystem.itests.defect;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -45,6 +49,7 @@ import org.junit.Test;
import org.ops4j.pax.tinybundles.core.InnerClassStrategy;
import org.ops4j.pax.tinybundles.core.TinyBundles;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
import org.osgi.framework.hooks.weaving.WeavingHook;
@@ -75,6 +80,7 @@ public class Aries1435Test extends Subsy
private static final String COMPOSITE_C = "composite.c.esa";
private static final String COMPOSITE_D = "composite.d.esa";
private static final String COMPOSITE_E = "composite.e.esa";
+ private static final String COMPOSITE_F = "composite.f.esa";
private static final String FEATURE_A = "feature.a.esa";
private static final String FEATURE_B = "feature.b.esa";
private static final String FEATURE_C = "feature.c.esa";
@@ -99,6 +105,7 @@ public class Aries1435Test extends Subsy
createFeatureD();
createApplicationE();
createCompositeE();
+ createCompositeF();
createdTestFiles = true;
}
@@ -376,6 +383,63 @@ public class Aries1435Test extends Subsy
}
}
+ @Test
+ public void testWovenSubsystemParentPolicyAllowsProvider() throws Exception {
+ registerWeavingHook("b");
+ Subsystem root = getRootSubsystem();
+ BundleContext context = root.getBundleContext();
+ Bundle bundleB = context.installBundle(BUNDLE_B, new ByteArrayInputStream(createBundleBContent()));
+ try {
+ Subsystem applicationB1 = installSubsystemFromFile(root, new File(APPLICATION_B), APPLICATION_B + "1");
+ try {
+ Subsystem compositeF = installSubsystemFromFile(applicationB1, COMPOSITE_F);
+ try {
+ assertPackageFiltersInParentConnection(compositeF, applicationB1, 2, 1);
+ Subsystem applicationB2 = installSubsystemFromFile(compositeF, new File(APPLICATION_B), APPLICATION_B + "2");
+ try {
+ testDynamicImport(applicationB2, "b.B");
+ testSharingPolicy(applicationB2, "b", true);
+ testSharingPolicy(compositeF, "b", true);
+ assertPackageFiltersInParentConnection(compositeF, applicationB1, 2, 1);
+ testSharingPolicy(applicationB1, "b", true);
+ testSharingPolicy(root, "b", false);
+ }
+ finally {
+ uninstallSubsystemSilently(applicationB2);
+ }
+ }
+ finally {
+ uninstallSubsystemSilently(compositeF);
+ }
+ }
+ finally {
+ uninstallSubsystemSilently(applicationB1);
+ }
+ }
+ finally {
+ uninstallSilently(bundleB);
+ }
+ }
+
+ private void assertPackageFiltersInParentConnection(Subsystem subsystem, Subsystem parent, int expectedEdges, int expectedFilters) {
+ Region parentRegion = getRegion(parent);
+ Region region = getRegion(subsystem);
+ Set<FilteredRegion> edges = region.getEdges();
+ assertEquals("Wrong number of edges", expectedEdges, edges.size());
+ for (FilteredRegion edge : region.getEdges()) {
+ if (!edge.getRegion().equals(parentRegion)) {
+ continue;
+ }
+ RegionFilter filter = edge.getFilter();
+ Map<String, Collection<String>> policy = filter.getSharingPolicy();
+ Collection<String> packages = policy.get(PackageNamespace.PACKAGE_NAMESPACE);
+ assertNotNull("Wrong number of packages", packages);
+ assertEquals("Wrong number of packages", expectedFilters, packages.size());
+ return;
+ }
+ fail("No connection to parent found");
+ }
+
private void createApplicationA() throws IOException {
createApplicationAManifest();
createSubsystem(APPLICATION_A, APPLICATION_B);
@@ -570,6 +634,19 @@ public class Aries1435Test extends Subsy
createManifest(COMPOSITE_E + ".mf", attributes);
}
+ private void createCompositeF() throws IOException {
+ createCompositeFManifest();
+ createSubsystem(COMPOSITE_F);
+ }
+
+ private void createCompositeFManifest() throws IOException {
+ Map<String, String> attributes = new HashMap<String, String>();
+ attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, COMPOSITE_F);
+ attributes.put(SubsystemConstants.SUBSYSTEM_TYPE, SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE);
+ attributes.put(Constants.IMPORT_PACKAGE, "b;resolution:=optional");
+ createManifest(COMPOSITE_F + ".mf", attributes);
+ }
+
private void createFeatureA() throws IOException {
createFeatureAManifest();
createSubsystem(FEATURE_A, APPLICATION_B);