Search in sources :

Example 76 with RuntimeEnvironment

use of org.opensolaris.opengrok.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.
 * @throws Exception
 */
@Test
@ConditionalRun(condition = RepositoryInstalled.MercurialInstalled.class)
public void testRemoveFileOnFileChange() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    if (!env.validateExuberantCtags()) {
        System.out.println("Skipping test due to no ctags");
    }
    TestRepository testrepo = new TestRepository();
    testrepo.create(HistoryGuru.class.getResourceAsStream("repositories.zip"));
    env.setSourceRoot(testrepo.getSourceRoot());
    env.setDataRoot(testrepo.getDataRoot());
    env.setRepositories(testrepo.getSourceRoot());
    // create index
    Project project = new Project("mercurial", "/mercurial");
    IndexDatabase idb = new IndexDatabase(project);
    assertNotNull(idb);
    RemoveIndexChangeListener listener = new RemoveIndexChangeListener();
    idb.addIndexChangedListener(listener);
    idb.update(parallelizer);
    Assert.assertEquals(5, listener.filesToAdd.size());
    listener.reset();
    // Change a file so that it gets picked up by the indexer.
    Thread.sleep(1100);
    File bar = new File(testrepo.getSourceRoot() + File.separator + "mercurial", "bar.txt");
    Assert.assertTrue(bar.exists());
    FileWriter fw = new FileWriter(bar, true);
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write("foo\n");
    bw.close();
    fw.close();
    // reindex
    idb.update(parallelizer);
    // 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.opensolaris.opengrok.configuration.Project) TestRepository(org.opensolaris.opengrok.util.TestRepository) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) FileWriter(java.io.FileWriter) HistoryGuru(org.opensolaris.opengrok.history.HistoryGuru) File(java.io.File) BufferedWriter(java.io.BufferedWriter) ConditionalRun(org.opensolaris.opengrok.condition.ConditionalRun) Test(org.junit.Test)

Example 77 with RuntimeEnvironment

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

the class IndexerTest method testDefaultProjectsNonExistent.

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

Example 78 with RuntimeEnvironment

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

the class IndexerTest method testBug3430.

@Test
public void testBug3430() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    if (env.validateExuberantCtags()) {
        Project project = new Project("bug3430");
        project.setPath("/bug3430");
        IndexDatabase idb = new IndexDatabase(project);
        assertNotNull(idb);
        MyIndexChangeListener listener = new MyIndexChangeListener();
        idb.addIndexChangedListener(listener);
        idb.update(parallelizer);
        assertEquals(1, listener.files.size());
    } else {
        System.out.println("Skipping test. Could not find a ctags I could use in path.");
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) Test(org.junit.Test)

Example 79 with RuntimeEnvironment

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

the class TestRepository method createEmpty.

public void createEmpty() throws IOException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    sourceRoot = FileUtilities.createTemporaryDirectory("source");
    dataRoot = FileUtilities.createTemporaryDirectory("data");
    env.setSourceRoot(sourceRoot.getAbsolutePath());
    env.setDataRoot(dataRoot.getAbsolutePath());
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment)

Example 80 with RuntimeEnvironment

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

the class DirectoryListingTest method setUp.

@Before
public void setUp() throws Exception {
    directory = FileUtilities.createTemporaryDirectory("directory");
    entries = new FileEntry[3];
    entries[0] = new FileEntry("foo.c", "foo.c", 0, 112);
    entries[1] = new FileEntry("bar.h", "bar.h", Long.MAX_VALUE, 0);
    // Will test getSimplifiedPath() behavior for ignored directories.
    // Use DIRECTORY_INTERNAL_SIZE value for length so it is checked as the directory
    // should contain "-" (DIRECTORY_SIZE_PLACEHOLDER) string.
    entries[2] = new FileEntry("subdir", "subdir/", 0, Arrays.asList(new FileEntry[] { new FileEntry("SCCS", "SCCS/", 0, Arrays.asList(new FileEntry[] { new FileEntry("version", "version", 0, 312) })) }));
    for (FileEntry entry : entries) {
        entry.create();
    }
    // Create the entry that will be ignored separately.
    FileEntry hgtags = new FileEntry(".hgtags", ".hgtags", 0, 1);
    hgtags.create();
    // Need to populate list of ignored entries for all repository types.
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    RepositoryFactory.initializeIgnoredNames(env);
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) Before(org.junit.Before)

Aggregations

RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)81 File (java.io.File)31 Project (org.opensolaris.opengrok.configuration.Project)27 IOException (java.io.IOException)23 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)17 TestRepository (org.opensolaris.opengrok.util.TestRepository)13 ForbiddenSymlinkException (org.opensolaris.opengrok.util.ForbiddenSymlinkException)12 BeforeClass (org.junit.BeforeClass)11 Ctags (org.opensolaris.opengrok.analysis.Ctags)6 BufferedReader (java.io.BufferedReader)5 FileNotFoundException (java.io.FileNotFoundException)5 InputStreamReader (java.io.InputStreamReader)5 ParseException (java.text.ParseException)5 DateFormat (java.text.DateFormat)4 Date (java.util.Date)4 RepositoryInfo (org.opensolaris.opengrok.history.RepositoryInfo)4 OutputStreamWriter (java.io.OutputStreamWriter)3 ConnectException (java.net.ConnectException)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3