Search in sources :

Example 61 with RuntimeEnvironment

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

the class IndexerTest method testSetRepositories.

@Test
@EnabledForRepository(MERCURIAL)
void testSetRepositories() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    TestRepository testrepo = new TestRepository();
    testrepo.create(HistoryGuru.class.getResource("/repositories"));
    env.setSourceRoot(testrepo.getSourceRoot());
    env.setRepositories(testrepo.getSourceRoot());
    assertEquals(7, env.getRepositories().size());
    String[] repoNames = { "mercurial", "git" };
    env.setRepositories(Arrays.stream(repoNames).map(t -> Paths.get(env.getSourceRootPath(), t).toString()).distinct().toArray(String[]::new));
    assertEquals(2, env.getRepositories().size());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) Repository(org.opengrok.indexer.history.Repository) RepositoryFactory(org.opengrok.indexer.history.RepositoryFactory) Arrays(java.util.Arrays) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Project(org.opengrok.indexer.configuration.Project) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Executor(org.opengrok.indexer.util.Executor) TandemPath(org.opengrok.indexer.util.TandemPath) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) FileUtilities(org.opengrok.indexer.util.FileUtilities) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Path(java.nio.file.Path) TestRepository(org.opengrok.indexer.util.TestRepository) CommandTimeoutType(org.opengrok.indexer.configuration.CommandTimeoutType) EnabledIf(org.junit.jupiter.api.condition.EnabledIf) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) AnalyzerGuru(org.opengrok.indexer.analysis.AnalyzerGuru) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) MERCURIAL(org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL) FileReader(java.io.FileReader) Queue(java.util.Queue) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AnalyzerFactory(org.opengrok.indexer.analysis.AnalyzerFactory) TestRepository(org.opengrok.indexer.util.TestRepository) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) Test(org.junit.jupiter.api.Test) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 62 with RuntimeEnvironment

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

the class IndexerTest method testDefaultProjectsAll.

/**
 * Should include all projects in the source root.
 * @throws Exception
 */
@Test
void testDefaultProjectsAll() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    env.setHistoryEnabled(false);
    Set<String> defaultProjects = new TreeSet<>();
    defaultProjects.add("/c");
    defaultProjects.add("/data");
    defaultProjects.add("__all__");
    defaultProjects.add("/no-project-x32ds1");
    Indexer.getInstance().prepareIndexer(env, true, true, false, null, null);
    env.setDefaultProjectsFromNames(defaultProjects);
    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::getName).collect(Collectors.toSet()));
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) TreeSet(java.util.TreeSet) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 63 with RuntimeEnvironment

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

the class IndexerTest method testIncrementalIndexAddRemoveFile.

/**
 * Test IndexChangedListener behavior in repository with invalid files.
 * @throws Exception
 */
@Test
void testIncrementalIndexAddRemoveFile() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    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();
    assertEquals(1, listener.files.size());
    listener.reset();
    repository.addDummyFile(ppath);
    idb.update();
    assertEquals(1, listener.files.size(), "No new file added");
    repository.removeDummyFile(ppath);
    idb.update();
    assertEquals(1, listener.files.size(), "(added)files changed unexpectedly");
    assertEquals(1, listener.removedFiles.size(), "Didn't remove the dummy file");
    assertEquals(listener.files.peek(), listener.removedFiles.peek(), "Should have added then removed the same file");
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Test(org.junit.jupiter.api.Test)

Example 64 with RuntimeEnvironment

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

the class IndexerTest method testIndexWithSetIndexVersionedFilesOnly.

/**
 * Test indexing w.r.t. setIndexVersionedFilesOnly() setting,
 * i.e. if this option is set to true, index only files tracked by SCM.
 * @throws Exception
 */
@Test
void testIndexWithSetIndexVersionedFilesOnly() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    env.setRepositories(repository.getSourceRoot());
    List<RepositoryInfo> repos = env.getRepositories();
    Repository r = null;
    for (RepositoryInfo ri : repos) {
        if (ri.getDirectoryName().equals(repository.getSourceRoot() + "/rfe2575")) {
            r = RepositoryFactory.getRepository(ri, CommandTimeoutType.INDEXER);
            break;
        }
    }
    if (r != null && r.isWorking()) {
        Project project = new Project("rfe2575");
        project.setPath("/rfe2575");
        IndexDatabase idb = new IndexDatabase(project);
        assertNotNull(idb);
        MyIndexChangeListener listener = new MyIndexChangeListener();
        idb.addIndexChangedListener(listener);
        idb.update();
        assertEquals(2, listener.files.size());
        repository.purgeData();
        RuntimeEnvironment.getInstance().setIndexVersionedFilesOnly(true);
        idb = new IndexDatabase(project);
        listener = new MyIndexChangeListener();
        idb.addIndexChangedListener(listener);
        idb.update();
        assertEquals(1, listener.files.size());
        RuntimeEnvironment.getInstance().setIndexVersionedFilesOnly(false);
    } else {
        System.out.println("Skipping test. Repository for rfe2575 not found or an sccs I could use in path.");
    }
}
Also used : Project(org.opengrok.indexer.configuration.Project) Repository(org.opengrok.indexer.history.Repository) TestRepository(org.opengrok.indexer.util.TestRepository) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) Test(org.junit.jupiter.api.Test)

Example 65 with RuntimeEnvironment

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

the class CtagsUtilTest method getLanguages.

@Test
public void getLanguages() {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    List<String> result = CtagsUtil.getLanguages(env.getCtags());
    assertNotNull(result, "should get Ctags languages");
    assertTrue(result.contains("C++"), "Ctags languages should contains C++");
    // Test that the [disabled] tag is stripped for OldC.
    assertTrue(result.contains("OldC"), "Ctags languages should contains OldC");
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)81 File (java.io.File)26 Project (org.opengrok.indexer.configuration.Project)24 Test (org.junit.jupiter.api.Test)22 IOException (java.io.IOException)18 BeforeAll (org.junit.jupiter.api.BeforeAll)13 ArrayList (java.util.ArrayList)12 TestRepository (org.opengrok.indexer.util.TestRepository)12 Path (java.nio.file.Path)8 ForbiddenSymlinkException (org.opengrok.indexer.util.ForbiddenSymlinkException)8 Document (org.apache.lucene.document.Document)6 Ctags (org.opengrok.indexer.analysis.Ctags)6 Executor (org.opengrok.indexer.util.Executor)6 BufferedReader (java.io.BufferedReader)5 FileNotFoundException (java.io.FileNotFoundException)5 InputStreamReader (java.io.InputStreamReader)5 EnabledForRepository (org.opengrok.indexer.condition.EnabledForRepository)5 HistoryGuru (org.opengrok.indexer.history.HistoryGuru)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)4