use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class ProjectsController method disableProject.
private Project disableProject(String projectName) {
Project project = env.getProjects().get(projectName);
if (project == null) {
throw new IllegalStateException("cannot get project \"" + projectName + "\"");
}
// Remove the project from searches so no one can trip over incomplete index data.
project.setIndexed(false);
return project;
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class ProjectsController method deleteProject.
@DELETE
@Path("/{project}")
public Response deleteProject(@Context HttpServletRequest request, @PathParam("project") String projectNameParam) {
// Avoid classification as a taint bug.
final String projectName = Laundromat.launderInput(projectNameParam);
Project project = disableProject(projectName);
LOGGER.log(Level.INFO, "deleting configuration for project {0}", projectName);
return ApiTaskManager.getInstance().submitApiTask(PROJECTS_PATH, new ApiTask(request.getRequestURI(), () -> {
deleteProjectWorkHorse(projectName, project);
return null;
}, Response.Status.NO_CONTENT));
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class ProjectsController method deleteHistoryCacheWorkHorse.
private void deleteHistoryCacheWorkHorse(String projectName, boolean clearHistoryGuru) {
Project project = disableProject(projectName);
LOGGER.log(Level.INFO, "deleting history cache for project {0}", projectName);
List<RepositoryInfo> repos = env.getProjectRepositoriesMap().get(project);
if (repos == null || repos.isEmpty()) {
LOGGER.log(Level.INFO, "history cache for project {0} is not present", projectName);
return;
}
// Delete history cache data.
HistoryGuru guru = HistoryGuru.getInstance();
guru.removeCache(repos.stream().map(x -> {
try {
return env.getPathRelativeToSourceRoot(new File((x).getDirectoryName()));
} catch (ForbiddenSymlinkException e) {
LOGGER.log(Level.FINER, e.getMessage());
return "";
} catch (IOException e) {
LOGGER.log(Level.WARNING, "cannot remove files for repository {0}", x.getDirectoryName());
// {@code removeCache()} will return nothing.
return "";
}
}).filter(x -> !x.isEmpty()).collect(Collectors.toSet()), clearHistoryGuru);
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class MessagesUtilsTest method testGetMessagesForNonExistentProject.
@Test
public void testGetMessagesForNonExistentProject() {
String projectName = "nonexistent";
Project foo = new Project(projectName, "/doesnotexist");
HashMap<String, Project> projects = new HashMap<>();
projects.put(projectName, foo);
env.setProjectsEnabled(true);
env.setProjects(projects);
String jsonString = MessagesUtils.messagesToJson(projectName);
assertNotNull(jsonString);
assertEquals("", jsonString);
}
use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.
the class ProjectHelper method hasFavourite.
/**
* Checks if given group contains a favourite project.
*
* Favourite project is a project which is contained in the OpenGrokProject
* cookie, i. e. it has been searched or viewed by the user.
*
* This should by used to determine if this group should be displayed
* expanded or rolled up.
*
* @param group group
* @return true if it has favourite project
*/
@SuppressWarnings(value = "unchecked")
public boolean hasFavourite(Group group) {
Boolean val;
Map<String, Boolean> p = (Map<String, Boolean>) cfg.getRequestAttribute(PROJECT_HELPER_FAVOURITE_GROUP);
if (p == null) {
p = new TreeMap<>();
cfg.setRequestAttribute(PROJECT_HELPER_FAVOURITE_GROUP, p);
}
val = p.get(group.getName());
if (val == null) {
Set<Project> favourite = getAllGrouped();
favourite.removeIf(t -> {
// project is favourite
if (!isFavourite(t)) {
return true;
}
// project is contained in group repositories
if (getRepositories(group).contains(t)) {
return false;
}
// project is contained in group projects
if (getProjects(group).contains(t)) {
return false;
}
// project is contained in subgroup's repositories and projects
for (Group g : filterGroups(group.getDescendants())) {
if (getProjects(g).contains(t)) {
return false;
}
if (getRepositories(g).contains(t)) {
return false;
}
}
return true;
});
val = !favourite.isEmpty();
p.put(group.getName(), val);
}
cfg.setRequestAttribute(PROJECT_HELPER_FAVOURITE_GROUP, p);
return val;
}
Aggregations