Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

PluginManager.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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
  63. * its {@linkplain PluginDescriptor metadata}
  64. * @throws PluginException if load of plugin fails
  65. */
  66. String loadPlugin(Path pluginPath) throws PluginException;
  67. /**
  68. * Start all active plugins.
  69. */
  70. void startPlugins();
  71. /**
  72. * Start the specified plugin and its dependencies.
  73. *
  74. * @return the plugin state
  75. */
  76. PluginState startPlugin(String pluginId) throws PluginException;
  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. */
  86. PluginState stopPlugin(String pluginId) throws PluginException;
  87. /**
  88. * Unload a plugin.
  89. *
  90. * @param pluginId the unique plugin identifier, specified in its metadata
  91. * @return true if the plugin was unloaded
  92. */
  93. boolean unloadPlugin(String pluginId) throws PluginException;
  94. /**
  95. * Disables a plugin from being loaded.
  96. *
  97. * @param pluginId the unique plugin identifier, specified in its metadata
  98. * @return true if plugin is disabled
  99. */
  100. boolean disablePlugin(String pluginId) throws PluginException;
  101. /**
  102. * Enables a plugin that has previously been disabled.
  103. *
  104. * @param pluginId the unique plugin identifier, specified in its metadata
  105. * @return true if plugin is enabled
  106. */
  107. boolean enablePlugin(String pluginId) throws PluginException;
  108. /**
  109. * Deletes a plugin.
  110. *
  111. * @param pluginId the unique plugin identifier, specified in its metadata
  112. * @return true if the plugin was deleted
  113. */
  114. boolean deletePlugin(String pluginId) throws PluginException;
  115. ClassLoader getPluginClassLoader(String pluginId);
  116. List<Class<?>> getExtensionClasses(String pluginId);
  117. <T> List<Class<? extends T>> getExtensionClasses(Class<T> type);
  118. <T> List<Class<? extends T>> getExtensionClasses(Class<T> type, String pluginId);
  119. <T> List<T> getExtensions(Class<T> type);
  120. <T> List<T> getExtensions(Class<T> type, String pluginId);
  121. List getExtensions(String pluginId);
  122. Set<String> getExtensionClassNames(String pluginId);
  123. ExtensionFactory getExtensionFactory();
  124. /**
  125. * The runtime mode. Must currently be either DEVELOPMENT or DEPLOYMENT.
  126. */
  127. RuntimeMode getRuntimeMode();
  128. /**
  129. * Returns {@code true} id the runtime mode is {@code RuntimeMode.DEVELOPMENT}.
  130. */
  131. default boolean isDevelopment() {
  132. return RuntimeMode.DEVELOPMENT.equals(getRuntimeMode());
  133. }
  134. /**
  135. * Retrieves the {@link PluginWrapper} that loaded the given class 'clazz'.
  136. */
  137. PluginWrapper whichPlugin(Class<?> clazz);
  138. void addPluginStateListener(PluginStateListener listener);
  139. void removePluginStateListener(PluginStateListener listener);
  140. /**
  141. * Set the system version. This is used to compare against the plugin
  142. * requires attribute. The default system version is 0.0.0 which
  143. * disables all version checking.
  144. *
  145. * @default 0.0.0
  146. * @param version
  147. */
  148. void setSystemVersion(String version);
  149. /**
  150. * Returns the system version.
  151. *
  152. * @return the system version
  153. */
  154. String getSystemVersion();
  155. /**
  156. * Gets the path of the folder where plugins are installed
  157. * @return Path of plugins root
  158. */
  159. Path getPluginsRoot();
  160. VersionManager getVersionManager();
  161. }