| package org.eclipse.e4.languages.javascript.framework.test; |
| |
| import java.net.URL; |
| import java.util.Arrays; |
| import java.util.Collection; |
| import java.util.Collections; |
| import java.util.List; |
| |
| import org.osgi.framework.Bundle; |
| import org.osgi.framework.BundleActivator; |
| import org.osgi.framework.BundleContext; |
| import org.osgi.service.packageadmin.PackageAdmin; |
| |
| public class Activator implements BundleActivator { |
| |
| private static BundleContext context; |
| private static PackageAdmin packageAdmin; |
| |
| static BundleContext getContext() { |
| return context; |
| } |
| |
| |
| |
| public void start(BundleContext bundleContext) throws Exception { |
| context = bundleContext; |
| packageAdmin = (PackageAdmin) context.getService(context.getServiceReference(PackageAdmin.class.getName())); |
| } |
| |
| public void stop(BundleContext bundleContext) throws Exception { |
| packageAdmin = null; |
| context = null; |
| } |
| |
| public static synchronized Bundle getBundle(String symbolicName) { |
| if (packageAdmin == null) |
| throw new IllegalStateException("Not started"); //$NON-NLS-1$ |
| |
| 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 Collection getFrameworkScripts() { |
| Bundle frameworkBundle = Activator.getBundle("org.eclipse.e4.languages.javascript.framework"); |
| //if (true) return Arrays.asList(new URL[]{frameworkBundle.getEntry("/orion.js")}); |
| List result = Collections.list(frameworkBundle.findEntries("/scripts", "*.js", false)); |
| URL global = frameworkBundle.getEntry("/scripts/__global.js"); |
| result.remove(global); |
| result.add(0, global); |
| return result; |
| } |
| |
| |
| } |