@Option(name="-deploy",usage="Deploy plugins right away without postponing them until the reboot.")
public boolean dynamicLoad;
protected int run() throws Exception {
Jenkins h = Jenkins.getInstance();
h.checkPermission(Jenkins.ADMINISTER);
PluginManager pm = h.getPluginManager();
for (String source : sources) {
// is this a file?
if (channel!=null) {
FilePath f = new FilePath(channel, source);
if (f.exists()) {
stdout.println(Messages.InstallPluginCommand_InstallingPluginFromLocalFile(f));
if (name==null)
name = f.getBaseName();
f.copyTo(getTargetFilePath());
if (dynamicLoad)
pm.dynamicLoad(getTargetFile());
continue;
}
}
// is this an URL?
try {
URL u = new URL(source);
stdout.println(Messages.InstallPluginCommand_InstallingPluginFromUrl(u));
if (name==null) {
name = u.getPath();
name = name.substring(name.lastIndexOf('/')+1);
name = name.substring(name.lastIndexOf('\\')+1);
int idx = name.lastIndexOf('.');
if (idx>0) name = name.substring(0,idx);
}
getTargetFilePath().copyFrom(u);
if (dynamicLoad)
pm.dynamicLoad(getTargetFile());
continue;
} catch (MalformedURLException e) {
// not an URL
}
// is this a plugin the update center?
UpdateSite.Plugin p = h.getUpdateCenter().getPlugin(source);
if (p!=null) {
stdout.println(Messages.InstallPluginCommand_InstallingFromUpdateCenter(source));
Throwable e = p.deploy(dynamicLoad).get().getError();
if (e!=null)
throw new IOException2("Failed to install plugin "+source,e);
continue;
}
stdout.println(Messages.InstallPluginCommand_NotAValidSourceName(source));
if (!source.contains(".") && !source.contains(":") && !source.contains("/") && !source.contains("\\")) {
// looks like a short plugin name. Why did we fail to find it in the update center?
if (h.getUpdateCenter().getSites().isEmpty()) {
stdout.println(Messages.InstallPluginCommand_NoUpdateCenterDefined());
} else {
Set<String> candidates = new HashSet<String>();
for (UpdateSite s : h.getUpdateCenter().getSites()) {
Data dt = s.getData();
if (dt==null)
stdout.println(Messages.InstallPluginCommand_NoUpdateDataRetrieved(s.getUrl()));
else
candidates.addAll(dt.plugins.keySet());
}
stdout.println(Messages.InstallPluginCommand_DidYouMean(source,EditDistance.findNearest(source,candidates)));
}
}
return 1;
}
if (restart)
h.restart();
return 0; // all success
}