Skip to content

Commit

Permalink
Merge pull request #2719 from oleg-nenashev/javadoc/pluginManager-get…
Browse files Browse the repository at this point in the history
…Methods

Clarify PluginManager#getPlugin() and Jenkins#getPlugin() methods
  • Loading branch information
daniel-beck committed Jan 16, 2017
2 parents e663b31 + 5b370be commit 23e1850
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,11 @@ public List<FailedPlugin> getFailedPlugins() {
/**
* Get the plugin instance with the given short name.
* @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) {
for (PluginWrapper p : getPlugins()) {
if(p.getShortName().equals(shortName))
Expand All @@ -1159,8 +1162,11 @@ public PluginWrapper getPlugin(String shortName) {
* Get the plugin instance that implements a specific class, use to find your plugin singleton.
* Note: beware the classloader fun.
* @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) {
for (PluginWrapper p : getPlugins()) {
if(pluginClazz.isInstance(p.getPlugin()))
Expand Down
14 changes: 10 additions & 4 deletions core/src/main/java/jenkins/model/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -1556,11 +1556,14 @@ public CopyOnWriteList<SCMListener> getSCMListeners() {

/**
* Gets the plugin object from its short name.
*
* <p>
* This allows URL <tt>hudson/plugin/ID</tt> to be served by the views
* 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) {
PluginWrapper p = pluginManager.getPlugin(shortName);
if(p==null) return null;
Expand All @@ -1574,12 +1577,15 @@ public Plugin getPlugin(String shortName) {
* This allows easy storage of plugin information in the plugin singleton without
* 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
* from within the jpi that defines the plugin class, it may or may not work in other cases)
*
* @return The plugin instance.
* @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.
*/
@SuppressWarnings("unchecked")
@CheckForNull
public <P extends Plugin> P getPlugin(Class<P> clazz) {
PluginWrapper p = pluginManager.getPlugin(clazz);
if(p==null) return null;
Expand Down

0 comments on commit 23e1850

Please sign in to comment.