Search in sources :

Example 56 with RuntimeEnvironment

use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class Util method dumpConfiguration.

/**
 * 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.isProjectsEnabled());
    out.append("<tr><td>Ignored files</td><td>");
    printUnorderedList(out, env.getIgnoredNames().getItems());
    out.append("</td></tr>");
    printTableRow(out, "lucene RAM_BUFFER_SIZE_MB", env.getRamBufferSize());
    printTableRow(out, "Allow leading wildcard in search", env.isAllowLeadingWildcard());
    printTableRow(out, "History cache", HistoryGuru.getInstance().getCacheInfo());
    printTableRow(out, "Authorization plugin directory", env.getPluginDirectory());
    printTableRow(out, "Authorization watchdog directory", env.getPluginDirectory());
    printTableRow(out, "Authorization watchdog enabled", env.isAuthorizationWatchdog());
    printTableRow(out, "Authorization stack", "<pre>" + env.getAuthorizationFramework().getStack().hierarchyToString() + "</pre>");
    out.append("</table>");
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment)

Example 57 with RuntimeEnvironment

use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class IndexerMainTest method testMainWithH.

/**
 * Test cleanup of renamed thread pool after indexing with -H.
 */
@Test
public void testMainWithH() {
    System.out.println("Generate index by using command line options with -H");
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String[] argv = { "-S", "-H", "-s", repository.getSourceRoot(), "-d", repository.getDataRoot(), "-v", "-c", env.getCtags() };
    Indexer.main(argv);
    checkNumberOfThreads();
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Test(org.junit.jupiter.api.Test)

Example 58 with RuntimeEnvironment

use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class IndexerTest method testDefaultProjectsNonExistent.

/**
 * Should discard the non existing project.
 * @throws Exception
 */
@Test
void testDefaultProjectsNonExistent() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    env.setHistoryEnabled(false);
    Set<String> projectSet = new TreeSet<>();
    projectSet.add("/lisp");
    projectSet.add("/pascal");
    projectSet.add("/perl");
    projectSet.add("/data");
    projectSet.add("/no-project-x32ds1");
    Indexer.getInstance().prepareIndexer(env, true, true, false, null, null);
    env.setDefaultProjectsFromNames(projectSet);
    assertEquals(4, env.getDefaultProjects().size());
    assertEquals(new TreeSet<>(Arrays.asList("lisp", "pascal", "perl", "data")), env.getDefaultProjects().stream().map(Project::getName).collect(Collectors.toSet()));
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) TreeSet(java.util.TreeSet) Test(org.junit.jupiter.api.Test)

Example 59 with RuntimeEnvironment

use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class IndexerTest method testRemoveFileOnFileChange.

/**
 * Test that reindex after changing a file does not wipe out history index
 * for this file. This is important for the incremental history indexing.
 */
@Test
@EnabledForRepository(MERCURIAL)
void testRemoveFileOnFileChange() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String path = "/mercurial/bar.txt";
    TestRepository testrepo = new TestRepository();
    testrepo.create(HistoryGuru.class.getResource("/repositories"));
    env.setSourceRoot(testrepo.getSourceRoot());
    env.setDataRoot(testrepo.getDataRoot());
    env.setRepositories(testrepo.getSourceRoot());
    // Create history cache.
    Indexer.getInstance().prepareIndexer(env, true, true, false, null, List.of("mercurial"));
    File historyFile = new File(env.getDataRootPath(), TandemPath.join("historycache" + path, ".gz"));
    assertTrue(historyFile.exists(), String.format("history cache for %s has to exist", path));
    // create index
    Project project = new Project("mercurial", "/mercurial");
    IndexDatabase idb = new IndexDatabase(project);
    assertNotNull(idb);
    RemoveIndexChangeListener listener = new RemoveIndexChangeListener(path);
    idb.addIndexChangedListener(listener);
    idb.update();
    assertEquals(5, listener.filesToAdd.size());
    listener.reset();
    // Change a file so that it gets picked up by the indexer.
    File bar = new File(testrepo.getSourceRoot() + File.separator + "mercurial", "bar.txt");
    assertTrue(bar.exists());
    try (BufferedWriter bw = new BufferedWriter(new FileWriter(bar, true))) {
        bw.write("foo\n");
    }
    // reindex
    idb.update();
    // Make sure that the file was actually processed.
    assertEquals(1, listener.removedFiles.size());
    assertEquals(1, listener.filesToAdd.size());
    assertEquals("/mercurial/bar.txt", listener.removedFiles.peek());
    testrepo.destroy();
}
Also used : Project(org.opengrok.indexer.configuration.Project) TestRepository(org.opengrok.indexer.util.TestRepository) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) FileWriter(java.io.FileWriter) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) File(java.io.File) BufferedWriter(java.io.BufferedWriter) Test(org.junit.jupiter.api.Test) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 60 with RuntimeEnvironment

