1 6 package fr.jayasoft.ivy.ant; 7 8 import java.io.File ; 9 import java.net.URL ; 10 import java.util.ArrayList ; 11 import java.util.Collection ; 12 import java.util.Date ; 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 import java.util.Map ; 17 18 import org.apache.tools.ant.BuildException; 19 20 import fr.jayasoft.ivy.Artifact; 21 import fr.jayasoft.ivy.ArtifactRevisionId; 22 import fr.jayasoft.ivy.Ivy; 23 import fr.jayasoft.ivy.ModuleRevisionId; 24 import fr.jayasoft.ivy.util.IvyPatternHelper; 25 import fr.jayasoft.ivy.util.Message; 26 27 33 public class IvyPublish extends IvyTask { 34 private String _organisation; 35 private String _module; 36 private String _revision; 37 private String _pubRevision; 38 private File _cache; 39 private String _srcivypattern; 40 private String _status; 41 private String _conf=null; 42 private String _pubdate; 43 private String _deliverTarget; 44 private String _publishResolverName = null; 45 private List _artifactspattern = new ArrayList (); 46 private File _deliveryList; 47 private boolean _publishivy = true; 48 private boolean _warnonmissing = true; 49 private boolean _haltonmissing = true; 50 private boolean _overwrite = false; 51 private boolean _update = false; 52 private boolean _replacedynamicrev = true; 53 private boolean _forcedeliver; 54 private Collection _artifacts = new ArrayList (); 55 56 public File getCache() { 57 return _cache; 58 } 59 public void setCache(File cache) { 60 _cache = cache; 61 } 62 public String getSrcivypattern() { 63 return _srcivypattern; 64 } 65 public void setSrcivypattern(String destivypattern) { 66 _srcivypattern = destivypattern; 67 } 68 72 public String getDeliverivypattern() { 73 return _srcivypattern; 74 } 75 79 public void setDeliverivypattern(String destivypattern) { 80 _srcivypattern = destivypattern; 81 } 82 public String getModule() { 83 return _module; 84 } 85 public void setModule(String module) { 86 _module = module; 87 } 88 public String getOrganisation() { 89 return _organisation; 90 } 91 public void setOrganisation(String organisation) { 92 _organisation = organisation; 93 } 94 public String getPubdate() { 95 return _pubdate; 96 } 97 public void setPubdate(String pubdate) { 98 _pubdate = pubdate; 99 } 100 public String getPubrevision() { 101 return _pubRevision; 102 } 103 public void setPubrevision(String pubRevision) { 104 _pubRevision = pubRevision; 105 } 106 public String getRevision() { 107 return _revision; 108 } 109 public void setRevision(String revision) { 110 _revision = revision; 111 } 112 public String getStatus() { 113 return _status; 114 } 115 public void setStatus(String status) { 116 _status = status; 117 } 118 public void setConf(String conf) { 119 _conf = conf; 120 } 121 public void setDelivertarget(String deliverTarget) { 122 _deliverTarget = deliverTarget; 123 } 124 public void setDeliveryList(File deliveryList) { 125 _deliveryList = deliveryList; 126 } 127 public String getResolver() { 128 return _publishResolverName; 129 } 130 public void setResolver(String publishResolverName) { 131 _publishResolverName = publishResolverName; 132 } 133 public String getArtifactspattern() { 134 return (String ) (_artifactspattern.isEmpty()?null:_artifactspattern.get(0)); 135 } 136 public void setArtifactspattern(String artifactsPattern) { 137 _artifactspattern.clear(); 138 _artifactspattern.add(artifactsPattern); 139 } 140 public void addArtifactspattern(String artifactsPattern) { 141 _artifactspattern.add(artifactsPattern); 142 } 143 public void addConfiguredArtifacts(ArtifactsPattern p) { 144 _artifactspattern.add(p.getPattern()); 145 } 146 public boolean isReplacedynamicrev() { 147 return _replacedynamicrev; 148 } 149 public void setReplacedynamicrev(boolean replacedynamicrev) { 150 _replacedynamicrev = replacedynamicrev; 151 } 152 153 public void execute() throws BuildException { 154 Ivy ivy = getIvyInstance(); 155 _organisation = getProperty(_organisation, ivy, "ivy.organisation"); 156 _module = getProperty(_module, ivy, "ivy.module"); 157 _revision = getProperty(_revision, ivy, "ivy.revision"); 158 _pubRevision = getProperty(_pubRevision, ivy, "ivy.deliver.revision"); 159 if (_cache == null) { 160 _cache = ivy.getDefaultCache(); 161 } 162 if (_artifactspattern.isEmpty()) { 163 String p = getProperty(null, ivy, "ivy.publish.src.artifacts.pattern"); 164 if (p != null) { 165 _artifactspattern.add(p); 166 } 167 } 168 if (_srcivypattern == null) { 169 _srcivypattern = getArtifactspattern(); 170 } 171 _status = getProperty(_status, ivy, "ivy.status"); 172 if (_organisation == null) { 173 throw new BuildException("no organisation provided for ivy publish task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to <resolve/>"); 174 } 175 if (_module == null) { 176 throw new BuildException("no module name provided for ivy publish task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to <resolve/>"); 177 } 178 if (_revision == null) { 179 throw new BuildException("no module revision provided for ivy publish task: It can either be set explicitely via the attribute 'revision' or via 'ivy.revision' property or a prior call to <resolve/>"); 180 } 181 if (_artifactspattern.isEmpty()) { 182 throw new BuildException("no artifacts pattern: either provide it through parameter or through ivy.publish.src.artifacts.pattern property"); 183 } 184 if (_publishResolverName == null) { 185 throw new BuildException("no publish deliver name: please provide it through parameter 'resolver'"); 186 } 187 if ("working".equals(_revision)) { 188 _revision = "working@"+Ivy.getLocalHostName(); 189 } 190 Date pubdate = getPubDate(_pubdate, new Date ()); 191 if (_pubRevision == null) { 192 if (_revision.startsWith("working@")) { 193 _pubRevision = Ivy.DATE_FORMAT.format(pubdate); 194 } else { 195 _pubRevision = _revision; 196 } 197 } 198 if (_status == null) { 199 throw new BuildException("no status provided: either provide it as parameter or through the ivy.status.default property"); 200 } 201 ModuleRevisionId mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision); 202 try { 203 File ivyFile = new File (IvyPatternHelper.substitute(_srcivypattern, _organisation, _module, _pubRevision, "ivy", "ivy", "xml")); 204 if (null!=_conf && isPublishivy()) { 205 if (isPublishivy()) { 206 Message.warn("Impossible to publish ivy file when conf is specified"); 207 Message.warn("Please, set publishivy to false"); 208 setPublishivy(false); 209 } 210 } 211 if (_publishivy && (!ivyFile.exists() || _forcedeliver)) { 212 IvyDeliver deliver = new IvyDeliver(); 213 deliver.setProject(getProject()); 214 deliver.setCache(getCache()); 215 deliver.setDeliverpattern(getSrcivypattern()); 216 deliver.setDelivertarget(_deliverTarget); 217 deliver.setDeliveryList(_deliveryList); 218 deliver.setModule(getModule()); 219 deliver.setOrganisation(getOrganisation()); 220 deliver.setPubdate(Ivy.DATE_FORMAT.format(pubdate)); 221 deliver.setPubrevision(getPubrevision()); 222 deliver.setRevision(getRevision()); 223 deliver.setStatus(getStatus()); 224 deliver.setValidate(doValidate(ivy)); 225 deliver.setReplacedynamicrev(isReplacedynamicrev()); 226 227 deliver.execute(); 228 } 229 230 Collection missing = ivy.publish( 231 mrid, 232 _pubRevision, 233 _cache, 234 _artifactspattern, 235 _publishResolverName, 236 _publishivy?_srcivypattern:null, 237 getStatus(), 238 pubdate, 239 (Artifact[]) _artifacts.toArray(new Artifact[_artifacts.size()]), doValidate(ivy), 240 _overwrite, 241 _update, 242 _conf); 243 if (_warnonmissing) { 244 for (Iterator iter = missing.iterator(); iter.hasNext();) { 245 Artifact artifact = (Artifact)iter.next(); 246 Message.warn("missing artifact: "+artifact); 247 } 248 } 249 if (_haltonmissing && !missing.isEmpty()) { 250 throw new BuildException("missing published artifacts for "+mrid+": "+missing); 251 } 252 253 } catch (Exception e) { 254 throw new BuildException("impossible to publish artifacts for "+mrid+": "+e, e); 255 } 256 } 257 public PublishArtifact createArtifact() { 258 PublishArtifact art = new PublishArtifact(); 259 _artifacts .add(art); 260 return art; 261 } 262 public boolean isPublishivy() { 263 return _publishivy; 264 } 265 266 public void setPublishivy(boolean publishivy) { 267 _publishivy = publishivy; 268 } 269 public boolean isWarnonmissing() { 270 return _warnonmissing; 271 } 272 273 public void setWarnonmissing(boolean warnonmissing) { 274 _warnonmissing = warnonmissing; 275 } 276 public boolean isHaltonmissing() { 277 return _haltonmissing; 278 } 279 280 public void setHaltonmissing(boolean haltonmissing) { 281 _haltonmissing = haltonmissing; 282 } 283 public boolean isOverwrite() { 284 return _overwrite; 285 } 286 public void setOverwrite(boolean overwrite) { 287 _overwrite = overwrite; 288 } 289 public void setForcedeliver(boolean b) { 290 _forcedeliver = b; 291 } 292 public boolean isForcedeliver() { 293 return _forcedeliver; 294 } 295 public boolean isUpdate() { 296 return _update; 297 } 298 public void setUpdate(boolean update) { 299 _update = update; 300 } 301 public class PublishArtifact implements Artifact { 302 private String _ext; 303 private String _name; 304 private String _type; 305 306 public String [] getConfigurations() { 307 return null; 308 } 309 310 public String getExt() { 311 return _ext==null?_type:_ext; 312 } 313 314 public ArtifactRevisionId getId() { 315 return null; 316 } 317 318 public ModuleRevisionId getModuleRevisionId() { 319 return null; 320 } 321 322 public String getName() { 323 return _name; 324 } 325 326 public Date getPublicationDate() { 327 return null; 328 } 329 330 public String getType() { 331 return _type; 332 } 333 334 public URL getUrl() { 335 return null; 336 } 337 338 public void setExt(String ext) { 339 _ext = ext; 340 } 341 342 public void setName(String name) { 343 _name = name; 344 } 345 346 public void setType(String type) { 347 _type = type; 348 } 349 350 public String getAttribute(String attName) { 351 return null; 352 } 353 354 public Map getAttributes() { 355 return new HashMap (); 356 } 357 358 public String getExtraAttribute(String attName) { 359 return null; 360 } 361 362 public Map getExtraAttributes() { 363 return new HashMap (); 364 } 365 366 public String getStandardAttribute(String attName) { 367 return null; 368 } 369 370 public Map getStandardAttributes() { 371 return new HashMap (); 372 } 373 } 374 public static class ArtifactsPattern { 375 private String _pattern; 376 377 public String getPattern() { 378 return _pattern; 379 } 380 381 public void setPattern(String pattern) { 382 _pattern = pattern; 383 } 384 } 385 } 386 | Popular Tags |