Search in sources :

Example 56 with Project

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.");
    }
}
Also used : Project(org.opengrok.indexer.configuration.Project) Repository(org.opengrok.indexer.history.Repository) TestRepository(org.opengrok.indexer.util.TestRepository) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) Test(org.junit.jupiter.api.Test)

Example 57 with Project

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()));
}
Also used : Project(org.opengrok.indexer.configuration.Project) TestRepository(org.opengrok.indexer.util.TestRepository) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) File(java.io.File) HashSet(java.util.HashSet) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 58 with Project

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());
}
Also used : Project(org.opengrok.indexer.configuration.Project) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 59 with Project

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;
    }));
}
Also used : Project(org.opengrok.indexer.configuration.Project) Repository(org.opengrok.indexer.history.Repository) RepositoryFactory.getRepository(org.opengrok.indexer.history.RepositoryFactory.getRepository) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) NotFoundException(jakarta.ws.rs.NotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) ApiTask(org.opengrok.web.api.ApiTask) Path(jakarta.ws.rs.Path) Consumes(jakarta.ws.rs.Consumes) PUT(jakarta.ws.rs.PUT)

Example 60 with Project

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();
}
Also used : Project(org.opengrok.indexer.configuration.Project) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Aggregations

Project (org.opengrok.indexer.configuration.Project)88 Test (org.junit.jupiter.api.Test)42 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)27 File (java.io.File)22 Group (org.opengrok.indexer.configuration.Group)20 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)17 ArrayList (java.util.ArrayList)16 TreeSet (java.util.TreeSet)11 IOException (java.io.IOException)10 DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)10 List (java.util.List)8 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)7 Path (jakarta.ws.rs.Path)7 HistoryGuru (org.opengrok.indexer.history.HistoryGuru)7 Path (java.nio.file.Path)6 Map (java.util.Map)6 Paths (java.nio.file.Paths)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 MercurialRepositoryTest (org.opengrok.indexer.history.MercurialRepositoryTest)5