Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2010-04-30 00:04:40 +0000
committerslewis2010-04-30 00:04:40 +0000
commit801713d89a75d450343aeb140c89beb4aac41685 (patch)
tree2fc7cd24d2e357a97187d39f4ce65b64399d44ea
parentc48b879c5e628470b24bec4d596376dfbc948914 (diff)
downloadorg.eclipse.ecf-801713d89a75d450343aeb140c89beb4aac41685.tar.gz
org.eclipse.ecf-801713d89a75d450343aeb140c89beb4aac41685.tar.xz
org.eclipse.ecf-801713d89a75d450343aeb140c89beb4aac41685.zip
Added bundleutil class
-rwxr-xr-xtests/bundles/org.eclipse.ecf.tests/META-INF/MANIFEST.MF3
-rw-r--r--tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/util/BundleUtil.java100
2 files changed, 102 insertions, 1 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests/META-INF/MANIFEST.MF b/tests/bundles/org.eclipse.ecf.tests/META-INF/MANIFEST.MF
index a0a40e78c..c40988d33 100755
--- a/tests/bundles/org.eclipse.ecf.tests/META-INF/MANIFEST.MF
+++ b/tests/bundles/org.eclipse.ecf.tests/META-INF/MANIFEST.MF
@@ -15,7 +15,8 @@ Export-Package: org.eclipse.ecf.internal.tests;x-internal:=true,
org.eclipse.ecf.tests.connect,
org.eclipse.ecf.tests.core;x-internal:=true,
org.eclipse.ecf.tests.core.identity;x-internal:=true,
- org.eclipse.ecf.tests.core.util;x-internal:=true
+ org.eclipse.ecf.tests.core.util;x-internal:=true,
+ org.eclipse.ecf.tests.util
Import-Package: org.eclipse.osgi.util;version="1.1.0",
org.osgi.framework;version="1.4.0",
org.osgi.util.tracker;version="1.3.2"
diff --git a/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/util/BundleUtil.java b/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/util/BundleUtil.java
new file mode 100644
index 000000000..0a00cee16
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests/src/org/eclipse/ecf/tests/util/BundleUtil.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Composent, Inc. 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:
+ * Composent, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.tests.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+public class BundleUtil {
+
+ private BundleContext context;
+
+ public BundleUtil(BundleContext context) {
+ Assert.isNotNull(context);
+ this.context = context;
+ }
+
+ public Bundle[] getBundles(String bundleSymbolicName, String version) {
+ if (bundleSymbolicName == null)
+ return new Bundle[0];
+ Bundle[] bundles = context.getBundles();
+ List results = new ArrayList();
+ for (int i = 0; i < bundles.length; i++) {
+ if (bundles[i].getSymbolicName().equals(bundleSymbolicName)) {
+ if (version == null
+ || !bundles[i].getVersion().toString().equals(version))
+ results.add(bundles[i]);
+ }
+ }
+ return (Bundle[]) results.toArray(new Bundle[] {});
+ }
+
+ public Bundle[] getBundles(String bundleSymbolicName) {
+ return getBundles(bundleSymbolicName, null);
+ }
+
+ public void startBundles(String bundleSymbolicName, String version) throws BundleException {
+ Bundle[] bundles = getBundles(bundleSymbolicName, version);
+ if (bundles != null && bundles.length > 0) {
+ for(int i=0; i < bundles.length; i++) {
+ bundles[i].start();
+ }
+ }
+ }
+
+ public void startBundles(String bundleSymbolicName) throws BundleException {
+ startBundles(bundleSymbolicName, null);
+ }
+
+ public void startBundle(String bundleSymbolicName, String version) throws BundleException {
+ Bundle[] bundles = getBundles(bundleSymbolicName, version);
+ if (bundles.length > 1) throw new BundleException("More than one bundle with symbolicname="+bundleSymbolicName+", version="+version);
+ if (bundles.length < 1) throw new BundleException("No bundle with symbolicname="+bundleSymbolicName+", version="+version);
+ bundles[0].start();
+ }
+
+ public void startBundle(String bundleSymbolicName) throws BundleException {
+ startBundle(bundleSymbolicName,null);
+ }
+
+ public void stopBundles(String bundleSymbolicName, String version) throws BundleException {
+ Bundle[] bundles = getBundles(bundleSymbolicName, version);
+ if (bundles != null && bundles.length > 0) {
+ for(int i=0; i < bundles.length; i++) {
+ bundles[i].stop();
+ }
+ }
+ }
+
+ public void stopBundles(String bundleSymbolicName) throws BundleException {
+ stopBundles(bundleSymbolicName, null);
+ }
+
+ public void stopBundle(String bundleSymbolicName, String version) throws BundleException {
+ Bundle[] bundles = getBundles(bundleSymbolicName, version);
+ if (bundles.length > 1) throw new BundleException("More than one bundle with symbolicname="+bundleSymbolicName+", version="+version);
+ if (bundles.length < 1) throw new BundleException("No bundle with symbolicname="+bundleSymbolicName+", version="+version);
+ bundles[0].stop();
+ }
+
+ public void stopBundle(String bundleSymbolicName) throws BundleException {
+ stopBundle(bundleSymbolicName,null);
+ }
+
+ public void close() {
+ this.context = null;
+ }
+
+}

Back to the top