提交 860cc9eb 编写于 作者: A Andrew Bayer

Merge pull request #418 from alexlehm/master

Fixed JENKINS-13129: Updating built-in plugins doesn't work, the file doesn't get pinned and is overwritten on the next startup
......@@ -196,7 +196,7 @@ public abstract class PluginManager extends AbstractModelObject {
PluginWrapper p = strategy.createPluginWrapper(arc);
if (isDuplicate(p)) return;
p.isBundled = bundledPlugins.contains(arc.getName());
p.isBundled = containsHpiJpi(bundledPlugins, arc.getName());
plugins.add(p);
} catch (IOException e) {
failedPlugins.add(new FailedPlugin(arc.getName(),e));
......@@ -344,6 +344,15 @@ public abstract class PluginManager extends AbstractModelObject {
}});
}
/*
* contains operation that considers xxx.hpi and xxx.jpi as equal
* this is necessary since the bundled plugins are still called *.hpi
*/
private boolean containsHpiJpi(Collection<String> bundledPlugins, String name) {
return bundledPlugins.contains(name.replaceAll("\\.hpi",".jpi"))
|| bundledPlugins.contains(name.replaceAll("\\.jpi",".hpi"));
}
/**
* TODO: revisit where/how to expose this. This is an experiment.
*/
......
package hudson;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.servlet.ServletContext;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.recipes.WithPlugin;
import org.xml.sax.SAXException;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.apache.commons.io.FileUtils;
public class PluginManagerTest2 extends HudsonTestCase {
@Override
protected void setUp() throws Exception {
setPluginManager(null); // use a fresh instance
super.setUp();
}
private ServletContext servletContext;
// need to keep the ServletContext to use in the actual test
protected ServletContext createWebServer() throws Exception {
servletContext=super.createWebServer();
return servletContext;
}
@WithPlugin("tasks.jpi")
public void testPinned() throws Exception {
PluginWrapper tasks = hudson.getPluginManager().getPlugin("tasks");
assertFalse("tasks shouldn't be bundled",tasks.isBundled());
assertFalse("tasks shouldn't be pinned before update",tasks.isPinned());
uploadPlugin("tasks.jpi", false);
assertFalse("tasks shouldn't be pinned after update",tasks.isPinned());
PluginWrapper cvs = hudson.getPluginManager().getPlugin("cvs");
assertTrue("cvs should be bundled",cvs.isBundled());
assertFalse("cvs shouldn't be pinned before update",cvs.isPinned());
uploadPlugin("cvs.hpi", true);
assertTrue("cvs should be pinned after update",cvs.isPinned());
}
private void uploadPlugin(String pluginName, boolean useServerRoot) throws IOException, SAXException, Exception {
HtmlPage page = new WebClient().goTo("pluginManager/advanced");
HtmlForm f = page.getFormByName("uploadPlugin");
File plugin;
if(useServerRoot) {
String pluginsPath=servletContext.getRealPath("WEB-INF/plugins");
plugin = new File(pluginsPath+"/"+pluginName);
} else {
File dir = env.temporaryDirectoryAllocator.allocate();
plugin = new File(dir, pluginName);
URL resource = getClass().getClassLoader().getResource("plugins/"+pluginName);
FileUtils.copyURLToFile(resource,plugin);
}
f.getInputByName("name").setValueAttribute(plugin.getAbsolutePath());
submit(f);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册