1 6 package fr.jayasoft.ivy.ant; 7 8 import java.io.File ; 9 import java.util.Date ; 10 11 import org.apache.tools.ant.BuildException; 12 import org.apache.tools.ant.taskdefs.CallTarget; 13 import org.apache.tools.ant.taskdefs.Echo; 14 import org.apache.tools.ant.taskdefs.Input; 15 import org.apache.tools.ant.taskdefs.Property; 16 17 import fr.jayasoft.ivy.DefaultPublishingDRResolver; 18 import fr.jayasoft.ivy.Ivy; 19 import fr.jayasoft.ivy.IvyContext; 20 import fr.jayasoft.ivy.ModuleDescriptor; 21 import fr.jayasoft.ivy.ModuleRevisionId; 22 import fr.jayasoft.ivy.PublishingDependencyRevisionResolver; 23 import fr.jayasoft.ivy.status.StatusManager; 24 import fr.jayasoft.ivy.util.Message; 25 import fr.jayasoft.ivy.util.MessageImpl; 26 27 34 public class IvyDeliver extends IvyTask { 35 private final class DeliverDRResolver extends DefaultPublishingDRResolver { 36 public String resolve(ModuleDescriptor published, 37 String publishedStatus, ModuleRevisionId depMrid, 38 String depStatus) { 39 if (StatusManager.getCurrent().isIntegration(publishedStatus)) { 40 return super.resolve(published, publishedStatus, depMrid, 42 depStatus); 43 } 44 45 47 if (!StatusManager.getCurrent().isIntegration(depStatus)) { 48 return super.resolve(published, publishedStatus, depMrid, 50 depStatus); 51 } 52 53 55 String statusProperty = depMrid.getName() + "." + depMrid.getRevision() + ".status"; 56 String versionProperty = depMrid.getName() + "." + depMrid.getRevision() + ".version"; 57 String deliveredProperty = depMrid.getName() + "." + depMrid.getRevision() + ".delivered"; 58 59 String version = getProject().getProperty(versionProperty); 60 String status = getProject().getProperty(statusProperty); 61 String delivered = getProject().getProperty(deliveredProperty); 62 Message.debug("found version = " + version + " status=" + status+" delivered="+delivered); 63 if (version != null && status != null) { 64 if ("true".equals(delivered)) { 65 return version; 67 } else { 68 deliverDependency(depMrid, version, status, depStatus); 69 loadDeliveryList(); 70 return version; 71 } 72 } 73 74 85 String globalStatusProperty = "recursive.delivery.status"; 86 String globalVersionProperty = "recursive.delivery.version"; 87 version = getProject().getProperty(globalVersionProperty); 88 status = getProject().getProperty(globalStatusProperty); 89 if (version != null && status != null) { 90 delivered = getProject().getProperty("recursive."+depMrid.getName()+ ".delivered"); 92 Message.debug("found global version = " + version + " and global status=" + status+" - delivered = "+delivered); 93 if ("true".equals(delivered)) { 94 return version; 96 } else { 97 getProject().setProperty(statusProperty, status); 98 deliverDependency(depMrid, version, status, depStatus); 99 loadDeliveryList(); 100 return version; 101 } 102 } 103 104 Input input = (Input) getProject().createTask("input"); 107 input.setOwningTarget(getOwningTarget()); 108 input.init(); 109 110 input.setMessage(depMrid.getName() + " " + depMrid.getRevision() 112 + ": please enter a status: "); 113 input.setValidargs(StatusManager.getCurrent().getDeliveryStatusListString()); 114 input.setAddproperty(statusProperty); 115 input.perform(); 116 status = getProject().getProperty(statusProperty); 117 appendDeliveryList(statusProperty + " = " + status); 118 119 input.setMessage(depMrid.getName() + " " + depMrid.getRevision() 121 + ": please enter a version: "); 122 input.setValidargs(null); 123 input.setAddproperty(versionProperty); 124 input.perform(); 125 126 version = getProject().getProperty(versionProperty); 127 appendDeliveryList(versionProperty + " = " + version); 128 deliverDependency(depMrid, version, status, depStatus); 129 130 loadDeliveryList(); 131 132 return version; 133 } 134 135 public void deliverDependency(ModuleRevisionId depMrid, String version, String status, String depStatus) { 136 if (_deliverTarget != null && _deliverTarget.trim().length() > 0) { 138 139 CallTarget ct = (CallTarget) getProject().createTask("antcall"); 140 ct.setOwningTarget(getOwningTarget()); 141 ct.init(); 142 ct.setTarget(_deliverTarget); 143 ct.setInheritAll(true); 144 ct.setInheritRefs(true); 145 Property param = ct.createParam(); 146 param.setName("dependency.name"); 147 param.setValue(depMrid.getName()); 148 param = ct.createParam(); 149 param.setName("dependency.published.status"); 150 param.setValue(status); 151 param = ct.createParam(); 152 param.setName("dependency.published.version"); 153 param.setValue(version); 154 param = ct.createParam(); 155 param.setName("dependency.version"); 156 param.setValue(depMrid.getRevision()); 157 param = ct.createParam(); 158 param.setName("dependency.status"); 159 param.setValue(depStatus==null?"null":depStatus); 160 161 MessageImpl impl = IvyContext.getContext().getMessageImpl(); 162 try { 163 IvyContext.getContext().setMessageImpl(null); 164 ct.perform(); 165 } finally { 166 IvyContext.getContext().setMessageImpl(impl); 167 } 168 169 String deliveredProperty = depMrid.getName() + "." + depMrid.getRevision() + ".delivered"; 170 getProject().setProperty(deliveredProperty, "true"); 171 appendDeliveryList(deliveredProperty + " = true"); 172 173 getProject().setProperty("recursive."+depMrid.getName() + ".delivered", "true"); 174 appendDeliveryList("recursive."+depMrid.getName() + ".delivered" + " = true"); 175 } 176 } 177 178 } 179 180 private String _organisation; 181 182 private String _module; 183 184 private String _revision; 185 186 private String _pubRevision; 187 188 private File _cache; 189 190 private String _deliverpattern; 191 192 private String _status; 193 194 private String _pubdate; 195 196 private String _deliverTarget; 197 198 private File _deliveryList; 199 200 private boolean _replacedynamicrev = true; 201 202 public File getCache() { 203 return _cache; 204 } 205 206 public void setCache(File cache) { 207 _cache = cache; 208 } 209 210 public String getDeliverpattern() { 211 return _deliverpattern; 212 } 213 214 public void setDeliverpattern(String destivypattern) { 215 _deliverpattern = destivypattern; 216 } 217 218 public String getModule() { 219 return _module; 220 } 221 222 public void setModule(String module) { 223 _module = module; 224 } 225 226 public String getOrganisation() { 227 return _organisation; 228 } 229 230 public void setOrganisation(String organisation) { 231 _organisation = organisation; 232 } 233 234 public String getPubdate() { 235 return _pubdate; 236 } 237 238 public void setPubdate(String pubdate) { 239 _pubdate = pubdate; 240 } 241 242 public String getPubrevision() { 243 return _pubRevision; 244 } 245 246 public void setPubrevision(String pubRevision) { 247 _pubRevision = pubRevision; 248 } 249 250 public String getRevision() { 251 return _revision; 252 } 253 254 public void setRevision(String revision) { 255 _revision = revision; 256 } 257 258 public String getStatus() { 259 return _status; 260 } 261 262 public void setStatus(String status) { 263 _status = status; 264 } 265 266 public void setDelivertarget(String deliverTarget) { 267 _deliverTarget = deliverTarget; 268 } 269 270 public void setDeliveryList(File deliveryList) { 271 _deliveryList = deliveryList; 272 } 273 274 public boolean isReplacedynamicrev() { 275 return _replacedynamicrev; 276 } 277 278 public void setReplacedynamicrev(boolean replacedynamicrev) { 279 _replacedynamicrev = replacedynamicrev; 280 } 281 282 public void execute() throws BuildException { 283 Ivy ivy = getIvyInstance(); 284 _organisation = getProperty(_organisation, ivy, "ivy.organisation"); 285 _module = getProperty(_module, ivy, "ivy.module"); 286 _revision = getProperty(_revision, ivy, "ivy.revision"); 287 _pubRevision = getProperty(_pubRevision, ivy, "ivy.deliver.revision"); 288 if (_cache == null) { 289 _cache = ivy.getDefaultCache(); 290 } 291 _deliverpattern = getProperty(_deliverpattern, ivy, 292 "ivy.deliver.ivy.pattern"); 293 _status = getProperty(_status, ivy, "ivy.status"); 294 if (_deliveryList == null) { 295 String deliveryListPath = getProperty(ivy, "ivy.delivery.list.file"); 296 if (deliveryListPath == null) { 297 _deliveryList = new File (System.getProperty("java.io.tmpdir") 298 + "/delivery.properties"); 299 } else { 300 _deliveryList = getProject().resolveFile( 301 ivy.substitute(deliveryListPath)); 302 } 303 } 304 if (_organisation == null) { 305 throw new BuildException( 306 "no organisation provided for ivy deliver task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to <resolve/>"); 307 } 308 if (_module == null) { 309 throw new BuildException( 310 "no module name provided for ivy deliver task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to <resolve/>"); 311 } 312 if (_revision == null) { 313 _revision = "working@"+Ivy.getLocalHostName(); 314 } 315 Date pubdate = getPubDate(_pubdate, new Date ()); 316 if (_pubRevision == null) { 317 if (_revision.startsWith("working@")) { 318 _pubRevision = Ivy.DATE_FORMAT.format(pubdate); 319 } else { 320 _pubRevision = _revision; 321 } 322 } 323 if (_deliverpattern == null) { 324 throw new BuildException( 325 "deliver ivy pattern is missing: either provide it as parameters or through ivy.deliver.ivy.pattern properties"); 326 } 327 if (_status == null) { 328 throw new BuildException( 329 "no status provided: either provide it as parameter or through the ivy.status.default property"); 330 } 331 ModuleRevisionId mrid = ModuleRevisionId.newInstance( 332 _organisation, _module, _revision); 333 boolean isLeading = false; 334 try { 335 if (!_deliveryList.exists()) { 336 isLeading = true; 337 } 338 339 loadDeliveryList(); 340 341 PublishingDependencyRevisionResolver drResolver; 342 if (_deliverTarget != null && _deliverTarget.trim().length() > 0) { 343 drResolver = new DeliverDRResolver(); 344 } else { 345 drResolver = new DefaultPublishingDRResolver(); 346 } 347 ivy.deliver(mrid, _pubRevision, _cache, _deliverpattern, _status, 348 pubdate, drResolver, doValidate(ivy), _replacedynamicrev); 349 350 } catch (Exception e) { 351 throw new BuildException("impossible to deliver " + mrid + ": " + e, e); 352 } finally { 353 if (isLeading) { 354 if (_deliveryList.exists()) { 355 _deliveryList.delete(); 356 } 357 } 358 } 359 } 360 361 private void loadDeliveryList() { 362 Property property = (Property) getProject().createTask("property"); 363 property.setOwningTarget(getOwningTarget()); 364 property.init(); 365 property.setFile(_deliveryList); 366 property.perform(); 367 } 368 369 private void appendDeliveryList(String msg) { 370 Echo echo = (Echo) getProject().createTask("echo"); 371 echo.setOwningTarget(getOwningTarget()); 372 echo.init(); 373 echo.setFile(_deliveryList); 374 echo.setMessage(msg + "\n"); 375 echo.setAppend(true); 376 echo.perform(); 377 } 378 379 } 380 | Popular Tags |