Search in sources :

Example 31 with Project

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

the class Indexer method doIndexerExecution.

/*
     * This is the second phase of the indexer which generates Lucene index
     * by passing source code files through Exuberant ctags, generating xrefs
     * and storing data from the source files in the index (along with history,
     * if any).
     */
public void doIndexerExecution(final boolean update, int noThreads, List<String> subFiles, IndexChangedListener progress) throws IOException {
    Statistics elapsed = new Statistics();
    RuntimeEnvironment env = RuntimeEnvironment.getInstance().register();
    LOGGER.info("Starting indexing");
    ExecutorService executor = Executors.newFixedThreadPool(noThreads);
    if (subFiles == null || subFiles.isEmpty()) {
        if (update) {
            IndexDatabase.updateAll(executor, progress);
        } else if (env.isOptimizeDatabase()) {
            IndexDatabase.optimizeAll(executor);
        }
    } else {
        List<IndexDatabase> dbs = new ArrayList<>();
        for (String path : subFiles) {
            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;
                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);
                }
            }
        }
        for (final IndexDatabase db : dbs) {
            final boolean optimize = env.isOptimizeDatabase();
            db.addIndexChangedListener(progress);
            executor.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        if (update) {
                            db.update();
                        } else if (optimize) {
                            db.optimize();
                        }
                    } catch (Throwable e) {
                        LOGGER.log(Level.SEVERE, "An error occured while " + (update ? "updating" : "optimizing") + " index", e);
                    }
                }
            });
        }
    }
    executor.shutdown();
    while (!executor.isTerminated()) {
        try {
            // Wait forever
            executor.awaitTermination(999, TimeUnit.DAYS);
        } catch (InterruptedException exp) {
            LOGGER.log(Level.WARNING, "Received interrupt while waiting for executor to finish", exp);
        }
    }
    try {
        // It can happen that history index is not done in prepareIndexer()
        // but via db.update() above in which case we must make sure the
        // thread pool for renamed file handling is destroyed.
        RuntimeEnvironment.destroyRenamedHistoryExecutor();
    } catch (InterruptedException ex) {
        LOGGER.log(Level.SEVERE, "destroying of renamed thread pool failed", ex);
    }
    elapsed.report(LOGGER, "Done indexing data of all repositories");
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) ArrayList(java.util.ArrayList) Statistics(org.opensolaris.opengrok.util.Statistics) Project(org.opensolaris.opengrok.configuration.Project) ExecutorService(java.util.concurrent.ExecutorService)

Example 32 with Project

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

the class IndexDatabase method optimizeAll.

/**
     * Optimize all index databases
     *
     * @param executor An executor to run the job
     * @throws IOException if an error occurs
     */
static void optimizeAll(ExecutorService executor) throws IOException {
    List<IndexDatabase> dbs = new ArrayList<>();
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    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 (db.isDirty()) {
            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 33 with Project

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

the class AuthorizationFrameworkTest method createUnallowedProject.

private Project createUnallowedProject() {
    Project p = new Project();
    p.setName("not_allowed" + "_" + "project" + Math.random());
    return p;
}
Also used : Project(org.opensolaris.opengrok.configuration.Project)

Example 34 with Project

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

the class IndexerTest method testIncrementalIndexAddRemoveFile.

@Test
public void testIncrementalIndexAddRemoveFile() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setCtags(System.getProperty(ctagsProperty, "ctags"));
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    if (env.validateExuberantCtags()) {
        Project project = new Project();
        String ppath = "bug3430";
        project.setPath("/" + ppath);
        IndexDatabase idb = new IndexDatabase(project);
        assertNotNull(idb);
        MyIndexChangeListener listener = new MyIndexChangeListener();
        idb.addIndexChangedListener(listener);
        idb.update();
        assertEquals(1, listener.files.size());
        listener.reset();
        repository.addDummyFile(ppath);
        idb.update();
        assertEquals("No new file added", 1, listener.files.size());
        repository.removeDummyFile(ppath);
        idb.update();
        assertEquals("Didn't remove the dummy file", 0, listener.files.size());
        assertEquals("Didn't remove the dummy file", 1, listener.removedFiles.size());
    } else {
        System.out.println("Skipping test. Could not find a ctags I could use in path.");
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) Test(org.junit.Test)

Example 35 with Project

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

the class ProjectHelperTest method testGetGroupedProjects.

/**
     * Test of getGroupedProjects method, of class ProjectHelper.
     */
@Test
public void testGetGroupedProjects() {
    Set<Project> result = helper.getGroupedProjects();
    Assert.assertEquals(4, result.size());
    for (Project p : result) {
        Assert.assertTrue(p.getName().startsWith("allowed_"));
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) Test(org.junit.Test)

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