diff --git a/core/src/main/java/hudson/PluginManager.java b/core/src/main/java/hudson/PluginManager.java index 3b31735410..941cde4a88 100644 --- a/core/src/main/java/hudson/PluginManager.java +++ b/core/src/main/java/hudson/PluginManager.java @@ -93,6 +93,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.Future; import java.util.logging.Level; import java.util.logging.Logger; @@ -738,16 +739,18 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas * Prepares plugins for some expected XML configuration. * If the configuration (typically a job’s {@code config.xml}) * needs some plugins to be installed (or updated), those jobs - * will be triggered. Requires {@link Jenkins#ADMINISTER}. + * will be triggered. + * Plugins are dynamically loaded if possible (see {@link hudson.model.UpdateSite.Plugin#deploy(boolean)}). + * Requires {@link Jenkins#ADMINISTER}. * @param configXml configuration that might be uploaded - * @return an empty list if all is well, else a list of jobs which must be completed before this configuration can be fully read + * @return an empty list if all is well, else a list of submitted jobs which must be completed before this configuration can be fully read * @throws IOException if loading or parsing the configuration failed * @see ItemGroupMixIn#createProjectFromXML * @see AbstractItem#updateByXml(javax.xml.transform.Source) * @see XStream2 * @since XXX */ - public List prevalidateConfig(InputStream configXml) throws IOException { + public List> prevalidateConfig(InputStream configXml) throws IOException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); return Collections.emptyList(); // XXX } diff --git a/test/src/test/java/hudson/PluginManagerTest.java b/test/src/test/java/hudson/PluginManagerTest.java index b138b1d2f0..fd0ffedcce 100644 --- a/test/src/test/java/hudson/PluginManagerTest.java +++ b/test/src/test/java/hudson/PluginManagerTest.java @@ -23,11 +23,18 @@ */ package hudson; +import com.gargoylesoftware.htmlunit.HttpMethod; +import com.gargoylesoftware.htmlunit.Page; +import com.gargoylesoftware.htmlunit.WebRequestSettings; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.PluginManager.UberClassLoader; import hudson.model.Hudson; +import hudson.model.UpdateCenter; +import hudson.model.UpdateCenter.UpdateCenterJob; +import hudson.model.UpdateSite; import hudson.scm.SubversionSCM; +import hudson.util.PersistedList; import org.apache.commons.io.FileUtils; import org.jvnet.hudson.test.HudsonTestCase; import org.jvnet.hudson.test.Url; @@ -37,6 +44,11 @@ import org.jvnet.hudson.test.recipes.WithPluginManager; import java.io.File; import java.net.URL; import java.net.URLClassLoader; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.Future; +import org.apache.commons.io.IOUtils; +import org.apache.tools.ant.filters.StringInputStream; /** * @author Kohsuke Kawaguchi @@ -190,4 +202,35 @@ public class PluginManagerTest extends HudsonTestCase { Class c = jenkins.getPluginManager().uberClassLoader.loadClass("htmlpublisher.HtmlPublisher$DescriptorImpl"); assertNotNull(jenkins.getDescriptorByType(c)); } + + public void testPrevalidateConfig() throws Exception { + PersistedList sites = jenkins.getUpdateCenter().getSites(); + sites.clear(); + URL url = PluginManagerTest.class.getResource("/plugins/tasks-update-center.json"); + UpdateSite site = new UpdateSite(UpdateCenter.ID_DEFAULT, url.toString()); + sites.add(site); + try { + UpdateSite.signatureCheck = false; + { // XXX pending UpdateSite.updateDirectly: + jenkins.setCrumbIssuer(null); + WebRequestSettings wrs = new WebRequestSettings(new URL(getURL(), "/updateCenter/byId/default/postBack"), HttpMethod.POST); + wrs.setRequestBody(IOUtils.toString(url.openStream())); + Page p = createWebClient().getPage(wrs); + assertEquals(/* FormValidation.OK */"
", p.getWebResponse().getContentAsString()); + } + } finally { + UpdateSite.signatureCheck = true; + } + assertNotNull(site.getData()); + assertEquals(Collections.emptyList(), jenkins.getPluginManager().prevalidateConfig(new StringInputStream(""))); + assertNull(jenkins.getPluginManager().getPlugin("tasks")); + List> jobs = jenkins.getPluginManager().prevalidateConfig(new StringInputStream("")); + assertEquals(1, jobs.size()); + UpdateCenterJob job = jobs.get(0).get(); // blocks for completion + assertEquals("InstallationJob", job.getType()); + UpdateCenter.InstallationJob ijob = (UpdateCenter.InstallationJob) job; + assertEquals("tasks", ijob.plugin.name); + assertNotNull(jenkins.getPluginManager().getPlugin("tasks")); + } + }