1 37 package net.sourceforge.cruisecontrol.publishers; 38 39 import net.sourceforge.cruisecontrol.CruiseControlException; 40 import net.sourceforge.cruisecontrol.Publisher; 41 import net.sourceforge.cruisecontrol.util.ManagedCommandline; 42 import net.sourceforge.cruisecontrol.util.ValidationHelper; 43 import net.sourceforge.cruisecontrol.util.XMLLogHelper; 44 import org.apache.log4j.Logger; 45 import org.jdom.CDATA; 46 import org.jdom.Element; 47 48 import java.util.ArrayList ; 49 import java.util.Iterator ; 50 import java.util.List ; 51 52 62 public class ClearCaseBaselinePublisher implements Publisher { 63 private boolean full = false; 64 private String baselineprefix; 65 private String viewtag; 66 private String component; 67 68 private static final Logger LOG = Logger.getLogger(ClearCaseBaselinePublisher.class); 69 70 75 public void setBaselineprefix(String baselineprefix) { 76 this.baselineprefix = baselineprefix; 77 } 79 84 public String getBaselineprefix() { 85 return this.baselineprefix; 86 } 88 93 public void setViewtag(String viewtag) { 94 this.viewtag = viewtag; 95 } 97 102 public String getViewtag() { 103 return this.viewtag; 104 } 106 111 public void setFull(boolean full) { 112 this.full = full; 113 } 115 120 public boolean getFull() { 121 return this.full; 122 } 124 129 public void setComponent(String comp) { 130 this.component = comp; 131 } 133 138 public String getComponent() { 139 return this.component; 140 } 142 145 public void validate() throws CruiseControlException { 146 ValidationHelper.assertIsSet(viewtag, "viewtag", this.getClass()); 147 } 149 156 public List getActivities(Element log) { 157 List activityList = new ArrayList (); 158 159 if (log != null) { 161 Element modifications = log.getChild("modifications"); 162 if (modifications != null) { 163 for (Iterator modificationList = modifications.getChildren( 165 "modification").iterator(); modificationList.hasNext();) { 166 Element modification = (Element) modificationList.next(); 167 String type = modification.getAttributeValue("type"); 168 if (type != null && type.equals("activity")) { 169 String activity = modification.getChild("revision").getText(); 170 171 if (activity != null) { 172 activityList.add(activity.trim()); 173 } 174 } 175 } 176 } 177 } 178 return activityList; 179 180 } 182 188 public boolean shouldPublish(Element log) { 189 List newActivities = getActivities(log); 191 if (newActivities.size() < 1) { 192 LOG.info("No UCM activities in build. Skipping publisher."); 193 return false; 194 } 195 return true; 196 } 198 201 public void publish(Element log) throws CruiseControlException { 202 XMLLogHelper helper = new XMLLogHelper(log); 203 204 if (!shouldPublish(log)) { 206 return; 207 } 208 209 String baselinename; 211 if (getBaselineprefix() != null) { 212 baselinename = getBaselineprefix() + helper.getLabel(); 213 } else { 214 baselinename = helper.getLabel(); 215 } 216 217 ManagedCommandline cmd = new ManagedCommandline(); 219 cmd.setExecutable("cleartool"); 220 cmd.createArgument().setValue("mkbl"); 221 cmd.createArgument().setValue("-view"); 222 cmd.createArgument().setValue(getViewtag()); 223 if (getFull()) { 224 cmd.createArgument().setValue("-full"); 225 } 226 if (getComponent() != null) { 227 cmd.createArgument().setValue("-component"); 228 cmd.createArgument().setValue(getComponent()); 229 } 230 cmd.createArgument().setValue(baselinename); 231 232 try { 234 cmd.execute(); 235 cmd.assertExitCode(0); 236 } catch (Exception e) { 237 StringBuffer error = new StringBuffer ("Failed to create baseline: "); 238 error.append(baselinename); 239 throw new CruiseControlException(error.toString(), e); 240 } 241 242 StringBuffer message = new StringBuffer ("Created baseline: "); 244 message.append(baselinename); 245 LOG.info(message.toString()); 246 247 249 } 251 254 public static void main(String [] args) { 255 256 Element logElement = new Element("cruisecontrol"); 258 Element mods = new Element("modifications"); 260 logElement.addContent(mods); 261 Element mod = new Element("modification"); 262 mod.setAttribute("type", "activity"); 263 mods.addContent(mod); 264 Element rev = new Element("revision"); 265 rev.addContent(new CDATA("Some activitiy")); 266 mod.addContent(rev); 267 Element info = new Element("info"); 269 logElement.addContent(info); 270 Element prop = new Element("property"); 271 prop.setAttribute("name", "label"); 272 prop.setAttribute("value", "1_TST"); 273 info.addContent(prop); 274 275 ClearCaseBaselinePublisher baseline = new ClearCaseBaselinePublisher(); 276 baseline.setViewtag("RatlBankModel_int"); 277 try { 281 baseline.publish(logElement); 282 } catch (CruiseControlException ex) { 283 ex.printStackTrace(); 284 } 285 } 286 287 } | Popular Tags |