Esempio n. 1
0
  /**
   * Optimize all index databases
   *
   * @param executor An executor to run the job
   * @throws IOException if an error occurs
   */
  static void optimizeAll(ExecutorService executor) throws IOException {
    List<IndexDatabase> dbs = new ArrayList<IndexDatabase>();
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    if (env.hasProjects()) {
      for (Project project : env.getProjects()) {
        dbs.add(new IndexDatabase(project));
      }
    } else {
      dbs.add(new IndexDatabase());
    }

    for (IndexDatabase d : dbs) {
      final IndexDatabase db = d;
      if (db.isDirty()) {
        executor.submit(
            new Runnable() {
              @Override
              public void run() {
                try {
                  db.update();
                } catch (Throwable e) {
                  log.log(Level.SEVERE, "Problem updating lucene index database: ", e);
                }
              }
            });
      }
    }
  }
Esempio n. 2
0
  static void listFrequentTokens(List<String> subFiles) throws IOException {
    final int limit = 4;

    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    if (env.hasProjects()) {
      if (subFiles == null || subFiles.isEmpty()) {
        for (Project project : env.getProjects()) {
          IndexDatabase db = new IndexDatabase(project);
          db.listTokens(4);
        }
      } else {
        for (String path : subFiles) {
          Project project = Project.getProject(path);
          if (project == null) {
            log.log(Level.WARNING, "Warning: Could not find a project for \"{0}\"", path);
          } else {
            IndexDatabase db = new IndexDatabase(project);
            db.listTokens(4);
          }
        }
      }
    } else {
      IndexDatabase db = new IndexDatabase();
      db.listTokens(limit);
    }
  }
Esempio n. 3
0
  /**
   * Update the index database for all of the projects
   *
   * @param executor An executor to run the job
   * @param listener where to signal the changes to the database
   * @throws IOException if an error occurs
   */
  static void updateAll(ExecutorService executor, IndexChangedListener listener)
      throws IOException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    List<IndexDatabase> dbs = new ArrayList<>();

    if (env.hasProjects()) {
      for (Project project : env.getProjects()) {
        dbs.add(new IndexDatabase(project));
      }
    } else {
      dbs.add(new IndexDatabase());
    }

    for (IndexDatabase d : dbs) {
      final IndexDatabase db = d;
      if (listener != null) {
        db.addIndexChangedListener(listener);
      }

      executor.submit(
          new Runnable() {
            @Override
            public void run() {
              try {
                db.update();
              } catch (Throwable e) {
                LOGGER.log(Level.SEVERE, "Problem updating lucene index database: ", e);
              }
            }
          });
    }
  }
Esempio n. 4
0
  /**
   * Update the index database for a number of sub-directories
   *
   * @param executor An executor to run the job
   * @param listener where to signal the changes to the database
   * @param paths
   * @throws IOException if an error occurs
   */
  public static void update(
      ExecutorService executor, IndexChangedListener listener, List<String> paths)
      throws IOException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    List<IndexDatabase> dbs = new ArrayList<IndexDatabase>();

    for (String path : paths) {
      Project project = Project.getProject(path);
      if (project == null && env.hasProjects()) {
        log.log(Level.WARNING, "Could not find a project for \"{0}\"", path);
      } else {
        IndexDatabase db;

        try {
          if (project == null) {
            db = new IndexDatabase();
          } else {
            db = new IndexDatabase(project);
          }

          int idx = dbs.indexOf(db);
          if (idx != -1) {
            db = dbs.get(idx);
          }

          if (db.addDirectory(path)) {
            if (idx == -1) {
              dbs.add(db);
            }
          } else {
            log.log(Level.WARNING, "Directory does not exist \"{0}\"", path);
          }
        } catch (IOException e) {
          log.log(Level.WARNING, "An error occured while updating index", e);
        }
      }

      for (final IndexDatabase db : dbs) {
        db.addIndexChangedListener(listener);
        executor.submit(
            new Runnable() {
              @Override
              public void run() {
                try {
                  db.update();
                } catch (Throwable e) {
                  log.log(Level.SEVERE, "An error occured while updating index", e);
                }
              }
            });
      }
    }
  }
