Beispiel #1
0
  /**
   * Get dependencies of a source file.
   *
   * @param path The canonical path of source file.
   * @return Path of dependencies.
   */
  private ArrayList<String> getDependencies(String path) {
    if (!dependenceMap.containsKey(path)) {
      ArrayList<String> dependencies = new ArrayList<String>();
      Matcher m = PATTERN_REQUIRE.matcher(read(path, charset));

      while (m.find()) {
        // Decide which root path to use.
        // Path wrapped in <> is related to root path.
        // Path wrapped in "" is related to parent folder of the source file.
        String root = null;

        if (m.group(1).equals("<")) {
          root = this.root;
        } else {
          root = new File(path).getParent();
        }

        // Get path of required file.
        String required = m.group(2);

        File f = new File(root, required);

        if (f.exists()) {
          dependencies.add(canonize(f));
        } else {
          App.exit("Cannot find required file " + required + " in " + path);
        }
      }

      dependenceMap.put(path, dependencies);
    }

    return dependenceMap.get(path);
  }