Search in sources :

Example 26 with Project

use of org.opensolaris.opengrok.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().getProjects()) {
        // filterProjects only groups which match project's description
        Set<Group> copy = new TreeSet<>(groups);
        copy.removeIf(new Predicate<Group>() {

            @Override
            public boolean test(Group g) {
                return !g.match(project);
            }
        });
        // if no group matches the project, add it to not-grouped projects
        if (copy.isEmpty()) {
            if (cfg.getEnv().getProjectRepositoriesMap().get(project) == null) {
                projects.add(project);
            } else {
                repositories.add(project);
            }
        }
    }
    // populate all grouped
    for (Group g : getGroups()) {
        all_projects.addAll(getProjects(g));
        all_repositories.addAll(getRepositories(g));
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) Group(org.opensolaris.opengrok.configuration.Group) TreeSet(java.util.TreeSet)

Example 27 with Project

use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.

the class PageConfig method getRequestedProjects.

/**
     * Same as {@link #getRequestedProjects()}, but with a variable cookieName
     * and parameter name. This way it is trivial to implement a project filter
     * ...
     *
     * @param paramName the name of the request parameter, which possibly
     * contains the project list in question.
     * @param cookieName name of the cookie which possible contains project
     * lists used as fallback
     * @return a possible empty set but never {@code null}.
     */
protected SortedSet<String> getRequestedProjects(String paramName, String cookieName) {
    TreeSet<String> set = new TreeSet<>();
    List<Project> projects = getEnv().getProjects();
    if (projects == null) {
        return set;
    }
    if (projects.size() == 1 && authFramework.isAllowed(req, projects.get(0))) {
        set.add(projects.get(0).getName());
        return set;
    }
    List<String> vals = getParamVals(paramName);
    for (String s : vals) {
        Project x = Project.getByName(s);
        if (x != null && authFramework.isAllowed(req, x)) {
            set.add(s);
        }
    }
    if (set.isEmpty()) {
        List<String> cookies = getCookieVals(cookieName);
        for (String s : cookies) {
            Project x = Project.getByName(s);
            if (x != null && authFramework.isAllowed(req, x)) {
                set.add(s);
            }
        }
    }
    if (set.isEmpty()) {
        Project defaultProject = env.getDefaultProject();
        if (defaultProject != null && authFramework.isAllowed(req, defaultProject)) {
            set.add(defaultProject.getName());
        }
    }
    return set;
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) TreeSet(java.util.TreeSet)

Example 28 with Project

use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.

the class IndexDatabase method updateAll.

/**
     * Update the index database for all of the projects
     *
     * @param executor An executor to run the job
     * @param listener where to signal the changes to the database
     * @throws IOException if an error occurs
     */
static void updateAll(ExecutorService executor, IndexChangedListener listener) throws IOException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    List<IndexDatabase> dbs = new ArrayList<>();
    if (env.hasProjects()) {
        for (Project project : env.getProjects()) {
            dbs.add(new IndexDatabase(project));
        }
    } else {
        dbs.add(new IndexDatabase());
    }
    for (IndexDatabase d : dbs) {
        final IndexDatabase db = d;
        if (listener != null) {
            db.addIndexChangedListener(listener);
        }
        executor.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    db.update();
                } catch (Throwable e) {
                    LOGGER.log(Level.SEVERE, "Problem updating lucene index database: ", e);
                }
            }
        });
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) ArrayList(java.util.ArrayList)

Example 29 with Project

use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.

the class IndexDatabase method update.

/**
     * Update the index database for a number of sub-directories
     *
     * @param executor An executor to run the job
     * @param listener where to signal the changes to the database
     * @param paths list of paths to be indexed
     * @throws IOException if an error occurs
     */
public static void update(ExecutorService executor, IndexChangedListener listener, List<String> paths) throws IOException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    List<IndexDatabase> dbs = new ArrayList<>();
    for (String path : paths) {
        Project project = Project.getProject(path);
        if (project == null && env.hasProjects()) {
            LOGGER.log(Level.WARNING, "Could not find a project for \"{0}\"", path);
        } else {
            IndexDatabase db;
            try {
                if (project == null) {
                    db = new IndexDatabase();
                } else {
                    db = new IndexDatabase(project);
                }
                int idx = dbs.indexOf(db);
                if (idx != -1) {
                    db = dbs.get(idx);
                }
                if (db.addDirectory(path)) {
                    if (idx == -1) {
                        dbs.add(db);
                    }
                } else {
                    LOGGER.log(Level.WARNING, "Directory does not exist \"{0}\" .", path);
                }
            } catch (IOException e) {
                LOGGER.log(Level.WARNING, "An error occured while updating index", e);
            }
        }
        for (final IndexDatabase db : dbs) {
            db.addIndexChangedListener(listener);
            executor.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        db.update();
                    } catch (Throwable e) {
                        LOGGER.log(Level.SEVERE, "An error occured while updating index", e);
                    }
                }
            });
        }
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 30 with Project

use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.

the class IndexDatabase method listAllFiles.

/**
     * List all files in some of the index databases
     *
     * @param subFiles Subdirectories for the various projects to list the files
     * for (or null or an empty list to dump all projects)
     * @throws IOException if an error occurs
     */
public static void listAllFiles(List<String> subFiles) throws IOException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    if (env.hasProjects()) {
        if (subFiles == null || subFiles.isEmpty()) {
            for (Project project : env.getProjects()) {
                IndexDatabase db = new IndexDatabase(project);
                db.listFiles();
            }
        } else {
            for (String path : subFiles) {
                Project project = Project.getProject(path);
                if (project == null) {
                    LOGGER.log(Level.WARNING, "Could not find a project for \"{0}\"", path);
                } else {
                    IndexDatabase db = new IndexDatabase(project);
                    db.listFiles();
                }
            }
        }
    } else {
        IndexDatabase db = new IndexDatabase();
        db.listFiles();
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment)

Aggregations

Project (org.opensolaris.opengrok.configuration.Project)44 Test (org.junit.Test)22 RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)12 Group (org.opensolaris.opengrok.configuration.Group)9 ArrayList (java.util.ArrayList)8 RepositoryInfo (org.opensolaris.opengrok.history.RepositoryInfo)6 File (java.io.File)4 TreeSet (java.util.TreeSet)4 IOException (java.io.IOException)3 HistoryException (org.opensolaris.opengrok.history.HistoryException)3 FileNotFoundException (java.io.FileNotFoundException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Document (org.apache.lucene.document.Document)2 Genre (org.opensolaris.opengrok.analysis.FileAnalyzer.Genre)2 RepoRepository (org.opensolaris.opengrok.history.RepoRepository)2 DummyHttpServletRequest (org.opensolaris.opengrok.web.DummyHttpServletRequest)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1