Search in sources :

Example 1 with TriggerDescriptor

use of hudson.triggers.TriggerDescriptor in project hudson-2.x by hudson.

the class AbstractProject method buildTriggers.

protected void buildTriggers(StaplerRequest req, JSONObject json, List<TriggerDescriptor> descriptors) throws FormException {
    for (TriggerDescriptor d : descriptors) {
        String propertyName = d.getJsonSafeClassName();
        CascadingUtil.setChildrenTrigger(this, d, propertyName, req, json);
    }
}
Also used : TriggerDescriptor(hudson.triggers.TriggerDescriptor)

Example 2 with TriggerDescriptor

use of hudson.triggers.TriggerDescriptor in project workflow-job-plugin by jenkinsci.

the class PipelineTriggersJobProperty method getTriggersMap.

public Map<TriggerDescriptor, Trigger<?>> getTriggersMap() {
    Map<TriggerDescriptor, Trigger<?>> triggerMap = new HashMap<>();
    for (Trigger t : getTriggers()) {
        TriggerDescriptor td = t.getDescriptor();
        triggerMap.put(td, t);
    }
    return triggerMap;
}
Also used : Trigger(hudson.triggers.Trigger) HashMap(java.util.HashMap) TriggerDescriptor(hudson.triggers.TriggerDescriptor)

Example 3 with TriggerDescriptor

use of hudson.triggers.TriggerDescriptor in project workflow-job-plugin by jenkinsci.

the class PipelineTriggersJobProperty method reconfigure.

@CheckForNull
@Override
public PipelineTriggersJobProperty reconfigure(@Nonnull StaplerRequest req, @CheckForNull JSONObject form) throws Descriptor.FormException {
    DescribableList<Trigger<?>, TriggerDescriptor> trigList = new DescribableList<>(Saveable.NOOP);
    try {
        JSONObject triggerSection = new JSONObject();
        if (form != null) {
            triggerSection = form.getJSONObject("triggers");
        }
        trigList.rebuild(req, triggerSection, Trigger.for_(owner));
    } catch (IOException e) {
        throw new Descriptor.FormException(e, "triggers");
    }
    PipelineTriggersJobProperty oldProp = owner.getTriggersJobProperty();
    try {
        owner.removeProperty(this);
        PipelineTriggersJobProperty thisProp = new PipelineTriggersJobProperty(new ArrayList<Trigger>(trigList.toList()));
        owner.addTriggersJobPropertyWithoutStart(thisProp);
        thisProp.startTriggers(true);
        return thisProp;
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "could not configure triggers", e);
    }
    if (owner.getTriggersJobProperty() == null && oldProp != null) {
        try {
            owner.addTriggersJobPropertyWithoutStart(oldProp);
            oldProp.startTriggers(true);
        } catch (IOException e) {
            LOGGER.log(Level.WARNING, "could not revert to original configured triggers", e);
            throw new Descriptor.FormException("Could not revert to original configured triggers", e, "triggers");
        }
    }
    return oldProp;
}
Also used : Trigger(hudson.triggers.Trigger) JSONObject(net.sf.json.JSONObject) DescribableList(hudson.util.DescribableList) TriggerDescriptor(hudson.triggers.TriggerDescriptor) Descriptor(hudson.model.Descriptor) JobPropertyDescriptor(hudson.model.JobPropertyDescriptor) IOException(java.io.IOException) IOException(java.io.IOException) TriggerDescriptor(hudson.triggers.TriggerDescriptor) CheckForNull(javax.annotation.CheckForNull)

Example 4 with TriggerDescriptor

use of hudson.triggers.TriggerDescriptor in project hudson-2.x by hudson.

the class LegacyProjectTest method testConvertLegacyTriggers.

/**
 * Tests unmarshalling FreeStyleProject configuration and checks whether Triggers properties
 * from Job are configured.
 *
 * @throws Exception if any.
 */
@Test
public void testConvertLegacyTriggers() throws Exception {
    AbstractProject project = (AbstractProject) Items.getConfigFile(config).read();
    project.setAllowSave(false);
    project.initProjectProperties();
    Hudson hudson = createMock(Hudson.class);
    String scmTriggerPropertyKey = "hudson-trigger-SCMTrigger";
    TriggerDescriptor scmTriggerDescriptor = createMock(SCMTrigger.DescriptorImpl.class);
    expect(scmTriggerDescriptor.getJsonSafeClassName()).andReturn(scmTriggerPropertyKey);
    expect(hudson.getDescriptorOrDie(SCMTrigger.class)).andReturn(scmTriggerDescriptor);
    String timerTriggerPropertyKey = "hudson-trigger-TimerTrigger";
    TriggerDescriptor timerTriggerDescriptor = createMock(TimerTrigger.DescriptorImpl.class);
    expect(timerTriggerDescriptor.getJsonSafeClassName()).andReturn(timerTriggerPropertyKey);
    expect(hudson.getDescriptorOrDie(TimerTrigger.class)).andReturn(timerTriggerDescriptor);
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    replayAll();
    project.setAllowSave(false);
    project.initProjectProperties();
    assertNull(project.getProperty(scmTriggerPropertyKey));
    assertNull(project.getProperty(timerTriggerPropertyKey));
    project.convertTriggerProperties();
    assertNotNull(project.getProperty(scmTriggerPropertyKey));
    Trigger trigger = (Trigger) project.getProperty(scmTriggerPropertyKey).getValue();
    assertEquals("5 * * * *", trigger.getSpec());
    assertNotNull(project.getProperty(timerTriggerPropertyKey));
    trigger = (Trigger) project.getProperty(timerTriggerPropertyKey).getValue();
    assertEquals("*/10 * * * *", trigger.getSpec());
    verifyAll();
}
Also used : Trigger(hudson.triggers.Trigger) SCMTrigger(hudson.triggers.SCMTrigger) TimerTrigger(hudson.triggers.TimerTrigger) SCMTrigger(hudson.triggers.SCMTrigger) TimerTrigger(hudson.triggers.TimerTrigger) TriggerDescriptor(hudson.triggers.TriggerDescriptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TriggerDescriptor (hudson.triggers.TriggerDescriptor)4 Trigger (hudson.triggers.Trigger)3 Descriptor (hudson.model.Descriptor)1 JobPropertyDescriptor (hudson.model.JobPropertyDescriptor)1 SCMTrigger (hudson.triggers.SCMTrigger)1 TimerTrigger (hudson.triggers.TimerTrigger)1 DescribableList (hudson.util.DescribableList)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 CheckForNull (javax.annotation.CheckForNull)1 JSONObject (net.sf.json.JSONObject)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1