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);
}
}
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;
}
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;
}
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();
}
Aggregations