Search in sources :

Example 66 with Project

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

the class IndexerTest method testDefaultProjectsAll.

/**
 * Should include all projects in the source root.
 *
 * @throws Exception
 */
@Test
public void testDefaultProjectsAll() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    env.setHistoryEnabled(false);
    Indexer.getInstance().prepareIndexer(env, true, true, new TreeSet<>(Arrays.asList(new String[] { "/c", "/data", "__all__", "/no-project-x32ds1" })), false, false, null, null, new ArrayList<>(), false);
    Set<String> projects = new TreeSet<>(Arrays.asList(new File(repository.getSourceRoot()).list()));
    assertEquals(projects.size(), env.getDefaultProjects().size());
    assertEquals(projects, env.getDefaultProjects().stream().map((Project p) -> p.getName()).collect(Collectors.toSet()));
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) TreeSet(java.util.TreeSet) File(java.io.File) Test(org.junit.Test)

Example 67 with Project

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

the class IndexerTest method testRemoveFileOnFileChange.

/**
 * Test that reindex after changing a file does not wipe out history index
 * for this file. This is important for the incremental history indexing.
 * @throws Exception
 */
@Test
@ConditionalRun(condition = RepositoryInstalled.MercurialInstalled.class)
public void testRemoveFileOnFileChange() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    if (!env.validateExuberantCtags()) {
        System.out.println("Skipping test due to no ctags");
    }
    TestRepository testrepo = new TestRepository();
    testrepo.create(HistoryGuru.class.getResourceAsStream("repositories.zip"));
    env.setSourceRoot(testrepo.getSourceRoot());
    env.setDataRoot(testrepo.getDataRoot());
    env.setRepositories(testrepo.getSourceRoot());
    // create index
    Project project = new Project("mercurial", "/mercurial");
    IndexDatabase idb = new IndexDatabase(project);
    assertNotNull(idb);
    RemoveIndexChangeListener listener = new RemoveIndexChangeListener();
    idb.addIndexChangedListener(listener);
    idb.update(parallelizer);
    Assert.assertEquals(5, listener.filesToAdd.size());
    listener.reset();
    // Change a file so that it gets picked up by the indexer.
    Thread.sleep(1100);
    File bar = new File(testrepo.getSourceRoot() + File.separator + "mercurial", "bar.txt");
    Assert.assertTrue(bar.exists());
    FileWriter fw = new FileWriter(bar, true);
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write("foo\n");
    bw.close();
    fw.close();
    // reindex
    idb.update(parallelizer);
    // Make sure that the file was actually processed.
    assertEquals(1, listener.removedFiles.size());
    assertEquals(1, listener.filesToAdd.size());
    assertEquals("/mercurial/bar.txt", listener.removedFiles.peek());
    testrepo.destroy();
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) TestRepository(org.opensolaris.opengrok.util.TestRepository) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) FileWriter(java.io.FileWriter) HistoryGuru(org.opensolaris.opengrok.history.HistoryGuru) File(java.io.File) BufferedWriter(java.io.BufferedWriter) ConditionalRun(org.opensolaris.opengrok.condition.ConditionalRun) Test(org.junit.Test)

Example 68 with Project

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

the class IndexerTest method testDefaultProjectsNonExistent.

/**
 * Should discard the non existing project.
 *
 * @throws Exception
 */
@Test
public void testDefaultProjectsNonExistent() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    env.setHistoryEnabled(false);
    Indexer.getInstance().prepareIndexer(env, true, true, new TreeSet<>(Arrays.asList(new String[] { "/lisp", "/pascal", "/perl", "/data", "/no-project-x32ds1" })), false, false, null, null, new ArrayList<>(), false);
    assertEquals(4, env.getDefaultProjects().size());
    assertEquals(new TreeSet<>(Arrays.asList(new String[] { "/lisp", "/pascal", "/perl", "/data" })), env.getDefaultProjects().stream().map((Project p) -> '/' + p.getName()).collect(Collectors.toSet()));
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) Test(org.junit.Test)

Example 69 with Project

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

