/eclipse-moreunit-2.4.6/org.moreunit.mock/src/org/moreunit/mock/MoreUnitMockPlugin.java

# · Java · 93 lines · 74 code · 19 blank · 0 comment · 2 complexity · 9bdd8a0df415287016880c2d0ac22367 MD5 · raw file

  1. package org.moreunit.mock;
  2. import org.eclipse.core.runtime.IStatus;
  3. import org.eclipse.core.runtime.Status;
  4. import org.eclipse.ui.plugin.AbstractUIPlugin;
  5. import org.moreunit.mock.log.Logger;
  6. import org.moreunit.mock.templates.MockingTemplateLoader;
  7. import org.moreunit.mock.templates.MockingTemplateStore;
  8. import org.osgi.framework.BundleContext;
  9. import com.google.inject.Guice;
  10. import com.google.inject.Inject;
  11. import com.google.inject.Injector;
  12. import com.google.inject.Module;
  13. import static org.ops4j.peaberry.Peaberry.osgiModule;
  14. import static org.ops4j.peaberry.eclipse.EclipseRegistry.eclipseRegistry;
  15. public class MoreUnitMockPlugin extends AbstractUIPlugin
  16. {
  17. public static final String PLUGIN_ID = "org.moreunit.mock"; //$NON-NLS-1$
  18. private static MoreUnitMockPlugin plugin;
  19. private Injector injector;
  20. private Logger logger;
  21. private MockingTemplateLoader templateLoader;
  22. private MockingTemplateStore mockingTemplateStore;
  23. public static MoreUnitMockPlugin getDefault()
  24. {
  25. return plugin;
  26. }
  27. @Override
  28. public void start(BundleContext context) throws Exception
  29. {
  30. super.start(context);
  31. log("Starting MoreUnit Mock Plugin...");
  32. plugin = this;
  33. init(new MockPluginCoreModule());
  34. log("MoreUnit Mock Plugin started.");
  35. }
  36. void init(Module module)
  37. {
  38. BundleContext bundleContext = getBundle().getBundleContext();
  39. Guice.createInjector(osgiModule(bundleContext, eclipseRegistry()), module).injectMembers(this);
  40. templateLoader.loadTemplates();
  41. }
  42. private void log(String message)
  43. {
  44. if(logger == null)
  45. {
  46. getLog().log(new Status(IStatus.INFO, MoreUnitMockPlugin.PLUGIN_ID, message));
  47. }
  48. else
  49. {
  50. logger.info(message);
  51. }
  52. }
  53. @Inject
  54. void initDependencies(Injector injector, Logger logger, MockingTemplateLoader templateLoader, MockingTemplateStore templateStore)
  55. {
  56. this.injector = injector;
  57. this.logger = logger;
  58. this.templateLoader = templateLoader;
  59. this.mockingTemplateStore = templateStore;
  60. }
  61. @Override
  62. public void stop(BundleContext context) throws Exception
  63. {
  64. log("Stopping MoreUnit Mock Plugin...");
  65. mockingTemplateStore.clear();
  66. plugin = null;
  67. log("MoreUnit Mock Plugin stopped.");
  68. super.stop(context);
  69. }
  70. public Injector getInjector()
  71. {
  72. return injector;
  73. }
  74. }