mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-04 07:35:53 +00:00
hooking up the dynamic loading logic into the UI
This commit is contained in:
1 parent
f4474cc865
commit
c6d81ef2e2
9 files changed
+199
-24
No files matched your search
@@ -34,10 +34,13 @@ import hudson.model.UpdateSite;
|
||||
import hudson.util.CyclicGraphDetector;
|
||||
import hudson.util.CyclicGraphDetector.CycleDetectedException;
|
||||
import hudson.util.FormValidation;
|
||||
import hudson.util.IOException2;
|
||||
import hudson.util.PersistedList;
|
||||
import hudson.util.Service;
|
||||
import jenkins.ClassLoaderReflectionToolkit;
|
||||
import jenkins.InitReactorRunner;
|
||||
import jenkins.RestartRequiredException;
|
||||
import jenkins.YesNoMaybe;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
@@ -47,6 +50,7 @@ import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jvnet.hudson.reactor.Executable;
|
||||
import org.jvnet.hudson.reactor.Reactor;
|
||||
import org.jvnet.hudson.reactor.ReactorException;
|
||||
import org.jvnet.hudson.reactor.TaskBuilder;
|
||||
import org.jvnet.hudson.reactor.TaskGraphBuilder;
|
||||
import org.kohsuke.stapler.HttpRedirect;
|
||||
@@ -124,7 +128,7 @@ public abstract class PluginManager extends AbstractModelObject {
|
||||
|
||||
/**
|
||||
* Once plugin is uploaded, this flag becomes true.
|
||||
* This is used to report a message that Hudson needs to be restarted
|
||||
* This is used to report a message that Jenkins needs to be restarted
|
||||
* for new plugins to take effect.
|
||||
*/
|
||||
public volatile boolean pluginUploaded = false;
|
||||
@@ -330,10 +334,15 @@ public abstract class PluginManager extends AbstractModelObject {
|
||||
/**
|
||||
* TODO: revisit where/how to expose this. This is an experiment.
|
||||
*/
|
||||
public void dynamicLoad(File arc) throws Exception {
|
||||
public void dynamicLoad(File arc) throws IOException, InterruptedException, RestartRequiredException {
|
||||
LOGGER.info("Attempting to dynamic load "+arc);
|
||||
final PluginWrapper p = strategy.createPluginWrapper(arc);
|
||||
if (getPlugin(p.getShortName())!=null)
|
||||
throw new IllegalArgumentException("Dynamic reloading isn't possible");
|
||||
String sn = p.getShortName();
|
||||
if (getPlugin(sn)!=null)
|
||||
throw new RestartRequiredException(Messages._PluginManager_PluginIsAlreadyInstalled_RestartRequired(sn));
|
||||
|
||||
if (p.supportsDynamicLoad()== YesNoMaybe.NO)
|
||||
throw new RestartRequiredException(Messages._PluginManager_PluginDoesntSupportDynamicLoad_RestartRequired(sn));
|
||||
|
||||
// there's no need to do cyclic dependency check, because we are deploying one at a time,
|
||||
// so existing plugins can't be depending on this newly deployed one.
|
||||
@@ -349,10 +358,10 @@ public abstract class PluginManager extends AbstractModelObject {
|
||||
|
||||
p.getPlugin().postInitialize();
|
||||
} catch (Exception e) {
|
||||
failedPlugins.add(new FailedPlugin(p.getShortName(), e));
|
||||
failedPlugins.add(new FailedPlugin(sn, e));
|
||||
activePlugins.remove(p);
|
||||
plugins.remove(p);
|
||||
throw e;
|
||||
throw new IOException2("Failed to install "+ sn +" plugin",e);
|
||||
}
|
||||
|
||||
// run initializers in the added plugin
|
||||
@@ -363,7 +372,12 @@ public abstract class PluginManager extends AbstractModelObject {
|
||||
return e.getDeclaringClass().getClassLoader()!=p.classLoader || super.filter(e);
|
||||
}
|
||||
}.discoverTasks(r));
|
||||
new InitReactorRunner().run(r);
|
||||
try {
|
||||
new InitReactorRunner().run(r);
|
||||
} catch (ReactorException e) {
|
||||
throw new IOException2("Failed to initialize "+ sn +" plugin",e);
|
||||
}
|
||||
LOGGER.info("Plugin " + sn + " dynamically installed");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -559,6 +573,8 @@ public abstract class PluginManager extends AbstractModelObject {
|
||||
* Performs the installation of the plugins.
|
||||
*/
|
||||
public void doInstall(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
|
||||
boolean dynamicLoad = req.getParameter("dynamicLoad")!=null;
|
||||
|
||||
Enumeration<String> en = req.getParameterNames();
|
||||
while (en.hasMoreElements()) {
|
||||
String n = en.nextElement();
|
||||
@@ -569,7 +585,7 @@ public abstract class PluginManager extends AbstractModelObject {
|
||||
UpdateSite.Plugin p = Jenkins.getInstance().getUpdateCenter().getById(pluginInfo[1]).getPlugin(pluginInfo[0]);
|
||||
if(p==null)
|
||||
throw new Failure("No such plugin: "+n);
|
||||
p.deploy();
|
||||
p.deploy(dynamicLoad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user