Class Indexer

java.lang.Object
org.opengrok.indexer.index.Indexer

public final class Indexer extends Object
Creates and updates an inverted source index as well as generates Xref, file stats etc., if specified in the options.

We shall use / as path delimiter in whole opengrok for uuids and paths from Windows systems, the path shall be converted when entering the index or web and converted back if needed* to access original file

Windows already supports opening /var/opengrok as C:\var\opengrok

  • Field Details

    • PATH_SEPARATOR

      public static final char PATH_SEPARATOR
      See Also:
    • PATH_SEPARATOR_STRING

      public static final String PATH_SEPARATOR_STRING
  • Method Details

    • getInstance

      public static Indexer getInstance()
    • main

      public static void main(String[] argv)
      Program entry point.
      Parameters:
      argv - argument vector
    • runMain

      @VisibleForTesting public static int runMain(String[] argv)
      The body of main(String[]). Avoids System.exit() so that it can be used for testing without the test runner thinking the VM went away unexpectedly.
      Parameters:
      argv - argument vector passed from the wrapper
      Returns:
      0 on success, positive number on error
    • parseOptions

      public static String[] parseOptions(String[] argv) throws ParseException
      Parse OpenGrok Indexer options This method was created so that it would be easier to write unit tests against the Indexer option parsing mechanism.

      Limit usage lines to OptionParser.Option.MAX_DESCRIPTION_LINE_LENGTH characters for concise formatting.

      Parameters:
      argv - the command line arguments
      Returns:
      array of remaining non option arguments
      Throws:
      ParseException - if parsing failed
    • writeConfigToFile

      public static void writeConfigToFile(RuntimeEnvironment env, String filename) throws IOException
      Write configuration to a file.
      Parameters:
      env - runtime environment
      filename - file name to write the configuration to
      Throws:
      IOException - if I/O exception occurred
    • prepareIndexer

      @TestOnly public Map<Repository,Optional<Exception>> prepareIndexer(RuntimeEnvironment env, boolean searchRepositories, boolean addProjects, List<String> subFiles, List<String> repositories) throws IndexerException, IOException
      Wrapper for prepareIndexer() that always generates history cache.
      Returns:
      map of repository to optional exception
      Throws:
      IndexerException
      IOException
    • prepareIndexer

      public Map<Repository,Optional<Exception>> prepareIndexer(RuntimeEnvironment env, Set<String> searchPaths, boolean addProjects, boolean createHistoryCache, List<String> repositories) throws IndexerException
      Generate history cache and/or scan the repositories.

      This is the first phase of the indexing where history cache is being generated for repositories (at least for those which support getting history per directory).

      Parameters:
      env - runtime environment
      searchPaths - list of paths relative to source root in which to search for repositories
      addProjects - if true, add projects
      createHistoryCache - create history cache flag
      repositories - list of repository paths relative to source root
      Returns:
      map of repository to exception
      Throws:
      IndexerException - indexer exception
    • doIndexerExecution

      @VisibleForTesting public void doIndexerExecution(Set<Project> projects, IndexChangedListener progress) throws IOException, IndexerException
      Throws:
      IOException
      IndexerException
    • doIndexerExecution

      public void doIndexerExecution(@Nullable @Nullable Set<Project> projects, @Nullable @Nullable IndexChangedListener progress, Map<Repository,Optional<Exception>> historyCacheResults) throws IOException, IndexerException
      This is the second phase of the indexer which generates Lucene index by passing source code files through ctags, generating xrefs and storing data from the source files in the index (along with history, if any).
      Parameters:
      projects - if not null, index just the projects specified
      progress - if not null, an object to receive notifications as indexer progress is made
      historyCacheResults - per repository results of history cache update
      Throws:
      IOException - if I/O exception occurred
      IndexerException - if the indexing has failed for any reason
    • sendToConfigHost

      public void sendToConfigHost(RuntimeEnvironment env, String webAppURI)