Search in sources :

Example 1 with Publisher

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);
}
Also used : Hudson(hudson.model.Hudson) ExternalProjectProperty(org.hudsonci.model.project.property.ExternalProjectProperty) Mailer(hudson.tasks.Mailer) Descriptor(hudson.model.Descriptor) Publisher(hudson.tasks.Publisher) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with Publisher

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();
}
Also used : ArrayList(java.util.ArrayList) Publisher(hudson.tasks.Publisher) BuildTrigger(hudson.tasks.BuildTrigger) BuildStepDescriptor(hudson.tasks.BuildStepDescriptor) BuildWrapperDescriptor(hudson.tasks.BuildWrapperDescriptor) TriggerDescriptor(hudson.triggers.TriggerDescriptor) IAbstractProject(org.hudsonci.api.model.IAbstractProject) HashSet(java.util.HashSet)

Example 3 with Publisher

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();
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Hudson(hudson.model.Hudson) StaplerRequest(org.kohsuke.stapler.StaplerRequest) ArrayList(java.util.ArrayList) Publisher(hudson.tasks.Publisher) JSONObject(net.sf.json.JSONObject) Descriptor(hudson.model.Descriptor) JavadocArchiver(hudson.tasks.JavadocArchiver) Job(hudson.model.Job) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Publisher (hudson.tasks.Publisher)3 Descriptor (hudson.model.Descriptor)2 Hudson (hudson.model.Hudson)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 FreeStyleProjectMock (hudson.model.FreeStyleProjectMock)1 Job (hudson.model.Job)1 BuildStepDescriptor (hudson.tasks.BuildStepDescriptor)1 BuildTrigger (hudson.tasks.BuildTrigger)1 BuildWrapperDescriptor (hudson.tasks.BuildWrapperDescriptor)1 JavadocArchiver (hudson.tasks.JavadocArchiver)1 Mailer (hudson.tasks.Mailer)1 TriggerDescriptor (hudson.triggers.TriggerDescriptor)1 HashSet (java.util.HashSet)1 JSONObject (net.sf.json.JSONObject)1 IAbstractProject (org.hudsonci.api.model.IAbstractProject)1 ExternalProjectProperty (org.hudsonci.model.project.property.ExternalProjectProperty)1 StaplerRequest (org.kohsuke.stapler.StaplerRequest)1