Search in sources :

Example 1 with TriggerProjectProperty

use of org.hudsonci.model.project.property.TriggerProjectProperty in project hudson-2.x by hudson.

the class CascadingUtil method setChildrenTrigger.

/**
     * Sets trigger for job and all its children if necessary.
     *
     * @param job parentJob
     * @param descriptor trigger descriptor
     * @param key trigger property key
     * @param req stapler request
     * @param json submited json
     * @throws Descriptor.FormException if incorrect parameters
     */
@SuppressWarnings("unchecked")
public static void setChildrenTrigger(Job job, TriggerDescriptor descriptor, String key, StaplerRequest req, JSONObject json) throws Descriptor.FormException {
    TriggerProjectProperty property = CascadingUtil.getTriggerProjectProperty(job, key);
    if (property.getValue() != null) {
        property.getValue().stop();
    }
    Trigger trigger = null;
    if (json.has(key)) {
        trigger = descriptor.newInstance(req, json.getJSONObject(key));
        trigger.start(job, true);
    }
    property.setValue(trigger);
    Set<String> cascadingChildrenNames = job.getCascadingChildrenNames();
    if (null != cascadingChildrenNames) {
        for (String childName : cascadingChildrenNames) {
            Job childJob = (Job) Hudson.getInstance().getItem(childName);
            if (null != childJob && StringUtils.equals(job.getName(), childJob.getCascadingProjectName())) {
                TriggerProjectProperty childProperty = CascadingUtil.getTriggerProjectProperty(childJob, key);
                if (!childProperty.isOverridden()) {
                    setChildrenTrigger(childJob, descriptor, key, req, json);
                } else if (!childProperty.allowOverrideValue(trigger, childProperty.getValue())) {
                    childProperty.setOverridden(false);
                }
            }
        }
    }
}
Also used : TriggerProjectProperty(org.hudsonci.model.project.property.TriggerProjectProperty) Trigger(hudson.triggers.Trigger) ICascadingJob(org.hudsonci.api.model.ICascadingJob) Job(hudson.model.Job)

Aggregations

Job (hudson.model.Job)1 Trigger (hudson.triggers.Trigger)1 ICascadingJob (org.hudsonci.api.model.ICascadingJob)1 TriggerProjectProperty (org.hudsonci.model.project.property.TriggerProjectProperty)1