1 package fr.jayasoft.ivy.ant; 2 3 import java.io.File ; 4 5 import org.apache.tools.ant.BuildException; 6 7 import fr.jayasoft.ivy.Ivy; 8 import fr.jayasoft.ivy.ModuleId; 9 import fr.jayasoft.ivy.filter.Filter; 10 import fr.jayasoft.ivy.filter.FilterHelper; 11 import fr.jayasoft.ivy.report.ResolveReport; 12 import fr.jayasoft.ivy.util.Message; 13 import fr.jayasoft.ivy.util.StringUtils; 14 15 22 public abstract class IvyPostResolveTask extends IvyTask { 23 private String _conf; 24 private boolean _haltOnFailure = true; 25 private boolean _transitive = true; 26 private boolean _inline = false; 27 private File _cache; 28 29 private String _organisation; 30 private String _module; 31 private String _revision = "latest.integration"; 32 33 private String _type; 34 35 36 private Filter _artifactFilter = null; 37 private boolean useOrigin = false; 38 39 public boolean isUseOrigin() { 40 return useOrigin; 41 } 42 43 public void setUseOrigin(boolean useOrigin) { 44 this.useOrigin = useOrigin; 45 } 46 47 protected void prepareAndCheck() { 48 Ivy ivy = getIvyInstance(); 49 50 boolean orgAndModSetManually = (_organisation != null) && (_module != null); 51 52 _organisation = getProperty(_organisation, ivy, "ivy.organisation"); 53 _module = getProperty(_module, ivy, "ivy.module"); 54 55 if (isInline()) { 56 _conf = _conf == null ? "*" : _conf; 57 if (_organisation == null) { 58 throw new BuildException("no organisation provided for ivy cache task in inline mode: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property"); 59 } 60 if (_module == null) { 61 throw new BuildException("no module name provided for ivy cache task in inline mode: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property"); 62 } 63 String [] toResolve = getConfsToResolve(getOrganisation(), getModule()+"-caller", _conf, true); 64 if (toResolve.length > 0) { 65 Message.verbose("using inline mode to resolve "+getOrganisation()+" "+getModule()+" "+getRevision()+" ("+StringUtils.join(toResolve, ", ")+")"); 66 IvyResolve resolve = createResolve(isHaltonfailure(), isUseOrigin()); 67 resolve.setOrganisation(getOrganisation()); 68 resolve.setModule(getModule()); 69 resolve.setRevision(getRevision()); 70 resolve.setInline(true); 71 resolve.setConf(_conf); 72 resolve.execute(); 73 } else { 74 Message.verbose("inline resolve already done for "+getOrganisation()+" "+getModule()+" "+getRevision()+" ("+_conf+")"); 75 } 76 if ("*".equals(_conf)) { 77 _conf = StringUtils.join(getResolvedConfigurations(getOrganisation(), getModule()+"-caller", true), ", "); 78 } 79 } else { 80 Message.debug("using standard ensure resolved"); 81 82 if (!orgAndModSetManually) { 87 ensureResolved(isHaltonfailure(), isUseOrigin(), isTransitive(), getOrganisation(), getModule(), getProperty(_conf, ivy, "ivy.resolved.configurations")); 88 } 89 90 _conf = getProperty(_conf, ivy, "ivy.resolved.configurations"); 91 if ("*".equals(_conf)) { 92 _conf = getProperty(ivy, "ivy.resolved.configurations"); 93 if (_conf == null) { 94 throw new BuildException("bad conf provided for ivy cache task: * can only be used with a prior call to <resolve/>"); 95 } 96 } 97 } 98 _organisation = getProperty(_organisation, ivy, "ivy.organisation"); 99 _module = getProperty(_module, ivy, "ivy.module"); 100 if (_organisation == null) { 101 throw new BuildException("no organisation provided for ivy cache task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to <resolve/>"); 102 } 103 if (_module == null) { 104 throw new BuildException("no module name provided for ivy cache task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to <resolve/>"); 105 } 106 if (_conf == null) { 107 throw new BuildException("no conf provided for ivy cache task: It can either be set explicitely via the attribute 'conf' or via 'ivy.resolved.configurations' property or a prior call to <resolve/>"); 108 } 109 if (_cache == null) { 110 _cache = ivy.getDefaultCache(); 111 } 112 113 _artifactFilter = FilterHelper.getArtifactTypeFilter(_type); 114 } 115 116 protected ModuleId getResolvedModuleId() { 117 return isInline()?new ModuleId(getOrganisation(), getModule()+"-caller"):new ModuleId(getOrganisation(), getModule()); 118 } 119 120 protected ResolveReport getResolvedReport() { 121 return getResolvedReport(getOrganisation(), isInline()?getModule()+"-caller":getModule()); 122 } 123 124 public String getType() { 125 return _type; 126 } 127 public void setType(String type) { 128 _type = type; 129 } 130 131 public String getConf() { 132 return _conf; 133 } 134 135 public void setConf(String conf) { 136 _conf = conf; 137 } 138 139 public String getModule() { 140 return _module; 141 } 142 public void setModule(String module) { 143 _module = module; 144 } 145 public String getOrganisation() { 146 return _organisation; 147 } 148 public void setOrganisation(String organisation) { 149 _organisation = organisation; 150 } 151 public boolean isHaltonfailure() { 152 return _haltOnFailure; 153 } 154 public void setHaltonfailure(boolean haltOnFailure) { 155 _haltOnFailure = haltOnFailure; 156 } 157 public File getCache() { 158 return _cache; 159 } 160 public void setCache(File cache) { 161 _cache = cache; 162 } 163 164 public String getRevision() { 165 return _revision; 166 } 167 168 public void setRevision(String rev) { 169 _revision = rev; 170 } 171 172 173 174 public Filter getArtifactFilter() { 175 return _artifactFilter; 176 } 177 178 public boolean isTransitive() { 179 return _transitive; 180 } 181 182 public void setTransitive(boolean transitive) { 183 _transitive = transitive; 184 } 185 186 public boolean isInline() { 187 return _inline; 188 } 189 190 public void setInline(boolean inline) { 191 _inline = inline; 192 } 193 194 } 195 | Popular Tags |