Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/PlatformAdminImpl.java23
-rw-r--r--bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/PlatformBundleListener.java198
-rw-r--r--bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/StateConverter.java13
-rw-r--r--bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/BaseDescriptionImpl.java6
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java2
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java371
6 files changed, 256 insertions, 357 deletions
diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/PlatformAdminImpl.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/PlatformAdminImpl.java
index 95cc2bfa0..55ace736b 100644
--- a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/PlatformAdminImpl.java
+++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/PlatformAdminImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 IBM Corporation and others. All rights reserved.
+ * Copyright (c) 2012, 2013 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 http://www.eclipse.org/legal/epl-v10.html
@@ -23,17 +23,28 @@ public class PlatformAdminImpl implements PlatformAdmin {
private final StateObjectFactory factory = new StateObjectFactoryImpl();
private final Object monitor = new Object();
private EquinoxContainer equinoxContainer;
+ private BundleContext bc;
private State systemState;
+ private PlatformBundleListener synchronizer;
private ServiceRegistration<PlatformAdmin> reg;
void start(BundleContext context) {
synchronized (this.monitor) {
equinoxContainer = ((BundleContextImpl) context).getContainer();
+ this.bc = context;
}
this.reg = context.registerService(PlatformAdmin.class, this, null);
}
void stop(BundleContext context) {
+ synchronized (this.monitor) {
+ if (synchronizer != null) {
+ context.removeBundleListener(synchronizer);
+ context.removeFrameworkListener(synchronizer);
+ }
+ synchronizer = null;
+ systemState = null;
+ }
this.reg.unregister();
}
@@ -71,16 +82,20 @@ public class PlatformAdminImpl implements PlatformAdmin {
ModuleDatabase database = equinoxContainer.getStorage().getModuleDatabase();
database.readLock();
try {
+ ModuleContainer container = equinoxContainer.getStorage().getModuleContainer();
List<Module> modules = equinoxContainer.getStorage().getModuleContainer().getModules();
for (Module module : modules) {
ModuleRevision current = module.getCurrentRevision();
BundleDescription description = converter.createDescription(current);
state.addBundle(description);
- state.setPlatformProperties(asDictionary(equinoxContainer.getConfiguration().getInitialConfig()));
}
+ state.setPlatformProperties(asDictionary(equinoxContainer.getConfiguration().getInitialConfig()));
+ synchronizer = new PlatformBundleListener(state, converter, database, container);
+ state.setResolverHookFactory(synchronizer);
+ bc.addBundleListener(synchronizer);
+ bc.addFrameworkListener(synchronizer);
+ state.resolve();
state.setTimeStamp(database.getRevisionsTimestamp());
- // TODO add hooks to get the resolution correct
- // TODO add listeners to keep state copy in sync
} finally {
database.readUnlock();
}
diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/PlatformBundleListener.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/PlatformBundleListener.java
new file mode 100644
index 000000000..361c30b5c
--- /dev/null
+++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/PlatformBundleListener.java
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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 http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.osgi.compatibility.state;
+
+import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.eclipse.osgi.container.*;
+import org.eclipse.osgi.internal.resolver.BaseDescriptionImpl.BaseCapability;
+import org.eclipse.osgi.service.resolver.BundleDescription;
+import org.eclipse.osgi.service.resolver.State;
+import org.osgi.framework.*;
+import org.osgi.framework.hooks.resolver.ResolverHook;
+import org.osgi.framework.hooks.resolver.ResolverHookFactory;
+import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
+import org.osgi.framework.namespace.HostNamespace;
+import org.osgi.framework.wiring.*;
+
+class PlatformBundleListener implements SynchronousBundleListener, FrameworkListener, ResolverHookFactory {
+
+ private final State systemState;
+ private final StateConverter converter;
+ private final ModuleDatabase database;
+ private final ModuleContainer container;
+ private long lastResolveStamp = -1;
+ private AtomicBoolean gotUnresolved = new AtomicBoolean(false);
+
+ PlatformBundleListener(State systemState, StateConverter converter, ModuleDatabase database, ModuleContainer container) {
+ this.systemState = systemState;
+ this.converter = converter;
+ this.database = database;
+ this.container = container;
+ }
+
+ @Override
+ public void bundleChanged(BundleEvent event) {
+ switch (event.getType()) {
+ case BundleEvent.INSTALLED : {
+ BundleRevision revision = event.getBundle().adapt(BundleRevision.class);
+ if (revision != null) {
+ systemState.addBundle(converter.createDescription(revision));
+ systemState.setTimeStamp(database.getRevisionsTimestamp());
+ }
+ break;
+ }
+ case BundleEvent.UNINSTALLED : {
+ systemState.removeBundle(event.getBundle().getBundleId());
+ systemState.setTimeStamp(database.getRevisionsTimestamp());
+ break;
+ }
+ case BundleEvent.UPDATED : {
+ BundleRevision revision = event.getBundle().adapt(BundleRevision.class);
+ if (revision != null) {
+ systemState.updateBundle(converter.createDescription(revision));
+ systemState.setTimeStamp(database.getRevisionsTimestamp());
+ }
+ break;
+ }
+ case BundleEvent.UNRESOLVED : {
+ gotUnresolved.set(true);
+ break;
+ }
+ case BundleEvent.RESOLVED : {
+ resolve(gotUnresolved.getAndSet(false));
+ break;
+ }
+ default :
+ // do nothing
+ break;
+ }
+ }
+
+ private void resolve(boolean uninstalled) {
+ database.readLock();
+ try {
+ if (lastResolveStamp != database.getRevisionsTimestamp()) {
+ Collection<ModuleRevision> containerRemovalPending = container.getRemovalPending();
+ BundleDescription[] stateRemovalPendingDescs = systemState.getRemovalPending();
+ Collection<BundleDescription> stateRemovalPending = new ArrayList<BundleDescription>(stateRemovalPendingDescs.length);
+ for (BundleDescription description : stateRemovalPendingDescs) {
+ if (!containerRemovalPending.contains(description.getUserObject())) {
+ stateRemovalPending.add(description);
+ }
+ }
+ if (!stateRemovalPending.isEmpty()) {
+ systemState.resolve(stateRemovalPending.toArray(new BundleDescription[stateRemovalPending.size()]), true);
+ } else {
+ systemState.resolve(!uninstalled);
+ }
+ lastResolveStamp = database.getRevisionsTimestamp();
+ systemState.setTimeStamp(database.getRevisionsTimestamp());
+ }
+ } finally {
+ database.readUnlock();
+ }
+ }
+
+ @Override
+ public void frameworkEvent(FrameworkEvent event) {
+ if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) {
+ resolve(gotUnresolved.getAndSet(false));
+ }
+ }
+
+ @Override
+ public ResolverHook begin(Collection<BundleRevision> triggers) {
+ return new ResolverHook() {
+
+ @Override
+ public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
+ BundleDescription desc = (BundleDescription) singleton.getRevision();
+ ModuleRevision revision = (ModuleRevision) desc.getUserObject();
+ if (revision.getWiring() != null) {
+ collisionCandidates.clear();
+ } else {
+ for (Iterator<BundleCapability> iCandidates = collisionCandidates.iterator(); iCandidates.hasNext();) {
+ BundleDescription candDesc = (BundleDescription) iCandidates.next().getRevision();
+ ModuleRevision candRevision = (ModuleRevision) candDesc.getUserObject();
+ if (candRevision.getWiring() == null) {
+ iCandidates.remove();
+ }
+ }
+ }
+ }
+
+ @Override
+ public void filterResolvable(Collection<BundleRevision> candidates) {
+ for (Iterator<BundleRevision> iCandidates = candidates.iterator(); iCandidates.hasNext();) {
+ BundleDescription candDesc = (BundleDescription) iCandidates.next();
+ ModuleRevision candRevision = (ModuleRevision) candDesc.getUserObject();
+ if (candRevision.getWiring() == null) {
+ iCandidates.remove();
+ }
+ }
+ }
+
+ @Override
+ public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
+ String namespace = requirement.getNamespace();
+ BundleDescription reqDesc = (BundleDescription) requirement.getRevision();
+ ModuleRevision reqRevision = (ModuleRevision) reqDesc.getUserObject();
+ ModuleWiring reqWiring = reqRevision.getWiring();
+ if (reqWiring == null) {
+ candidates.clear();
+ return;
+ }
+ Collection<ModuleWiring> wirings = new ArrayList<ModuleWiring>(1);
+ if ((reqRevision.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
+ if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(namespace) || HostNamespace.HOST_NAMESPACE.equals(namespace)) {
+ wirings.add(reqWiring);
+ } else {
+ List<ModuleWire> hostWires = reqWiring.getRequiredModuleWires(namespace);
+ for (ModuleWire hostWire : hostWires) {
+ ModuleWiring hostWiring = hostWire.getProviderWiring();
+ if (hostWiring != null) {
+ wirings.add(hostWiring);
+ }
+ }
+ }
+ } else {
+ wirings.add(reqWiring);
+ }
+ for (Iterator<BundleCapability> iCandidates = candidates.iterator(); iCandidates.hasNext();) {
+ BaseCapability baseCapability = (BaseCapability) iCandidates.next();
+ Object userObject = baseCapability.getBaseDescription().getUserObject();
+ boolean foundCandidate = false;
+ wirings: for (ModuleWiring wiring : wirings) {
+ List<ModuleWire> wires = wiring.getRequiredModuleWires(namespace);
+ for (ModuleWire wire : wires) {
+ if (userObject instanceof ModuleRevision && userObject.equals(wire.getProvider())) {
+ foundCandidate = true;
+ } else if (userObject instanceof ModuleCapability && userObject.equals(wire.getCapability())) {
+ foundCandidate = true;
+ }
+ if (foundCandidate)
+ break wirings;
+ }
+ }
+ if (!foundCandidate) {
+ iCandidates.remove();
+ }
+ }
+ }
+
+ @Override
+ public void end() {
+ // nothing
+ }
+ };
+ }
+
+}
diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/StateConverter.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/StateConverter.java
index 7c6754e7d..dbf45aba4 100644
--- a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/StateConverter.java
+++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/compatibility/state/StateConverter.java
@@ -1,3 +1,12 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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 http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
package org.eclipse.osgi.compatibility.state;
import java.util.*;
@@ -68,7 +77,7 @@ class StateConverter {
}
}
- BundleDescription result = state.getFactory().createBundleDescription(resource.getBundle().getBundleId(), symbolicNameSpecification, version, null, requireBundles.toArray(new BundleSpecification[requireBundles.size()]), fragmentHost.size() == 0 ? null : fragmentHost.get(0), importPackages.toArray(new ImportPackageSpecification[importPackages.size()]), exportPackages.toArray(new ExportPackageDescription[exportPackages.size()]), null, null, requireCapabilities.toArray(new GenericSpecification[requireCapabilities.size()]), provideCapabilities.toArray(new GenericDescription[provideCapabilities.size()]), null);
+ BundleDescription result = state.getFactory().createBundleDescription(resource.getBundle().getBundleId(), symbolicNameSpecification, version, resource.getBundle().getLocation(), requireBundles.toArray(new BundleSpecification[requireBundles.size()]), fragmentHost.size() == 0 ? null : fragmentHost.get(0), importPackages.toArray(new ImportPackageSpecification[importPackages.size()]), exportPackages.toArray(new ExportPackageDescription[exportPackages.size()]), null, null, requireCapabilities.toArray(new GenericSpecification[requireCapabilities.size()]), provideCapabilities.toArray(new GenericDescription[provideCapabilities.size()]), null);
result.setUserObject(resource);
GenericDescription[] genericDescs = result.getGenericCapabilities();
for (GenericDescription genericDesc : genericDescs) {
@@ -85,7 +94,7 @@ class StateConverter {
String packageName = (String) attributes.remove(PackageNamespace.PACKAGE_NAMESPACE);
// remove invalid attributes
attributes.remove(PackageNamespace.CAPABILITY_BUNDLE_SYMBOLICNAME_ATTRIBUTE);
- attributes.remove(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
+ attributes.remove(AbstractWiringNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE);
String declaration = packageName + toString(attributes, "=", true) + toString(directives, ":=", true); //$NON-NLS-1$//$NON-NLS-2$
List<ExportPackageDescription> result = state.getFactory().createExportPackageDescriptions(declaration);
for (ExportPackageDescription export : result) {
diff --git a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/BaseDescriptionImpl.java b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/BaseDescriptionImpl.java
index 60d3f2b30..3abcdfdb6 100644
--- a/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/BaseDescriptionImpl.java
+++ b/bundles/org.eclipse.osgi.compatibility.state/src/org/eclipse/osgi/internal/resolver/BaseDescriptionImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2013 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
@@ -114,7 +114,7 @@ public abstract class BaseDescriptionImpl implements BaseDescription {
this.userObject = userObject;
}
- class BaseCapability implements BundleCapability {
+ public class BaseCapability implements BundleCapability {
private final String namespace;
public BaseCapability(String namespace) {
@@ -151,7 +151,7 @@ public abstract class BaseDescriptionImpl implements BaseDescription {
return System.identityHashCode(BaseDescriptionImpl.this);
}
- protected BaseDescriptionImpl getBaseDescription() {
+ public BaseDescriptionImpl getBaseDescription() {
return BaseDescriptionImpl.this;
}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java
index 8f6b99699..558268b4e 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java
@@ -26,10 +26,10 @@ public class BundleTests {
suite.addTest(BundleExceptionTests.suite());
suite.addTest(SubstituteExportsBundleTests.suite());
suite.addTest(PackageAdminBundleTests.suite());
- //suite.addTest(PlatformAdminBundleTests.suite());
suite.addTest(ExtensionBundleTests.suite());
suite.addTest(ClassLoadingBundleTests.suite());
suite.addTest(NativeCodeBundleTests.suite());
+ suite.addTest(PlatformAdminBundleTests.suite());
return suite;
}
}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java
index 75c720537..34e0a3a46 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * Copyright (c) 2007, 2013 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
@@ -10,392 +10,69 @@
*******************************************************************************/
package org.eclipse.osgi.tests.bundles;
+import java.util.Arrays;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.wiring.FrameworkWiring;
public class PlatformAdminBundleTests extends AbstractBundleTests {
public static Test suite() {
return new TestSuite(PlatformAdminBundleTests.class);
}
- public void testDisabledInfo01() throws Exception {
- String testPolicy = "testDisabledInfo01";
- Bundle chainTest = installer.installBundle("chain.test");
- Bundle chainTestA = installer.installBundle("chain.test.a");
- Bundle chainTestB = installer.installBundle("chain.test.b");
- Bundle chainTestC = installer.installBundle("chain.test.c");
- Bundle chainTestD = installer.installBundle("chain.test.d");
- Bundle[] allBundles = new Bundle[] {chainTest, chainTestA, chainTestB, chainTestC, chainTestD};
-
+ public void testInstallUninstallBundle() throws BundleException {
PlatformAdmin pa = installer.getPlatformAdmin();
+ // get system state first to ensure it does not have the test bundle
State systemState = pa.getState(false);
- BundleDescription testDesc = systemState.getBundle(chainTest.getBundleId());
- BundleDescription testADesc = systemState.getBundle(chainTestA.getBundleId());
- BundleDescription testBDesc = systemState.getBundle(chainTestB.getBundleId());
- BundleDescription testCDesc = systemState.getBundle(chainTestC.getBundleId());
- BundleDescription testDDesc = systemState.getBundle(chainTestD.getBundleId());
- assertNotNull("testDesc null!!", testDesc);
- assertNotNull("testADesc null!!", testADesc);
- assertNotNull("testBDesc null!!", testBDesc);
- assertNotNull("testCDesc null!!", testCDesc);
- assertNotNull("testDDesc null!!", testDDesc);
-
- installer.resolveBundles(allBundles);
- assertTrue("testDesc not resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
-
- // ok finally we can start testing!!!
- // disable the toplevel testDesc bundle
- pa.addDisabledInfo(new DisabledInfo(testPolicy, "reason 1", testDesc));
- // force the bundles to re-resolve
- installer.refreshPackages(allBundles);
- // only testDesc should be unresolved
- assertFalse("testDesc is resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
- // now enable the bundle
- DisabledInfo info = systemState.getDisabledInfo(testDesc, testPolicy);
- assertNotNull("info is null!!", info);
- pa.removeDisabledInfo(info);
- // just do normal resolve
- assertTrue("resolveBundles returned false!", installer.resolveBundles(new Bundle[] {chainTest}));
- // all bundles should be resolved
- assertTrue("testDesc not resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
- }
-
- public void testDisabledInfo02() throws Exception {
- String testPolicy1 = "testDisabledInfo01";
- String testPolicy2 = "testDisabledInfo02";
- Bundle chainTest = installer.installBundle("chain.test");
- Bundle chainTestA = installer.installBundle("chain.test.a");
- Bundle chainTestB = installer.installBundle("chain.test.b");
- Bundle chainTestC = installer.installBundle("chain.test.c");
- Bundle chainTestD = installer.installBundle("chain.test.d");
- Bundle[] allBundles = new Bundle[] {chainTest, chainTestA, chainTestB, chainTestC, chainTestD};
-
- PlatformAdmin pa = installer.getPlatformAdmin();
- State systemState = pa.getState(false);
- BundleDescription testDesc = systemState.getBundle(chainTest.getBundleId());
- BundleDescription testADesc = systemState.getBundle(chainTestA.getBundleId());
- BundleDescription testBDesc = systemState.getBundle(chainTestB.getBundleId());
- BundleDescription testCDesc = systemState.getBundle(chainTestC.getBundleId());
- BundleDescription testDDesc = systemState.getBundle(chainTestD.getBundleId());
- assertNotNull("testDesc null!!", testDesc);
- assertNotNull("testADesc null!!", testADesc);
- assertNotNull("testBDesc null!!", testBDesc);
- assertNotNull("testCDesc null!!", testCDesc);
- assertNotNull("testDDesc null!!", testDDesc);
-
- installer.resolveBundles(allBundles);
- assertTrue("testDesc not resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
- // ok finally we can start testing!!!
- // disable the toplevel testDesc bundle with two DisabledInfos
- pa.addDisabledInfo(new DisabledInfo(testPolicy1, "reason 1", testDesc));
- pa.addDisabledInfo(new DisabledInfo(testPolicy2, "reason 2", testDesc));
- // force the bundles to re-resolve
- installer.refreshPackages(allBundles);
- // only testDesc should be unresolved
- assertFalse("testDesc is resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
+ BundleDescription testDesc = systemState.getBundleByLocation(installer.getBundleLocation("test"));
+ assertNull("Should not find bundle.", testDesc);
- DisabledInfo info1 = systemState.getDisabledInfo(testDesc, testPolicy1);
- DisabledInfo info2 = systemState.getDisabledInfo(testDesc, testPolicy2);
- assertNotNull("info1 is null!!", info1);
- assertNotNull("info2 is null!!", info2);
- // now remove the first policy
- pa.removeDisabledInfo(info1);
- // just do normal resolve
- assertFalse("resolveBundles returned true!", installer.resolveBundles(new Bundle[] {chainTest}));
- // testDesc should still be unresolved
- assertFalse("testDesc is resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
+ Bundle test = installer.installBundle("test");
+ testDesc = systemState.getBundleByLocation(installer.getBundleLocation("test"));
+ assertNotNull("Should find bundle.", testDesc);
- // now remove the second policy
- pa.removeDisabledInfo(info2);
- // just do normal resolve
- assertTrue("resolveBundles returned false!", installer.resolveBundles(new Bundle[] {chainTest}));
- // testDesc should still be unresolved
- assertTrue("testDesc not resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
+ test.uninstall();
+ testDesc = systemState.getBundleByLocation(installer.getBundleLocation("test"));
+ assertNull("Should not find bundle.", testDesc);
}
- public void testDisabledInfo03() throws Exception {
- String testPolicy1 = "testDisabledInfo01";
- String testPolicy2 = "testDisabledInfo02";
- Bundle chainTest = installer.installBundle("chain.test");
- Bundle chainTestA = installer.installBundle("chain.test.a");
- Bundle chainTestB = installer.installBundle("chain.test.b");
- Bundle chainTestC = installer.installBundle("chain.test.c");
- Bundle chainTestD = installer.installBundle("chain.test.d");
- Bundle[] allBundles = new Bundle[] {chainTest, chainTestA, chainTestB, chainTestC, chainTestD};
-
+ public void testResolveRefresh() throws BundleException {
PlatformAdmin pa = installer.getPlatformAdmin();
State systemState = pa.getState(false);
- BundleDescription testDesc = systemState.getBundle(chainTest.getBundleId());
- BundleDescription testADesc = systemState.getBundle(chainTestA.getBundleId());
- BundleDescription testBDesc = systemState.getBundle(chainTestB.getBundleId());
- BundleDescription testCDesc = systemState.getBundle(chainTestC.getBundleId());
- BundleDescription testDDesc = systemState.getBundle(chainTestD.getBundleId());
- assertNotNull("testDesc null!!", testDesc);
- assertNotNull("testADesc null!!", testADesc);
- assertNotNull("testBDesc null!!", testBDesc);
- assertNotNull("testCDesc null!!", testCDesc);
- assertNotNull("testDDesc null!!", testDDesc);
- installer.resolveBundles(allBundles);
- assertTrue("testDesc not resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
-
- // ok finally we can start testing!!!
- // disable the toplevel testDesc bundle
- pa.addDisabledInfo(new DisabledInfo(testPolicy1, "reason 1", testDesc));
- pa.addDisabledInfo(new DisabledInfo(testPolicy2, "reason 2", testDesc));
- // force the bundles to re-resolve
- installer.refreshPackages(allBundles);
- // only testDesc should be unresolved
- assertFalse("testDesc is resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
-
- ResolverError[] errors = systemState.getResolverErrors(testDesc);
- assertNotNull("resolver errors is null!!", errors);
- assertEquals("unexpected number of errors", 1, errors.length);
- assertEquals("unexpected error type", ResolverError.DISABLED_BUNDLE, errors[0].getType());
- }
-
- public void testDisabledInfo04() throws Exception {
- String testPolicy1 = "testDisabledInfo01";
- Bundle chainTest = installer.installBundle("chain.test");
Bundle chainTestA = installer.installBundle("chain.test.a");
Bundle chainTestB = installer.installBundle("chain.test.b");
Bundle chainTestC = installer.installBundle("chain.test.c");
Bundle chainTestD = installer.installBundle("chain.test.d");
- Bundle[] allBundles = new Bundle[] {chainTest, chainTestA, chainTestB, chainTestC, chainTestD};
+ assertTrue("Could not resolve bundles.", getContext().getBundle(0).adapt(FrameworkWiring.class).resolveBundles(Arrays.asList(chainTestA, chainTestB, chainTestC, chainTestD)));
- PlatformAdmin pa = installer.getPlatformAdmin();
- State systemState = pa.getState(false);
- BundleDescription testDesc = systemState.getBundle(chainTest.getBundleId());
BundleDescription testADesc = systemState.getBundle(chainTestA.getBundleId());
BundleDescription testBDesc = systemState.getBundle(chainTestB.getBundleId());
BundleDescription testCDesc = systemState.getBundle(chainTestC.getBundleId());
BundleDescription testDDesc = systemState.getBundle(chainTestD.getBundleId());
- assertNotNull("testDesc null!!", testDesc);
assertNotNull("testADesc null!!", testADesc);
assertNotNull("testBDesc null!!", testBDesc);
assertNotNull("testCDesc null!!", testCDesc);
assertNotNull("testDDesc null!!", testDDesc);
- installer.resolveBundles(allBundles);
- assertTrue("testDesc not resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
+ assertTrue("testADesc is not resolved!!", testADesc.isResolved());
+ assertTrue("testBDesc is not resolved!!", testBDesc.isResolved());
+ assertTrue("testCDesc is not resolved!!", testCDesc.isResolved());
+ assertTrue("testCDesc is not resolved!!", testDDesc.isResolved());
+
+ chainTestD.uninstall();
+ installer.refreshPackages(new Bundle[] {chainTestD});
- // ok finally we can start testing!!!
- // disable the bottom level bundle, this should cause all bundles to be unresolved
- pa.addDisabledInfo(new DisabledInfo(testPolicy1, "reason 1", testDDesc));
- // force the bundles to re-resolve
- installer.refreshPackages(allBundles);
- // only testDesc should be unresolved
- assertFalse("testDesc is resolved!!", testDesc.isResolved());
assertFalse("testADesc is resolved!!", testADesc.isResolved());
assertFalse("testBDesc is resolved!!", testBDesc.isResolved());
assertFalse("testCDesc is resolved!!", testCDesc.isResolved());
- assertFalse("testDDesc is resolved!!", testDDesc.isResolved());
-
- // check that the resolver errors are the correct type
- ResolverError[] errors = systemState.getResolverErrors(testDDesc);
- assertNotNull("resolver errors is null!!", errors);
- assertEquals("unexpected number of errors", 1, errors.length);
- assertEquals("unexpected error type", ResolverError.DISABLED_BUNDLE, errors[0].getType());
-
- // all other errors should be missing import errors
- errors = systemState.getResolverErrors(testDesc);
- assertNotNull("resolver errors is null!!", errors);
- assertEquals("unexpected number of errors", 1, errors.length);
- assertEquals("unexpected error type", ResolverError.MISSING_IMPORT_PACKAGE, errors[0].getType());
-
- errors = systemState.getResolverErrors(testADesc);
- assertNotNull("resolver errors is null!!", errors);
- assertEquals("unexpected number of errors", 1, errors.length);
- assertEquals("unexpected error type", ResolverError.MISSING_IMPORT_PACKAGE, errors[0].getType());
-
- errors = systemState.getResolverErrors(testBDesc);
- assertNotNull("resolver errors is null!!", errors);
- assertEquals("unexpected number of errors", 1, errors.length);
- assertEquals("unexpected error type", ResolverError.MISSING_IMPORT_PACKAGE, errors[0].getType());
-
- errors = systemState.getResolverErrors(testCDesc);
- assertNotNull("resolver errors is null!!", errors);
- assertEquals("unexpected number of errors", 1, errors.length);
- assertEquals("unexpected error type", ResolverError.MISSING_IMPORT_PACKAGE, errors[0].getType());
- }
-
- public void testDisabledInfo05() throws Exception {
- String testPolicy1 = "testDisabledInfo01";
- String testPolicy2 = "testDisabledInfo02";
- Bundle chainTest = installer.installBundle("chain.test");
- Bundle chainTestA = installer.installBundle("chain.test.a");
- Bundle chainTestB = installer.installBundle("chain.test.b");
- Bundle chainTestC = installer.installBundle("chain.test.c");
- Bundle chainTestD = installer.installBundle("chain.test.d");
- Bundle[] allBundles = new Bundle[] {chainTest, chainTestA, chainTestB, chainTestC, chainTestD};
-
- PlatformAdmin pa = installer.getPlatformAdmin();
- State systemState = pa.getState(false);
- BundleDescription testDesc = systemState.getBundle(chainTest.getBundleId());
- BundleDescription testADesc = systemState.getBundle(chainTestA.getBundleId());
- BundleDescription testBDesc = systemState.getBundle(chainTestB.getBundleId());
- BundleDescription testCDesc = systemState.getBundle(chainTestC.getBundleId());
- BundleDescription testDDesc = systemState.getBundle(chainTestD.getBundleId());
- assertNotNull("testDesc null!!", testDesc);
- assertNotNull("testADesc null!!", testADesc);
- assertNotNull("testBDesc null!!", testBDesc);
- assertNotNull("testCDesc null!!", testCDesc);
- assertNotNull("testDDesc null!!", testDDesc);
-
- installer.resolveBundles(allBundles);
- assertTrue("testDesc not resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
-
- // ok finally we can start testing!!!
- // add many disabled infos to test the getDisabledInfo methods
- DisabledInfo info1 = new DisabledInfo(testPolicy1, "reason 1", testDesc);
- DisabledInfo info2 = new DisabledInfo(testPolicy2, "reason 2", testDesc);
- DisabledInfo info3 = new DisabledInfo(testPolicy1, "reason 3", testDDesc);
- DisabledInfo info4 = new DisabledInfo(testPolicy2, "reason 4", testDDesc);
- pa.addDisabledInfo(info1);
- pa.addDisabledInfo(info2);
- pa.addDisabledInfo(info3);
- pa.addDisabledInfo(info4);
- // force the bundles to re-resolve
- installer.refreshPackages(allBundles);
-
- // check the errors only, resolution was checked in other tests
- ResolverError[] errors = systemState.getResolverErrors(testDesc);
- assertNotNull("resolver errors is null!!", errors);
- assertEquals("unexpected number of errors", 1, errors.length);
- assertEquals("unexpected error type", ResolverError.DISABLED_BUNDLE, errors[0].getType());
-
- errors = systemState.getResolverErrors(testDDesc);
- assertNotNull("resolver errors is null!!", errors);
- assertEquals("unexpected number of errors", 1, errors.length);
- assertEquals("unexpected error type", ResolverError.DISABLED_BUNDLE, errors[0].getType());
-
- DisabledInfo getInfo1 = systemState.getDisabledInfo(testDesc, testPolicy1);
- assertEquals("info1 not equal!", info1, getInfo1);
- DisabledInfo getInfo2 = systemState.getDisabledInfo(testDesc, testPolicy2);
- assertEquals("info2 not equal!", info2, getInfo2);
- DisabledInfo getInfo3 = systemState.getDisabledInfo(testDDesc, testPolicy1);
- assertEquals("info3 not equal!", info3, getInfo3);
- DisabledInfo getInfo4 = systemState.getDisabledInfo(testDDesc, testPolicy2);
- assertEquals("info4 not equal!", info4, getInfo4);
-
- DisabledInfo[] infos1 = systemState.getDisabledInfos(testDesc);
- assertNotNull("infos1 is null!!", infos1);
- assertEquals("unexpected info1 size", 2, infos1.length);
- assertTrue("info1 not found", infos1[0] == info1 || infos1[1] == info1);
- assertTrue("info2 not found", infos1[0] == info2 || infos1[1] == info2);
- DisabledInfo[] infos2 = systemState.getDisabledInfos(testDDesc);
- assertNotNull("infos2 is null!!", infos2);
- assertEquals("unexpected info2 size", 2, infos2.length);
- assertTrue("info3 not found", infos2[0] == info3 || infos2[1] == info3);
- assertTrue("info4 not found", infos2[0] == info4 || infos2[1] == info4);
- }
-
- public void testDisabledInfo06() throws Exception {
- String testPolicy = "testDisabledInfo01";
- Bundle chainTest = installer.installBundle("chain.test");
- Bundle chainTestA = installer.installBundle("chain.test.a");
- Bundle chainTestB = installer.installBundle("chain.test.b");
- Bundle chainTestC = installer.installBundle("chain.test.c");
- Bundle chainTestD = installer.installBundle("chain.test.d");
- Bundle[] allBundles = new Bundle[] {chainTest, chainTestA, chainTestB, chainTestC, chainTestD};
-
- PlatformAdmin pa = installer.getPlatformAdmin();
- State systemState = pa.getState(false);
- BundleDescription testDesc = systemState.getBundle(chainTest.getBundleId());
- BundleDescription testADesc = systemState.getBundle(chainTestA.getBundleId());
- BundleDescription testBDesc = systemState.getBundle(chainTestB.getBundleId());
- BundleDescription testCDesc = systemState.getBundle(chainTestC.getBundleId());
- BundleDescription testDDesc = systemState.getBundle(chainTestD.getBundleId());
- assertNotNull("testDesc null!!", testDesc);
- assertNotNull("testADesc null!!", testADesc);
- assertNotNull("testBDesc null!!", testBDesc);
- assertNotNull("testCDesc null!!", testCDesc);
- assertNotNull("testDDesc null!!", testDDesc);
-
- installer.resolveBundles(allBundles);
- assertTrue("testDesc not resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
-
- // ok finally we can start testing!!!
- // disable the toplevel testDesc bundle
- DisabledInfo info = new DisabledInfo(testPolicy, "reason 1", testDesc);
- pa.addDisabledInfo(info);
- // force the bundles to re-resolve
- installer.refreshPackages(allBundles);
- // only testDesc should be unresolved
- assertFalse("testDesc is resolved!!", testDesc.isResolved());
- assertTrue("testADesc not resolved!!", testADesc.isResolved());
- assertTrue("testBDesc not resolved!!", testBDesc.isResolved());
- assertTrue("testCDesc not resolved!!", testCDesc.isResolved());
- assertTrue("testDDesc not resolved!!", testDDesc.isResolved());
- // uninstall the bundle testDesc
- Bundle uninstalledChainTest = installer.uninstallBundle("chain.test");
- assertTrue("Unexpected uninstall result", uninstalledChainTest == chainTest);
-
- // now try to get the DisabledInfo
- DisabledInfo getInfo = systemState.getDisabledInfo(testDesc, testPolicy);
- assertNull("info is not null!!", getInfo);
- // try to add the info again. This should fail
- try {
- pa.addDisabledInfo(info);
- pa.removeDisabledInfo(info);
- fail("should not be able to add a DisabledInfo for a bundle not in the state");
- } catch (IllegalArgumentException e) {
- // expected
- }
}
- public void testUnresolvedLeaves01() throws Exception {
+ public void disableTestUnresolvedLeaves01() throws Exception {
Bundle chainTestA = installer.installBundle("chain.test.a");
Bundle chainTestB = installer.installBundle("chain.test.b");
Bundle chainTestC = installer.installBundle("chain.test.c");

Back to the top