use of org.opengrok.indexer.configuration.Project 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);
}
}
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class ProjectsController method get.
@GET
@Path("/{project}/property/{field}")
@Produces(MediaType.APPLICATION_JSON)
public Object get(@PathParam("project") String projectName, @PathParam("field") String field) 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) {
throw new WebApplicationException("cannot find project " + projectName + " to get a property", Response.Status.BAD_REQUEST);
}
return ClassUtil.getFieldValue(project, field);
}
use of org.opengrok.indexer.configuration.Project 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);
}
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class SearchHelperTest method testPrepareExecInvalidInput.
@Test
void testPrepareExecInvalidInput() {
SortedSet<String> projectNames = new TreeSet<>();
SearchHelper searchHelper;
env.setProjectsEnabled(true);
// Fake project addition to avoid reindex.
Project project = new Project("c", "/c");
env.getProjects().put("c", project);
project = new Project("java", "/java");
project.setIndexed(true);
env.getProjects().put("java", project);
// Try to prepare search for project that is not yet indexed.
projectNames.add("c");
projectNames.add("java");
searchHelper = this.getSearchHelper("foobar").prepareExec(projectNames);
assertNotNull(searchHelper.getErrorMsg());
assertTrue(searchHelper.getErrorMsg().contains("not indexed"));
assertFalse(searchHelper.getErrorMsg().contains("java"));
// Try to prepare search for list that contains non-existing project.
projectNames.add("totally_nonexistent_project");
searchHelper = this.getSearchHelper("foobar").prepareExec(projectNames);
assertNotNull(searchHelper.getErrorMsg());
assertTrue(searchHelper.getErrorMsg().contains("invalid projects"));
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class ProjectHelper method populateGroups.
/**
* Generates ungrouped projects and repositories.
*/
private void populateGroups() {
groups.addAll(cfg.getEnv().getGroups());
for (Project project : cfg.getEnv().getProjectList()) {
// filterProjects() only adds groups which match project's name.
Set<Group> copy = Group.matching(project, groups);
// If no group matches the project, add it to not-grouped projects.
if (copy.isEmpty()) {
if (cfg.getEnv().getProjectRepositoriesMap().get(project) == null) {
ungroupedProjects.add(project);
} else {
ungroupedRepositories.add(project);
}
}
}
// populate all grouped
for (Group g : getGroups()) {
allProjects.addAll(g.getProjects());
allRepositories.addAll(g.getRepositories());
}
}
Aggregations