*/
@SuppressWarnings("unchecked")
public static void setParameterDefinitionProperties(Job job,
String key,
CopyOnWriteList<ParametersDefinitionProperty> parameterDefinitionProperties) {
CopyOnWriteListProjectProperty projectProperty = getCopyOnWriteListProjectProperty(job, key);
CopyOnWriteList<ParametersDefinitionProperty> pdProperties
= new CopyOnWriteList<ParametersDefinitionProperty>();
//Create new instance for each parameter in order to set owner and use in cascading children.
for (ParametersDefinitionProperty pdp : parameterDefinitionProperties) {
ParametersDefinitionProperty copiedDefinitionProperty = new ParametersDefinitionProperty(
new ArrayList<ParameterDefinition>(pdp.getParameterDefinitions()));
copiedDefinitionProperty.setOwner((AbstractProject) job);
pdProperties.add(copiedDefinitionProperty);
}
projectProperty.setValue(pdProperties);
Set<String> cascadingChildrenNames = job.getCascadingChildrenNames();
//Iterate through cascading children and recursively update property for each child.
if (null != cascadingChildrenNames) {
for (String childName : cascadingChildrenNames) {
Job childJob = (Job) Hudson.getInstance().getItem(childName);
//Check only direct children in order to avoid deep checking for properties overridden properties.
if (null != childJob && StringUtils.equals(job.getName(), childJob.getCascadingProjectName())) {
CopyOnWriteListProjectProperty childProperty = getCopyOnWriteListProjectProperty(childJob, key);
//If child value is equal to parent - mark this value as unmodified.
if (!childProperty.allowOverrideValue(childProperty.getValue(), pdProperties)) {
childProperty.setOverridden(false);
} else if (!childProperty.isOverridden()) {
//If child property was not overridden, update this property and cascading children if any.
setParameterDefinitionProperties(childJob, key, parameterDefinitionProperties);
}
}
}