/** Bare-minimum configuration mechanism to change the update center. */ public HttpResponse doSiteConfigure(@QueryParameter String site) throws IOException { Jenkins hudson = Jenkins.getInstance(); hudson.checkPermission(CONFIGURE_UPDATECENTER); UpdateCenter uc = hudson.getUpdateCenter(); PersistedList<UpdateSite> sites = uc.getSites(); for (UpdateSite s : sites) { if (s.getId().equals(UpdateCenter.ID_DEFAULT)) sites.remove(s); } sites.add(new UpdateSite(UpdateCenter.ID_DEFAULT, site)); return HttpResponses.redirectToContextRoot(); }
@Override protected void onModified() throws IOException { super.onModified(); for (BranchSource branchSource : this) { branchSource.getSource().setOwner((MultiBranchProject) owner); } }
/** {@inheritDoc} */ @Override public boolean isBuildable() { if (sources == null) { return false; // still loading } return !sources.isEmpty(); }
/** {@inheritDoc} */ @Override protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, Descriptor.FormException { super.submit(req, rsp); synchronized (this) { JSONObject json = req.getSubmittedForm(); /* Set<String> oldSourceIds = new HashSet<String>(); for (SCMSource source : getSCMSources()) { oldSourceIds.add(source.getId()); } */ sources.replaceBy(req.bindJSONToList(BranchSource.class, json.opt("sources"))); for (SCMSource scmSource : getSCMSources()) { scmSource.setOwner(this); } setProjectFactory( req.bindJSON(BranchProjectFactory.class, json.getJSONObject("projectFactory"))); save(); /* TODO currently ComputedFolder.save always reschedules indexing; could define API to be more discerning Set<String> newSourceIds = new HashSet<String>(); for (SCMSource source : getSCMSources()) { newSourceIds.add(source.getId()); } reindex = !newSourceIds.equals(oldSourceIds); */ } }
/** * The sources of branches. * * @return the sources of branches. */ @NonNull public List<BranchSource> getSources() { if (sources != null) { return sources.toList(); } else { // return empty, this object is still being constructed return Collections.emptyList(); } }
public void testPrevalidateConfig() throws Exception { PersistedList<UpdateSite> 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); assertEquals(FormValidation.ok(), site.updateDirectly(false).get()); assertNotNull(site.getData()); assertEquals(Collections.emptyList(), jenkins.getPluginManager().prevalidateConfig(new StringInputStream("<whatever><runant plugin=\"[email protected]\"/></whatever>"))); assertNull(jenkins.getPluginManager().getPlugin("tasks")); List<Future<UpdateCenterJob>> jobs = jenkins.getPluginManager().prevalidateConfig(new StringInputStream("<whatever><tasks plugin=\"[email protected]\"/></whatever>")); 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")); // TODO restart scheduled (SuccessButRequiresRestart) after upgrade or Support-Dynamic-Loading: false // TODO dependencies installed or upgraded too // TODO required plugin installed but inactive }