use of org.opengrok.indexer.history.RepositoryInfo 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.history.RepositoryInfo in project OpenGrok by OpenGrok.
the class IndexerTest method testIndexWithSetIndexVersionedFilesOnly.
/**
* Test indexing w.r.t. setIndexVersionedFilesOnly() setting,
* i.e. if this option is set to true, index only files tracked by SCM.
* @throws Exception
*/
@Test
void testIndexWithSetIndexVersionedFilesOnly() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setSourceRoot(repository.getSourceRoot());
env.setDataRoot(repository.getDataRoot());
env.setRepositories(repository.getSourceRoot());
List<RepositoryInfo> repos = env.getRepositories();
Repository r = null;
for (RepositoryInfo ri : repos) {
if (ri.getDirectoryName().equals(repository.getSourceRoot() + "/rfe2575")) {
r = RepositoryFactory.getRepository(ri, CommandTimeoutType.INDEXER);
break;
}
}
if (r != null && r.isWorking()) {
Project project = new Project("rfe2575");
project.setPath("/rfe2575");
IndexDatabase idb = new IndexDatabase(project);
assertNotNull(idb);
MyIndexChangeListener listener = new MyIndexChangeListener();
idb.addIndexChangedListener(listener);
idb.update();
assertEquals(2, listener.files.size());
repository.purgeData();
RuntimeEnvironment.getInstance().setIndexVersionedFilesOnly(true);
idb = new IndexDatabase(project);
listener = new MyIndexChangeListener();
idb.addIndexChangedListener(listener);
idb.update();
assertEquals(1, listener.files.size());
RuntimeEnvironment.getInstance().setIndexVersionedFilesOnly(false);
} else {
System.out.println("Skipping test. Repository for rfe2575 not found or an sccs I could use in path.");
}
}
use of org.opengrok.indexer.history.RepositoryInfo in project OpenGrok by OpenGrok.
the class ProjectHelperTest method testAllowedGetRepositoryInfo.
/**
* Test of getRepositoryInfo method, of class ProjectHelper.
*/
@Test
public void testAllowedGetRepositoryInfo() {
Project p = new Project("allowed_grouped_repository_0_1");
p.setIndexed(true);
List<RepositoryInfo> result = helper.getRepositoryInfo(p);
assertEquals(1, result.size());
assertEquals("allowed_grouped_repository_0_1_" + 0, result.get(0).getParent());
}
use of org.opengrok.indexer.history.RepositoryInfo in project OpenGrok by OpenGrok.
the class ProjectHelperTest method testSynchronization.
/**
* Test if projects and groups are always reloaded fully from the env.
*
* This ensures that when the RuntimeEnvironment changes that it also
* updates the projects in the UI.
*/
@Test
public void testSynchronization() {
HashMap<String, Project> oldProjects = new HashMap<>(env.getProjects());
List<RepositoryInfo> oldRepositories = new ArrayList<>(env.getRepositories());
Set<Group> oldGroups = new TreeSet<>(env.getGroups());
Map<Project, List<RepositoryInfo>> oldMap = new TreeMap<>(getRepositoriesMap());
env.getAuthorizationFramework().removeAll();
// needed for setDirectoryName() below
env.setSourceRoot("/src");
cfg = PageConfig.get(getRequest());
helper = cfg.getProjectHelper();
// basic setup
assertEquals(40, env.getProjects().size(), "There should be 40 env projects");
assertEquals(20, env.getRepositories().size(), "There should be 20 env repositories");
assertEquals(4, env.getGroups().size(), "There should be 4 env groups");
assertEquals(8, helper.getAllUngrouped().size(), "There are 8 ungrouped projects");
assertEquals(40, helper.getAllProjects().size(), "There are 40 projects");
assertEquals(4, helper.getRepositories().size(), "There are 4 projects");
assertEquals(4, helper.getGroups().size(), "There are 4 groups");
// project
Project p = new Project("some random name not in any group");
p.setIndexed(true);
// group
Group g = new Group("some random name of a group");
// repository
Project repo = new Project("some random name not in any other group");
repo.setIndexed(true);
RepositoryInfo info = new RepoRepository();
info.setParent(repo.getName());
info.setDirectoryName(new File("/foo"));
List<RepositoryInfo> infos = getRepositoriesMap().get(repo);
if (infos == null) {
infos = new ArrayList<>();
}
infos.add(info);
getRepositoriesMap().put(repo, infos);
env.getRepositories().add(info);
env.getProjects().put("foo", p);
env.getProjects().put("bar", repo);
env.getGroups().add(g);
assertEquals(42, env.getProjects().size());
assertEquals(21, env.getRepositories().size());
assertEquals(5, env.getGroups().size());
// simulate another request
cfg = PageConfig.get(getRequest());
helper = cfg.getProjectHelper();
// check for updates
assertEquals(10, helper.getAllUngrouped().size(), "The helper state should refresh");
assertEquals(42, helper.getAllProjects().size(), "The helper state should refresh");
assertEquals(5, helper.getRepositories().size(), "The helper state should refresh");
assertEquals(5, helper.getGroups().size(), "The helper state should refresh");
setRepositoriesMap(oldMap);
env.setProjects(oldProjects);
env.setRepositories(oldRepositories);
env.setGroups(oldGroups);
}
use of org.opengrok.indexer.history.RepositoryInfo in project OpenGrok by OpenGrok.
the class ProjectHelperTestBase method getRepositoriesMap.
@SuppressWarnings("unchecked")
protected static Map<Project, List<RepositoryInfo>> getRepositoriesMap() {
try {
Field field = RuntimeEnvironment.class.getDeclaredField("repository_map");
field.setAccessible(true);
return (Map<Project, List<RepositoryInfo>>) field.get(RuntimeEnvironment.getInstance());
} catch (Throwable ex) {
throw new AssertionError("invoking getRepositoriesMap should not throw an exception");
}
}
Aggregations