/*
   * Get the set of modules for the current project. This include old-style (using application.conf)
   * and new style, with dependencies starting at 1.2 (load everything from the modules/ dir)
   */
  private Set<File> modules() {
    Set<File> modules = new HashSet<File>();

    // Old-skool
    for (Map.Entry<String, String> entry : properties().entrySet()) {
      if (!entry.getKey().startsWith("module.")) {
        continue;
      }
      String s = project.replaceProperties(entry.getValue());
      File moduleDir;
      if (!FileUtils.isAbsolutePath(s)) {
        moduleDir = new File(new File(applicationDir, "conf"), s);
      } else {
        moduleDir = new File(s);
      }
      if (!moduleDir.exists()) {
        project.log(
            "Failed add non existing module to classpath! " + moduleDir.getAbsolutePath(),
            Project.MSG_WARN);
        continue;
      }
      modules.add(moduleDir);
    }

    // 1.2+ fashion
    File modulesDir = new File(applicationDir, "modules");
    if (modulesDir.exists()) {
      for (File child : modulesDir.listFiles()) {
        if (child == null) {
          // No-op
        } else if (child.isDirectory()) {
          modules.add(child);
        } else {
          modules.add(new File(IO.readContentAsString(child)));
        }
      }
    }
    return modules;
  }
  public void execute() {
    if (applicationDir == null) {
      throw new BuildException("No applicationDir set!");
    }

    // Add the properties from application.conf as ant properties
    for (Map.Entry<String, String> entry : properties().entrySet()) {
      String key = entry.getKey();
      String value = project.replaceProperties(entry.getValue());
      project.setProperty(prefix + key, value);
      project.log("Loaded property '" + prefix + key + "'='" + value + "'", Project.MSG_VERBOSE);
    }

    // Add the module classpath as an ant property
    Path path = new Path(project);
    FilenameSelector endsToJar = new FilenameSelector();
    endsToJar.setName("*.jar");

    for (File module : modules()) {
      File moduleLib = new File(module, "lib");
      if (moduleLib.exists()) {
        FileSet fileSet = new FileSet();
        fileSet.setDir(moduleLib);
        fileSet.addFilename(endsToJar);
        path.addFileset(fileSet);
        project.log("Added fileSet to path: " + fileSet, Project.MSG_VERBOSE);
      } else {
        project.log(
            "Ignoring non existing lib dir: " + moduleLib.getAbsolutePath(), Project.MSG_VERBOSE);
      }
    }
    project.addReference(modulesClasspath, path);
    project.log(
        "Generated classpath '" + modulesClasspath + "':" + project.getReference(modulesClasspath),
        Project.MSG_VERBOSE);
  }
예제 #3
0
 public void addText(String name) {
   Project p = getProject();
   _javaClassNames.add(p.replaceProperties(name));
 }