Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PluginModule.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2006-2015 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.plugins;
  23. import com.dmdirc.interfaces.EventBus;
  24. import com.dmdirc.interfaces.SystemLifecycleComponent;
  25. import com.dmdirc.interfaces.config.IdentityController;
  26. import com.dmdirc.updater.manager.UpdateManager;
  27. import javax.inject.Singleton;
  28. import dagger.Module;
  29. import dagger.ObjectGraph;
  30. import dagger.Provides;
  31. import static com.dmdirc.commandline.CommandLineOptionsModule.Directory;
  32. import static com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
  33. /**
  34. * Dagger module for plugin-related components.
  35. */
  36. @SuppressWarnings("TypeMayBeWeakened")
  37. @Module(library = true, complete = false)
  38. public class PluginModule {
  39. @Provides
  40. @Singleton
  41. public PluginManager getPluginManager(
  42. final EventBus eventBus,
  43. final IdentityController identityController,
  44. final UpdateManager updateManager,
  45. final ObjectGraph objectGraph,
  46. final ServiceManager serviceManager,
  47. final CorePluginHelper pluginHelper,
  48. final PluginFileHandler fileHandler,
  49. @Directory(DirectoryType.PLUGINS) final String directory) {
  50. final PluginManager manager = new PluginManager(eventBus, serviceManager,
  51. identityController, updateManager, objectGraph, fileHandler, directory);
  52. manager.refreshPlugins();
  53. final CorePluginExtractor extractor = new CorePluginExtractor(manager, directory);
  54. pluginHelper.checkBundledPlugins(extractor, manager,
  55. identityController.getGlobalConfiguration());
  56. for (String service : new String[]{"ui", "tabcompletion", "parser"}) {
  57. pluginHelper.ensureExists(extractor, manager, service);
  58. }
  59. // The user may have an existing parser plugin (e.g. twitter) which
  60. // will satisfy the service existence check above, but will render the
  61. // client pretty useless, so we'll force IRC extraction for now.
  62. extractor.extractCorePlugins("parser_irc");
  63. manager.refreshPlugins();
  64. return manager;
  65. }
  66. @Provides
  67. public ServiceManager getServiceManager(final ServiceManagerImpl serviceManager) {
  68. return serviceManager;
  69. }
  70. @Provides
  71. public ServiceLocator getServiceLocator(final LegacyServiceLocator locator) {
  72. return locator;
  73. }
  74. @Provides(type = Provides.Type.SET)
  75. @Singleton
  76. public SystemLifecycleComponent getEventFormatManager(final PluginEventFormatManager manager) {
  77. return manager;
  78. }
  79. }