Search in sources :

Example 21 with RuntimeEnvironment

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

the class IndexerTest method testBug11896.

@Test
public void testBug11896() throws Exception {
    boolean test = true;
    if (FileUtilities.findProgInPath("mkfifo") == null) {
        System.out.println("Error: mkfifo not found in PATH !\n");
        test = false;
    }
    if (test) {
        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);
        if (env.validateExuberantCtags()) {
            Project project = new Project();
            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());
        } else {
            System.out.println("Skipping test. Could not find a ctags I could use in path.");
        }
    } else {
        System.out.println("Skipping test for bug 11896. Could not find a mkfifo in path.");
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) Executor(org.opensolaris.opengrok.util.Executor) Test(org.junit.Test)

Example 22 with RuntimeEnvironment

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

the class IndexerTest method testRFE2575.

@Test
public void testRFE2575() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setCtags(System.getProperty(ctagsProperty, "ctags"));
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    HistoryGuru.getInstance().addRepositories(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);
            break;
        }
    }
    if (r != null && r.isWorking() && env.validateExuberantCtags()) {
        Project project = new Project();
        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 could not find a ctags or an sccs I could use in path.");
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) Repository(org.opensolaris.opengrok.history.Repository) TestRepository(org.opensolaris.opengrok.util.TestRepository) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) RepositoryInfo(org.opensolaris.opengrok.history.RepositoryInfo) Test(org.junit.Test)

Example 23 with RuntimeEnvironment

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

the class IndexerTest method testRescanProjects.

/**
     * Test that rescanning for projects does not erase customization of
     * existing projects. Bug #16006.
     * @throws java.lang.Exception*/
@Test
public void testRescanProjects() throws Exception {
    // Generate one project that will be found in source.zip, and set
    // some properties that we can verify after the rescan.
    Project p1 = new Project();
    p1.setPath("/java");
    p1.setName("Project 1");
    p1.setTabSize(3);
    // Generate one project that will not be found in source.zip, and that
    // should not be in the list of projects after the rescan.
    Project p2 = new Project();
    p2.setPath("/this_path_does_not_exist");
    p2.setName("Project 2");
    // Make the runtime environment aware of these two projects.
    List<Project> projects = new ArrayList<>();
    projects.add(p1);
    projects.add(p2);
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setProjects(projects);
    // 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, // don't search for repositories
    false, // scan and add projects
    true, // no default project
    null, // don't write config file
    null, // don't refresh history
    false, // 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);
    List<Project> newProjects = env.getProjects();
    // p2 should not be in the project list anymore
    for (Project p : newProjects) {
        assertFalse("p2 not removed", p.getPath().equals(p2.getPath()));
    }
    // p1 should be there
    Project newP1 = null;
    for (Project p : newProjects) {
        if (p.getPath().equals(p1.getPath())) {
            newP1 = p;
            break;
        }
    }
    assertNotNull("p1 not in list", newP1);
    // The properties of p1 should be preserved
    assertEquals("project path", p1.getPath(), newP1.getPath());
    assertEquals("project description", p1.getName(), newP1.getName());
    assertEquals("project tabsize", p1.getTabSize(), newP1.getTabSize());
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 24 with RuntimeEnvironment

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

the class SearchEngineTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    repository = new TestRepository();
    repository.create(HistoryGuru.class.getResourceAsStream("repositories.zip"));
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setCtags(System.getProperty("org.opensolaris.opengrok.analysis.Ctags", "ctags"));
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    if (env.validateExuberantCtags()) {
        env.setSourceRoot(repository.getSourceRoot());
        env.setDataRoot(repository.getDataRoot());
        env.setVerbose(false);
        Indexer.getInstance().prepareIndexer(env, true, true, "/c", null, false, false, false, null, null, new ArrayList<>(), false);
        Indexer.getInstance().doIndexerExecution(true, 1, null, null);
    } else {
        System.out.println("Skipping test. Could not find a ctags I could use in path.");
        skip = true;
    }
    configFile = File.createTempFile("configuration", ".xml");
    env.writeConfiguration(configFile);
    RuntimeEnvironment.getInstance().readConfiguration(new File(configFile.getAbsolutePath()));
}
Also used : TestRepository(org.opensolaris.opengrok.util.TestRepository) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) HistoryGuru(org.opensolaris.opengrok.history.HistoryGuru) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 25 with RuntimeEnvironment

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

the class SearchTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    repository = new TestRepository();
    repository.create(IndexerTest.class.getResourceAsStream("source.zip"));
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setCtags(System.getProperty("org.opensolaris.opengrok.analysis.Ctags", "ctags"));
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    if (env.validateExuberantCtags()) {
        env.setSourceRoot(repository.getSourceRoot());
        env.setDataRoot(repository.getDataRoot());
        env.setVerbose(false);
        Indexer.getInstance().prepareIndexer(env, true, true, "/c", null, false, false, false, null, null, new ArrayList<>(), false);
        Indexer.getInstance().doIndexerExecution(true, 1, null, null);
    } else {
        System.out.println("Skipping test. Could not find a ctags I could use in path.");
        skip = true;
    }
    configFile = File.createTempFile("configuration", ".xml");
    env.writeConfiguration(configFile);
    RuntimeEnvironment.getInstance().readConfiguration(new File(configFile.getAbsolutePath()));
    PrintStream stream = new PrintStream(new ByteArrayOutputStream());
    System.setErr(stream);
}
Also used : PrintStream(java.io.PrintStream) TestRepository(org.opensolaris.opengrok.util.TestRepository) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) IndexerTest(org.opensolaris.opengrok.index.IndexerTest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Aggregations

RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)45 File (java.io.File)20 IOException (java.io.IOException)17 Project (org.opensolaris.opengrok.configuration.Project)12 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 FileNotFoundException (java.io.FileNotFoundException)5 ParseException (java.text.ParseException)5 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 DateFormat (java.text.DateFormat)4 TestRepository (org.opensolaris.opengrok.util.TestRepository)4 Date (java.util.Date)3 IndexReader (org.apache.lucene.index.IndexReader)3 BeforeClass (org.junit.BeforeClass)3 OutputStreamWriter (java.io.OutputStreamWriter)2 HistoryException (org.opensolaris.opengrok.history.HistoryException)2 Repository (org.opensolaris.opengrok.history.Repository)2 Executor (org.opensolaris.opengrok.util.Executor)2 BufferedWriter (java.io.BufferedWriter)1