1 7 package fr.jayasoft.ivy.ant; 8 9 import java.io.File ; 10 11 import org.apache.tools.ant.BuildException; 12 13 import fr.jayasoft.ivy.Artifact; 14 import fr.jayasoft.ivy.Ivy; 15 import fr.jayasoft.ivy.ModuleId; 16 import fr.jayasoft.ivy.util.IvyPatternHelper; 17 import fr.jayasoft.ivy.xml.XmlReportParser; 18 19 24 public class IvyArtifactProperty extends IvyTask { 25 private String _conf; 26 private String _name; 27 private String _value; 28 29 private String _organisation; 30 private String _module; 31 private boolean _haltOnFailure = true; 32 private File _cache; 33 34 public String getConf() { 35 return _conf; 36 } 37 public void setConf(String conf) { 38 _conf = conf; 39 } 40 public String getName() { 41 return _name; 42 } 43 public void setName(String name) { 44 _name = name; 45 } 46 public String getValue() { 47 return _value; 48 } 49 public void setValue(String value) { 50 _value = value; 51 } 52 public String getModule() { 53 return _module; 54 } 55 public void setModule(String module) { 56 _module = module; 57 } 58 public String getOrganisation() { 59 return _organisation; 60 } 61 public void setOrganisation(String organisation) { 62 _organisation = organisation; 63 } 64 public boolean isHaltonfailure() { 65 return _haltOnFailure; 66 } 67 public void setHaltonfailure(boolean haltOnFailure) { 68 _haltOnFailure = haltOnFailure; 69 } 70 public File getCache() { 71 return _cache; 72 } 73 public void setCache(File cache) { 74 _cache = cache; 75 } 76 77 public void execute() throws BuildException { 78 Ivy ivy = getIvyInstance(); 79 80 _organisation = getProperty(_organisation, ivy, "ivy.organisation"); 81 _module = getProperty(_module, ivy, "ivy.module"); 82 83 ensureResolved(isHaltonfailure(), false, getOrganisation(), getModule()); 84 85 _conf = getProperty(_conf, ivy, "ivy.resolved.configurations"); 86 if ("*".equals(_conf)) { 87 _conf = getProperty(ivy, "ivy.resolved.configurations"); 88 if (_conf == null) { 89 throw new BuildException("bad provided for ivy artifactproperty: * can only be used with a prior call to <resolve/>"); 90 } 91 } 92 _organisation = getProperty(_organisation, ivy, "ivy.organisation"); 93 _module = getProperty(_module, ivy, "ivy.module"); 94 if (_cache == null) { 95 _cache = ivy.getDefaultCache(); 96 } 97 98 if (_organisation == null) { 99 throw new BuildException("no organisation provided for ivy artifactproperty: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to <resolve/>"); 100 } 101 if (_module == null) { 102 throw new BuildException("no module name provided for ivy artifactproperty: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to <resolve/>"); 103 } 104 if (_conf == null) { 105 throw new BuildException("no conf provided for ivy artifactproperty: It can either be set explicitely via the attribute 'conf' or via 'ivy.resolved.configurations' property or a prior call to <resolve/>"); 106 } 107 try { 108 XmlReportParser parser = new XmlReportParser(); 109 String [] confs = splitConfs(_conf); 110 for (int i = 0; i < confs.length; i++) { 111 Artifact[] artifacts = parser.getArtifacts(new ModuleId(_organisation, _module), confs[i], _cache); 112 for (int j = 0; j < artifacts.length; j++) { 113 Artifact artifact = artifacts[j]; 114 String name = IvyPatternHelper.substitute(ivy.substitute(getName()), artifact, confs[i]); 115 String value = IvyPatternHelper.substitute(ivy.substitute(getValue()), artifact, confs[i]); 116 getProject().setProperty(name, value); 117 } 118 } 119 } catch (Exception ex) { 120 throw new BuildException("impossible to add artifact properties: "+ex, ex); 121 } 122 } 123 } 124 | Popular Tags |