/**
   * Loads the bundle archives built from this project.
   *
   * <p>The jar files to analyze is determined from:
   *
   * <ul>
   *   <li>The project property named <code>jarfile</code>. This is used to create a file set with
   *       dir set to the directory part of the property value that selects the file named by the
   *       file name part of the property value.
   *   <li>The project properties <code>jars.dir</code> and <code>jardir.name</code> (set by all
   *       projects based on <code>bundlebuild.xml</code>. The file set derived from these
   *       properties will have its dir-property set to the value <code>jars.dir</code> and an
   *       includes pattern of the form <code>${jardir.name}/&ast;&ast;/&ast;.jar</code>.
   *   <li>The file set with id <code>docbuild.jarfiles</code>.
   * </ul>
   *
   * @return bundle archives object holding the bundle archives selected by the file sets described
   *     above or null if no file set was defined.
   */
  private BundleArchives getBundleArchives() {
    final List<ResourceCollection> fileSets = new ArrayList<ResourceCollection>();
    final Project proj = getProject();

    // File set for bundlebuild.xml properties
    final String jarsDir = proj.getProperty("jars.dir");
    if (null != jarsDir && 0 < jarsDir.length()) {
      final File file = new File(jarsDir);
      if (file.exists()) {
        final FileSet fileSet = new FileSet();
        fileSet.setProject(proj);
        fileSet.setDir(file);
        final FilenameSelector fns = new FilenameSelector();
        fns.setName(proj.getProperty("jardir.name") + "/**/*.jar");
        fileSet.add(fns);
        fileSet.setExcludes("**/*-source.jar,**/*-javadoc.jar");
        fileSets.add(fileSet);
        log("Found build results (bundlebuild): " + fileSet, Project.MSG_DEBUG);
      }
    }

    // File set for jarfile-property (e.g., framework.jar)
    final String jarfile = proj.getProperty("jarfile");
    if (null != jarfile && 0 < jarfile.length()) {
      final File file = new File(jarfile);
      if (file.exists()) {
        final FileSet fileSet = new FileSet();
        fileSet.setProject(proj);
        fileSet.setDir(file.getParentFile());
        final FilenameSelector fns = new FilenameSelector();
        fns.setName(file.getName());
        fileSet.add(fns);
        fileSets.add(fileSet);
        log("Found build results (jarfile): " + fileSet, Project.MSG_DEBUG);
      }
    }

    // FileSet defined with id (for bundle overview documentation).
    final FileSet docbuildeFileSet = (FileSet) proj.getReference("docbuild.jarfiles");
    if (null != docbuildeFileSet) {
      fileSets.add(docbuildeFileSet);
      log("Found build results (docbuild.jarfiles): " + docbuildeFileSet, Project.MSG_DEBUG);
    }

    if (0 < fileSets.size()) {
      final BundleArchives bas = new BundleArchives(this, fileSets, true);
      bas.doProviders();
      return bas;
    }
    return null;
  }
  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);
  }