Search in sources :

Example 71 with RuntimeEnvironment

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

the class IndexerRepoTest method testSymlinks.

/**
 * Test that symlinked directories from source root get their relative
 * path set correctly in RepositoryInfo objects.
 * @throws org.opensolaris.opengrok.index.IndexerException
 * @throws java.io.IOException
 */
@ConditionalRun(condition = RepositoryInstalled.MercurialInstalled.class)
@Test
public void testSymlinks() throws IndexerException, IOException {
    final String SYMLINK = "symlink";
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    // Set source root to pristine directory so that there is only one
    // repository to deal with (which makes this faster and easier to write)
    // and clone the mercurial repository outside of the source root.
    File realSource = FileUtilities.createTemporaryDirectory("real");
    File sourceRoot = FileUtilities.createTemporaryDirectory("src");
    MercurialRepositoryTest.runHgCommand(sourceRoot, "clone", repository.getSourceRoot() + File.separator + "mercurial", realSource.getPath());
    // Create symlink from source root to the real repository.
    String symlinkPath = sourceRoot.toString() + File.separator + SYMLINK;
    Files.createSymbolicLink(Paths.get(symlinkPath), Paths.get(realSource.getPath()));
    env.setSourceRoot(sourceRoot.toString());
    env.setDataRoot(repository.getDataRoot());
    // Need to have history cache enabled in order to perform scan of repositories.
    env.setHistoryEnabled(true);
    // Normally the Indexer would add the symlink automatically.
    env.setAllowedSymlinks(new HashSet<String>(Arrays.asList(symlinkPath)));
    // Do a rescan of the projects, and only that (we don't care about
    // the other aspects of indexing in this test case).
    Indexer.getInstance().prepareIndexer(env, // search for repositories
    true, // scan and add projects
    true, // no default project
    null, // don't list files
    false, // don't create dictionary
    false, // subFiles - not needed since we don't list files
    null, // repositories - not needed when not refreshing history
    null, // don't zap cache
    new ArrayList<>(), // don't list repos
    false);
    // Check the respository paths.
    List<RepositoryInfo> repos = env.getRepositories();
    assertEquals(repos.size(), 1);
    RepositoryInfo repo = repos.get(0);
    assertEquals("/" + SYMLINK, repo.getDirectoryNameRelative());
    String epath = sourceRoot.toString() + File.separator + SYMLINK;
    String apath = repo.getDirectoryName();
    assertTrue("Should match (with macOS leeway):\n" + epath + "\nv.\n" + apath, epath.equals(apath) || apath.equals("/private" + epath));
    // Check that history exists for a file in the repository.
    File repoRoot = new File(env.getSourceRootFile(), SYMLINK);
    File fileInRepo = new File(repoRoot, "main.c");
    assertTrue(fileInRepo.exists());
    assertTrue(HistoryGuru.getInstance().hasHistory(fileInRepo));
    assertTrue(HistoryGuru.getInstance().hasCacheForFile(fileInRepo));
    // cleanup
    IOUtils.removeRecursive(realSource.toPath());
    IOUtils.removeRecursive(sourceRoot.toPath());
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) RepositoryInfo(org.opensolaris.opengrok.history.RepositoryInfo) File(java.io.File) ConditionalRun(org.opensolaris.opengrok.condition.ConditionalRun) Test(org.junit.Test) MercurialRepositoryTest(org.opensolaris.opengrok.history.MercurialRepositoryTest)

Example 72 with RuntimeEnvironment

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

the class IndexerTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    assertTrue("No point in running indexer tests without valid ctags", env.validateExuberantCtags());
    RepositoryFactory.initializeIgnoredNames(env);
    parallelizer = new IndexerParallelizer(env);
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) BeforeClass(org.junit.BeforeClass)

Example 73 with RuntimeEnvironment

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

the class IndexerTest method testIncrementalIndexAddRemoveFile.

/**
 * Test IndexChangedListener behavior in repository with invalid files.
 * @throws Exception
 */
@Test
public void testIncrementalIndexAddRemoveFile() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    if (env.validateExuberantCtags()) {
        String ppath = "/bug3430";
        Project project = new Project("bug3430", ppath);
        IndexDatabase idb = new IndexDatabase(project);
        assertNotNull(idb);
        MyIndexChangeListener listener = new MyIndexChangeListener();
        idb.addIndexChangedListener(listener);
        idb.update(parallelizer);
        assertEquals(1, listener.files.size());
        listener.reset();
        repository.addDummyFile(ppath);
        idb.update(parallelizer);
        assertEquals("No new file added", 1, listener.files.size());
        repository.removeDummyFile(ppath);
        idb.update(parallelizer);
        assertEquals("(added)files changed unexpectedly", 1, listener.files.size());
        assertEquals("Didn't remove the dummy file", 1, listener.removedFiles.size());
        assertEquals("Should have added then removed the same file", listener.files.peek(), listener.removedFiles.peek());
    } 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 74 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment 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 75 with RuntimeEnvironment

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

the class IndexerTest method testIndexGeneration.

/**
 * Test of doIndexerExecution method, of class Indexer.
 * @throws java.lang.Exception
 */
@Test
public void testIndexGeneration() throws Exception {
    System.out.println("Generating index by using the class methods");
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    if (env.validateExuberantCtags()) {
        env.setSourceRoot(repository.getSourceRoot());
        env.setDataRoot(repository.getDataRoot());
        env.setVerbose(true);
        env.setHistoryEnabled(false);
        Indexer.getInstance().prepareIndexer(env, true, true, new TreeSet<>(Arrays.asList(new String[] { "/c" })), false, false, null, null, new ArrayList<>(), false);
        Indexer.getInstance().doIndexerExecution(true, null, null);
    } else {
        System.out.println("Skipping test. Could not find a ctags I could use in path.");
    }
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) Test(org.junit.Test)

Aggregations

RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)81 File (java.io.File)31 Project (org.opensolaris.opengrok.configuration.Project)27 IOException (java.io.IOException)23 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)17 TestRepository (org.opensolaris.opengrok.util.TestRepository)13 ForbiddenSymlinkException (org.opensolaris.opengrok.util.ForbiddenSymlinkException)12 BeforeClass (org.junit.BeforeClass)11 Ctags (org.opensolaris.opengrok.analysis.Ctags)6 BufferedReader (java.io.BufferedReader)5 FileNotFoundException (java.io.FileNotFoundException)5 InputStreamReader (java.io.InputStreamReader)5 ParseException (java.text.ParseException)5 DateFormat (java.text.DateFormat)4 Date (java.util.Date)4 RepositoryInfo (org.opensolaris.opengrok.history.RepositoryInfo)4 OutputStreamWriter (java.io.OutputStreamWriter)3 ConnectException (java.net.ConnectException)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3