1 37 package net.sourceforge.cruisecontrol.publishers; 38 39 import java.util.HashMap ; 40 import java.util.Iterator ; 41 import java.util.Map ; 42 43 import org.apache.log4j.Logger; 44 import org.jdom.Attribute; 45 import org.jdom.Element; 46 47 import net.sourceforge.cruisecontrol.CruiseControlException; 48 import net.sourceforge.cruisecontrol.Publisher; 49 import net.sourceforge.cruisecontrol.builders.AntBuilder; 50 import net.sourceforge.cruisecontrol.builders.Property; 51 import net.sourceforge.cruisecontrol.util.XMLLogHelper; 52 53 62 public class AntPublisher implements Publisher { 63 64 private static final Logger LOG = Logger.getLogger(AntPublisher.class); 65 66 private AntBuilder delegate = new AntBuilder(); 67 68 71 public void publish(Element log) throws CruiseControlException { 72 73 Map properties = new HashMap (); 74 75 populatePropertesForAntBuilder(log, properties); 76 77 Element result = delegate.build(properties); 79 if (result == null) { 80 LOG.error("Publisher failed.\n\n"); 81 } else { 82 Attribute error = result.getAttribute("error"); 83 if (error == null) { 84 LOG.info("Publisher successful."); 85 } else { 86 LOG.error("Publisher failed.\n\n" 87 + error.getValue() 88 + "\n"); 89 } 90 } 91 } 92 93 public void validate() throws CruiseControlException { 94 delegate.validate(); 95 } 96 97 100 public void setSaveLogDir(String dir) { 101 delegate.setSaveLogDir(dir); 102 } 103 104 107 public void setAntWorkingDir(String dir) { 108 delegate.setAntWorkingDir(dir); 109 } 110 111 114 public void setAntScript(String antScript) { 115 delegate.setAntScript(antScript); 116 } 117 118 121 public void setAntHome(String antHome) { 122 delegate.setAntHome(antHome); 123 } 124 125 128 public void setTempFile(String tempFileName) { 129 delegate.setTempFile(tempFileName); 130 } 131 132 135 public void setTarget(String target) { 136 delegate.setTarget(target); 137 } 138 139 142 public void setBuildFile(String buildFile) { 143 delegate.setBuildFile(buildFile); 144 } 145 146 149 public void setUseLogger(boolean useLogger) { 150 delegate.setUseLogger(useLogger); 151 } 152 153 156 public Object createJVMArg() { 157 return delegate.createJVMArg(); 158 } 159 160 163 public Property createProperty() { 164 return delegate.createProperty(); 165 } 166 167 170 public void setUseDebug(boolean debug) { 171 delegate.setUseDebug(debug); 172 } 173 174 177 public void setUseQuiet(boolean quiet) { 178 delegate.setUseQuiet(quiet); 179 } 180 181 184 public String getLoggerClassName() { 185 return delegate.getLoggerClassName(); 186 } 187 188 191 public void setLoggerClassName(String string) { 192 delegate.setLoggerClassName(string); 193 } 194 195 198 public void setTimeout(long timeout) { 199 delegate.setTimeout(timeout); 200 } 201 202 void populatePropertesForAntBuilder(Element log, Map properties) { 203 XMLLogHelper helper = new XMLLogHelper(log); 204 if (helper.isBuildSuccessful()) { 205 properties.put("thisbuildsuccessful", "true"); 206 } else { 207 properties.put("thisbuildsuccessful", "false"); 208 } 209 210 Iterator propertyIterator = log.getChild("info").getChildren("property").iterator(); 211 while (propertyIterator.hasNext()) { 212 Element property = (Element) propertyIterator.next(); 213 properties.put(property.getAttributeValue("name"), 214 property.getAttributeValue("value")); 215 } 216 } 217 } 218 | Popular Tags |