use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.
the class IndexerTest method testDefaultProjectsAll.
/**
* Should include all projects in the source root.
*
* @throws Exception
*/
@Test
public void testDefaultProjectsAll() 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[] { "/c", "/data", "__all__", "/no-project-x32ds1" })), false, false, null, null, new ArrayList<>(), false);
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 p) -> p.getName()).collect(Collectors.toSet()));
}
use of org.opensolaris.opengrok.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.
* @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();
}
use of org.opensolaris.opengrok.configuration.Project 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()));
}
use of org.opensolaris.opengrok.configuration.Project 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.");
}
}
use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.
the class PageConfigTest method testGetResourceFileList.
/**
* Testing the root of /xref for authorization filtering.
*/
@Test
public void testGetResourceFileList() {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
// backup original values
String oldSourceRootPath = env.getSourceRootPath();
AuthorizationFramework oldAuthorizationFramework = env.getAuthorizationFramework();
Map<String, Project> oldProjects = env.getProjects();
// Set up the source root directory containing some projects.
env.setSourceRoot(repository.getSourceRoot());
env.setProjectsEnabled(true);
// Enable projects.
for (String file : new File(repository.getSourceRoot()).list()) {
Project proj = new Project(file);
proj.setIndexed(true);
env.getProjects().put(file, proj);
}
HttpServletRequest req = createRequest("/source", "/xref", "");
PageConfig cfg = PageConfig.get(req);
List<String> allFiles = new ArrayList<>(cfg.getResourceFileList());
/**
* Check if there are some files (the "5" here is just a sufficient
* value for now which won't break any future repository tests) without
* any authorization.
*/
assertTrue(allFiles.size() > 5);
assertTrue(allFiles.contains("git"));
assertTrue(allFiles.contains("mercurial"));
/**
* Now set up the same projects with authorization plugin enabling only
* some of them.
* <pre>
* - disabling "git"
* - disabling "mercurial"
* </pre>
*/
env.setAuthorizationFramework(new AuthorizationFramework());
env.getAuthorizationFramework().reload();
env.getAuthorizationFramework().getStack().add(new AuthorizationPlugin(AuthControlFlag.REQUIRED, new TestPlugin() {
@Override
public boolean isAllowed(HttpServletRequest request, Project project) {
return !project.getName().startsWith("git") && !project.getName().startsWith("mercurial");
}
}));
req = createRequest("/source", "/xref", "");
cfg = PageConfig.get(req);
List<String> filteredFiles = new ArrayList<>(cfg.getResourceFileList());
// list subtraction - retains only disabled files
allFiles.removeAll(filteredFiles);
assertEquals(2, allFiles.size());
assertTrue(allFiles.contains("git"));
assertTrue(allFiles.contains("mercurial"));
// restore original values
env.setAuthorizationFramework(oldAuthorizationFramework);
env.setSourceRoot(oldSourceRootPath);
env.setProjects(oldProjects);
}
Aggregations