use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class IndexerTest method testRescanProjects.

/**
 * Test that rescanning for projects does not erase customization of
 * existing projects. Bug #16006.
 */
@Test
void testRescanProjects() throws Exception {
    // Generate one project that will be found in source.zip, and set
    // some properties that we can verify after the rescan.
    Project p1 = new Project("java", "/java");
    p1.setTabSize(3);
    // Generate one project that will not be found in source.zip, and that
    // should not be in the list of projects after the rescan.
    Project p2 = new Project("Project 2", "/this_path_does_not_exist");
    // Make the runtime environment aware of these two projects.
    Map<String, Project> projects = new HashMap<>();
    projects.put(p1.getName(), p1);
    projects.put("nonexistent", p2);
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setProjects(projects);
    env.setHistoryEnabled(false);
    // Do a rescan of the projects, and only that (we don't care about
    // the other aspects of indexing in this test case).
    Indexer.getInstance().prepareIndexer(env, // don't search for repositories
    false, // scan and add projects
    true, // don't create dictionary
    false, // subFiles - not needed since we don't list files
    null, // repositories - not needed when not refreshing history
    null);
    List<Project> newProjects = env.getProjectList();
    // p2 should not be in the project list anymore
    for (Project p : newProjects) {
        assertNotEquals(p.getPath(), p2.getPath(), "p2 not removed");
    }
    // p1 should be there
    Project newP1 = null;
    for (Project p : newProjects) {
        if (p.getPath().equals(p1.getPath())) {
            newP1 = p;
            break;
        }
    }
    assertNotNull(newP1, "p1 not in list");
    // The properties of p1 should be preserved
    assertEquals(p1.getPath(), newP1.getPath(), "project path");
    assertEquals(p1.getName(), newP1.getName(), "project name");
    assertEquals(p1.getTabSize(), newP1.getTabSize(), "project tabsize");
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Aggregations

RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)81 File (java.io.File)26 Project (org.opengrok.indexer.configuration.Project)24 Test (org.junit.jupiter.api.Test)22 IOException (java.io.IOException)18 BeforeAll (org.junit.jupiter.api.BeforeAll)13 ArrayList (java.util.ArrayList)12 TestRepository (org.opengrok.indexer.util.TestRepository)12 Path (java.nio.file.Path)8 ForbiddenSymlinkException (org.opengrok.indexer.util.ForbiddenSymlinkException)8 Document (org.apache.lucene.document.Document)6 Ctags (org.opengrok.indexer.analysis.Ctags)6 Executor (org.opengrok.indexer.util.Executor)6 BufferedReader (java.io.BufferedReader)5 FileNotFoundException (java.io.FileNotFoundException)5 InputStreamReader (java.io.InputStreamReader)5 EnabledForRepository (org.opengrok.indexer.condition.EnabledForRepository)5 HistoryGuru (org.opengrok.indexer.history.HistoryGuru)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)4