提交 23e18504 编写于 作者: D Daniel Beck 提交者: GitHub

Merge pull request #2719 from oleg-nenashev/javadoc/pluginManager-getMethods

Clarify PluginManager#getPlugin() and Jenkins#getPlugin() methods
...@@ -1145,8 +1145,11 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas ...@@ -1145,8 +1145,11 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
/** /**
* Get the plugin instance with the given short name. * Get the plugin instance with the given short name.
* @param shortName the short name of the plugin * @param shortName the short name of the plugin
* @return The plugin singleton or <code>null</code> if a plugin with the given short name does not exist. * @return The plugin singleton or {@code null} if a plugin with the given short name does not exist.
* The fact the plugin is loaded does not mean it is enabled and fully initialized for the current Jenkins session.
* Use {@link PluginWrapper#isActive()} to check it.
*/ */
@CheckForNull
public PluginWrapper getPlugin(String shortName) { public PluginWrapper getPlugin(String shortName) {
for (PluginWrapper p : getPlugins()) { for (PluginWrapper p : getPlugins()) {
if(p.getShortName().equals(shortName)) if(p.getShortName().equals(shortName))
...@@ -1159,8 +1162,11 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas ...@@ -1159,8 +1162,11 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
* Get the plugin instance that implements a specific class, use to find your plugin singleton. * Get the plugin instance that implements a specific class, use to find your plugin singleton.
* Note: beware the classloader fun. * Note: beware the classloader fun.
* @param pluginClazz The class that your plugin implements. * @param pluginClazz The class that your plugin implements.
* @return The plugin singleton or <code>null</code> if for some reason the plugin is not loaded. * @return The plugin singleton or {@code null} if for some reason the plugin is not loaded.
* The fact the plugin is loaded does not mean it is enabled and fully initialized for the current Jenkins session.
* Use {@link Plugin#getWrapper()} and then {@link PluginWrapper#isActive()} to check it.
*/ */
@CheckForNull
public PluginWrapper getPlugin(Class<? extends Plugin> pluginClazz) { public PluginWrapper getPlugin(Class<? extends Plugin> pluginClazz) {
for (PluginWrapper p : getPlugins()) { for (PluginWrapper p : getPlugins()) {
if(pluginClazz.isInstance(p.getPlugin())) if(pluginClazz.isInstance(p.getPlugin()))
......
...@@ -1556,11 +1556,14 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve ...@@ -1556,11 +1556,14 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
/** /**
* Gets the plugin object from its short name. * Gets the plugin object from its short name.
*
* <p>
* This allows URL <tt>hudson/plugin/ID</tt> to be served by the views * This allows URL <tt>hudson/plugin/ID</tt> to be served by the views
* of the plugin class. * of the plugin class.
* @param shortName Short name of the plugin
* @return The plugin singleton or {@code null} if for some reason the plugin is not loaded.
* The fact the plugin is loaded does not mean it is enabled and fully initialized for the current Jenkins session.
* Use {@link Plugin#getWrapper()} and then {@link PluginWrapper#isActive()} to check it.
*/ */
@CheckForNull
public Plugin getPlugin(String shortName) { public Plugin getPlugin(String shortName) {
PluginWrapper p = pluginManager.getPlugin(shortName); PluginWrapper p = pluginManager.getPlugin(shortName);
if(p==null) return null; if(p==null) return null;
...@@ -1574,12 +1577,15 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve ...@@ -1574,12 +1577,15 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
* This allows easy storage of plugin information in the plugin singleton without * This allows easy storage of plugin information in the plugin singleton without
* every plugin reimplementing the singleton pattern. * every plugin reimplementing the singleton pattern.
* *
* @param <P> Class of the plugin
* @param clazz The plugin class (beware class-loader fun, this will probably only work * @param clazz The plugin class (beware class-loader fun, this will probably only work
* from within the jpi that defines the plugin class, it may or may not work in other cases) * from within the jpi that defines the plugin class, it may or may not work in other cases)
* * @return The plugin singleton or {@code null} if for some reason the plugin is not loaded.
* @return The plugin instance. * The fact the plugin is loaded does not mean it is enabled and fully initialized for the current Jenkins session.
* Use {@link Plugin#getWrapper()} and then {@link PluginWrapper#isActive()} to check it.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@CheckForNull
public <P extends Plugin> P getPlugin(Class<P> clazz) { public <P extends Plugin> P getPlugin(Class<P> clazz) {
PluginWrapper p = pluginManager.getPlugin(clazz); PluginWrapper p = pluginManager.getPlugin(clazz);
if(p==null) return null; if(p==null) return null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册