PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/atlassian-plugins-core/src/main/java/com/atlassian/plugin/Plugin.java

https://bitbucket.org/rmanalan/atlassian-plugins
Java | 311 lines | 51 code | 46 blank | 214 comment | 0 complexity | 26c266db7dae6a55739dcf80e6162253 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. package com.atlassian.plugin;
  2. import java.io.InputStream;
  3. import java.net.URL;
  4. import java.util.*;
  5. public interface Plugin extends Resourced, Comparable<Plugin>
  6. {
  7. /**
  8. * This is the historical version of plugins. Which is mostly static plugins loaded from the same classpath to the
  9. * application.
  10. */
  11. static final int VERSION_1 = 1;
  12. /**
  13. * This is the version of plugins which introduced dynamic plugins for all. Based on OSGi and Spring DM. Those plugins
  14. * undergo some transformations to make the plugin artifact compatible with the OSGi + Spring DM container.
  15. */
  16. static final int VERSION_2 = 2;
  17. /**
  18. * This is the versions of plugins that adds remotes plugins (developed outside of the plugin framework itself).
  19. * Plugins version 3 don't undergo any transformation so it is up to the plugin developer to write their own Spring
  20. * configuration files if this is their chosen framework, but other frameworks can be introduced.
  21. */
  22. static final int VERSION_3 = 3;
  23. /**
  24. * @deprecated since 2.2.0. This comparator only takes into account the plugin name and assumes it is not null,
  25. * yet a) that constraint is not validated anywhere in plugin loading and b) the plugin could have used the i18n
  26. * name, and only the application can resolve that to a name useful for comparisons.
  27. */
  28. public static final Comparator<Plugin> NAME_COMPARATOR = new PluginNameComparator();
  29. /**
  30. * Gets the version of the plugins system to handle this plugin
  31. * @return The plugins version. If undefined, assumed to be 1.
  32. */
  33. int getPluginsVersion();
  34. /**
  35. * Sets the version of the plugins system
  36. * @param version The version
  37. */
  38. void setPluginsVersion(int version);
  39. /**
  40. * Returns the non-localised name of this plugin if defined.
  41. *
  42. * <p> This corresponds to the value of the {@code name} field in the plugin's XML configuration file.
  43. *
  44. * <p> You would expect a plugin developer to fill in one of either {@code name}, or {@code i18n-name-key},
  45. * but the framework does no validation and makes no guarantees that this is the case.
  46. *
  47. * @return the non-localised name of this plugin if defined, or null.
  48. * @see #getI18nNameKey()
  49. */
  50. String getName();
  51. /**
  52. * Sets the non-localised name of this plugin.
  53. *
  54. * @param name the name.
  55. * @see #getName()
  56. */
  57. void setName(String name);
  58. /**
  59. * Returns the i18nKey used to get an internationalised name for this plugin.
  60. *
  61. * <p> This corresponds to the value of the {@code i18n-name-key} field in the plugin's XML configuration file.
  62. *
  63. * <p> You would expect a plugin developer to fill in one of either {@code name}, or {@code i18n-name-key},
  64. * but the framework does no validation and makes no guarantees that this is the case.
  65. *
  66. * @return the i18n Name Key for this plugin if defined, or null.
  67. * @see #getName()
  68. */
  69. String getI18nNameKey();
  70. /**
  71. * Sets the i18nKey used to get an internationalised name for this plugin.
  72. *
  73. * @param i18nNameKey the i18n Name Key.
  74. * @see #getI18nNameKey()
  75. */
  76. void setI18nNameKey(String i18nNameKey);
  77. String getKey();
  78. void setKey(String aPackage);
  79. void addModuleDescriptor(ModuleDescriptor<?> moduleDescriptor);
  80. /**
  81. * Get the {@link Collection} of {@link ModuleDescriptor descriptors}.
  82. *
  83. * <p> The iteration order of the collection is
  84. * the order that the modules will be enabled, and should be the same order that the modules appear in the
  85. * plugin descriptor.
  86. *
  87. * @return the modules contained by this plugin in the order they are to be enabled
  88. */
  89. Collection<ModuleDescriptor<?>> getModuleDescriptors();
  90. /**
  91. * Get the {@link ModuleDescriptor} for a particular key. Returns <tt>null</tt> if the plugin does not exist.
  92. * <p>
  93. * Note: The {@link ModuleDescriptor#getModule()} may throw {@link ClassCastException} if the expected type is incorrect.
  94. *
  95. * @param key the {@link String} complete key of the module, in the form "org.example.plugin:module-key".
  96. * @return the {@link ModuleDescriptor} of the expected type.
  97. */
  98. ModuleDescriptor<?> getModuleDescriptor(String key);
  99. /**
  100. * Get the {@link ModuleDescriptor descriptors} whose module class implements or is assignable from the supplied {@link Class}.
  101. * <p>
  102. * Note: The {@link ModuleDescriptor#getModule()} may throw {@link ClassCastException} if the expected type is incorrect.
  103. * Normally this method would not be supplied with anything other than {@link Object} or &lt;?&gt;, unless you are
  104. * confident in the super type of the module classes this {@link Plugin} provides.
  105. *
  106. * @param <M> The expected module type of the returned {@link ModuleDescriptor descriptors}.
  107. * @param moduleClass the {@link Class super class} the {@link ModuleDescriptor descriptors} return.
  108. * @return the {@link List} of {@link ModuleDescriptor descriptors} of the expected type.
  109. */
  110. <M> List<ModuleDescriptor<M>> getModuleDescriptorsByModuleClass(Class<M> moduleClass);
  111. boolean isEnabledByDefault();
  112. void setEnabledByDefault(boolean enabledByDefault);
  113. PluginInformation getPluginInformation();
  114. void setPluginInformation(PluginInformation pluginInformation);
  115. void setResources(Resourced resources);
  116. /**
  117. * Returns this plugin's current state.
  118. *
  119. * @return the current state of the plugin.
  120. * @since 2.2.0
  121. */
  122. PluginState getPluginState();
  123. /**
  124. * @deprecated since 2.2.0, use {@link #getPluginState()} instead
  125. * @return {@code true} if this plugin is enabled.
  126. */
  127. boolean isEnabled();
  128. /**
  129. * Whether the plugin is a "system" plugin that shouldn't be made visible to the user.
  130. *
  131. * @return {@code true} if this plugin is a "system" plugin.
  132. * @deprecated since 2.6.0 use {@link com.atlassian.plugin.metadata.PluginMetadataManager#isSystemProvided(Plugin)}}
  133. * instead.
  134. */
  135. boolean isSystemPlugin();
  136. /**
  137. * @param system whether the plugin is a "system" plugin that shouldn't be made visible to the user.
  138. * @deprecated since 2.6.0 provide {@link com.atlassian.plugin.metadata.PluginMetadataManager} with information about the
  139. * plugin instead. There is no way to programatically set this value now.
  140. */
  141. void setSystemPlugin(boolean system);
  142. boolean containsSystemModule();
  143. /**
  144. * Whether the plugin is a "bundled" plugin that can't be removed.
  145. *
  146. * @return {@code true} if this plugin is a "bundled" plugin.
  147. */
  148. boolean isBundledPlugin();
  149. /**
  150. * The date this plugin was loaded into the system.
  151. *
  152. * @return The date this plugin was loaded into the system.
  153. */
  154. Date getDateLoaded();
  155. /**
  156. * Whether or not this plugin can be 'uninstalled'.
  157. *
  158. * @return {@code true} if this plugin can be 'uninstalled'.
  159. */
  160. boolean isUninstallable();
  161. /**
  162. * Should the plugin file be deleted on unistall?
  163. *
  164. * @return {@code true} if this plugin file should be deleted on unistall.
  165. */
  166. boolean isDeleteable();
  167. /**
  168. * Whether or not this plugin is loaded dynamically at runtime.
  169. *
  170. * @return {@code true} if this plugin is loaded dynamically at runtime.
  171. */
  172. boolean isDynamicallyLoaded();
  173. /**
  174. * Get the plugin to load a specific class.
  175. *
  176. * @param clazz The name of the class to be loaded
  177. * @param callingClass The class calling the loading (used to help find a classloader)
  178. * @return The loaded class.
  179. * @throws ClassNotFoundException if the class cannot be located.
  180. */
  181. <T> Class<T> loadClass(String clazz, Class<?> callingClass) throws ClassNotFoundException;
  182. /**
  183. * Get the classloader for the plugin.
  184. *
  185. * @return The classloader used to load classes for this plugin
  186. */
  187. ClassLoader getClassLoader();
  188. /**
  189. * Retrieve the URL of the resource from the plugin.
  190. *
  191. * @param path the name of the resource to be loaded
  192. * @return The URL to the resource, or null if the resource is not found
  193. */
  194. URL getResource(String path);
  195. /**
  196. * Load a given resource from the plugin. Plugins that are loaded dynamically will need
  197. * to implement this in a way that loads the resource from the same context as the plugin.
  198. * Static plugins can just pull them from their own classloader.
  199. *
  200. * @param name The name of the resource to be loaded.
  201. * @return An InputStream for the resource, or null if the resource is not found.
  202. */
  203. InputStream getResourceAsStream(String name);
  204. /**
  205. * @param enabled new enabled state
  206. * @deprecated Since 2.2.0, use {@link #enable()} or {@link #disable()} instead
  207. */
  208. void setEnabled(boolean enabled);
  209. /**
  210. * Free any resources held by this plugin. To be called during uninstallation of the {@link Plugin}.
  211. * @deprecated Since 2.2.0, use {@link #uninstall()} instead
  212. */
  213. void close();
  214. /**
  215. * Installs the plugin into any internal, managing container. This method will be called on every startup. Unless
  216. * an exception is thrown, the plugin should be in the {@link PluginState#INSTALLED} state. If the plugin is already
  217. * in the {@link PluginState#INSTALLED} state, nothing will happen.
  218. *
  219. * @since 2.2.0
  220. * @throws PluginException If the plugin could not be installed
  221. */
  222. void install() throws PluginException;
  223. /**
  224. * Uninstalls the plugin from any internal container. This method will be called on every shutdown. Unless an
  225. * exception is thrown, the plugin should be in the {@link PluginState#UNINSTALLED} state. If the plugin is already
  226. * in the {@link PluginState#UNINSTALLED} state, nothing will happen.
  227. *
  228. * @since 2.2.0
  229. * @throws PluginException If the plugin could not be uninstalled
  230. */
  231. void uninstall() throws PluginException;
  232. /**
  233. * Enables the plugin. Unless an exception is thrown, the plugin should then be in either the
  234. * {@link PluginState#ENABLING} or {@link PluginState#ENABLED} state. If the plugin is already in the
  235. * {@link PluginState#ENABLING} or {@link PluginState#ENABLED} state, nothing will happen.
  236. *
  237. *
  238. * @since 2.2.0
  239. * @throws PluginException If the plugin could not be enabled
  240. */
  241. void enable() throws PluginException;
  242. /**
  243. * Disables the plugin. Unless an exception is thrown, the plugin should be in the {@link PluginState#DISABLED}
  244. * state. If the plugin is already in the {@link PluginState#DISABLED} state, nothing will happen.
  245. *
  246. * @since 2.2.0 If the plugin could not be disabled
  247. * @throws PluginException If the plugin could not be disabled
  248. */
  249. void disable() throws PluginException;
  250. /**
  251. * @return A list of plugin keys that this plugin is dependent upon, or an empty list if none
  252. * @since 2.2.0
  253. */
  254. Set<String> getRequiredPlugins();
  255. /**
  256. * @return the list of permissions currently valid for the plugin
  257. * @since 3.0
  258. */
  259. Set<String> getActivePermissions();
  260. /**
  261. * @return {@code true} if the plugin has all the permissions
  262. * @since 3.0
  263. */
  264. boolean hasAllPermissions();
  265. }