Search in sources :

Example 16 with RepositoryInfo

use of org.opengrok.indexer.history.RepositoryInfo in project OpenGrok by OpenGrok.

the class ProjectHelperTestBase method createRepository.

protected static Project createRepository(int index, int number, int cnt, boolean grouped, boolean allowed, List<RepositoryInfo> rps, Map<String, Project> prjs, Map<Project, List<RepositoryInfo>> map) {
    Project p = createProject(index, number, grouped, allowed, true, rps, prjs, map);
    for (int i = 0; i < cnt; i++) {
        RepositoryInfo info = new RepoRepository();
        info.setParent(p.getName() + "_" + i);
        info.setDirectoryNameRelative(p.getPath());
        rps.add(info);
        List<RepositoryInfo> infos = map.get(p);
        if (infos == null) {
            infos = new ArrayList<>();
        }
        infos.add(info);
        map.put(p, infos);
    }
    return p;
}
Also used : Project(org.opengrok.indexer.configuration.Project) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) RepoRepository(org.opengrok.indexer.history.RepoRepository)

Example 17 with RepositoryInfo

use of org.opengrok.indexer.history.RepositoryInfo in project OpenGrok by OpenGrok.

the class ProjectsController method set.

@PUT
@Path("/{project}/property/{field}")
public void set(@PathParam("project") String projectName, @PathParam("field") String field, final String value) throws IOException {
    // Avoid classification as a taint bug.
    projectName = Laundromat.launderInput(projectName);
    field = Laundromat.launderInput(field);
    Project project = env.getProjects().get(projectName);
    if (project != null) {
        // Set the property.
        ClassUtil.setFieldValue(project, field, value);
        // Refresh field values for project's repositories for this project as well.
        List<RepositoryInfo> riList = env.getProjectRepositoriesMap().get(project);
        if (riList != null) {
            for (RepositoryInfo ri : riList) {
                // Set the property if there is one.
                if (ClassUtil.hasField(ri, field)) {
                    ClassUtil.setFieldValue(ri, field, value);
                }
            }
        }
    } else {
        LOGGER.log(Level.WARNING, "cannot find project {0} to set a property", projectName);
    }
}
Also used : Project(org.opengrok.indexer.configuration.Project) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) Path(jakarta.ws.rs.Path) PUT(jakarta.ws.rs.PUT)

Example 18 with RepositoryInfo

use of org.opengrok.indexer.history.RepositoryInfo in project OpenGrok by OpenGrok.

the class ProjectsController method deleteProjectWorkHorse.

private void deleteProjectWorkHorse(String projectName, Project project) {
    // Delete index data associated with the project.
    deleteProjectDataWorkHorse(projectName, true);
    // Remove the project from its groups.
    for (Group group : project.getGroups()) {
        group.getRepositories().remove(project);
        group.getProjects().remove(project);
    }
    if (env.isHistoryEnabled()) {
        // Now remove the repositories associated with this project.
        List<RepositoryInfo> repos = env.getProjectRepositoriesMap().get(project);
        if (repos != null) {
            env.getRepositories().removeAll(repos);
        }
        env.getProjectRepositoriesMap().remove(project);
    }
    env.getProjects().remove(projectName, project);
    // Prevent the project to be included in new searches.
    env.refreshSearcherManagerMap();
}
Also used : Group(org.opengrok.indexer.configuration.Group) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo)

Example 19 with RepositoryInfo

use of org.opengrok.indexer.history.RepositoryInfo 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 20 with RepositoryInfo

use of org.opengrok.indexer.history.RepositoryInfo 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

RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)21 Project (org.opengrok.indexer.configuration.Project)16 Test (org.junit.jupiter.api.Test)10 File (java.io.File)9 ArrayList (java.util.ArrayList)7 List (java.util.List)6 Path (jakarta.ws.rs.Path)5 Group (org.opengrok.indexer.configuration.Group)5 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)5 MercurialRepositoryTest (org.opengrok.indexer.history.MercurialRepositoryTest)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 EnabledForRepository (org.opengrok.indexer.condition.EnabledForRepository)4 GET (jakarta.ws.rs.GET)3 Produces (jakarta.ws.rs.Produces)3 Response (jakarta.ws.rs.core.Response)3 Paths (java.nio.file.Paths)3 Collections (java.util.Collections)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3