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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 a plugin.
  90. *
  91. * @param pluginId the unique plugin identifier, specified in its metadata
  92. * @return true if the plugin was unloaded
  93. * @throws PluginRuntimeException if something goes wrong
  94. */
  95. boolean unloadPlugin(String pluginId);
  96. /**
  97. * Disables a plugin from being loaded.
  98. *
  99. * @param pluginId the unique plugin identifier, specified in its metadata
  100. * @return true if plugin is disabled
  101. * @throws PluginRuntimeException if something goes wrong
  102. */
  103. boolean disablePlugin(String pluginId);
  104. /**
  105. * Enables a plugin that has previously been disabled.
  106. *
  107. * @param pluginId the unique plugin identifier, specified in its metadata
  108. * @return true if plugin is enabled
  109. * @throws PluginRuntimeException if something goes wrong
  110. */
  111. boolean enablePlugin(String pluginId);
  112. /**
  113. * Deletes a plugin.
  114. *
  115. * @param pluginId the unique plugin identifier, specified in its metadata
  116. * @return true if the plugin was deleted
  117. * @throws PluginRuntimeException if something goes wrong
  118. */
  119. boolean deletePlugin(String pluginId);
  120. ClassLoader getPluginClassLoader(String pluginId);
  121. List<Class<?>> getExtensionClasses(String pluginId);
  122. <T> List<Class<? extends T>> getExtensionClasses(Class<T> type);
  123. <T> List<Class<? extends T>> getExtensionClasses(Class<T> type, String pluginId);
  124. <T> List<T> getExtensions(Class<T> type);
  125. <T> List<T> getExtensions(Class<T> type, String pluginId);
  126. List getExtensions(String pluginId);
  127. Set<String> getExtensionClassNames(String pluginId);
  128. ExtensionFactory getExtensionFactory();
  129. /**
  130. * The runtime mode. Must currently be either DEVELOPMENT or DEPLOYMENT.
  131. */
  132. RuntimeMode getRuntimeMode();
  133. /**
  134. * Returns {@code true} if the runtime mode is {@code RuntimeMode.DEVELOPMENT}.
  135. */
  136. default boolean isDevelopment() {
  137. return RuntimeMode.DEVELOPMENT.equals(getRuntimeMode());
  138. }
  139. /**
  140. * Returns {@code true} if the runtime mode is not {@code RuntimeMode.DEVELOPMENT}.
  141. */
  142. default boolean isNotDevelopment() {
  143. return !isDevelopment();
  144. }
  145. /**
  146. * Retrieves the {@link PluginWrapper} that loaded the given class 'clazz'.
  147. */
  148. PluginWrapper whichPlugin(Class<?> clazz);
  149. void addPluginStateListener(PluginStateListener listener);
  150. void removePluginStateListener(PluginStateListener listener);
  151. /**
  152. * Set the system version. This is used to compare against the plugin
  153. * requires attribute. The default system version is 0.0.0 which
  154. * disables all version checking.
  155. *
  156. * @default 0.0.0
  157. * @param version
  158. */
  159. void setSystemVersion(String version);
  160. /**
  161. * Returns the system version.
  162. *
  163. * @return the system version
  164. */
  165. String getSystemVersion();
  166. /**
  167. * Gets the path of the folder where plugins are installed.
  168. *
  169. * @return Path of plugins root
  170. */
  171. Path getPluginsRoot();
  172. VersionManager getVersionManager();
  173. }