Add dependency resolution to manually uploaded plugins.

This commit is contained in:
Alex Earl authored and Alex Earl committed 2016-04-07 10:19:16 -07:00
1 parent 1fe9cf7b7a
commit fcdebe56c0
7 files changed
+156 -1

No files matched your search

+23 -1
View File
@@ -62,6 +62,7 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.LogFactory;
import org.jenkinsci.bytecode.Transformer;
import org.jvnet.hudson.reactor.Executable;
@@ -1298,12 +1299,33 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
pluginUploaded = true;
JSONArray dependencies = new JSONArray();
try {
Manifest m = new JarFile(t).getManifest();
String deps = m.getMainAttributes().getValue("Plugin-Dependencies");
if (StringUtils.isNotBlank(deps)) {
// now we get to parse it!
String[] plugins = deps.split(",");
for (String p : plugins) {
// should have name:version[;resolution:=optional]
String[] attrs = p.split("[:;]");
dependencies.add(new JSONObject()
.element("name", attrs[0])
.element("version", attrs[1])
.element("optional", p.contains("resolution:=optional")));
}
}
} catch(IOException e) {
LOGGER.log(WARNING, "Unable to setup dependency list for plugin upload", e);
}
// Now create a dummy plugin that we can dynamically load (the InstallationJob will force a restart if one is needed):
JSONObject cfg = new JSONObject().
element("name", baseName).
element("version", "0"). // unused but mandatory
element("url", t.toURI().toString()).
element("dependencies", new JSONArray());
element("dependencies", dependencies);
new UpdateSite(UpdateCenter.ID_UPLOAD, null).new Plugin(UpdateCenter.ID_UPLOAD, cfg).deploy(true);
return new HttpRedirect("../updateCenter");
} catch (IOException e) {