// Parse the request
FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
String fileName = Util.getFileName(fileItem.getName());
if("".equals(fileName)){
return new HttpRedirect("advanced");
}
// we allow the upload of the new jpi's and the legacy hpi's
if(!fileName.endsWith(".jpi") && !fileName.endsWith(".hpi")){
throw new Failure(hudson.model.Messages.Hudson_NotAPlugin(fileName));
}
final String baseName = FilenameUtils.getBaseName(fileName);
fileItem.write(new File(rootDir, baseName + ".jpi")); // rename all new plugins to *.jpi
fileItem.delete();
PluginWrapper existing = getPlugin(baseName);
if (existing!=null && existing.isBundled){
existing.doPin();
}
pluginUploaded = true;
return new HttpRedirect(".");
} catch (IOException e) {
throw e;
} catch (Exception e) {// grrr. fileItem.write throws this
throw new ServletException(e);
}