1 28 29 package com.idaremedia.antx; 30 31 import org.apache.tools.ant.Project; 32 33 import com.idaremedia.antx.apis.Requester; 34 import com.idaremedia.antx.helpers.Tk; 35 import com.idaremedia.antx.parameters.MergeBehavior; 36 37 61 62 public class Defaults implements FixtureCore 63 { 64 68 public final String defaultPropertiesPrefixName() 69 { 70 return Iteration.configId()+".defaults.property.prefix"; 71 } 72 73 74 80 public String defaultPropertiesPrefix() 81 { 82 return AntXFixture.getProperty(defaultPropertiesPrefixName(), 83 "defaults."); 84 } 85 86 87 88 95 public String defaultPropertiesPrefix(Project project) 96 { 97 String s = project.getProperty(defaultPropertiesPrefixName()); 98 return Tk.isWhitespace(s) ? defaultPropertiesPrefix() : s; 99 } 100 101 102 103 107 public final String isHaltIfErrorName() 108 { 109 return Iteration.configId()+".defaults.haltiferror.flag"; 110 } 111 112 113 114 118 public final String isHaltIfErrorName(String feature) 119 { 120 return Iteration.configId()+".defaults.haltiferror."+feature+".flag"; 121 } 122 123 124 131 public boolean isHaltIfError() 132 { 133 String s = AntXFixture.getProperty(isHaltIfErrorName(),"no"); 134 return Tk.booleanFrom(s); 135 } 136 137 138 139 149 public boolean isHaltIfError(String feature) 150 { 151 String defaultYN= isHaltIfError() ? "yes" : "no"; 152 String s = AntXFixture.getProperty(isHaltIfErrorName(feature), 153 defaultYN); 154 return Tk.booleanFrom(s); 155 } 156 157 158 162 public final String isAssertionsDisabledName() 163 { 164 return Iteration.configId()+".defaults.asserts.flag"; 165 } 166 167 168 174 public boolean isAssertionsDisabled() 175 { 176 String s = AntXFixture.getProperty(isAssertionsDisabledName(), 177 "yes"); 178 return !Tk.booleanFrom(s); 179 } 180 181 182 183 187 public final String isTempFileDeletionDelayedName() 188 { 189 return Iteration.configId()+".defaults.delaydelete.flag"; 190 } 191 192 193 194 201 public boolean isTempFileDeletionDelayed() 202 { 203 String s = AntXFixture.getProperty(isTempFileDeletionDelayedName(), 204 "no"); 205 return Tk.booleanFrom(s); 206 207 } 208 209 210 211 216 public boolean isTempFileDeletionDelayed(Project project) 217 { 218 String s = project.getProperty(isTempFileDeletionDelayedName()); 219 return !Tk.isWhitespace(s) ? Tk.booleanFrom(s) 220 : isTempFileDeletionDelayed(); 221 } 222 223 224 225 229 public final String isShortLocationsEnabledName() 230 { 231 return Iteration.configId()+".defaults.shortlocations.flag"; 232 } 233 234 235 241 public boolean isShortLocationsEnabled() 242 { 243 String s = AntXFixture.getProperty(isShortLocationsEnabledName(), 244 "yes"); 245 return Tk.booleanFrom(s); 246 } 247 248 249 250 254 public final String isFixtureExcludesEnabledName() 255 { 256 return Iteration.configId()+".defaults.fixtureexcludes.flag"; 257 } 258 259 260 261 267 public boolean isFixtureExcludesEnabled() 268 { 269 String s = AntXFixture.getProperty(isFixtureExcludesEnabledName(), 270 "no"); 271 return Tk.booleanFrom(s); 272 } 273 274 275 279 public final String passwordFileLocationName() 280 { 281 return Iteration.configId()+".defaults.passwordfile"; 282 } 283 284 285 286 298 public String passwordFileLocation(Project project) 299 { 300 return Tk.getTheProperty(project, passwordFileLocationName()); 301 } 302 303 304 305 309 public final String mergeBehaviorName() 310 { 311 return Iteration.configId()+".defaults.mergecontrol"; 312 } 313 314 315 319 public final String mergeBehaviorName(String feature) 320 { 321 return Iteration.configId()+".defaults.mergecontrol."+feature; 322 } 323 324 325 333 public MergeBehavior mergeBehavior() 334 { 335 return mergeBehavior(MergeBehavior.FIRST); 336 } 337 338 339 340 347 public MergeBehavior mergeBehavior(MergeBehavior pref) 348 { 349 String s = AntXFixture.getProperty(mergeBehaviorName(), 350 pref.getValue()); 351 return MergeBehavior.from(s, pref); 352 } 353 354 355 356 372 public MergeBehavior mergeBehavior(String feature, MergeBehavior pref) 373 { 374 String s = AntXFixture.getProperty(mergeBehaviorName(feature), 375 pref.getValue()); 376 return MergeBehavior.from(s, pref); 377 } 378 379 380 381 387 protected Defaults() 388 { 389 } 390 391 392 393 401 public String valueFrom(String field, Requester clnt) 402 { 403 if ("assertions".equals(field)) { 404 return String.valueOf(!isAssertionsDisabled()); 405 } 406 if ("haltiferror".equals(field)) { 407 return String.valueOf(isHaltIfError()); 408 } 409 if (field!=null && field.startsWith("haltiferror.")) { 410 String feature = field.substring("haltiferror.".length()); 411 return String.valueOf(isHaltIfError(feature)); 412 } 413 if ("mergecontrol".equals(field)) { 414 return String.valueOf(mergeBehavior()); 415 } 416 if ("configid".equals(field)) { 417 return Iteration.configId(); 418 } 419 if ("noiselevel".equals(field)) { 420 return NoiseLevel.getDefault(clnt.getProject()).toString(); 421 } 422 if ("passwordfile".equals(field)) { 423 return passwordFileLocation(clnt.getProject()); 424 } 425 if ("delaydelete".equals(field)) { 426 return String.valueOf(isTempFileDeletionDelayed(clnt.getProject())); 427 } 428 if ("defaults.prefix".equals(field)) { 429 return defaultPropertiesPrefix(clnt.getProject()); 430 } 431 if ("shortlocations".equals(field)) { 432 return String.valueOf(isShortLocationsEnabled()); 433 } 434 if ("fixtureexcludes".equals(field)) { 435 return String.valueOf(isFixtureExcludesEnabled()); 436 } 437 return null; 438 } 439 440 441 442 451 public String propertyFrom(String field, Requester clnt) 452 { 453 if (field==null) { 454 return null; 455 } 456 if ("assertions".equals(field)) { 457 return isAssertionsDisabledName(); 458 } 459 if ("haltiferror".equals(field)) { 460 return isHaltIfErrorName(); 461 } 462 if (field.startsWith("haltiferror.")) { 463 String feature = field.substring("haltiferror.".length()); 464 return isHaltIfErrorName(feature); 465 } 466 if ("mergecontrol".equals(field)) { 467 return mergeBehaviorName(); 468 } 469 if (field.startsWith("mergecontrol.")) { 470 String feature = field.substring("mergecontrol.".length()); 471 return mergeBehaviorName(feature); 472 } 473 if ("noiselevel".equals(field)) { 474 return AntX.DEFAULT_NOISELEVEL_PROP; 475 } 476 if ("passwordfile".equals(field)) { 477 return passwordFileLocationName(); 478 } 479 if ("delaydelete".equals(field)) { 480 return isTempFileDeletionDelayedName(); 481 } 482 if ("prefix".equals(field)) { 483 return defaultPropertiesPrefixName(); 484 } 485 if ("shortlocations".equals(field)) { 486 return isShortLocationsEnabledName(); 487 } 488 if ("fixtureexcludes".equals(field)) { 489 return isFixtureExcludesEnabledName(); 490 } 491 return null; 492 } 493 } 494 495 | Popular Tags |