mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-09 10:06:13 +00:00
Cleanup warnings for missing getPlugin() null checks (#5222)
This commit is contained in:
1 parent
b95da6ef32
commit
b49610e29f
5 files changed
+33
-8
No files matched your search
@@ -390,7 +390,7 @@ public class ClassicPluginStrategy implements PluginStrategy {
|
||||
|
||||
// initialize plugin
|
||||
try {
|
||||
Plugin plugin = wrapper.getPlugin();
|
||||
Plugin plugin = wrapper.getPluginOrFail();
|
||||
plugin.setServletContext(pluginManager.context);
|
||||
startPlugin(wrapper);
|
||||
} catch(Throwable t) {
|
||||
@@ -403,7 +403,7 @@ public class ClassicPluginStrategy implements PluginStrategy {
|
||||
}
|
||||
|
||||
public void startPlugin(PluginWrapper plugin) throws Exception {
|
||||
plugin.getPlugin().start();
|
||||
plugin.getPluginOrFail().start();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -572,7 +572,7 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
|
||||
return;
|
||||
}
|
||||
try {
|
||||
p.getPlugin().postInitialize();
|
||||
p.getPluginOrFail().postInitialize();
|
||||
} catch (Exception e) {
|
||||
failedPlugins.add(new FailedPlugin(p.getShortName(), e));
|
||||
activePlugins.remove(p);
|
||||
@@ -980,7 +980,9 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
|
||||
throw new IOException("Failed to refresh extensions after installing some plugins", e);
|
||||
}
|
||||
for (PluginWrapper p : plugins) {
|
||||
p.getPlugin().postInitialize();
|
||||
//TODO:According to the postInitialize() documentation, one may expect that
|
||||
//p.getPluginOrFail() NPE will continue the initialization. Keeping the original behavior ATM
|
||||
p.getPluginOrFail().postInitialize();
|
||||
}
|
||||
|
||||
// run initializers in the added plugins
|
||||
@@ -1707,6 +1709,7 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
|
||||
return installJobs;
|
||||
}
|
||||
|
||||
@CheckForNull
|
||||
private UpdateSite.Plugin getPlugin(String pluginName, String siteName) {
|
||||
UpdateSite updateSite = Jenkins.get().getUpdateCenter().getById(siteName);
|
||||
if (updateSite == null) {
|
||||
|
||||
@@ -523,12 +523,25 @@ public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
|
||||
|
||||
/**
|
||||
* Gets the instance of {@link Plugin} contributed by this plugin.
|
||||
* @return Plugin instace or {@code null} if it is not present in the plugin instance store.
|
||||
*/
|
||||
public @CheckForNull Plugin getPlugin() {
|
||||
PluginInstanceStore pis = Jenkins.lookup(PluginInstanceStore.class);
|
||||
return pis != null ? pis.store.get(this) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the instance of {@link Plugin} contributed by this plugin.
|
||||
* @throws Exception no plugin in the {@link PluginInstanceStore}
|
||||
*/
|
||||
public @NonNull Plugin getPluginOrFail() throws Exception {
|
||||
Plugin plugin = getPlugin();
|
||||
if (plugin == null) {
|
||||
throw new Exception("Cannot find the plugin instance: " + shortName);
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL that shows more information about this plugin.
|
||||
* @return
|
||||
|
||||
@@ -411,8 +411,9 @@ public class UpdateSite {
|
||||
* The short name of the plugin. Corresponds to {@link PluginWrapper#getShortName()}.
|
||||
*
|
||||
* @return
|
||||
* null if no such information is found.
|
||||
* {@code null} if no such information is found.
|
||||
*/
|
||||
@CheckForNull
|
||||
public Plugin getPlugin(String artifactId) {
|
||||
Data dt = getData();
|
||||
if(dt==null) return null;
|
||||
|
||||
@@ -2,6 +2,7 @@ package jenkins.model;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.Plugin;
|
||||
import hudson.PluginWrapper;
|
||||
import hudson.StructuredForm;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.jenkinsci.Symbol;
|
||||
@@ -23,11 +24,18 @@ public class GlobalPluginConfiguration extends GlobalConfiguration {
|
||||
@Override
|
||||
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
|
||||
try {
|
||||
for( JSONObject o : StructuredForm.toList(json, "plugin"))
|
||||
Jenkins.get().pluginManager.getPlugin(o.getString("name")).getPlugin().configure(req, o);
|
||||
for( JSONObject o : StructuredForm.toList(json, "plugin")) {
|
||||
String pluginName = o.getString("name");
|
||||
PluginWrapper pw = Jenkins.get().pluginManager.getPlugin(pluginName);
|
||||
Plugin p = pw != null ? pw.getPlugin() : null;
|
||||
if (p == null) {
|
||||
throw new FormException("Cannot find the plugin instance: " + pluginName, "plugin");
|
||||
}
|
||||
p.configure(req, o);
|
||||
}
|
||||
return true;
|
||||
} catch (IOException | ServletException e) {
|
||||
throw new FormException(e,"plugin");
|
||||
throw new FormException(e, "plugin");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user