Standard Libraries

/** Classes to represent targets in Apache Ant build files. */

import XML

/** An AntTarget is an element representing an ant target. */
class AntTarget extends XMLElement {
  AntTarget() { super.getName() = "target" }

  /** get the name of the target */
  string getName() { result = this.getAttributeValue("name") }

  /** construct a string containing this target's dependencies with a leading and
      trailing comma; this is convenient for extracting individual dependencies */
  string getDependsString() { 
    result = "," +
      this.getAttributeValue("depends").replaceAll(" ", "")
          .replaceAll("\r","").replaceAll("\n","").replaceAll("\t","") + ","
  }

  /** does this ant target depend on that? */
  predicate dependsOn(AntTarget that) {
     this.getFile() = that.getFile() and
     this.getDependsString().matches("%,"+that.getName()+",%")
  }

  /** get some ant target that depends on this one */
  AntTarget getADependency() {
     this.dependsOn(result)
  }
}

/** A MainAntTarget is an element representing an ant target in file "build.xml". */
class MainAntTarget extends AntTarget {
  MainAntTarget() { this.getFile().getName() = "build.xml" }
}