use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.
the class HistoryContextTest method testGetContext4args.
@Test
@EnabledForRepository(MERCURIAL)
public void testGetContext4args() throws Exception {
String path = "/mercurial/Makefile";
Path file = Paths.get(repositories.getSourceRoot(), "mercurial", "Makefile");
String parent = file.getParent().toString();
String base = file.getFileName().toString();
// Construct a query equivalent to hist:dummy
TermQuery q1 = new TermQuery(new Term("hist", "dummy"));
StringWriter sw = new StringWriter();
assertTrue(new HistoryContext(q1).getContext(parent, base, path, sw, null), parent + " has context");
assertTrue(sw.toString().contains("Created a small <b>dummy</b> program"));
// Construct a query equivalent to hist:"dummy program"
PhraseQuery.Builder q2 = new PhraseQuery.Builder();
q2.add(new Term("hist", "dummy"));
q2.add(new Term("hist", "program"));
sw = new StringWriter();
assertTrue(new HistoryContext(q2.build()).getContext(parent, base, path, sw, null), parent + " has context");
assertTrue(sw.toString().contains("Created a small <b>dummy program</b>"));
// Search for a term that doesn't exist
TermQuery q3 = new TermQuery(new Term("hist", "term_does_not_exist"));
sw = new StringWriter();
assertFalse(new HistoryContext(q3).getContext(parent, base, path, sw, null), parent + " has no context");
assertEquals("", sw.toString());
// Search for term with multiple hits - hist:small OR hist:target
BooleanQuery.Builder q4 = new BooleanQuery.Builder();
q4.add(new TermQuery(new Term("hist", "small")), Occur.SHOULD);
q4.add(new TermQuery(new Term("hist", "target")), Occur.SHOULD);
sw = new StringWriter();
assertTrue(new HistoryContext(q4.build()).getContext(parent, base, path, sw, null), parent + " has context");
String result = sw.toString();
assertTrue(result.contains("Add lint make <b>target</b> and fix lint warnings"));
assertTrue(result.contains("Created a <b>small</b> dummy program"));
}
use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.
the class RepositoryFactoryTest method testMercurialRepositoryWhenDisabled.
@EnabledForRepository(RepositoryInstalled.Type.MERCURIAL)
@Test
public void testMercurialRepositoryWhenDisabled() throws IllegalAccessException, InvocationTargetException, ForbiddenSymlinkException, InstantiationException, NoSuchMethodException, IOException {
env.setDisabledRepositories(new HashSet<>(Collections.singletonList("MercurialRepository")));
File root = new File(repository.getSourceRoot(), "mercurial");
env.setSourceRoot(root.getAbsolutePath());
assertNull(RepositoryFactory.getRepository(root), "should not get repository for mercurial/ if disabled");
List<Class<? extends Repository>> clazzes = RepositoryFactory.getRepositoryClasses();
assertFalse(clazzes.contains(MercurialRepository.class), "should not contain MercurialRepository");
}
use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.
the class HistoryGuruTest method testAddSubRepository.
@Test
@EnabledForRepository(MERCURIAL)
void testAddSubRepository() {
HistoryGuru instance = HistoryGuru.getInstance();
// Clone a Mercurial repository underneath a Mercurial repository.
File hgRoot = new File(repository.getSourceRoot(), "mercurial");
assertTrue(hgRoot.exists());
assertTrue(hgRoot.isDirectory());
MercurialRepositoryTest.runHgCommand(hgRoot, "clone", hgRoot.getAbsolutePath(), "subrepo");
Collection<RepositoryInfo> addedRepos = instance.addRepositories(Collections.singleton(Paths.get(repository.getSourceRoot(), "mercurial").toString()));
assertEquals(2, addedRepos.size());
}
use of org.opengrok.indexer.condition.EnabledForRepository 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.
*/
@Test
@EnabledForRepository(MERCURIAL)
void testRemoveFileOnFileChange() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
String path = "/mercurial/bar.txt";
TestRepository testrepo = new TestRepository();
testrepo.create(HistoryGuru.class.getResource("/repositories"));
env.setSourceRoot(testrepo.getSourceRoot());
env.setDataRoot(testrepo.getDataRoot());
env.setRepositories(testrepo.getSourceRoot());
// Create history cache.
Indexer.getInstance().prepareIndexer(env, true, true, false, null, List.of("mercurial"));
File historyFile = new File(env.getDataRootPath(), TandemPath.join("historycache" + path, ".gz"));
assertTrue(historyFile.exists(), String.format("history cache for %s has to exist", path));
// create index
Project project = new Project("mercurial", "/mercurial");
IndexDatabase idb = new IndexDatabase(project);
assertNotNull(idb);
RemoveIndexChangeListener listener = new RemoveIndexChangeListener(path);
idb.addIndexChangedListener(listener);
idb.update();
assertEquals(5, listener.filesToAdd.size());
listener.reset();
// Change a file so that it gets picked up by the indexer.
File bar = new File(testrepo.getSourceRoot() + File.separator + "mercurial", "bar.txt");
assertTrue(bar.exists());
try (BufferedWriter bw = new BufferedWriter(new FileWriter(bar, true))) {
bw.write("foo\n");
}
// reindex
idb.update();
// 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.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.
the class IndexerTest method testSetRepositories.
@Test
@EnabledForRepository(MERCURIAL)
void testSetRepositories() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
TestRepository testrepo = new TestRepository();
testrepo.create(HistoryGuru.class.getResource("/repositories"));
env.setSourceRoot(testrepo.getSourceRoot());
env.setRepositories(testrepo.getSourceRoot());
assertEquals(7, env.getRepositories().size());
String[] repoNames = { "mercurial", "git" };
env.setRepositories(Arrays.stream(repoNames).map(t -> Paths.get(env.getSourceRootPath(), t).toString()).distinct().toArray(String[]::new));
assertEquals(2, env.getRepositories().size());
}
Aggregations