Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Fixed JENKINS-13129] Updating built-in plugins doesn't work, the fil…
…e doesn't get pinned and is overwritten on the next startup

changed bundled plugin detection, added unit test
(cherry picked from commit 2453985)
  • Loading branch information
alexlehm authored and vjuranek committed May 23, 2012
1 parent 5a28f6a commit e986dcd
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/src/main/java/hudson/PluginManager.java
Expand Up @@ -196,7 +196,7 @@ public void run(Reactor session1) throws Exception {
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));
Expand Down Expand Up @@ -332,6 +332,15 @@ public void run(Reactor reactor) throws Exception {
}});
}

/*
* 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.
*/
Expand Down
64 changes: 64 additions & 0 deletions test/src/test/java/hudson/PluginManagerTest2.java
@@ -0,0 +1,64 @@
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);
}

}

0 comments on commit e986dcd

Please sign in to comment.