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);
}
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);
}
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());
}
}
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);
}
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);
}
Aggregations