Activator.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ///////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2018 Intel Corporation. //
  3. // //
  4. // All rights reserved. This program and the accompanying materials //
  5. // are made available under the terms of the Eclipse Public License v1.0 //
  6. // which accompanies this distribution, and is available at //
  7. // http://www.eclipse.org/legal/epl-v10.html //
  8. // //
  9. // Contributors: //
  10. // Intel Corporation - initial implementation and documentation //
  11. ///////////////////////////////////////////////////////////////////////////
  12. package com.intel.sgx;
  13. import java.net.URL;
  14. import org.eclipse.core.runtime.FileLocator;
  15. import org.eclipse.core.runtime.IStatus;
  16. import org.eclipse.core.runtime.Path;
  17. import org.eclipse.core.runtime.Status;
  18. import org.eclipse.jface.resource.ImageDescriptor;
  19. import org.eclipse.ui.plugin.AbstractUIPlugin;
  20. import org.osgi.framework.Bundle;
  21. import org.osgi.framework.BundleContext;
  22. /**
  23. * The activator class controls the plug-in life cycle
  24. */
  25. public class Activator extends AbstractUIPlugin {
  26. public static final String PLUGIN_ID = "com.intel.sgx";//$NON-NLS-1$
  27. private static Activator plugin;
  28. public Activator() {
  29. }
  30. public void start(BundleContext context) throws Exception {
  31. super.start(context);
  32. plugin = this;
  33. }
  34. public void stop(BundleContext context) throws Exception {
  35. plugin = null;
  36. super.stop(context);
  37. }
  38. public static Activator getDefault() {
  39. return plugin;
  40. }
  41. public static ImageDescriptor getImageDescriptor(String path) {
  42. return imageDescriptorFromPlugin(PLUGIN_ID, path);
  43. }
  44. public static void log(Exception e) {
  45. plugin.getLog().log(newStatus(e));
  46. }
  47. public static IStatus newStatus(Exception e) {
  48. return new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e);
  49. }
  50. public static URL findFile(Path path) {
  51. return FileLocator.find(plugin.getBundle(), path, null);
  52. }
  53. public static Bundle getBundle(String id){
  54. for(Bundle bundle : plugin.getBundle().getBundleContext().getBundles()){
  55. if(bundle.getSymbolicName().equals(id))
  56. return bundle;
  57. }
  58. return null;
  59. }
  60. }