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);
}
}
}
Aggregations