blob: fab882f33cf1b5775c0ae10a32d8c696370d608f (
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
57
58
59
60
61
62
63
64
|
/*******************************************************************************
* Copyright (c) 2007 IBM Corporation and others
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.cm.test;
import org.osgi.framework.*;
import org.osgi.service.packageadmin.PackageAdmin;
public class Activator implements BundleActivator {
private static PackageAdmin packageAdmin;
private static BundleContext bundleContext;
private ServiceReference<PackageAdmin> packageAdminRef;
public void start(BundleContext context) throws Exception {
packageAdminRef = context.getServiceReference(PackageAdmin.class);
setPackageAdmin(context.getService(packageAdminRef));
setBundleContext(context);
}
public void stop(BundleContext context) throws Exception {
setBundleContext(null);
setPackageAdmin(null);
context.ungetService(packageAdminRef);
}
private static synchronized void setBundleContext(BundleContext context) {
bundleContext = context;
}
private static synchronized void setPackageAdmin(PackageAdmin service) {
packageAdmin = service;
}
static synchronized BundleContext getBundleContext() {
return bundleContext;
}
static synchronized 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;
}
}
|