for (Trigger trigger : oldTriggers.values()) {
triggers.add(trigger);
}
DescribableList<BuildWrapper, Descriptor<BuildWrapper>> implementationBuildWrappers = ((BuildableItemWithBuildWrappers) newImplementation).getBuildWrappersList();
CopyOnWriteList data = ReflectionUtils.getField(CopyOnWriteList.class, implementationBuildWrappers, "data");
//strip out any template definitions or implementation definitions copied from the template
List<BuildWrapper> toRemove = new LinkedList<BuildWrapper>();
for (BuildWrapper buildWrapper : implementationBuildWrappers) {
if(buildWrapper instanceof TemplateBuildWrapper) {
if(template.getName().equals(((TemplateBuildWrapper) buildWrapper).getTemplateName())) {
toRemove.add(buildWrapper);
}
} else if(buildWrapper instanceof ImplementationBuildWrapper) {
toRemove.add(buildWrapper);
}
}
for (BuildWrapper buildWrapper : toRemove) {
data.remove(buildWrapper);
}
//make sure the implementation definition is still in there
data.add(implementationBuildWrapper);
newImplementation.getConfigFile().write(newImplementation); //don't call save() because it calls the event handlers.
item = (TopLevelItem) Items.load(Jenkins.getInstance(), implementationXmlFile.getFile().getParentFile());
putItemInJenkins(Jenkins.getInstance(), item);