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 6.5KB

11 vuotta sitten
11 vuotta sitten
11 vuotta sitten
11 vuotta sitten
11 vuotta sitten
11 vuotta sitten
6 vuotta sitten
6 vuotta sitten
11 vuotta sitten
11 vuotta sitten
11 vuotta sitten
11 vuotta sitten
11 vuotta sitten
11 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
4 kuukautta sitten
6 vuotta sitten
11 vuotta sitten
5 vuotta sitten
5 vuotta sitten
6 vuotta sitten
4 kuukautta sitten
6 vuotta sitten
4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
7 vuotta sitten
4 kuukautta sitten
11 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. /**
  125. * Retrieves the class loader for the specified plugin.
  126. *
  127. * @param pluginId the unique plugin identifier, specified in its metadata
  128. * @return the class loader for the plugin
  129. */
  130. ClassLoader getPluginClassLoader(String pluginId);
  131. List<Class<?>> getExtensionClasses(String pluginId);
  132. <T> List<Class<? extends T>> getExtensionClasses(Class<T> type);
  133. <T> List<Class<? extends T>> getExtensionClasses(Class<T> type, String pluginId);
  134. <T> List<T> getExtensions(Class<T> type);
  135. <T> List<T> getExtensions(Class<T> type, String pluginId);
  136. /**
  137. * Retrieves the extensions for the specified plugin.
  138. *
  139. * @param pluginId the unique plugin identifier, specified in its metadata
  140. * @return the extensions for the plugin
  141. */
  142. List getExtensions(String pluginId);
  143. Set<String> getExtensionClassNames(String pluginId);
  144. ExtensionFactory getExtensionFactory();
  145. /**
  146. * The runtime mode. Must currently be either DEVELOPMENT or DEPLOYMENT.
  147. */
  148. RuntimeMode getRuntimeMode();
  149. /**
  150. * Returns {@code true} if the runtime mode is {@link RuntimeMode#DEVELOPMENT}.
  151. */
  152. default boolean isDevelopment() {
  153. return RuntimeMode.DEVELOPMENT.equals(getRuntimeMode());
  154. }
  155. /**
  156. * Returns {@code true} if the runtime mode is not {@link RuntimeMode#DEVELOPMENT}.
  157. */
  158. default boolean isNotDevelopment() {
  159. return !isDevelopment();
  160. }
  161. /**
  162. * Retrieves the {@link PluginWrapper} that loaded the given class 'clazz'.
  163. */
  164. PluginWrapper whichPlugin(Class<?> clazz);
  165. void addPluginStateListener(PluginStateListener listener);
  166. void removePluginStateListener(PluginStateListener listener);
  167. /**
  168. * Set the system version. This is used to compare against the plugin
  169. * requires attribute. The default system version is 0.0.0 which
  170. * disables all version checking.
  171. *
  172. * @default 0.0.0
  173. * @param version the system version
  174. */
  175. void setSystemVersion(String version);
  176. /**
  177. * Returns the system version.
  178. *
  179. * @return the system version
  180. */
  181. String getSystemVersion();
  182. /**
  183. * Gets the first path of the folders where plugins are installed.
  184. *
  185. * @deprecated Use {@link #getPluginsRoots()} instead to get all paths where plugins are could be installed.
  186. *
  187. * @return Path of plugins root
  188. */
  189. @Deprecated
  190. Path getPluginsRoot();
  191. /**
  192. * Gets a read-only list of all paths of the folders where plugins are installed.
  193. *
  194. * @return Paths of plugins roots
  195. */
  196. List<Path> getPluginsRoots();
  197. VersionManager getVersionManager();
  198. }