1 28 29 package com.idaremedia.antx.construct; 30 31 import java.util.Map ; 32 33 import org.apache.tools.ant.BuildException; 34 import org.apache.tools.ant.Project; 35 import org.apache.tools.ant.Task; 36 import org.apache.tools.ant.TaskContainer; 37 import org.apache.tools.ant.UnknownElement; 38 39 import com.idaremedia.antx.AssertableTask; 40 import com.idaremedia.antx.FixtureExaminer; 41 import com.idaremedia.antx.apis.Nameable; 42 import com.idaremedia.antx.ownhelpers.UEContainerProxy; 43 import com.idaremedia.antx.parameters.FeedbackLevel; 44 45 46 57 58 public abstract class ItemConstructorTask extends AssertableTask 59 implements Nameable, TaskContainer 60 { 61 64 protected ItemConstructorTask(String iam) 65 { 66 super(iam); 67 } 68 69 70 74 79 public void setName(String dstRefId) 80 { 81 require_(dstRefId!=null, "setName- nonzro refid"); 82 m_toRefId = dstRefId; 83 } 84 85 86 87 88 93 public final String getName() 94 { 95 return m_toRefId; 96 } 97 98 99 100 108 public void setHaltIfExists(boolean halt) 109 { 110 m_haltIfExists = halt; 111 } 112 113 114 115 120 public final boolean isHaltIfExists() 121 { 122 return m_haltIfExists; 123 } 124 125 126 127 134 public void setOverwrite(boolean allowOverwrite) 135 { 136 m_allowOverwrite = allowOverwrite; 137 } 138 139 140 141 146 public final boolean willAllowOverwrite() 147 { 148 return m_allowOverwrite; 149 } 150 151 152 153 160 public void setFeedback(String level) 161 { 162 require_(level!=null,"setFeedback- nonzro level"); 163 FeedbackLevel fbl = FeedbackLevel.from(level); 164 if (fbl==null) { 165 String e = getAntXMsg("task.illegal.param.value", 166 getTaskName(), level, "feedback"); 167 log(e, Project.MSG_ERR); 168 throw new BuildException(e, getLocation()); 169 } 170 m_fbLevel = fbl; 171 } 172 173 174 175 179 public final FeedbackLevel getFeedbackLevel() 180 { 181 return m_fbLevel; 182 } 183 184 185 189 190 194 public void addTask(Task task) 195 { 196 require_(task instanceof UnknownElement, "addTask- is UE proxy"); 197 UnknownElement ue = (UnknownElement)task; 198 if (m_itemUE!=null) { 199 String ermsg = uistrs().get("taskset.only.one.specialtask", 200 ue.getQName(), m_itemQName); 201 log(ermsg,Project.MSG_ERR); 202 throw new BuildException(ermsg,getLocation()); 203 } 204 m_itemQName = ue.getQName(); 205 m_itemUE = new UEContainerProxy(ue); 206 } 207 208 209 213 214 219 public void execute() 220 { 221 verifyCanExecute_("exec"); 222 223 String refid = getName(); 224 final Project P = getProject(); 225 boolean quiet = FeedbackLevel.isQuietish(m_fbLevel,true,true); 226 227 Object there = FixtureExaminer.trueReference(P,refid); 228 if (there==FixtureExaminer.PENDING_REFERENCE) { 229 quiet = true; 230 there = null; 231 } 232 233 Map refs = P.getReferences(); 234 if (there!=null) { 235 String msg = uistrs().get("task.warn.refid.exists",refid); 236 if (isHaltIfExists()) { 237 log(msg,Project.MSG_ERR); 238 throw new BuildException(msg,getLocation()); 239 } 240 if (!willAllowOverwrite()) { 241 if (!quiet) { 242 log(msg,Project.MSG_VERBOSE); 243 } 244 m_itemUE = null; 245 return; 246 } 247 if (!quiet) { 248 log(msg,Project.MSG_WARN); 249 } 250 } 251 252 Object actual = beforeInstall(m_itemUE); 253 verify_(actual!=null,"exec- nonzro item"); 254 255 if (quiet) { 256 refs.put(refid,actual); 257 } else { 258 P.addReference(refid,actual); 259 } 260 261 m_itemUE = null; 262 } 263 264 265 266 271 public void verifyIsDefined() 272 { 273 if (getName()==null) { 274 String ermsg = uistrs().get("task.needs.this.attr", 275 getTaskName(),"name"); 276 log(ermsg,Project.MSG_ERR); 277 throw new BuildException(ermsg,getLocation()); 278 } 279 if (m_itemUE==null) { 280 String ermsg = uistrs().get("task.needs.oneof.these.nested", 281 getTaskName(),"<any ant component>"); 282 log(ermsg,Project.MSG_ERR); 283 throw new BuildException(ermsg,getLocation()); 284 } 285 } 286 287 288 289 294 protected void verifyCanExecute_(String calr) 295 { 296 verifyInProject_(calr); 297 verifyIsDefined(); 298 } 299 300 301 302 310 protected Object beforeInstall(UEContainerProxy ue) 311 { 312 return ue; 313 } 314 315 316 private String m_toRefId; 317 private boolean m_haltIfExists; private boolean m_allowOverwrite=true; private FeedbackLevel m_fbLevel=FeedbackLevel.NORMAL; private UEContainerProxy m_itemUE; 321 private String m_itemQName; 322 } 323 324 | Popular Tags |