Search in sources :

Example 21 with Project

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;
}
Also used : Project(org.opengrok.indexer.configuration.Project)

Example 22 with 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));
}
Also used : Project(org.opengrok.indexer.configuration.Project) ApiTask(org.opengrok.web.api.ApiTask) Path(jakarta.ws.rs.Path) DELETE(jakarta.ws.rs.DELETE)

Example 23 with Project

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);
}
Also used : Repository(org.opengrok.indexer.history.Repository) SuggesterService(org.opengrok.web.api.v1.suggester.provider.service.SuggesterService) Context(jakarta.ws.rs.core.Context) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Group(org.opengrok.indexer.configuration.Group) Project(org.opengrok.indexer.configuration.Project) CompletableFuture(java.util.concurrent.CompletableFuture) GET(jakarta.ws.rs.GET) ForbiddenSymlinkException(org.opengrok.indexer.util.ForbiddenSymlinkException) PUT(jakarta.ws.rs.PUT) WebApplicationException(jakarta.ws.rs.WebApplicationException) TreeSet(java.util.TreeSet) ApiTask(org.opengrok.web.api.ApiTask) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Path(jakarta.ws.rs.Path) ClassUtil(org.opengrok.indexer.util.ClassUtil) Response(jakarta.ws.rs.core.Response) RepositoryFactory.getRepository(org.opengrok.indexer.history.RepositoryFactory.getRepository) Map(java.util.Map) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) ApiTaskManager(org.opengrok.web.api.ApiTaskManager) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Laundromat(org.opengrok.indexer.web.Laundromat) Produces(jakarta.ws.rs.Produces) CommandTimeoutType(org.opengrok.indexer.configuration.CommandTimeoutType) Consumes(jakarta.ws.rs.Consumes) NotFoundException(jakarta.ws.rs.NotFoundException) POST(jakarta.ws.rs.POST) IOUtils(org.opengrok.indexer.util.IOUtils) Set(java.util.Set) IOException(java.io.IOException) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) IndexDatabase(org.opengrok.indexer.index.IndexDatabase) File(java.io.File) List(java.util.List) MediaType(jakarta.ws.rs.core.MediaType) Paths(java.nio.file.Paths) LoggerFactory(org.opengrok.indexer.logger.LoggerFactory) DELETE(jakarta.ws.rs.DELETE) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) Inject(jakarta.inject.Inject) PathParam(jakarta.ws.rs.PathParam) Collections(java.util.Collections) Project(org.opengrok.indexer.configuration.Project) ForbiddenSymlinkException(org.opengrok.indexer.util.ForbiddenSymlinkException) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) IOException(java.io.IOException) File(java.io.File)

Example 24 with Project

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);
}
Also used : Project(org.opengrok.indexer.configuration.Project) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 25 with Project

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;
}
Also used : Project(org.opengrok.indexer.configuration.Project) Group(org.opengrok.indexer.configuration.Group) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

Project (org.opengrok.indexer.configuration.Project)88 Test (org.junit.jupiter.api.Test)42 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)27 File (java.io.File)22 Group (org.opengrok.indexer.configuration.Group)20 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)17 ArrayList (java.util.ArrayList)16 TreeSet (java.util.TreeSet)11 IOException (java.io.IOException)10 DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)10 List (java.util.List)8 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)7 Path (jakarta.ws.rs.Path)7 HistoryGuru (org.opengrok.indexer.history.HistoryGuru)7 Path (java.nio.file.Path)6 Map (java.util.Map)6 Paths (java.nio.file.Paths)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 MercurialRepositoryTest (org.opengrok.indexer.history.MercurialRepositoryTest)5