Search in sources :

Example 61 with Project

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

Example 62 with Project

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);
}
Also used : Project(org.opengrok.indexer.configuration.Project) WebApplicationException(jakarta.ws.rs.WebApplicationException) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Example 63 with Project

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);
    }
}
Also used : Project(org.opengrok.indexer.configuration.Project) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) Path(jakarta.ws.rs.Path) PUT(jakarta.ws.rs.PUT)

Example 64 with Project

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

Example 65 with Project

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

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