the class IndexerTest method testBug3430.

@Test
public void testBug3430() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    if (env.validateExuberantCtags()) {
        Project project = new Project("bug3430");
        project.setPath("/bug3430");
        IndexDatabase idb = new IndexDatabase(project);
        assertNotNull(idb);
        MyIndexChangeListener listener = new MyIndexChangeListener();
        idb.addIndexChangedListener(listener);
        idb.update(parallelizer);
        assertEquals(1, listener.files.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 70 with Project

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

the class PageConfigTest method testGetResourceFileList.

/**
 * Testing the root of /xref for authorization filtering.
 */
@Test
public void testGetResourceFileList() {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    // backup original values
    String oldSourceRootPath = env.getSourceRootPath();
    AuthorizationFramework oldAuthorizationFramework = env.getAuthorizationFramework();
    Map<String, Project> oldProjects = env.getProjects();
    // Set up the source root directory containing some projects.
    env.setSourceRoot(repository.getSourceRoot());
    env.setProjectsEnabled(true);
    // Enable projects.
    for (String file : new File(repository.getSourceRoot()).list()) {
        Project proj = new Project(file);
        proj.setIndexed(true);
        env.getProjects().put(file, proj);
    }
    HttpServletRequest req = createRequest("/source", "/xref", "");
    PageConfig cfg = PageConfig.get(req);
    List<String> allFiles = new ArrayList<>(cfg.getResourceFileList());
    /**
     * Check if there are some files (the "5" here is just a sufficient
     * value for now which won't break any future repository tests) without
     * any authorization.
     */
    assertTrue(allFiles.size() > 5);
    assertTrue(allFiles.contains("git"));
    assertTrue(allFiles.contains("mercurial"));
    /**
     * Now set up the same projects with authorization plugin enabling only
     * some of them.
     * <pre>
     *  - disabling "git"
     *  - disabling "mercurial"
     * </pre>
     */
    env.setAuthorizationFramework(new AuthorizationFramework());
    env.getAuthorizationFramework().reload();
    env.getAuthorizationFramework().getStack().add(new AuthorizationPlugin(AuthControlFlag.REQUIRED, new TestPlugin() {

        @Override
        public boolean isAllowed(HttpServletRequest request, Project project) {
            return !project.getName().startsWith("git") && !project.getName().startsWith("mercurial");
        }
    }));
    req = createRequest("/source", "/xref", "");
    cfg = PageConfig.get(req);
    List<String> filteredFiles = new ArrayList<>(cfg.getResourceFileList());
    // list subtraction - retains only disabled files
    allFiles.removeAll(filteredFiles);
    assertEquals(2, allFiles.size());
    assertTrue(allFiles.contains("git"));
    assertTrue(allFiles.contains("mercurial"));
    // restore original values
    env.setAuthorizationFramework(oldAuthorizationFramework);
    env.setSourceRoot(oldSourceRootPath);
    env.setProjects(oldProjects);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) AuthorizationFramework(org.opensolaris.opengrok.authorization.AuthorizationFramework) ArrayList(java.util.ArrayList) AuthorizationPlugin(org.opensolaris.opengrok.authorization.AuthorizationPlugin) TestPlugin(org.opensolaris.opengrok.authorization.TestPlugin) File(java.io.File) Test(org.junit.Test)

Aggregations

Project (org.opensolaris.opengrok.configuration.Project)79 Test (org.junit.Test)40 RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)31 File (java.io.File)20 ArrayList (java.util.ArrayList)20 Group (org.opensolaris.opengrok.configuration.Group)17 RepositoryInfo (org.opensolaris.opengrok.history.RepositoryInfo)14 IOException (java.io.IOException)12 TreeSet (java.util.TreeSet)12 HistoryException (org.opensolaris.opengrok.history.HistoryException)8 List (java.util.List)6 ParseException (java.text.ParseException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Repository (org.opensolaris.opengrok.history.Repository)5 TestRepository (org.opensolaris.opengrok.util.TestRepository)5 ConnectException (java.net.ConnectException)4