Search in sources :

Example 51 with Project

use of org.opengrok.indexer.configuration.Project 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 52 with Project

use of org.opengrok.indexer.configuration.Project 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 53 with Project

use of org.opengrok.indexer.configuration.Project 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)

Example 54 with Project

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

the class IndexerTest method testDefaultProjectsAll.

/**
 * Should include all projects in the source root.
 * @throws Exception
 */
@Test
void testDefaultProjectsAll() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    env.setHistoryEnabled(false);
    Set<String> defaultProjects = new TreeSet<>();
    defaultProjects.add("/c");
    defaultProjects.add("/data");
    defaultProjects.add("__all__");
    defaultProjects.add("/no-project-x32ds1");
    Indexer.getInstance().prepareIndexer(env, true, true, false, null, null);
    env.setDefaultProjectsFromNames(defaultProjects);
    Set<String> projects = new TreeSet<>(Arrays.asList(new File(repository.getSourceRoot()).list()));
    assertEquals(projects.size(), env.getDefaultProjects().size());
    assertEquals(projects, 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) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 55 with Project

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

the class IndexerTest method testIncrementalIndexAddRemoveFile.

/**
 * Test IndexChangedListener behavior in repository with invalid files.
 * @throws Exception
 */
@Test
void testIncrementalIndexAddRemoveFile() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    String ppath = "/bug3430";
    Project project = new Project("bug3430", ppath);
    IndexDatabase idb = new IndexDatabase(project);
    assertNotNull(idb);
    MyIndexChangeListener listener = new MyIndexChangeListener();
    idb.addIndexChangedListener(listener);
    idb.update();
    assertEquals(1, listener.files.size());
    listener.reset();
    repository.addDummyFile(ppath);
    idb.update();
    assertEquals(1, listener.files.size(), "No new file added");
    repository.removeDummyFile(ppath);
    idb.update();
    assertEquals(1, listener.files.size(), "(added)files changed unexpectedly");
    assertEquals(1, listener.removedFiles.size(), "Didn't remove the dummy file");
    assertEquals(listener.files.peek(), listener.removedFiles.peek(), "Should have added then removed the same file");
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

Project (org.opengrok.indexer.configuration.Project)88 Test (org.junit.jupiter.api.Test)42 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)27 File (java.io.File)22 Group (org.opengrok.indexer.configuration.Group)20 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)17 ArrayList (java.util.ArrayList)16 TreeSet (java.util.TreeSet)11 IOException (java.io.IOException)10 DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)10 List (java.util.List)8 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)7 Path (jakarta.ws.rs.Path)7 HistoryGuru (org.opengrok.indexer.history.HistoryGuru)7 Path (java.nio.file.Path)6 Map (java.util.Map)6 Paths (java.nio.file.Paths)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 MercurialRepositoryTest (org.opengrok.indexer.history.MercurialRepositoryTest)5