use of org.opengrok.indexer.configuration.Project 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.configuration.Project in project OpenGrok by OpenGrok.
the class SearchAndContextFormatterTest2 method setUpClass.
@BeforeAll
public static void setUpClass() throws Exception {
env = RuntimeEnvironment.getInstance();
originalProjectsEnabled = env.isProjectsEnabled();
env.setProjectsEnabled(true);
File sourceRoot = createTemporaryDirectory("srcroot");
assertTrue(sourceRoot.isDirectory(), "sourceRoot.isDirectory()");
File dataroot = createTemporaryDirectory("dataroot");
assertTrue(dataroot.isDirectory(), "dataroot.isDirectory()");
repository1 = new TestRepository();
repository1.create(HistoryGuru.class.getResource("/repositories"));
repository2 = new TestRepository();
repository2.create(HistoryGuru.class.getResource("/repositories"));
// Create symlink #1 underneath source root.
final String SYMLINK1 = "symlink1";
File symlink1 = new File(sourceRoot.getCanonicalFile(), SYMLINK1);
Files.createSymbolicLink(Paths.get(symlink1.getPath()), Paths.get(repository1.getSourceRoot()));
assertTrue(symlink1.exists(), "symlink1.exists()");
// Create symlink #2 underneath source root.
final String SYMLINK2 = "symlink2";
File symlink2 = new File(sourceRoot.getCanonicalFile(), SYMLINK2);
Files.createSymbolicLink(Paths.get(symlink2.getPath()), Paths.get(repository2.getSourceRoot()));
assertTrue(symlink2.exists(), "symlink2.exists()");
Set<String> allowedSymlinks = new HashSet<>();
allowedSymlinks.add(symlink1.getAbsolutePath());
allowedSymlinks.add(symlink2.getAbsolutePath());
env.setAllowedSymlinks(allowedSymlinks);
env.setCtags(System.getProperty("org.opengrok.indexer.analysis.Ctags", "ctags"));
env.setSourceRoot(sourceRoot.getPath());
env.setDataRoot(dataroot.getPath());
RepositoryFactory.initializeIgnoredNames(env);
env.setHistoryEnabled(false);
Indexer.getInstance().prepareIndexer(env, true, true, false, null, null);
env.setDefaultProjectsFromNames(new TreeSet<>(Collections.singletonList("/c")));
Project proj1 = env.getProjects().get(SYMLINK1);
assertNotNull(proj1, "symlink1 project");
proj1.setTabSize(TABSIZE);
Indexer.getInstance().doIndexerExecution(true, null, null);
configFile = File.createTempFile("configuration", ".xml");
env.writeConfiguration(configFile);
RuntimeEnvironment.getInstance().readConfiguration(new File(configFile.getAbsolutePath()));
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class IndexDatabaseTest method testCleanupAfterIndexRemoval.
/**
* Test removal of IndexDatabase. xrefs and history index entries after
* file has been removed from a repository.
*/
@Test
public void testCleanupAfterIndexRemoval() throws Exception {
final int origNumFiles;
String projectName = "git";
String ppath = "/" + projectName;
Project project = new Project(projectName, ppath);
IndexDatabase idb = new IndexDatabase(project);
assertNotNull(idb);
// Note that the file to remove has to be different than the one used
// in {@code testGetDefinitions} because it shares the same index
// and this test is going to remove the file and therefore related
// definitions.
String fileName = "header.h";
File gitRoot = new File(repository.getSourceRoot(), projectName);
assertTrue(new File(gitRoot, fileName).exists());
// Check that the file was indexed successfully in terms of generated data.
checkDataExistence(projectName + File.separator + fileName, true);
origNumFiles = idb.getNumFiles();
/*
* Initially was 6, then IndexAnalysisSettings added 1, then
* NumLinesLOCAggregator added 3.
*/
assertEquals(10, origNumFiles, "Lucene number of documents");
// Remove the file and reindex using IndexDatabase directly.
File file = new File(repository.getSourceRoot(), projectName + File.separator + fileName);
file.delete();
assertFalse(file.exists(), "file " + fileName + " not removed");
idb.update();
// Check that the data for the file has been removed.
checkDataExistence(projectName + File.separator + fileName, false);
assertEquals(origNumFiles - 1, idb.getNumFiles());
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class ProjectsController method markIndexed.
@PUT
@Path("/{project}/indexed")
@Consumes(MediaType.TEXT_PLAIN)
public Response markIndexed(@Context HttpServletRequest request, @PathParam("project") String projectNameParam) {
// Avoid classification as a taint bug.
final String projectName = Laundromat.launderInput(projectNameParam);
Project project = env.getProjects().get(projectName);
if (project == null) {
LOGGER.log(Level.WARNING, "cannot find project {0} to mark as indexed", projectName);
throw new NotFoundException(String.format("project '%s' does not exist", projectName));
}
project.setIndexed(true);
return ApiTaskManager.getInstance().submitApiTask(PROJECTS_PATH, new ApiTask(request.getRequestURI(), () -> {
// Refresh current version of the project's repositories.
List<RepositoryInfo> riList = env.getProjectRepositoriesMap().get(project);
if (riList != null) {
for (RepositoryInfo ri : riList) {
Repository repo = getRepository(ri, CommandTimeoutType.RESTFUL);
if (repo != null && repo.getCurrentVersion() != null && repo.getCurrentVersion().length() > 0) {
// getRepository() always creates fresh instance
// of the Repository object so there is no need
// to call setCurrentVersion() on it.
ri.setCurrentVersion(repo.determineCurrentVersion());
}
}
}
CompletableFuture.runAsync(() -> suggester.rebuild(projectName));
// In case this project has just been incrementally indexed,
// its IndexSearcher needs a poke.
env.maybeRefreshIndexSearchers(Collections.singleton(projectName));
env.refreshDateForLastIndexRun();
return null;
}));
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class ProjectsController method getRepositoriesType.
@GET
@Path("/{project}/repositories/type")
@Produces(MediaType.APPLICATION_JSON)
public Set<String> getRepositoriesType(@PathParam("project") String projectName) {
// Avoid classification as a taint bug.
projectName = Laundromat.launderInput(projectName);
Project project = env.getProjects().get(projectName);
if (project != null) {
List<RepositoryInfo> infos = env.getProjectRepositoriesMap().get(project);
if (infos != null) {
return infos.stream().map(RepositoryInfo::getType).collect(Collectors.toSet());
}
}
return Collections.emptySet();
}
Aggregations