Esempio n. 5
0
  /**
   * Check if a file is local to the current project. If we don't have projects, check if the file
   * is in the source root.
   *
   * @param path the path to a file
   * @return true if the file is local to the current repository
   */
  private boolean isLocal(String path) {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String srcRoot = env.getSourceRootPath();

    boolean local = false;

    if (path.startsWith(srcRoot)) {
      if (env.hasProjects()) {
        String relPath = path.substring(srcRoot.length());
        if (project.equals(Project.getProject(relPath))) {
          // File is under the current project, so it's local.
          local = true;
        }
      } else {
        // File is under source root, and we don't have projects, so
        // consider it local.
        local = true;
      }
    }

    return local;
  }
Esempio n. 6
0
 /**
  * Dump the configuration as an HTML table.
  *
  * @param out destination for the HTML output
  * @throws IOException if an error happens while writing to {@code out}
  * @throws HistoryException if the history guru cannot be accesses
  */
 @SuppressWarnings("boxing")
 public static void dumpConfiguration(Appendable out) throws IOException, HistoryException {
   out.append("<table border=\"1\" width=\"100%\">");
   out.append("<tr><th>Variable</th><th>Value</th></tr>");
   RuntimeEnvironment env = RuntimeEnvironment.getInstance();
   printTableRow(out, "Source root", env.getSourceRootPath());
   printTableRow(out, "Data root", env.getDataRootPath());
   printTableRow(out, "CTags", env.getCtags());
   printTableRow(out, "Bug page", env.getBugPage());
   printTableRow(out, "Bug pattern", env.getBugPattern());
   printTableRow(out, "User page", env.getUserPage());
   printTableRow(out, "User page suffix", env.getUserPageSuffix());
   printTableRow(out, "Review page", env.getReviewPage());
   printTableRow(out, "Review pattern", env.getReviewPattern());
   printTableRow(out, "Using projects", env.hasProjects());
   out.append("<tr><td>Ignored files</td><td>");
   printUnorderedList(out, env.getIgnoredNames().getItems());
   out.append("</td></tr>");
   printTableRow(out, "Index word limit", env.getIndexWordLimit());
   printTableRow(out, "Allow leading wildcard in search", env.isAllowLeadingWildcard());
   printTableRow(out, "History cache", HistoryGuru.getInstance().getCacheInfo());
   out.append("</table>");
 }
Esempio n. 7
0
  /**
   * Get an indexReader for the Index database where a given file
   *
   * @param path the file to get the database for
   * @return The index database where the file should be located or null if it cannot be located.
   */
  public static IndexReader getIndexReader(String path) {
    IndexReader ret = null;

    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    File indexDir = new File(env.getDataRootFile(), "index");

    if (env.hasProjects()) {
      Project p = Project.getProject(path);
      if (p == null) {
        return null;
      }
      indexDir = new File(indexDir, p.getPath());
    }
    try {
      FSDirectory fdir = FSDirectory.open(indexDir, NoLockFactory.getNoLockFactory());
      if (indexDir.exists() && DirectoryReader.indexExists(fdir)) {
        ret = DirectoryReader.open(fdir);
      }
    } catch (Exception ex) {
      log.log(Level.SEVERE, "Failed to open index: {0}", indexDir.getAbsolutePath());
      log.log(Level.FINE, "Stack Trace: ", ex);
    }
    return ret;
  }
Esempio n. 8
0
 /**
  * List all files in some of the index databases
  *
  * @param subFiles Subdirectories for the various projects to list the files for (or null or an
  *     empty list to dump all projects)
  * @throws IOException if an error occurs
  */
 public static void listAllFiles(List<String> subFiles) throws IOException {
   RuntimeEnvironment env = RuntimeEnvironment.getInstance();
   if (env.hasProjects()) {
     if (subFiles == null || subFiles.isEmpty()) {
       for (Project project : env.getProjects()) {
         IndexDatabase db = new IndexDatabase(project);
         db.listFiles();
       }
     } else {
       for (String path : subFiles) {
         Project project = Project.getProject(path);
         if (project == null) {
           LOGGER.log(Level.WARNING, "Could not find a project for \"{0}\"", path);
         } else {
           IndexDatabase db = new IndexDatabase(project);
           db.listFiles();
         }
       }
     }
   } else {
     IndexDatabase db = new IndexDatabase();
     db.listFiles();
   }
 }