aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1710841 - in /aries/trunk/subsystem/subsystem-core/src: main/java/org/apache/aries/subsystem/core/internal/ResolveContext.java test/java/org/apache/aries/subsystem/core/internal/ResolveContextTest.java
Date Tue, 27 Oct 2015 16:06:43 GMT
Author: davidb
Date: Tue Oct 27 16:06:42 2015
New Revision: 1710841

URL: http://svn.apache.org/viewvc?rev=1710841&view=rev
Log:
ARIES--1439 Aries ResolveContext.insertHostedCapability() calls unsupported add() method on
capabilies

Also added unit test.

Added:
    aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/ResolveContextTest.java
Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResolveContext.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResolveContext.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResolveContext.java?rev=1710841&r1=1710840&r2=1710841&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResolveContext.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResolveContext.java
Tue Oct 27 16:06:42 2015
@@ -48,7 +48,7 @@ public class ResolveContext extends org.
 	private final SubsystemResource resource;
 	private final Repository systemRepository;
 	private final Map<Resource, Wiring> wirings = computeWirings();
-	
+
 	public ResolveContext(SubsystemResource resource) {
 		this.resource = resource;
 		contentRepository = new ContentRepository(resource.getInstallableContent(), resource.getSharedContent());
@@ -57,13 +57,13 @@ public class ResolveContext extends org.
 		repositoryServiceRepository = new RepositoryServiceRepository();
 		systemRepository = Activator.getInstance().getSystemRepository();
 	}
-	
+
 	@Override
 	public List<Capability> findProviders(Requirement requirement) {
 		ArrayList<Capability> result = new ArrayList<Capability>();
 		try {
 			// Only check the system repository for osgi.ee and osgi.native
-			if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(requirement.getNamespace())

+			if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(requirement.getNamespace())
 					|| NativeNamespace.NATIVE_NAMESPACE.equals(requirement.getNamespace())) {
 				addDependenciesFromSystemRepository(requirement, result);
 			} else {
@@ -98,21 +98,27 @@ public class ResolveContext extends org.
 
 	@Override
 	public int insertHostedCapability(List<Capability> capabilities, HostedCapability
hostedCapability) {
-		capabilities.add(hostedCapability);
-		return capabilities.size() - 1;
+	    // Must specify the location where the capability is to be added. From the ResoveContext
javadoc:
+	    // "This method must insert the specified HostedCapability in a place that makes the
list maintain
+	    // the preference order."
+	    // The Felix implementation provides a list that requires the index to be specified
in the add() call,
+	    // otherwise it will throw an exception.
+        int sz = capabilities.size();
+		capabilities.add(sz, hostedCapability);
+        return sz;
 	}
 
 	@Override
 	public boolean isEffective(Requirement requirement) {
 		return true;
 	}
-	
+
 	@Override
 	public Collection<Resource> getMandatoryResources() {
 		return resource.getMandatoryResources();
 	}
-	
-	@Override 
+
+	@Override
 	public Collection<Resource> getOptionalResources() {
 		return resource.getOptionalResources();
 	}
@@ -121,7 +127,7 @@ public class ResolveContext extends org.
 	public Map<Resource, Wiring> getWirings() {
 		return wirings;
 	}
-	
+
 	private boolean addDependencies(Repository repository, Requirement requirement, List<Capability>
capabilities, boolean validate) throws BundleException, IOException, InvalidSyntaxException,
URISyntaxException {
 		if (repository == null)
 			return false;
@@ -172,7 +178,7 @@ public class ResolveContext extends org.
 			wirings.put(br, br.getWiring());
 		}
 	}
-	
+
 	private Map<Resource, Wiring> computeWirings() {
 		Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
 		for (BasicSubsystem subsystem : Activator.getInstance().getSubsystems().getSubsystems())
{ // NEED
@@ -198,7 +204,7 @@ public class ResolveContext extends org.
 				}
 				// For applications and features, we must ensure capabilities
 				// are visible to their scoped parent. Features import
-				// everything. Applications have their sharing policies 
+				// everything. Applications have their sharing policies
 				// computed, so if capabilities are visible to the parent, we
 				// know we can make them visible to the application.
 				return this.resource.getParents().iterator().next().getRegion();

Added: aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/ResolveContextTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/ResolveContextTest.java?rev=1710841&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/ResolveContextTest.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/ResolveContextTest.java
Tue Oct 27 16:06:42 2015
@@ -0,0 +1,99 @@
+/*
+ * Licensed 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.aries.subsystem.core.internal;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.easymock.EasyMock;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.resource.Capability;
+import org.osgi.service.resolver.HostedCapability;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+public class ResolveContextTest {
+    @Test
+    public void testInsertHostedCapability() throws Exception {
+        Activator prev = getActivator();
+        try {
+            Activator activator = createActivator();
+            setActivator(activator);
+
+            SubsystemResource res = new SubsystemResource(new File("."));
+            ResolveContext rc = new ResolveContext(res);
+
+            HostedCapability hc = EasyMock.createNiceMock(HostedCapability.class);
+
+            List<Capability> caps = new ArrayList<Capability>() {
+                // Must use add(idx, obj), get the other add() overloads to complain
+
+                @Override
+                public boolean add(Capability e) {
+                    throw new UnsupportedOperationException();
+                }
+
+                @Override
+                public boolean addAll(Collection<? extends Capability> c) {
+                    throw new UnsupportedOperationException();
+                }
+
+                @Override
+                public boolean addAll(int index, Collection<? extends Capability> c)
{
+                    throw new UnsupportedOperationException();
+                }
+            };
+            caps.add(0, EasyMock.createNiceMock(HostedCapability.class));
+
+            assertEquals(1, rc.insertHostedCapability(caps, hc));
+            assertSame(hc, caps.get(1));
+        } finally {
+            setActivator(prev);
+        }
+    }
+
+    private Activator createActivator() throws Exception {
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(bc);
+
+        Activator a = new Activator();
+
+        Field f = Activator.class.getDeclaredField("subsystems");
+        f.setAccessible(true);
+        f.set(a, new Subsystems());
+
+        Field f2 = Activator.class.getDeclaredField("systemRepositoryManager");
+        f2.setAccessible(true);
+        f2.set(a, new SystemRepositoryManager(bc));
+
+        return a;
+    }
+
+    private Activator getActivator() throws Exception {
+        Field f = Activator.class.getDeclaredField("instance");
+        f.setAccessible(true);
+        return (Activator) f.get(null);
+    }
+
+    private void setActivator(Activator a) throws Exception {
+        Field f = Activator.class.getDeclaredField("instance");
+        f.setAccessible(true);
+        f.set(null, a);
+    }
+}



Mime
View raw message