| /******************************************************************************* |
| * Copyright (c) 2009 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.e4.languages.javascript.debug.connect.test; |
| |
| import org.eclipse.e4.languages.javascript.JSBundle; |
| 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 packageAdminRef; |
| |
| public void start(BundleContext context) throws Exception { |
| packageAdminRef = context.getServiceReference(PackageAdmin.class.getName()); |
| setPackageAdmin((PackageAdmin) 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; |
| } |
| |
| public static JSBundle getJSBundle() { |
| return org.eclipse.e4.internal.languages.javascript.Activator.getJSBundle(getBundleContext().getBundle()); |
| } |
| } |