PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/atlassian-plugins-api/src/main/java/com/atlassian/plugin/PluginAccessor.java

https://bitbucket.org/atlassian/atlassian-plugins
Java | 228 lines | 48 code | 26 blank | 154 comment | 0 complexity | 2d932761e2a0966d300c32814128aee6 MD5 | raw file
  1. package com.atlassian.plugin;
  2. import com.atlassian.plugin.predicate.ModuleDescriptorPredicate;
  3. import com.atlassian.plugin.predicate.PluginPredicate;
  4. import java.io.InputStream;
  5. import java.util.Collection;
  6. import java.util.List;
  7. import java.util.function.Predicate;
  8. /**
  9. * Allows access to the current plugin system state
  10. */
  11. public interface PluginAccessor {
  12. /**
  13. * The plugin descriptor file.
  14. *
  15. * @since 2.2
  16. */
  17. final class Descriptor {
  18. /**
  19. * The default filename.
  20. */
  21. public static final String FILENAME = "atlassian-plugin.xml";
  22. private Descriptor() {
  23. }
  24. }
  25. /**
  26. * Gets all of the currently installed plugins.
  27. *
  28. * @return a collection of installed {@link Plugin}s.
  29. */
  30. Collection<Plugin> getPlugins();
  31. /**
  32. * Gets all installed plugins that match the given predicate.
  33. *
  34. * @param pluginPredicate the {@link PluginPredicate} to match.
  35. * @return a collection of {@link Plugin}s that match the given predicate.
  36. * @since 0.17
  37. * @deprecated in 5.0 for removal in 6.0, use {@link #getPlugins(Predicate)} instead
  38. */
  39. @Deprecated
  40. default Collection<Plugin> getPlugins(final PluginPredicate pluginPredicate) {
  41. return getPlugins((Predicate<Plugin>) pluginPredicate::matches);
  42. }
  43. /**
  44. * Gets all installed plugins that match the given predicate.
  45. *
  46. * @param pluginPredicate the {@link Predicate} describing which plugins to match.
  47. * @return a collection of {@link Plugin}s that match the given predicate.
  48. * @since 5.0
  49. */
  50. Collection<Plugin> getPlugins(Predicate<Plugin> pluginPredicate);
  51. /**
  52. * Get all of the currently enabled plugins.
  53. *
  54. * @return a collection of installed and enabled {@link Plugin}s.
  55. */
  56. Collection<Plugin> getEnabledPlugins();
  57. /**
  58. * Gets all installed modules that match the given predicate.
  59. *
  60. * @param moduleDescriptorPredicate the {@link com.atlassian.plugin.predicate.ModuleDescriptorPredicate} to match.
  61. * @return a collection of modules as per {@link ModuleDescriptor#getModule()} that match the given predicate.
  62. * @since 0.17
  63. * @deprecated in 5.0 for removal in 6.0. Use {@link #getModules(Predicate)} instead.
  64. */
  65. @Deprecated
  66. default <M> Collection<M> getModules(final ModuleDescriptorPredicate<M> moduleDescriptorPredicate) {
  67. return getModules((Predicate<ModuleDescriptor<M>>) moduleDescriptorPredicate::matches);
  68. }
  69. /**
  70. * Gets all module descriptors of installed modules that match the given predicate.
  71. *
  72. * @param moduleDescriptorPredicate the {@link com.atlassian.plugin.predicate.ModuleDescriptorPredicate} to match.
  73. * @return a collection of {@link ModuleDescriptor}s that match the given predicate.
  74. * @since 0.17
  75. * @deprecated in 5.0 for removal in 6.0. Use {@link #getModuleDescriptors(Predicate)} instead.
  76. */
  77. @Deprecated
  78. default <M> Collection<ModuleDescriptor<M>> getModuleDescriptors(final ModuleDescriptorPredicate<M> moduleDescriptorPredicate) {
  79. return getModuleDescriptors((Predicate<ModuleDescriptor<M>>) moduleDescriptorPredicate::matches);
  80. }
  81. /**
  82. * Gets all installed modules that match the given predicate.
  83. *
  84. * @param moduleDescriptorPredicate describes which modules to match
  85. * @return a collection of modules as per {@link ModuleDescriptor#getModule()} that match the given predicate.
  86. * @since 5.0
  87. */
  88. <M> Collection<M> getModules(Predicate<ModuleDescriptor<M>> moduleDescriptorPredicate);
  89. /**
  90. * Gets all module descriptors of installed modules that match the given predicate.
  91. *
  92. * @param moduleDescriptorPredicate describes which modules to match
  93. * @return a collection of {@link ModuleDescriptor}s that match the given predicate.
  94. * @since 5.0
  95. */
  96. <M> Collection<ModuleDescriptor<M>> getModuleDescriptors(Predicate<ModuleDescriptor<M>> moduleDescriptorPredicate);
  97. /**
  98. * Retrieve a given plugin (whether enabled or not).
  99. *
  100. * @param key The plugin key. Cannot be null.
  101. * @return The enabled plugin, or null if that plugin does not exist.
  102. * @throws IllegalArgumentException If the plugin key is null
  103. */
  104. Plugin getPlugin(String key);
  105. /**
  106. * Retrieve a given plugin if it is enabled.
  107. *
  108. * @return The enabled plugin, or null if that plugin does not exist or is disabled.
  109. * @throws IllegalArgumentException If the plugin key is null
  110. */
  111. Plugin getEnabledPlugin(String pluginKey);
  112. /**
  113. * Retrieve any plugin module by complete module key.
  114. * <p>
  115. * Note: the module may or may not be disabled.
  116. */
  117. ModuleDescriptor<?> getPluginModule(String completeKey);
  118. /**
  119. * Retrieve an enabled plugin module by complete module key.
  120. */
  121. ModuleDescriptor<?> getEnabledPluginModule(String completeKey);
  122. /**
  123. * Whether or not a given plugin is currently enabled.
  124. *
  125. * @throws IllegalArgumentException If the plugin key is null
  126. */
  127. boolean isPluginEnabled(String key);
  128. /**
  129. * Whether or not a given plugin module is currently enabled. This also checks
  130. * if the plugin it is contained within is enabled also
  131. *
  132. * @see #isPluginEnabled(String)
  133. */
  134. boolean isPluginModuleEnabled(String completeKey);
  135. /**
  136. * Retrieve all plugin modules that implement or extend a specific class.
  137. *
  138. * @return List of modules that implement or extend the given class.
  139. */
  140. <M> List<M> getEnabledModulesByClass(Class<M> moduleClass);
  141. /**
  142. * Get all enabled module descriptors that have a specific descriptor class.
  143. *
  144. * @param descriptorClazz module descriptor class
  145. * @return List of {@link ModuleDescriptor}s that implement or extend the given class.
  146. */
  147. <D extends ModuleDescriptor<?>> List<D> getEnabledModuleDescriptorsByClass(Class<D> descriptorClazz);
  148. /**
  149. * Get all enabled module descriptors that have a specific descriptor class and are considered active for
  150. * the current request.
  151. *<p>
  152. * Result of this method should not be cached across requests.
  153. *
  154. * @see com.atlassian.plugin.scope.ScopeManager
  155. * @param descriptorClazz module descriptor class
  156. * @return List of {@link ModuleDescriptor}s that implement or extend the given class and active for the current request.
  157. * @deprecated in 5.0 for removal in 6.0 when {@link com.atlassian.plugin.scope.ScopeManager} is removed. Use
  158. * {@link #getEnabledModuleDescriptorsByClass(Class)} instead.
  159. */
  160. @Deprecated
  161. default <D extends ModuleDescriptor<?>> List<D> getActiveModuleDescriptorsByClass(Class<D> descriptorClazz) {
  162. return getEnabledModuleDescriptorsByClass(descriptorClazz);
  163. }
  164. /**
  165. * Retrieve a resource from a currently loaded (and active) dynamically loaded plugin. Will return the first resource
  166. * found, so plugins with overlapping resource names will behave erratically.
  167. *
  168. * @param resourcePath the path to the resource to retrieve
  169. * @return the dynamically loaded resource that matches that path, or null if no such resource is found
  170. */
  171. InputStream getDynamicResourceAsStream(String resourcePath);
  172. /**
  173. * Retrieve the class loader responsible for loading classes and resources from plugins.
  174. *
  175. * @return the class loader
  176. * @since 0.21
  177. */
  178. ClassLoader getClassLoader();
  179. /**
  180. * @return true if the plugin is a system plugin.
  181. */
  182. boolean isSystemPlugin(String key);
  183. /**
  184. * Gets the state of the plugin upon restart. Only useful for plugins that contain module descriptors with the
  185. * \@RestartRequired annotation, and therefore, cannot be dynamically installed, upgraded, or removed at runtime
  186. *
  187. * @param key The plugin key
  188. * @return The state of the plugin on restart
  189. */
  190. PluginRestartState getPluginRestartState(String key);
  191. /**
  192. * Retrieve all currently registered dynamic modules i.e. any module that has been added to <code>plugin</code> via
  193. * {@link com.atlassian.plugin.PluginController#addDynamicModule(Plugin, org.dom4j.Element)} during the lifetime of
  194. * this plugin, but not removed via {@link com.atlassian.plugin.PluginController#removeDynamicModule(Plugin, ModuleDescriptor)}.
  195. *
  196. * @param plugin to query
  197. * @return modules added, may be empty
  198. * @see com.atlassian.plugin.PluginController#addDynamicModule(Plugin, org.dom4j.Element)
  199. * @see com.atlassian.plugin.PluginController#removeDynamicModule(Plugin, ModuleDescriptor)
  200. */
  201. Iterable<ModuleDescriptor<?>> getDynamicModules(Plugin plugin);
  202. }