Search in sources :

Example 31 with RuntimeEnvironment

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

the class IndexerTest method testXrefGeneration.

@Test
void testXrefGeneration() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    env.setHistoryEnabled(false);
    Indexer.getInstance().prepareIndexer(env, true, true, false, null, null);
    Indexer.getInstance().doIndexerExecution(true, null, null);
    // There should be certain number of xref files produced.
    List<String> result = null;
    try (Stream<Path> walk = Files.walk(Paths.get(env.getDataRootPath(), IndexDatabase.XREF_DIR))) {
        result = walk.filter(Files::isRegularFile).filter(f -> f.toString().endsWith(".gz")).map(Path::toString).collect(Collectors.toList());
    }
    assertNotNull(result);
    assertTrue(result.size() > 50);
    // Some files would have empty xref so the file should not be present.
    assertFalse(Paths.get(env.getDataRootPath(), IndexDatabase.XREF_DIR, "data", "Logo.png", ".gz").toFile().exists());
}
Also used : TandemPath(org.opengrok.indexer.util.TandemPath) Path(java.nio.file.Path) 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) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Files(java.nio.file.Files) Test(org.junit.jupiter.api.Test)

Example 32 with RuntimeEnvironment

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

the class IndexerTest method testDefaultProjectsSingleProject.

/**
 * Should include the existing project.
 * @throws Exception
 */
@Test
void testDefaultProjectsSingleProject() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    env.setHistoryEnabled(false);
    Indexer.getInstance().prepareIndexer(env, true, true, false, null, null);
    env.setDefaultProjectsFromNames(new TreeSet<>(Collections.singletonList("/c")));
    assertEquals(1, env.getDefaultProjects().size());
    assertEquals(new TreeSet<>(Collections.singletonList("c")), env.getDefaultProjects().stream().map(Project::getName).collect(Collectors.toSet()));
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Test(org.junit.jupiter.api.Test)

Example 33 with RuntimeEnvironment

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

the class IndexerTest method testBug11896.

/**
 * Test that named pipes are not indexed.
 * @throws Exception
 */
@Test
@EnabledIf("mkfifoInPath")
void testBug11896() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    Executor executor;
    executor = new Executor(new String[] { "mkdir", "-p", repository.getSourceRoot() + "/testBug11896" });
    executor.exec(true);
    executor = new Executor(new String[] { "mkfifo", repository.getSourceRoot() + "/testBug11896/FIFO" });
    executor.exec(true);
    Project project = new Project("testBug11896");
    project.setPath("/testBug11896");
    IndexDatabase idb = new IndexDatabase(project);
    assertNotNull(idb);
    MyIndexChangeListener listener = new MyIndexChangeListener();
    idb.addIndexChangedListener(listener);
    System.out.println("Trying to index a special file - FIFO in this case.");
    idb.update();
    assertEquals(0, listener.files.size());
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Executor(org.opengrok.indexer.util.Executor) Test(org.junit.jupiter.api.Test) EnabledIf(org.junit.jupiter.api.condition.EnabledIf)

Example 34 with RuntimeEnvironment

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

the class IndexerTest method setUpClass.

@BeforeAll
public static void setUpClass() {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    RepositoryFactory.initializeIgnoredNames(env);
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 35 with RuntimeEnvironment

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

the class IndexerTest method testBug3430.

@Test
void testBug3430() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    Project project = new Project("bug3430");
    project.setPath("/bug3430");
    IndexDatabase idb = new IndexDatabase(project);
    assertNotNull(idb);
    MyIndexChangeListener listener = new MyIndexChangeListener();
    idb.addIndexChangedListener(listener);
    idb.update();
    assertEquals(1, listener.files.size());
}
Also used : Project(org.opengrok.indexer.configuration.Project) 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