PageRenderTime 36ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/atlassian/atlassian-plugins
Java | 214 lines | 34 code | 25 blank | 155 comment | 1 complexity | 65c8c55cb8de1d8131a8c3408a4d81e8 MD5 | raw file
  1. package com.atlassian.plugin;
  2. import org.dom4j.Element;
  3. import javax.annotation.Nonnull;
  4. import java.util.Map;
  5. public interface ModuleDescriptor<T> extends ScopeAware, Resourced {
  6. /**
  7. * The complete key for this module, including the plugin key.
  8. * <p>
  9. * Format is plugin.key:module.key
  10. *
  11. * @return The complete key for this module.
  12. * @see #getKey()
  13. * @see #getPluginKey()
  14. */
  15. String getCompleteKey();
  16. /**
  17. * The plugin key for this module, derived from the complete key.
  18. *
  19. * @return The plugin key for this module.
  20. * @see #getKey()
  21. * @see #getCompleteKey()
  22. */
  23. String getPluginKey();
  24. /**
  25. * The key for this module, unique within the plugin.
  26. *
  27. * @return The key for this module.
  28. * @see #getCompleteKey()
  29. * @see #getPluginKey()
  30. */
  31. String getKey();
  32. /**
  33. * A simple string name for this descriptor.
  34. *
  35. * @return The name for this ModuleDescriptor.
  36. */
  37. String getName();
  38. /**
  39. * A simple description of this descriptor.
  40. *
  41. * @return The description for this ModuleDescriptor.
  42. */
  43. String getDescription();
  44. /**
  45. * The class of the module this descriptor creates.
  46. *
  47. * @return The class of the module this descriptor creates.
  48. * @see #getModule()
  49. */
  50. Class<T> getModuleClass();
  51. /**
  52. * The particular module object created by this plugin.
  53. *
  54. * @return The module object created by this plugin.
  55. * @see #getModuleClass()
  56. */
  57. T getModule();
  58. /**
  59. * Initialise a module given it's parent plugin and the XML element
  60. * representing the module.
  61. * <p>
  62. * Since atlassian-plugins v2.2, you can no longer load classes from the
  63. * plugin in this method, because the OSGi bundle that they will live in is
  64. * not built yet. Load classes in the {@link StateAware#enabled()}
  65. * method instead.
  66. *
  67. * @param plugin The plugin that the module belongs to. Must not be null.
  68. * @param element XML element representing the module. Must not be null.
  69. * @throws PluginParseException Can be thrown if an error occurs while
  70. * parsing the XML element.
  71. */
  72. void init(@Nonnull Plugin plugin, @Nonnull Element element);
  73. /**
  74. * Whether or not this plugin module is enabled by default.
  75. *
  76. * @return {@code true} if this plugin module is enabled by default.
  77. */
  78. boolean isEnabledByDefault();
  79. /**
  80. * Whether or not this plugin module is a "system" module that shouldn't be
  81. * made visible/disable-able to the user. System plugin modules also don't
  82. * have their permissions checked, as they may be created dynamically in
  83. * response to another, more safe module
  84. *
  85. * @return {@code true} if this plugin module is a "system" plugin that
  86. * shouldn't be made visible/disable-able to the user.
  87. */
  88. boolean isSystemModule();
  89. /**
  90. * Override this if your plugin needs to clean up when it's been removed.
  91. */
  92. void destroy();
  93. Float getMinJavaVersion();
  94. /**
  95. * If a min java version has been specified this will return true if the
  96. * running jvm is >= to the specified version. If this is not set then it is
  97. * treated as not having a preference.
  98. *
  99. * @return true if satisfied, false otherwise.
  100. */
  101. boolean satisfiesMinJavaVersion();
  102. Map<String, String> getParams();
  103. /**
  104. * Key used to override {@link #getName()} when using internationalisation.
  105. *
  106. * @return the i18n key. May be null.
  107. */
  108. String getI18nNameKey();
  109. /**
  110. * Key used to override {@link #getDescription()} when using
  111. * internationalisation.
  112. *
  113. * @return the i18n key. May be null.
  114. */
  115. String getDescriptionKey();
  116. /**
  117. * @return The plugin this module descriptor is associated with
  118. */
  119. Plugin getPlugin();
  120. /**
  121. * Compares the specified object with this module descriptor for equality.
  122. * <p>
  123. * Returns <tt>true</tt> if the given object is also a module descriptor and the two descriptors have the same
  124. * &quot;complete key&quot; as determined by {@link #getCompleteKey()}.
  125. * <p>
  126. * This ensures that the <tt>equals</tt> method works properly across
  127. * different implementations of the <tt>ModuleDescriptor</tt> interface.
  128. *
  129. * @param obj object to be compared for equality with this module descriptor.
  130. * @return <tt>true</tt> if the specified object is equal to this module descriptor.
  131. * @since 2.8.0
  132. */
  133. boolean equals(Object obj);
  134. /**
  135. * Returns the hash code value for this module descriptor. The hash code
  136. * of a module descriptor <tt>d</tt> is defined to be: <pre>
  137. * getCompleteKey() == null ? 0 : getCompleteKey().hashCode()
  138. * </pre>
  139. * This ensures that <tt>d1.equals(d2)</tt> implies that
  140. * <tt>d1.hashCode()==d2.hashCode()</tt> for any two Module Descriptors
  141. * <tt>d1</tt> and <tt>d2</tt>, as required by the general
  142. * contract of <tt>Object.hashCode</tt>.
  143. *
  144. * @return the hash code value for this module descriptor.
  145. * @see Object#hashCode()
  146. * @see Object#equals(Object)
  147. * @see #equals(Object)
  148. * @since 2.8.0
  149. */
  150. int hashCode();
  151. /**
  152. * Get whether this plugin module is enabled.
  153. *
  154. * @return If this module is enabled
  155. * @since 3.1
  156. */
  157. boolean isEnabled();
  158. /**
  159. * Changes state to "broken"
  160. * <p>
  161. * Being breakable is something subclasses can opt in to, therefore by default {@link ModuleDescriptor}s
  162. * are unbreakable, this is a no-op, and {@link #isBroken()} returns {@code false}
  163. */
  164. default void setBroken() {
  165. }
  166. /**
  167. * Returns true if this Module is "broken".
  168. * <p>
  169. * A "broken" module means that even though this ModuleDescriptor is enabled, calling {@code getModule()} results
  170. * in an error. This typically occurs when the plugin version is not compatible with the version of the host product.
  171. * <p>
  172. * Note that some modules are lazy-loaded, and so this method is optimistic:
  173. * it will return false until we discover that the Module is not loadable.
  174. *
  175. * @return {@code true} if broken, {@code false} otherwise
  176. */
  177. default boolean isBroken() {
  178. return false;
  179. }
  180. /**
  181. * Returns the display name of this descriptor, e.g. for use in log messages. Does not identify the owning plugin.
  182. *
  183. * @return a non-blank name
  184. * @since 4.6.3
  185. */
  186. default String getDisplayName() {
  187. return getName() == null ? getKey() : getName();
  188. }
  189. }