1 37 package net.sourceforge.cruisecontrol.sourcecontrols; 38 39 import java.util.ArrayList ; 40 import java.util.Date ; 41 import java.util.Hashtable ; 42 import java.util.Iterator ; 43 import java.util.List ; 44 import java.util.Map ; 45 46 import net.sourceforge.cruisecontrol.CruiseControlException; 47 import net.sourceforge.cruisecontrol.SourceControl; 48 import net.sourceforge.cruisecontrol.util.ValidationHelper; 49 50 87 public class Compound implements SourceControl { 88 89 private Hashtable properties = new Hashtable (); 90 91 private Triggers triggers = null; 92 private Targets targets = null; 93 private boolean includeTriggerChanges = false; 94 95 public Map getProperties() { 96 return this.properties; 97 } 98 99 112 public List getModifications(Date lastBuild, Date now) { 113 List triggerMods; 114 List targetMods = new ArrayList (); 115 116 triggerMods = triggers.getModifications(lastBuild, now); 117 118 if (!triggerMods.isEmpty()) { 119 targetMods = targets.getModifications(lastBuild, now); 120 properties.putAll(targets.getProperties()); 122 } 123 124 if (includeTriggerChanges) { 125 targetMods.addAll(triggerMods); 126 properties.putAll(triggers.getProperties()); 129 } 130 131 return targetMods; 132 } 133 134 142 public void validate() throws CruiseControlException { 143 ValidationHelper.assertTrue(triggers != null, 144 "Error: there must be exactly one \"triggers\" block in a compound block."); 145 ValidationHelper.assertTrue(targets != null, 146 "Error: there must be exactly one \"targets\" block in a compound block."); 147 } 148 149 155 public Object createTriggers() { 156 Triggers tr = new Triggers(this); 157 this.triggers = tr; 158 return tr; 159 } 160 161 167 public Object createTargets() { 168 Targets targ = new Targets(this); 169 this.targets = targ; 170 return targ; 171 } 172 173 179 public void setIncludeTriggerChanges(String changes) { 180 this.includeTriggerChanges = changes.equalsIgnoreCase("true"); 181 } 182 183 187 protected static class Entry implements SourceControl { 188 189 private Hashtable properties = new Hashtable (); 190 191 private List sourceControls = new ArrayList (); 192 private Compound parent; 193 194 198 public Entry() { 199 } 200 201 208 public Entry(Compound parent) { 209 this.parent = parent; 210 } 211 212 public Map getProperties() { 213 return this.properties; 214 } 215 216 225 public List getModifications(Date lastBuild, Date now) { 226 List retVal = new ArrayList (); 227 228 for (Iterator it = sourceControls.iterator(); it.hasNext(); ) { 229 SourceControl sourceControl = (SourceControl) it.next(); 230 retVal.addAll(sourceControl.getModifications(lastBuild, now)); 231 properties.putAll(sourceControl.getProperties()); 233 } 234 235 return retVal; 236 } 237 238 244 public void validate() throws CruiseControlException { 245 if (sourceControls.isEmpty()) { 246 throw new CruiseControlException("Error: there must be at least one source control in a " 247 + getEntryName() + " block."); 248 } 249 if (parent == null) { 250 throw new CruiseControlException("Error: " + getEntryName() 251 + " blocks must be contained within compound blocks."); 252 } 253 } 254 255 261 public void add(SourceControl sc) { 262 sourceControls.add(sc); 263 } 264 265 269 private String getEntryName() { 270 String classname = getClass().getName(); 271 int index = classname.lastIndexOf('.'); 272 if (index != -1) { 273 return classname.substring(index + 1).toLowerCase(); 274 } else { 275 return classname.toLowerCase(); 276 } 277 } 278 } 279 280 } | Popular Tags |