1 37 package net.sourceforge.cruisecontrol.publishers; 38 39 import java.io.File ; 40 import java.util.ArrayList ; 41 import java.util.Iterator ; 42 import java.util.List ; 43 import java.util.Properties ; 44 45 import org.apache.log4j.Logger; 46 import org.jdom.Element; 47 48 import net.sourceforge.cruisecontrol.Publisher; 49 import net.sourceforge.cruisecontrol.util.XMLLogHelper; 50 51 57 public abstract class CMSynergyPublisher implements Publisher { 58 59 private static final Logger LOG = Logger.getLogger(CMSynergyPublisher.class); 60 61 65 private File sessionFile; 66 67 70 private String sessionName; 71 72 76 private String projectSpec; 77 78 82 private String ccmExe; 83 84 97 public void setSessionFile(String sessionFile) { 98 this.sessionFile = new File (sessionFile); 99 } 100 101 107 public File getSessionFile() { 108 return this.sessionFile; 109 } 110 111 120 public void setSessionName(String sessionName) { 121 this.sessionName = sessionName; 122 } 123 124 129 public String getSessionName() { 130 return this.sessionName; 131 } 132 133 139 public void setProject(String projectSpec) { 140 this.projectSpec = projectSpec; 141 } 142 143 149 public String getProject() { 150 return this.projectSpec; 151 } 152 153 159 public void setCcmExe(String ccmExe) { 160 this.ccmExe = ccmExe; 161 } 162 163 169 public String getCcmExe() { 170 return this.ccmExe; 171 } 172 173 182 private boolean isBuildSuccessful(Element log) { 183 XMLLogHelper helper = new XMLLogHelper(log); 184 return helper.isBuildSuccessful(); 185 } 186 187 194 public Properties getBuildProperties(Element log) { 195 Properties buildProperties = new Properties (); 196 197 Iterator propertyIterator = log.getChild("info") 198 .getChildren("property").iterator(); 199 while (propertyIterator.hasNext()) { 200 Element property = (Element) propertyIterator.next(); 201 buildProperties.put(property.getAttributeValue("name"), property 202 .getAttributeValue("value")); 203 204 } 205 206 return buildProperties; 207 } 208 209 217 public List getNewTasks(Element log) { 218 List taskList = new ArrayList (); 219 220 Element modifications = log.getChild("modifications"); 222 if (modifications != null) { 223 for (Iterator modificationList = modifications.getChildren( 225 "modification").iterator(); modificationList.hasNext();) { 226 Element modification = (Element) modificationList.next(); 227 String type = modification.getAttributeValue("type"); 228 if (type != null && type.equals("ccmtask")) { 229 String task = modification.getChild("task").getText(); 230 if (task != null) { 231 taskList.add(task.trim()); 232 } 233 } 234 } 235 } 236 237 return taskList; 238 } 239 240 248 public boolean shouldPublish(Element log) { 249 if (!isBuildSuccessful(log)) { 251 LOG.info("Build failed. Skipping publisher."); 252 return false; 253 } 254 255 List newTasks = getNewTasks(log); 257 if (newTasks.size() < 1) { 258 LOG.info("No new CM Synergy tasks in build. Skipping publisher."); 259 return false; 260 } 261 262 return true; 263 } 264 } 265 | Popular Tags |