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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright 2012 Decebal Suiu
  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 pluginId for the plugin you are trying to get.
  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
  62. * @return the pluginId of the installed plugin or null
  63. */
  64. String loadPlugin(Path pluginPath);
  65. /**
  66. * Start all active plugins.
  67. */
  68. void startPlugins();
  69. /**
  70. * Start the specified plugin and it's dependencies.
  71. *
  72. * @return the plugin state
  73. */
  74. PluginState startPlugin(String pluginId);
  75. /**
  76. * Stop all active plugins.
  77. */
  78. void stopPlugins();
  79. /**
  80. * Stop the specified plugin and it's dependencies.
  81. *
  82. * @return the plugin state
  83. */
  84. PluginState stopPlugin(String pluginId);
  85. /**
  86. * Unload a plugin.
  87. *
  88. * @param pluginId
  89. * @return true if the plugin was unloaded
  90. */
  91. boolean unloadPlugin(String pluginId);
  92. /**
  93. * Disables a plugin from being loaded.
  94. *
  95. * @param pluginId
  96. * @return true if plugin is disabled
  97. */
  98. boolean disablePlugin(String pluginId);
  99. /**
  100. * Enables a plugin that has previously been disabled.
  101. *
  102. * @param pluginId
  103. * @return true if plugin is enabled
  104. */
  105. boolean enablePlugin(String pluginId);
  106. /**
  107. * Deletes a plugin.
  108. *
  109. * @param pluginId
  110. * @return true if the plugin was deleted
  111. */
  112. boolean deletePlugin(String pluginId);
  113. ClassLoader getPluginClassLoader(String pluginId);
  114. <T> List<T> getExtensions(Class<T> type);
  115. <T> List<T> getExtensions(Class<T> type, String pluginId);
  116. List getExtensions(String pluginId);
  117. Set<String> getExtensionClassNames(String pluginId);
  118. ExtensionFactory getExtensionFactory();
  119. /**
  120. * The runtime mode. Must currently be either DEVELOPMENT or DEPLOYMENT.
  121. */
  122. RuntimeMode getRuntimeMode();
  123. /**
  124. * Retrieves the {@link PluginWrapper} that loaded the given class 'clazz'.
  125. */
  126. PluginWrapper whichPlugin(Class<?> clazz);
  127. void addPluginStateListener(PluginStateListener listener);
  128. void removePluginStateListener(PluginStateListener listener);
  129. /**
  130. * Set the system version. This is used to compare against the plugin
  131. * requires attribute. The default system version is 0.0.0 which
  132. * disables all version checking.
  133. *
  134. * @default 0.0.0
  135. * @param version
  136. */
  137. void setSystemVersion(String version);
  138. /**
  139. * Returns the system version.
  140. *
  141. * @return the system version
  142. */
  143. String getSystemVersion();
  144. /**
  145. * Gets the path of the folder where plugins are installed
  146. * @return Path of plugins root
  147. */
  148. Path getPluginsRoot();
  149. VersionManager getVersionManager();
  150. }