提交 21642ad4 编写于 作者: K kohsuke

"upload plugin" form was not working anymore when I moved the page.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@10073 71c3de6d-444a-0410-be80-ed276b4c234a
上级 4607c5c1
package hudson;
import hudson.model.Hudson;
import hudson.model.UpdateCenter;
import hudson.model.AbstractModelObject;
import hudson.model.*;
import hudson.util.Service;
import java.util.Enumeration;
......@@ -22,6 +20,9 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.FileItem;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.QueryParameter;
......@@ -60,6 +61,13 @@ public final class PluginManager extends AbstractModelObject {
// and load plugin-contributed classes.
public final ClassLoader uberClassLoader = new UberClassLoader();
/**
* Once plugin is uploaded, this flag becomes true.
* This is used to report a message that Hudson needs to be restarted
* for new plugins to take effect.
*/
public transient volatile boolean pluginUploaded =false;
public PluginManager(ServletContext context) {
this.context = context;
rootDir = new File(Hudson.getInstance().getRootDir(),"plugins");
......@@ -100,6 +108,13 @@ public final class PluginManager extends AbstractModelObject {
}
}
/**
* Retrurns true if any new plugin was added, which means a restart is required for the change to take effect.
*/
public boolean isPluginUploaded() {
return pluginUploaded;
}
public List<PluginWrapper> getPlugins() {
return plugins;
}
......@@ -184,6 +199,35 @@ public final class PluginManager extends AbstractModelObject {
else System.setProperty(key,value);
}
/**
* Uploads a plugin.
*/
public void doUploadPlugin( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
try {
Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
// Parse the request
FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
String fileName = Util.getFileName(fileItem.getName());
if(!fileName.endsWith(".hpi")) {
sendError(hudson.model.Messages.Hudson_NotAPlugin(fileName),req,rsp);
return;
}
fileItem.write(new File(rootDir, fileName));
fileItem.delete();
pluginUploaded=true;
rsp.sendRedirect2(".");
} catch (IOException e) {
throw e;
} catch (Exception e) {// grrr. fileItem.write throws this
throw new ServletException(e);
}
}
private final class UberClassLoader extends ClassLoader {
public UberClassLoader() {
super(PluginManager.class.getClassLoader());
......
......@@ -272,13 +272,6 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
*/
private int slaveAgentPort =0;
/**
* Once plugin is uploaded, this flag becomes true.
* This is used to report a message that Hudson needs to be restarted
* for new plugins to take effect.
*/
private transient boolean pluginUploaded =false;
/**
* All labels known to Hudson. This allows us to reuse the same label instances
* as much as possible, even though that's not a strict requirement.
......@@ -1899,39 +1892,6 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
}.start();
}
public boolean isPluginUploaded() {
return pluginUploaded;
}
/**
* Uploads a plugin.
*/
public void doUploadPlugin( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
try {
checkPermission(ADMINISTER);
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
// Parse the request
FileItem fileItem = (FileItem) upload.parseRequest(req).get(0);
String fileName = Util.getFileName(fileItem.getName());
if(!fileName.endsWith(".hpi")) {
sendError(Messages.Hudson_NotAPlugin(fileName),req,rsp);
return;
}
fileItem.write(new File(getPluginManager().rootDir, fileName));
fileItem.delete();
pluginUploaded=true;
rsp.sendRedirect2("managePlugins");
} catch (IOException e) {
throw e;
} catch (Exception e) {// grrr. fileItem.write throws this
throw new ServletException(e);
}
}
/**
* Do a finger-print check.
*/
......
......@@ -405,7 +405,8 @@ public class UpdateCenter implements ModelObject {
byte[] buf = new byte[8192];
int len;
File baseDir = Hudson.getInstance().getPluginManager().rootDir;
PluginManager pm = Hudson.getInstance().getPluginManager();
File baseDir = pm.rootDir;
File target = new File(baseDir, plugin.name + ".tmp");
OutputStream out = new FileOutputStream(target);
......@@ -425,6 +426,7 @@ public class UpdateCenter implements ModelObject {
}
LOGGER.info("Installation successful: "+plugin.name);
pm.pluginUploaded = true;
status = new Success();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to install "+plugin.name,e);
......
......@@ -57,7 +57,7 @@
</j:choose>
</local:tabBar>
<j:if test="${app.isPluginUploaded()}">
<j:if test="${it.isPluginUploaded()}">
<div style="margin: 1em; height: 1em">
<div class="error">
${%New plugins will take effect once you restart Hudson}
......
......@@ -10,7 +10,7 @@
<s:form method="post" action="configSubmit">
<s:block>
<h1>${%Installed Plugins}</h1>
<j:if test="${app.isPluginUploaded()}">
<j:if test="${app.pluginManager.isPluginUploaded()}">
<div style="margin: 1em; height: 1em">
<div class="error">
${%New plugins will take effect once you restart Hudson}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册