Search in sources :

Example 66 with RuntimeEnvironment

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

the class IndexDatabaseTest method checkDataExistence.

private void checkDataExistence(String fileName, boolean shouldExist) {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    for (String dirName : new String[] { "historycache", IndexDatabase.XREF_DIR }) {
        File dataDir = new File(env.getDataRootFile(), dirName);
        File dataFile = new File(dataDir, TandemPath.join(fileName, ".gz"));
        if (shouldExist) {
            assertTrue(dataFile.exists(), "file " + fileName + " not found in " + dirName);
        } else {
            assertFalse(dataFile.exists(), "file " + fileName + " found in " + dirName);
        }
    }
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) File(java.io.File)

Example 67 with RuntimeEnvironment

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

the class IndexDatabaseTest method setUpClass.

@BeforeAll
public static void setUpClass() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    repository = new TestRepository();
    repository.create(HistoryGuru.class.getResource("/repositories"));
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    env.setHistoryEnabled(true);
    env.setProjectsEnabled(true);
    RepositoryFactory.initializeIgnoredNames(env);
    // Note that all tests in this class share the index created below.
    // Ergo, if they need to modify it, this has to be done in such a way
    // so that it does not affect other tests, no matter in which order
    // the tests are run.
    Indexer indexer = Indexer.getInstance();
    indexer.prepareIndexer(env, true, true, false, null, null);
    env.setDefaultProjectsFromNames(new TreeSet<>(Arrays.asList("/c")));
    indexer.doIndexerExecution(true, null, null);
}
Also used : TestRepository(org.opengrok.indexer.util.TestRepository) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 68 with RuntimeEnvironment

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

the class BitKeeperRepository method getHistory.

/**
 * Construct a History for a file in this repository.
 *
 * @param file a file in the repository
 * @param sinceRevision omit history from before, and including, this revision
 * @return history a history object
 */
@Override
History getHistory(File file, String sinceRevision) throws HistoryException {
    final File absolute = file.getAbsoluteFile();
    final File directory = absolute.getParentFile();
    final String basename = absolute.getName();
    final ArrayList<String> argv = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    argv.add(RepoCommand);
    argv.add("log");
    if (sinceRevision != null) {
        argv.add("-r" + sinceRevision + "..");
    }
    argv.add("-d" + LOG_DSPEC);
    argv.add(basename);
    final Executor executor = new Executor(argv, directory);
    final BitKeeperHistoryParser parser = new BitKeeperHistoryParser(datePatterns[0]);
    if (executor.exec(true, parser) != 0) {
        throw new HistoryException(executor.getErrorString());
    }
    final RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    final History history = parser.getHistory();
    // because we know it :-)
    if (env.isTagsEnabled()) {
        assignTagsInHistory(history);
    }
    return history;
}
Also used : Executor(org.opengrok.indexer.util.Executor) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) ArrayList(java.util.ArrayList) File(java.io.File)

Example 69 with RuntimeEnvironment

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

the class BitKeeperRepository method buildTagList.

/**
 * Constructs a set of tags up front.
 *
 * @param directory the repository directory
 * @param cmdType command timeout type
 */
@Override
public void buildTagList(File directory, CommandTimeoutType cmdType) {
    final ArrayList<String> argv = new ArrayList<>();
    argv.add("bk");
    argv.add("tags");
    argv.add("-d" + getTagDspec());
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    final Executor executor = new Executor(argv, directory, env.getCommandTimeout(cmdType));
    final BitKeeperTagParser parser = new BitKeeperTagParser(datePatterns[0]);
    int status = executor.exec(true, parser);
    if (status != 0) {
        LOGGER.log(Level.WARNING, "Failed to get tags for: \"{0}\" Exit code: {1}", new Object[] { directory.getAbsolutePath(), String.valueOf(status) });
    } else {
        tagList = parser.getEntries();
    }
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList)

Example 70 with RuntimeEnvironment

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

the class PerforceRepository method isInP4Depot.

/**
 * Check if a given file is in the depot.
 *
 * @param file The file to test
 * @param cmdType command timeout type
 * @return true if the given file is in the depot, false otherwise
 */
boolean isInP4Depot(File file, CommandTimeoutType cmdType) {
    boolean status = false;
    if (isWorking()) {
        RuntimeEnvironment env = RuntimeEnvironment.getInstance();
        ArrayList<String> cmd = new ArrayList<>();
        String name = protectPerforceFilename(file.getName());
        File dir = file.getParentFile();
        if (file.isDirectory()) {
            dir = file;
            name = "*";
            cmd.add(RepoCommand);
            cmd.add("dirs");
            cmd.add(name);
            Executor executor = new Executor(cmd, dir, env.getCommandTimeout(cmdType));
            executor.exec();
            /* OUTPUT:
                 stdout: //depot_path/name
                 stderr: name - no such file(s).
                 */
            status = (executor.getOutputString().contains("//"));
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.log(Level.FINEST, "p4 status is {0} for {1}", new Object[] { status, file });
            }
        }
        if (!status) {
            cmd.clear();
            cmd.add(RepoCommand);
            cmd.add("files");
            cmd.add(name);
            Executor executor = new Executor(cmd, dir, env.getCommandTimeout(cmdType));
            executor.exec();
            /* OUTPUT:
                 stdout: //depot_path/name
                 stderr: name - no such file(s).
                 */
            status = (executor.getOutputString().contains("//"));
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.log(Level.FINEST, "p4 status is {0} for {1}", new Object[] { status, file });
            }
        }
    }
    return status;
}
Also used : RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) File(java.io.File)

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