in core/src/main/java/hudson/cli/InstallPluginCommand.java [84:169]
protected int run() throws Exception {
Jenkins h = Jenkins.get();
h.checkPermission(Jenkins.ADMINISTER);
PluginManager pm = h.getPluginManager();
if (name != null) {
stderr.println("-name is deprecated; it is no longer necessary nor honored.");
}
for (String source : sources) {
if (source.equals("=")) {
stdout.println(Messages.InstallPluginCommand_InstallingPluginFromStdin());
File f = getTmpFile();
FileUtils.copyInputStreamToFile(stdin, f);
f = moveToFinalLocation(f);
if (dynamicLoad) {
pm.dynamicLoad(f);
}
continue;
}
// is this an URL?
try {
URL u = new URL(source);
stdout.println(Messages.InstallPluginCommand_InstallingPluginFromUrl(u));
File f = getTmpFile();
FileUtils.copyURLToFile(u, f); // TODO JENKINS-58248 proxy
f = moveToFinalLocation(f);
if (dynamicLoad) {
pm.dynamicLoad(f);
}
continue;
} catch (MalformedURLException e) {
// not an URL
}
// is this a plugin the update center?
int index = source.lastIndexOf(':');
UpdateSite.Plugin p;
if (index == -1) {
p = h.getUpdateCenter().getPlugin(source);
} else {
// try to find matching min version number
VersionNumber version = new VersionNumber(source.substring(index + 1));
p = h.getUpdateCenter().getPlugin(source.substring(0,index), version);
if (p == null) {
p = h.getUpdateCenter().getPlugin(source);
}
}
if (p!=null) {
stdout.println(Messages.InstallPluginCommand_InstallingFromUpdateCenter(source));
Throwable e = p.deploy(dynamicLoad).get().getError();
if (e!=null) {
AbortException myException = new AbortException("Failed to install plugin " + source);
myException.initCause(e);
throw myException;
}
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<>();
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)));
}
}
throw new AbortException("Error occurred, see previous output.");
}
if (restart)
h.safeRestart();
return 0; // all success
}