You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Plugin.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2006-2014 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.config.prefs.PreferencesDialogModel;
  24. import com.dmdirc.util.validators.ValidationResponse;
  25. import dagger.ObjectGraph;
  26. /**
  27. * Defines the standard methods that should be implemented by plugins.
  28. */
  29. public interface Plugin {
  30. /**
  31. * Check any further Prerequisites for this plugin to load that can not be checked using
  32. * metainfo.
  33. *
  34. * @return ValidationResponse detailing if the plugin passes any extra checks that plugin.info
  35. * can't handle
  36. */
  37. ValidationResponse checkPrerequisites();
  38. /**
  39. * Get the domain name settings for this plugin should be stored in.
  40. *
  41. * @deprecated Domain should be obtained from {@link PluginInfo}
  42. * @return Domain name for plugin settings
  43. */
  44. @Deprecated
  45. String getDomain();
  46. /**
  47. * Called when the plugin is loaded.
  48. */
  49. void onLoad();
  50. /**
  51. * Called when the plugin is about to be unloaded.
  52. */
  53. void onUnload();
  54. /**
  55. * Loads the plugin. This method is called when the plugin has been activated by the client,
  56. * either in response to a direct user request, or automatically as part of client startup or
  57. * during the course of another plugin being loaded.
  58. *
  59. * <p>
  60. * Plugins are provided with an {@link ObjectGraph} which they may extend and use to inflate
  61. * their classes. This is the only supported way of obtaining instances of core DMDirc classes,
  62. * or objects shared by this plugin's parent.
  63. *
  64. * <p>
  65. * Plugins wishing to use this form of dependency injection should define a new
  66. * {@link dagger.Module} which specifies an {@link dagger.Module#addsTo()} argument of either:
  67. *
  68. * <ul>
  69. * <li>For plugins with no parents, or plugins which do not have a dependency on their parent,
  70. * {@link com.dmdirc.ClientModule}.</li>
  71. * <li>For plugins with dependencies on a parent plugin, that plugin's own {@link dagger.Module}
  72. * implementation.</li>
  73. * </ul>
  74. *
  75. * <p>
  76. * The implementation of this method should then call
  77. * {@link ObjectGraph#plus(java.lang.Object[])} with an instance of the plugin's own module.
  78. *
  79. * <p>
  80. * To expose dependencies to child plugins, the relevant {@link ObjectGraph} should be returned
  81. * from the {@link #getObjectGraph()} method.
  82. *
  83. * <p>
  84. * While both this method and {@link #onLoad()} are defined, this method is guaranteed to be
  85. * called first. Implementations that support this method of loading can simply treat
  86. * {@link #onLoad()} as a no-op.
  87. *
  88. * @param pluginInfo The information object corresponding to this plugin.
  89. * @param graph The dependency-injection graph that may be used to instantiate plugin
  90. * classes.
  91. */
  92. void load(PluginInfo pluginInfo, ObjectGraph graph);
  93. /**
  94. * Returns an {@link ObjectGraph} that may be used by subplugins to inject dependencies provided
  95. * by this class.
  96. *
  97. * <p>
  98. * This should always be an extension of the {@link ObjectGraph} provided to the
  99. * {@link #load(com.dmdirc.plugins.PluginInfo, dagger.ObjectGraph)} method. If the plugin has no
  100. * dependencies it wishes to expose, it may return {@code null} and any subplugins will be given
  101. * the global {@link ObjectGraph}.
  102. *
  103. * <p>
  104. * It is recommended that implementations separate their internal dependencies from those that
  105. * will be published. This can be accomplished by using two modules, e.g.:
  106. *
  107. * <pre><code>
  108. * ObjectGraph external = graph.plus(new ExternalModule());
  109. * ObjectGraph internal = external.plus(new InternalModule());
  110. * </code></pre>
  111. *
  112. * <p>
  113. * The plugin can then inflate its own classes using the 'internal' graph, while only exposing
  114. * relevant dependencies in the 'external' graph.
  115. *
  116. * @return A graph to be used by child plugins, or {@code null} for the default graph.
  117. */
  118. ObjectGraph getObjectGraph();
  119. /**
  120. * Called by PluginInfo to set the domain name. This can only be called once, all other attempts
  121. * will be ignored.
  122. *
  123. * @deprecated Domain should be obtained from {@link PluginInfo}
  124. * @param newDomain Domain name for plugin settings
  125. */
  126. @Deprecated
  127. void setDomain(final String newDomain);
  128. /**
  129. * Called to allow plugins to add their configuration options to the manager.
  130. * PreferencesCategories added from this method should be of type
  131. * {@link com.dmdirc.config.prefs.PluginPreferencesCategory} as this gives the user feedback on
  132. * the status of your plugin.
  133. *
  134. * @param manager The preferences manager that configuration options need to be added to.
  135. */
  136. void showConfig(final PreferencesDialogModel manager);
  137. }