Search in sources :

Example 36 with RuntimeEnvironment

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

the class IndexerRepoTest method testSymlinks.

/**
 * Test that symlinked directories from source root get their relative
 * path set correctly in RepositoryInfo objects.
 */
@EnabledForRepository(MERCURIAL)
@Test
public void testSymlinks() throws IndexerException, IOException {
    final String SYMLINK = "symlink";
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    // Set source root to pristine directory so that there is only one
    // repository to deal with (which makes this faster and easier to write)
    // and clone the mercurial repository outside of the source root.
    Path realSource = Files.createTempDirectory("real");
    Path sourceRoot = Files.createTempDirectory("src");
    MercurialRepositoryTest.runHgCommand(sourceRoot.toFile(), "clone", repository.getSourceRoot() + File.separator + "mercurial", realSource.toString());
    // Create symlink from source root to the real repository.
    String symlinkPath = sourceRoot.toString() + File.separator + SYMLINK;
    Files.createSymbolicLink(Paths.get(symlinkPath), realSource);
    // Use alternative source root.
    env.setSourceRoot(sourceRoot.toString());
    // Need to have history cache enabled in order to perform scan of repositories.
    env.setHistoryEnabled(true);
    // Normally the Indexer would add the symlink automatically.
    env.setAllowedSymlinks(new HashSet<>(Arrays.asList(symlinkPath)));
    // 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, // search for repositories
    true, // 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);
    // Check the repository paths.
    List<RepositoryInfo> repos = env.getRepositories();
    assertEquals(repos.size(), 1);
    RepositoryInfo repo = repos.get(0);
    assertEquals(File.separator + SYMLINK, repo.getDirectoryNameRelative());
    String epath = sourceRoot.toString() + File.separator + SYMLINK;
    String apath = repo.getDirectoryName();
    assertTrue(epath.equals(apath) || apath.equals("/private" + epath), "Should match (with macOS leeway):\n" + epath + "\nv.\n" + apath);
    // Check that history exists for a file in the repository.
    File repoRoot = new File(env.getSourceRootFile(), SYMLINK);
    File fileInRepo = new File(repoRoot, "main.c");
    assertTrue(fileInRepo.exists());
    assertTrue(HistoryGuru.getInstance().hasHistory(fileInRepo));
    assertTrue(HistoryGuru.getInstance().hasCacheForFile(fileInRepo));
    // cleanup
    IOUtils.removeRecursive(realSource);
    IOUtils.removeRecursive(sourceRoot);
}
Also used : Path(java.nio.file.Path) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) File(java.io.File) MercurialRepositoryTest(org.opengrok.indexer.history.MercurialRepositoryTest) Test(org.junit.jupiter.api.Test) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 37 with RuntimeEnvironment

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

the class IndexerRepoTest method testPerProjectHistory.

private void testPerProjectHistory(boolean globalOn) throws IndexerException, IOException, HistoryException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    // Make sure we start from scratch.
    Path dataRoot = Files.createTempDirectory("dataForPerProjectHistoryTest");
    env.setDataRoot(dataRoot.toString());
    env.setProjectsEnabled(true);
    env.setHistoryEnabled(globalOn);
    Project proj = new Project("mercurial", "/mercurial");
    proj.setHistoryEnabled(!globalOn);
    env.getProjects().clear();
    env.getProjects().put("mercurial", proj);
    Indexer.getInstance().prepareIndexer(env, // search for repositories
    true, // 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);
    File repoRoot = new File(env.getSourceRootFile(), "git");
    File fileInRepo = new File(repoRoot, "main.c");
    assertTrue(fileInRepo.exists());
    if (globalOn) {
        assertNotNull(HistoryGuru.getInstance().getHistory(fileInRepo));
    } else {
        assertNull(HistoryGuru.getInstance().getHistory(fileInRepo));
    }
    repoRoot = new File(env.getSourceRootFile(), "mercurial");
    fileInRepo = new File(repoRoot, "main.c");
    assertTrue(fileInRepo.exists());
    if (globalOn) {
        assertNull(HistoryGuru.getInstance().getHistory(fileInRepo));
    } else {
        assertNotNull(HistoryGuru.getInstance().getHistory(fileInRepo));
    }
    IOUtils.removeRecursive(dataRoot);
}
Also used : Path(java.nio.file.Path) Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) File(java.io.File)

Example 38 with RuntimeEnvironment

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

the class PerforceRepositoryTest method setUpClass.

@BeforeAll
public static void setUpClass() {
    if (!root.exists()) {
        skip = true;
    } else {
        files = new ArrayList<>();
        RuntimeEnvironment env = RuntimeEnvironment.getInstance();
        RepositoryFactory.initializeIgnoredNames(env);
        FileUtilities.getAllFiles(root, files, false);
        env.setSourceRoot(root.getAbsolutePath());
    }
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 39 with RuntimeEnvironment

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

the class RepositoryWithPerPartesHistoryTest method testPerPartesOff.

@Test
void testPerPartesOff() throws HistoryException {
    FileHistoryCache cache = new FileHistoryCache();
    FileHistoryCache spyCache = Mockito.spy(cache);
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setHistoryCachePerPartesEnabled(false);
    assertFalse(env.isHistoryCachePerPartesEnabled());
    // Use non-null revision for better robustness (in case sinceRevision gets mixed up with tillRevision).
    gitRepository.createCache(spyCache, "b6413947a59f481ddc0a05e0d181731233557f6e");
    verify(spyCache, times(1)).store(any(), any(), isNull());
    env.setHistoryCachePerPartesEnabled(true);
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Test(org.junit.jupiter.api.Test)

Example 40 with RuntimeEnvironment

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

the class IndexCheckTest method setUpClass.

@BeforeAll
public static void setUpClass() {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    RepositoryFactory.initializeIgnoredNames(env);
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) BeforeAll(org.junit.jupiter.api.BeforeAll)

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