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.

PluginManager.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Copyright (C) 2012-present the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.pf4j;
  17. import java.nio.file.Path;
  18. import java.util.List;
  19. import java.util.Set;
  20. /**
  21. * Provides the functionality for plugin management such as load,
  22. * start and stop the plugins.
  23. *
  24. * @author Decebal Suiu
  25. */
  26. public interface PluginManager {
  27. /**
  28. * Retrieves all plugins.
  29. */
  30. List<PluginWrapper> getPlugins();
  31. /**
  32. * Retrieves all plugins with this state.
  33. */
  34. List<PluginWrapper> getPlugins(PluginState pluginState);
  35. /**
  36. * Retrieves all resolved plugins (with resolved dependency).
  37. */
  38. List<PluginWrapper> getResolvedPlugins();
  39. /**
  40. * Retrieves all unresolved plugins (with unresolved dependency).
  41. */
  42. List<PluginWrapper> getUnresolvedPlugins();
  43. /**
  44. * Retrieves all started plugins.
  45. */
  46. List<PluginWrapper> getStartedPlugins();
  47. /**
  48. * Retrieves the plugin with this id, or null if the plugin does not exist.
  49. *
  50. * @param pluginId the unique plugin identifier, specified in its metadata
  51. * @return A PluginWrapper object for this plugin, or null if it does not exist.
  52. */
  53. PluginWrapper getPlugin(String pluginId);
  54. /**
  55. * Load plugins.
  56. */
  57. void loadPlugins();
  58. /**
  59. * Load a plugin.
  60. *
  61. * @param pluginPath the plugin location
  62. * @return the pluginId of the installed plugin as specified in its {@linkplain PluginDescriptor metadata}
  63. * @throws PluginRuntimeException if something goes wrong
  64. */
  65. String loadPlugin(Path pluginPath);
  66. /**
  67. * Start all active plugins.
  68. */
  69. void startPlugins();
  70. /**
  71. * Start the specified plugin and its dependencies.
  72. *
  73. * @return the plugin state
  74. * @throws PluginRuntimeException if something goes wrong
  75. */
  76. PluginState startPlugin(String pluginId);
  77. /**
  78. * Stop all active plugins.
  79. */
  80. void stopPlugins();
  81. /**
  82. * Stop the specified plugin and its dependencies.
  83. *
  84. * @return the plugin state
  85. * @throws PluginRuntimeException if something goes wrong
  86. */
  87. PluginState stopPlugin(String pluginId);
  88. /**
  89. * Unload all plugins
  90. */
  91. void unloadPlugins();
  92. /**
  93. * Unload a plugin.
  94. *
  95. * @param pluginId the unique plugin identifier, specified in its metadata
  96. * @return true if the plugin was unloaded
  97. * @throws PluginRuntimeException if something goes wrong
  98. */
  99. boolean unloadPlugin(String pluginId);
  100. /**
  101. * Disables a plugin from being loaded.
  102. *
  103. * @param pluginId the unique plugin identifier, specified in its metadata
  104. * @return true if plugin is disabled
  105. * @throws PluginRuntimeException if something goes wrong
  106. */
  107. boolean disablePlugin(String pluginId);
  108. /**
  109. * Enables a plugin that has previously been disabled.
  110. *
  111. * @param pluginId the unique plugin identifier, specified in its metadata
  112. * @return true if plugin is enabled
  113. * @throws PluginRuntimeException if something goes wrong
  114. */
  115. boolean enablePlugin(String pluginId);
  116. /**
  117. * Deletes a plugin.
  118. *
  119. * @param pluginId the unique plugin identifier, specified in its metadata
  120. * @return true if the plugin was deleted
  121. * @throws PluginRuntimeException if something goes wrong
  122. */
  123. boolean deletePlugin(String pluginId);
  124. ClassLoader getPluginClassLoader(String pluginId);
  125. List<Class<?>> getExtensionClasses(String pluginId);
  126. <T> List<Class<? extends T>> getExtensionClasses(Class<T> type);
  127. <T> List<Class<? extends T>> getExtensionClasses(Class<T> type, String pluginId);
  128. <T> List<T> getExtensions(Class<T> type);
  129. <T> List<T> getExtensions(Class<T> type, String pluginId);
  130. List getExtensions(String pluginId);
  131. Set<String> getExtensionClassNames(String pluginId);
  132. ExtensionFactory getExtensionFactory();
  133. /**
  134. * The runtime mode. Must currently be either DEVELOPMENT or DEPLOYMENT.
  135. */
  136. RuntimeMode getRuntimeMode();
  137. /**
  138. * Returns {@code true} if the runtime mode is {@code RuntimeMode.DEVELOPMENT}.
  139. */
  140. default boolean isDevelopment() {
  141. return RuntimeMode.DEVELOPMENT.equals(getRuntimeMode());
  142. }
  143. /**
  144. * Returns {@code true} if the runtime mode is not {@code RuntimeMode.DEVELOPMENT}.
  145. */
  146. default boolean isNotDevelopment() {
  147. return !isDevelopment();
  148. }
  149. /**
  150. * Retrieves the {@link PluginWrapper} that loaded the given class 'clazz'.
  151. */
  152. PluginWrapper whichPlugin(Class<?> clazz);
  153. void addPluginStateListener(PluginStateListener listener);
  154. void removePluginStateListener(PluginStateListener listener);
  155. /**
  156. * Set the system version. This is used to compare against the plugin
  157. * requires attribute. The default system version is 0.0.0 which
  158. * disables all version checking.
  159. *
  160. * @default 0.0.0
  161. * @param version
  162. */
  163. void setSystemVersion(String version);
  164. /**
  165. * Returns the system version.
  166. *
  167. * @return the system version
  168. */
  169. String getSystemVersion();
  170. /**
  171. * Gets the path of the folder where plugins are installed.
  172. *
  173. * @return Path of plugins root
  174. */
  175. Path getPluginsRoot();
  176. VersionManager getVersionManager();
  177. }