Search in sources :

Example 61 with Executor

use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.

the class BitKeeperRepository method annotate.

/**
 * Annotate the specified file/revision. The options {@code -aur} to @{code bk annotate} specify that Bitkeeper will output the
 * last user to edit the line, the last revision the line was edited, and then the line itself, each separated by a
 * hard tab.
 *
 * @param file file to annotate
 * @param revision revision to annotate, or null for latest
 * @return annotation file annotation
 */
@Override
public Annotation annotate(File file, String revision) throws IOException {
    final File absolute = file.getCanonicalFile();
    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("annotate");
    argv.add("-aur");
    if (revision != null) {
        argv.add("-r" + revision);
    }
    argv.add(basename);
    final Executor executor = new Executor(argv, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    final BitKeeperAnnotationParser parser = new BitKeeperAnnotationParser(basename);
    int status = executor.exec(true, parser);
    if (status != 0) {
        LOGGER.log(Level.WARNING, "Failed to get annotations for: \"{0}\" Exit code: {1}", new Object[] { file.getAbsolutePath(), String.valueOf(status) });
        throw new IOException(executor.getErrorString());
    } else {
        return parser.getAnnotation();
    }
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 62 with Executor

use of org.opengrok.indexer.util.Executor 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 63 with Executor

use of org.opengrok.indexer.util.Executor 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)

Aggregations

Executor (org.opengrok.indexer.util.Executor)63 ArrayList (java.util.ArrayList)48 File (java.io.File)31 IOException (java.io.IOException)30 BufferedReader (java.io.BufferedReader)4 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)4 Properties (java.util.Properties)3 Matcher (java.util.regex.Matcher)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Scanner (java.util.Scanner)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1