PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/atlassian/atlassian-plugins
Java | 363 lines | 64 code | 48 blank | 251 comment | 0 complexity | ffa89c560828d11d907a3af644fe51ac MD5 | raw file
  1. package com.atlassian.plugin;
  2. import com.atlassian.annotations.Internal;
  3. import javax.annotation.Nonnull;
  4. import javax.annotation.Nullable;
  5. import java.io.InputStream;
  6. import java.net.URL;
  7. import java.util.Collection;
  8. import java.util.Date;
  9. import java.util.List;
  10. import java.util.Set;
  11. public interface Plugin extends ScopeAware, Resourced, Comparable<Plugin> {
  12. /**
  13. * This is the historical version of plugins. Which is mostly static plugins loaded from the same classpath to the
  14. * application.
  15. */
  16. int VERSION_1 = 1;
  17. /**
  18. * This is the version of plugins which introduced dynamic plugins for all. Based on OSGi and Spring DM. Those plugins
  19. * undergo some transformations to make the plugin artifact compatible with the OSGi + Spring DM container.
  20. */
  21. int VERSION_2 = 2;
  22. /**
  23. * This is the versions of plugins that adds remotes plugins (developed outside of the plugin framework itself).
  24. * Plugins version 3 don't undergo any transformation so it is up to the plugin developer to write their own Spring
  25. * configuration files if this is their chosen framework, but other frameworks can be introduced.
  26. */
  27. int VERSION_3 = 3;
  28. /**
  29. * Gets the version of the plugins system to handle this plugin
  30. *
  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. *
  37. * @param version The version
  38. */
  39. void setPluginsVersion(int version);
  40. /**
  41. * Returns the non-localised name of this plugin if defined.
  42. *
  43. * <p> This corresponds to the value of the {@code name} field in the plugin's XML configuration file.
  44. *
  45. * <p> You would expect a plugin developer to fill in one of either {@code name}, or {@code i18n-name-key},
  46. * but the framework does no validation and makes no guarantees that this is the case.
  47. *
  48. * @return the non-localised name of this plugin if defined, or null.
  49. * @see #getI18nNameKey()
  50. */
  51. String getName();
  52. /**
  53. * Sets the non-localised name of this plugin.
  54. *
  55. * @param name the name.
  56. * @see #getName()
  57. */
  58. void setName(String name);
  59. /**
  60. * Returns the i18nKey used to get an internationalised name for this plugin.
  61. *
  62. * <p> This corresponds to the value of the {@code i18n-name-key} field in the plugin's XML configuration file.
  63. *
  64. * <p> You would expect a plugin developer to fill in one of either {@code name}, or {@code i18n-name-key},
  65. * but the framework does no validation and makes no guarantees that this is the case.
  66. *
  67. * @return the i18n Name Key for this plugin if defined, or null.
  68. * @see #getName()
  69. */
  70. String getI18nNameKey();
  71. /**
  72. * Sets the i18nKey used to get an internationalised name for this plugin.
  73. *
  74. * @param i18nNameKey the i18n Name Key.
  75. * @see #getI18nNameKey()
  76. */
  77. void setI18nNameKey(String i18nNameKey);
  78. String getKey();
  79. void setKey(String aPackage);
  80. void addModuleDescriptor(ModuleDescriptor<?> moduleDescriptor);
  81. /**
  82. * Get the {@link Collection} of {@link ModuleDescriptor descriptors}.
  83. *
  84. * <p> The iteration order of the collection is
  85. * the order that the modules will be enabled, and should be the same order that the modules appear in the
  86. * plugin descriptor.
  87. *
  88. * @return the modules contained by this plugin in the order they are to be enabled
  89. */
  90. Collection<ModuleDescriptor<?>> getModuleDescriptors();
  91. /**
  92. * Get the {@link ModuleDescriptor} for a particular key. Returns <tt>null</tt> if the plugin does not exist.
  93. * <p>
  94. * Note: The {@link ModuleDescriptor#getModule()} may throw {@link ClassCastException} if the expected type is incorrect.
  95. *
  96. * @param key the {@link String} complete key of the module, in the form "org.example.plugin:module-key".
  97. * @return the {@link ModuleDescriptor} of the expected type.
  98. */
  99. ModuleDescriptor<?> getModuleDescriptor(String key);
  100. /**
  101. * Get the {@link ModuleDescriptor descriptors} whose module class implements or is assignable from the supplied {@link Class}.
  102. * <p>
  103. * Note: The {@link ModuleDescriptor#getModule()} may throw {@link ClassCastException} if the expected type is incorrect.
  104. * Normally this method would not be supplied with anything other than {@link Object} or &lt;?&gt;, unless you are
  105. * confident in the super type of the module classes this {@link Plugin} provides.
  106. *
  107. * @param <M> The expected module type of the returned {@link ModuleDescriptor descriptors}.
  108. * @param moduleClass the {@link Class super class} the {@link ModuleDescriptor descriptors} return.
  109. * @return the {@link List} of {@link ModuleDescriptor descriptors} of the expected type.
  110. */
  111. <M> List<ModuleDescriptor<M>> getModuleDescriptorsByModuleClass(Class<M> moduleClass);
  112. /**
  113. * Gets the installation mode
  114. *
  115. * @return the plugin's installation mode, local or remote.
  116. * @since 3.0
  117. */
  118. InstallationMode getInstallationMode();
  119. boolean isEnabledByDefault();
  120. void setEnabledByDefault(boolean enabledByDefault);
  121. PluginInformation getPluginInformation();
  122. void setPluginInformation(PluginInformation pluginInformation);
  123. void setResources(Resourced resources);
  124. /**
  125. * Returns this plugin's current state.
  126. *
  127. * @return the current state of the plugin.
  128. * @since 2.2.0
  129. */
  130. PluginState getPluginState();
  131. /**
  132. * Whether the plugin is a "system" plugin that shouldn't be made visible to the user.
  133. *
  134. * @return {@code true} if this plugin is a "system" plugin.
  135. * @deprecated since 2.6.0 use {@link com.atlassian.plugin.metadata.PluginMetadataManager#isSystemProvided(Plugin)}}
  136. * instead.
  137. */
  138. @Deprecated
  139. boolean isSystemPlugin();
  140. /**
  141. * @param system whether the plugin is a "system" plugin that shouldn't be made visible to the user.
  142. * @deprecated since 2.6.0 provide {@link com.atlassian.plugin.metadata.PluginMetadataManager} with information about the
  143. * plugin instead. There is no way to programatically set this value now.
  144. */
  145. @Deprecated
  146. void setSystemPlugin(boolean system);
  147. boolean containsSystemModule();
  148. /**
  149. * Whether the plugin is a "bundled" plugin that can't be removed.
  150. *
  151. * @return {@code true} if this plugin is a "bundled" plugin.
  152. */
  153. boolean isBundledPlugin();
  154. /**
  155. * The date this plugin was loaded into the system.
  156. *
  157. * @return The date this plugin was loaded into the system.
  158. */
  159. Date getDateLoaded();
  160. /**
  161. * The date this plugin was installed into the system, is the same as the loaded date for non artifact backed plugins
  162. *
  163. * @return The date this plugin was installed into the system
  164. * @since 3.0.0
  165. */
  166. Date getDateInstalled();
  167. /**
  168. * Whether or not this plugin can be 'uninstalled'.
  169. *
  170. * @return {@code true} if this plugin can be 'uninstalled'.
  171. */
  172. boolean isUninstallable();
  173. /**
  174. * Should the plugin file be deleted on uninstall?
  175. *
  176. * @return {@code true} if this plugin file should be deleted on uninstall.
  177. */
  178. boolean isDeleteable();
  179. /**
  180. * Whether or not this plugin is loaded dynamically at runtime.
  181. *
  182. * @return {@code true} if this plugin is loaded dynamically at runtime.
  183. */
  184. boolean isDynamicallyLoaded();
  185. /**
  186. * Get the plugin to load a specific class.
  187. *
  188. * @param clazz The name of the class to be loaded
  189. * @param callingClass The class calling the loading (used to help find a classloader)
  190. * @return The loaded class.
  191. * @throws ClassNotFoundException if the class cannot be located.
  192. */
  193. <T> Class<T> loadClass(String clazz, Class<?> callingClass) throws ClassNotFoundException;
  194. /**
  195. * Get the classloader for the plugin.
  196. *
  197. * @return The classloader used to load classes for this plugin
  198. */
  199. ClassLoader getClassLoader();
  200. /**
  201. * Retrieve the URL of the resource from the plugin.
  202. *
  203. * @param path the name of the resource to be loaded
  204. * @return The URL to the resource, or null if the resource is not found
  205. */
  206. URL getResource(String path);
  207. /**
  208. * Load a given resource from the plugin. Plugins that are loaded dynamically will need
  209. * to implement this in a way that loads the resource from the same context as the plugin.
  210. * Static plugins can just pull them from their own classloader.
  211. *
  212. * @param name The name of the resource to be loaded.
  213. * @return An InputStream for the resource, or null if the resource is not found.
  214. */
  215. InputStream getResourceAsStream(String name);
  216. /**
  217. * Installs the plugin into any internal, managing container. This method will be called on every startup. Unless
  218. * an exception is thrown, the plugin should be in the {@link PluginState#INSTALLED} state. If the plugin is already
  219. * in the {@link PluginState#INSTALLED} state, nothing will happen.
  220. *
  221. * @throws PluginException If the plugin could not be installed
  222. * @since 2.2.0
  223. */
  224. void install();
  225. /**
  226. * Uninstalls the plugin from any internal container. This method will be called on every shutdown. Unless an
  227. * exception is thrown, the plugin should be in the {@link PluginState#UNINSTALLED} state. If the plugin is already
  228. * in the {@link PluginState#UNINSTALLED} state, nothing will happen.
  229. *
  230. * @throws PluginException If the plugin could not be uninstalled
  231. * @since 2.2.0
  232. */
  233. void uninstall();
  234. /**
  235. * Enables the plugin. Unless an exception is thrown, the plugin should then be in either the
  236. * {@link PluginState#ENABLING} or {@link PluginState#ENABLED} state. If the plugin is already in the
  237. * {@link PluginState#ENABLING} or {@link PluginState#ENABLED} state, nothing will happen.
  238. *
  239. * @throws PluginException If the plugin could not be enabled
  240. * @since 2.2.0
  241. */
  242. void enable();
  243. /**
  244. * Disables the plugin. Unless an exception is thrown, the plugin should be in the {@link PluginState#DISABLED}
  245. * state. If the plugin is already in the {@link PluginState#DISABLED} state, nothing will happen.
  246. *
  247. * @throws PluginException If the plugin could not be disabled
  248. * @since 2.2.0 If the plugin could not be disabled
  249. */
  250. void disable();
  251. /**
  252. * Determines which plugin keys are dependencies, categorising them as mandatory, optional or dynamic.
  253. *
  254. * @return not null, possibly empty
  255. * @since 4.0
  256. */
  257. @Nonnull
  258. PluginDependencies getDependencies();
  259. /**
  260. * @return the list of permissions currently valid for the plugin
  261. * @since 3.0
  262. */
  263. Set<String> getActivePermissions();
  264. /**
  265. * @return {@code true} if the plugin has all the permissions
  266. * @since 3.0
  267. */
  268. boolean hasAllPermissions();
  269. /**
  270. * Perform any required resolution.
  271. *
  272. * This is a hook to allow the plugin system to perform a resolution pass over a group of modules
  273. * before the enable pass.
  274. *
  275. * @since 4.0.0
  276. */
  277. void resolve();
  278. /**
  279. * Obtain the date that the plugin system most recently commenced enabling this plugin.
  280. *
  281. * This may return null if the plugin has never commenced enabling, or if the value is
  282. * unavailable for other reasons, such as wrappers around legacy implementations.
  283. *
  284. * @return the date that the plugin most recently entered {@link PluginState#ENABLING}.
  285. * @since 4.0.0
  286. */
  287. @Nullable
  288. Date getDateEnabling();
  289. /**
  290. * Obtain the date that the plugin system most recently completed enabling of this plugin.
  291. *
  292. * This will return null if the plugin has never been enabled, has not completed enabling
  293. * since it most recently started enabling, or if the value is unavailable for any other
  294. * reason, such as wrappers around legacy implementations.
  295. *
  296. * @return the date that the plugin most recently entered {@link PluginState#ENABLED},
  297. * if this was not before the most recent {@link PluginState#ENABLING}, otherwise null.
  298. * @since 4.0.0
  299. */
  300. @Nullable
  301. Date getDateEnabled();
  302. /**
  303. * Retrieve the original, unprocessed or transformed {@link PluginArtifact} used to create this plugin instance.
  304. * <p>
  305. * Note that this method may be removed without notice; it is for use only by the host application.
  306. * <p>
  307. * This method was originally part of the internal <code>PluginArtifactBackedPlugin</code> interface that is no
  308. * longer present.
  309. *
  310. * @return null if this plugin has no artifact
  311. * @since 4.0.0
  312. */
  313. @Internal
  314. PluginArtifact getPluginArtifact();
  315. }