Search in sources :

Example 21 with RepositoryInfo

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

the class ProjectsController method addProjectWorkHorse.

private void addProjectWorkHorse(String projectName) {
    File srcRoot = env.getSourceRootFile();
    File projDir = new File(srcRoot, projectName);
    if (!env.getProjects().containsKey(projectName)) {
        Project project = new Project(projectName, "/" + projectName);
        if (env.isHistoryEnabled()) {
            // Add repositories in this project.
            List<RepositoryInfo> repos = getRepositoriesInDir(projDir);
            env.addRepositories(repos);
            env.getProjectRepositoriesMap().put(project, repos);
        }
        // Finally, introduce the project to the configuration.
        // Note that the project is inactive in the UI until it is indexed.
        // See isIndexed()
        env.getProjects().put(projectName, project);
        env.populateGroups(env.getGroups(), new TreeSet<>(env.getProjectList()));
    } else {
        Project project = env.getProjects().get(projectName);
        Map<Project, List<RepositoryInfo>> map = env.getProjectRepositoriesMap();
        if (env.isHistoryEnabled()) {
            // Refresh the list of repositories of this project.
            // This is the goal of this action: if an existing project
            // is re-added, this means its list of repositories has changed.
            List<RepositoryInfo> repos = getRepositoriesInDir(projDir);
            List<RepositoryInfo> allrepos = env.getRepositories();
            synchronized (allrepos) {
                // newly added repository
                for (RepositoryInfo repo : repos) {
                    if (!allrepos.contains(repo)) {
                        allrepos.add(repo);
                    }
                }
                // deleted repository
                if (map.containsKey(project)) {
                    for (RepositoryInfo repo : map.get(project)) {
                        if (!repos.contains(repo)) {
                            allrepos.remove(repo);
                        }
                    }
                }
            }
            map.put(project, repos);
        }
    }
}
Also used : Project(org.opengrok.indexer.configuration.Project) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

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