use of hudson.tasks.Publisher in project hudson-2.x by hudson.
the class DescribableListUtilTest method testConvertToProjectProperties3.
@Test
public void testConvertToProjectProperties3() throws IOException {
Hudson hudson = createMock(Hudson.class);
Mailer.DescriptorImpl descriptor = createMock(Mailer.DescriptorImpl.class);
String mailerName = "hudson-tasks-Mailer";
expect(descriptor.getJsonSafeClassName()).andReturn(mailerName);
expect(hudson.getDescriptorOrDie(Mailer.class)).andReturn(descriptor);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
prepareJob();
DescribableList<Publisher, Descriptor<Publisher>> list = new DescribableList<Publisher, Descriptor<Publisher>>();
list.add(new Mailer());
Map<String, ExternalProjectProperty<Publisher>> map = DescribableListUtil.convertToProjectProperties(list, job);
assertNotNull(map);
assertEquals(map.size(), 1);
assertNotNull(map.get(mailerName));
assertEquals(map.get(mailerName).getValue().getClass(), Mailer.class);
}
use of hudson.tasks.Publisher in project hudson-2.x by hudson.
the class AbstractProject method doConfigSubmit.
@Override
public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
super.doConfigSubmit(req, rsp);
updateTransientActions();
Set<AbstractProject> upstream = Collections.emptySet();
if (req.getParameter("pseudoUpstreamTrigger") != null) {
upstream = new HashSet<AbstractProject>(Items.fromNameList(req.getParameter("upstreamProjects"), AbstractProject.class));
}
// dependency setting might have been changed by the user, so rebuild.
Hudson.getInstance().rebuildDependencyGraph();
for (AbstractProject<?, ?> p : Hudson.getInstance().getAllItems(AbstractProject.class)) {
// Don't consider child projects such as MatrixConfiguration:
if (!p.isConfigurable())
continue;
boolean isUpstream = upstream.contains(p);
synchronized (p) {
// does 'p' include us in its BuildTrigger?
DescribableList<Publisher, Descriptor<Publisher>> pl = p.getPublishersList();
BuildTrigger trigger = pl.get(BuildTrigger.class);
List<AbstractProject> newChildProjects = trigger == null ? new ArrayList<AbstractProject>() : trigger.getChildProjects();
if (isUpstream) {
if (!newChildProjects.contains(this))
newChildProjects.add(this);
} else {
newChildProjects.remove(this);
}
if (newChildProjects.isEmpty()) {
pl.remove(BuildTrigger.class);
} else {
// here, we just need to replace the old one with the new one,
// but there was a regression (we don't know when it started) that put multiple BuildTriggers
// into the list.
// for us not to lose the data, we need to merge them all.
List<BuildTrigger> existingList = pl.getAll(BuildTrigger.class);
BuildTrigger existing;
switch(existingList.size()) {
case 0:
existing = null;
break;
case 1:
existing = existingList.get(0);
break;
default:
pl.removeAll(BuildTrigger.class);
Set<AbstractProject> combinedChildren = new HashSet<AbstractProject>();
for (BuildTrigger bt : existingList) combinedChildren.addAll(bt.getChildProjects());
existing = new BuildTrigger(new ArrayList<AbstractProject>(combinedChildren), existingList.get(0).getThreshold());
pl.add(existing);
break;
}
if (existing != null && existing.hasSame(newChildProjects))
// no need to touch
continue;
pl.replace(new BuildTrigger(newChildProjects, existing == null ? Result.SUCCESS : existing.getThreshold()));
}
BuildTrigger buildTrigger = pl.get(BuildTrigger.class);
CascadingUtil.getExternalProjectProperty(p, BUILD_TRIGGER_PROPERTY_NAME).setValue(buildTrigger);
}
}
// notify the queue as the project might be now tied to different node
Hudson.getInstance().getQueue().scheduleMaintenance();
// this is to reflect the upstream build adjustments done above
Hudson.getInstance().rebuildDependencyGraph();
}
use of hudson.tasks.Publisher in project hudson-2.x by hudson.
the class CascadingUtilTest method testBuildExternalProperties.
@Test
@PrepareForTest({ Hudson.class, StaplerRequest.class })
public void testBuildExternalProperties() throws Exception {
Job job = new FreeStyleProjectMock("job");
StaplerRequest req = createMock(StaplerRequest.class);
String javadocArchiverKey = "hudson-tasks-JavadocArchiver";
JSONObject archiver = new JSONObject();
archiver.put("javadoc_dir", "dir");
archiver.put("keep_all", true);
JSONObject json = new JSONObject();
json.put(javadocArchiverKey, archiver);
Hudson hudson = createMock(Hudson.class);
Descriptor<Publisher> javadocDescriptor = new JavadocArchiver.DescriptorImpl();
expect(hudson.getDescriptorOrDie(JavadocArchiver.class)).andReturn(javadocDescriptor);
JavadocArchiver javadocArchiver = new JavadocArchiver("dir", true);
expect(req.bindJSON(JavadocArchiver.class, archiver)).andReturn(javadocArchiver).anyTimes();
List<Descriptor<Publisher>> descriptors = new ArrayList<Descriptor<Publisher>>();
descriptors.add(javadocDescriptor);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
replay(Hudson.class, hudson, req);
assertNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
CascadingUtil.buildExternalProperties(req, archiver, descriptors, job);
assertNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
CascadingUtil.buildExternalProperties(req, json, descriptors, job);
assertNotNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
verifyAll();
}
Aggregations