1 28 29 package com.idaremedia.antx.apis; 30 31 import org.apache.tools.ant.Location; 32 import org.apache.tools.ant.Project; 33 import org.apache.tools.ant.ProjectComponent; 34 import org.apache.tools.ant.Target; 35 import org.apache.tools.ant.Task; 36 37 49 50 public interface Requester extends ProblemHandler, LogEnabled 51 { 52 57 String getName(); 58 59 60 61 65 Location getLocation(); 66 67 68 69 75 Project getProject(); 76 77 78 79 83 Target getSourceTarget(); 84 85 86 87 93 public static final Requester DEVNULL= new Requester() 94 { 95 98 public String getName() { 99 return "undefined"; 100 } 101 104 public Location getLocation() { 105 return Location.UNKNOWN_LOCATION; 106 } 107 110 public Project getProject() { 111 return null; 112 } 113 116 public Target getSourceTarget() { 117 return null; 118 } 119 122 public void log(String message) { 123 } 124 127 public void log(String message, int msgLevel) { 128 } 129 132 public void problem(Object nugget, int nl) { 133 } 134 }; 135 136 137 138 139 149 public static final class Anonymous extends LogEnabled.ForProject 150 implements Requester 151 { 152 private final Location m_loc; 153 154 157 public Anonymous() { 158 super(null); 159 m_loc = Location.UNKNOWN_LOCATION; 160 } 161 165 public Anonymous(Location loc) { 166 super(null); 167 m_loc = loc==null ? Location.UNKNOWN_LOCATION : loc; 168 } 169 174 public Anonymous(Project project, Location loc) { 175 super(project); 176 m_loc = loc==null ? Location.UNKNOWN_LOCATION : loc; 177 } 178 181 public String getName() { 182 return "undefined"; 183 } 184 188 public Location getLocation() { 189 return m_loc; 190 } 191 195 public Project getProject() { 196 return getImpl(); 197 } 198 201 public Target getSourceTarget() { 202 return null; 203 } 204 207 public void problem(Object nugget, int nl) { 208 log(Tk.stringFrom(nugget,null),nl); 209 } 210 } 211 212 213 214 217 public static final Requester ANONYMOUS= new Anonymous(); 218 219 220 221 228 public static class ForComponent extends LogEnabled.ForComponent 229 implements Requester 230 { 231 235 public ForComponent(ProjectComponent pc) { 236 super(pc); 237 } 238 242 public String getName() { 243 if (m_PC instanceof Task) { 244 return ((Task)m_PC).getTaskName(); 245 } 246 if (m_PC instanceof Named) { 247 String n = ((Named)m_PC).getName(); 248 if (n!=null) { 249 return n; 250 } 251 } 252 return Tk.leafNameFrom(m_PC.getClass()); 253 254 } 255 261 public Location getLocation() { 262 if (m_PC instanceof Task) { 263 return ((Task)m_PC).getLocation(); 264 } 265 if (m_PC instanceof ScriptLocatable) { 266 return ((ScriptLocatable)m_PC).getLocation(); 267 } 268 return Location.UNKNOWN_LOCATION; 269 } 270 274 public Target getSourceTarget() { 275 if (m_PC instanceof Task) { 276 return ((Task)m_PC).getOwningTarget(); 277 } 278 return null; 279 } 280 283 public Project getProject() { 284 return m_PC.getProject(); 285 } 286 289 public void problem(Object nugget, int nl) { 290 log(Tk.stringFrom(nugget,null),nl); 291 } 292 } 293 294 295 296 297 304 public static final class ForUtility extends LogEnabled.ForUtility 305 implements Requester 306 { 307 311 public ForUtility(ProjectDependent utility) { 312 super(utility); 313 } 314 317 public String getName() { 318 return Tk.leafNameFrom(getImpl().getClass()); 319 } 320 324 public Location getLocation() { 325 if (getImpl() instanceof ScriptLocatable) { 326 return ((ScriptLocatable)getImpl()).getLocation(); 327 } 328 return Location.UNKNOWN_LOCATION; 329 } 330 333 public Project getProject() { 334 return getImpl().getProject(); 335 } 336 339 public Target getSourceTarget() { 340 return null; 341 } 342 345 public void problem(Object nugget, int nl) { 346 log(Tk.stringFrom(nugget,null),nl); 347 } 348 } 349 350 351 352 359 public static final class ForProject extends LogEnabled.ForProject 360 implements Requester 361 { 362 366 public ForProject(Project project) { 367 super(project); 368 } 369 373 public String getName() { 374 Project P = getProject(); 375 if (P!=null) { 376 return P.getName(); 377 } 378 return "project"; 379 } 380 383 public Location getLocation() { 384 return Location.UNKNOWN_LOCATION; 385 } 386 389 public Project getProject() { 390 return getImpl(); 391 } 392 395 public Target getSourceTarget() { 396 return null; 397 } 398 401 public void problem(Object nugget, int nl) { 402 log(Tk.stringFrom(nugget,null),nl); 403 } 404 } 405 406 407 408 409 419 } 471 472 | Popular Tags |