diff --git a/core/src/main/java/hudson/PluginManager.java b/core/src/main/java/hudson/PluginManager.java index 75be36bb73..41580095c1 100644 --- a/core/src/main/java/hudson/PluginManager.java +++ b/core/src/main/java/hudson/PluginManager.java @@ -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 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. */ diff --git a/test/src/test/java/hudson/PluginManagerTest2.java b/test/src/test/java/hudson/PluginManagerTest2.java new file mode 100644 index 0000000000..fc1fbbf976 --- /dev/null +++ b/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); + } + +}