Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: aa1cb27e90b807b2dd45d1b3b71c9a098d17d6e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*******************************************************************************
 * Copyright (c) 2007 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.equinox.p2.tests;

import org.osgi.framework.*;
import org.osgi.service.packageadmin.PackageAdmin;

public class TestActivator implements BundleActivator {
	public static final String PI_PROV_TESTS = "org.eclipse.equinox.p2.test";
	public static BundleContext context;
	private static PackageAdmin packageAdmin = null;
	private static ServiceReference packageAdminRef = null;

	public static BundleContext getContext() {
		return context;
	}

	public void start(BundleContext context) throws Exception {
		TestActivator.context = context;
		packageAdminRef = context.getServiceReference(PackageAdmin.class.getName());
		packageAdmin = (PackageAdmin) context.getService(packageAdminRef);

		//This is a hack because the junit plugin launch config do not allow to start bundles
		getBundle("org.eclipse.equinox.p2.examplarysetup").start();
		getBundle("org.eclipse.equinox.frameworkadmin.equinox").start();
		getBundle("org.eclipse.equinox.simpleconfigurator.manipulator").start();
	}

	public void stop(BundleContext context) throws Exception {
		TestActivator.context = null;
	}

	public static Bundle getBundle(String symbolicName) {
		if (packageAdmin == null)
			return null;
		Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
		if (bundles == null)
			return null;
		//Return the first bundle that is not installed or uninstalled
		for (int i = 0; i < bundles.length; i++) {
			if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
				return bundles[i];
			}
		}
		return null;
	}

}

Back to the top