Search in sources :

Example 26 with Executor

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

the class SubversionRepository method getHistoryGet.

@Override
boolean getHistoryGet(OutputStream out, String parent, String basename, String rev) {
    File directory = new File(getDirectoryName());
    String filepath;
    try {
        filepath = (new File(parent, basename)).getCanonicalPath();
    } catch (IOException exp) {
        LOGGER.log(Level.SEVERE, "Failed to get canonical path: {0}", exp.getClass().toString());
        return false;
    }
    String filename = filepath.substring(getDirectoryName().length() + 1);
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("cat");
    cmd.add(NON_INTERACT_OPTION);
    cmd.addAll(getAuthCommandLineParams());
    cmd.add("-r");
    cmd.add(rev);
    cmd.add(escapeFileName(filename));
    Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    if (executor.exec() == 0) {
        try {
            copyBytes(out::write, executor.getOutputStream());
            return true;
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, "Failed to get content for {0}", basename);
        }
    }
    return false;
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 27 with Executor

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

the class SubversionRepository method getHistoryLogExecutor.

/**
 * Get an executor to be used for retrieving the history log for the named
 * file.
 *
 * @param file The file to retrieve history for
 * @param sinceRevision the revision number immediately preceding the first
 *                      revision we want, or {@code null} to fetch the entire
 *                      history
 * @param numEntries number of entries to return. If 0, return all.
 * @param cmdType command timeout type
 * @return An Executor ready to be started
 */
Executor getHistoryLogExecutor(final File file, String sinceRevision, int numEntries, CommandTimeoutType cmdType) throws IOException {
    String filename = getRepoRelativePath(file);
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("log");
    cmd.add(NON_INTERACT_OPTION);
    cmd.addAll(getAuthCommandLineParams());
    cmd.add(XML_OPTION);
    cmd.add("-v");
    if (numEntries > 0) {
        cmd.add("-l" + numEntries);
    }
    if (sinceRevision != null) {
        cmd.add("-r");
        // We would like to use sinceRevision+1 here, but if no new
        // revisions have been added after sinceRevision, it would fail
        // because there is no such revision as sinceRevision+1. Instead,
        // fetch the unneeded revision and remove it later.
        cmd.add("BASE:" + sinceRevision);
    }
    if (filename.length() > 0) {
        cmd.add(escapeFileName(filename));
    }
    return new Executor(cmd, new File(getDirectoryName()), RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) File(java.io.File)

Example 28 with Executor

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

the class SCCSget method getRevision.

public static InputStream getRevision(String command, File file, String revision) throws IOException {
    InputStream ret = null;
    ArrayList<String> argv = new ArrayList<>();
    argv.add(command);
    argv.add("get");
    argv.add("-p");
    if (revision != null) {
        argv.add("-r" + revision);
    }
    argv.add(file.getCanonicalPath());
    Executor executor = new Executor(argv);
    if (executor.exec() == 0) {
        ret = executor.getOutputStream();
    }
    return ret;
}
Also used : Executor(org.opengrok.indexer.util.Executor) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList)

Example 29 with Executor

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

the class SSCMRepository method annotate.

/**
 * Annotate the specified file/revision.
 *
 * @param file file to annotate
 * @param revision revision to annotate
 * @return file annotation
 */
@Override
Annotation annotate(File file, String revision) throws IOException {
    ArrayList<String> argv = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    argv.add(RepoCommand);
    argv.add("annotate");
    argv.add(file.getName());
    Properties props = getProperties(file);
    String branch = props.getProperty(BRANCH_PROPERTY);
    if (branch != null && !branch.isEmpty()) {
        argv.add("-b" + branch);
    }
    String repo = props.getProperty(REPOSITORY_PROPERTY);
    if (repo != null && !repo.isEmpty()) {
        argv.add("-p" + repo);
    }
    if (revision != null) {
        argv.add("-aV:" + revision);
    }
    Executor exec = new Executor(argv, file.getParentFile(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    int status = exec.exec();
    if (status != 0) {
        LOGGER.log(Level.WARNING, "Failed annotate for: {2} \"{0}\" Exit code: {1}", new Object[] { file.getAbsolutePath(), String.valueOf(status), revision });
    }
    return parseAnnotation(exec.getOutputReader(), file.getName());
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 30 with Executor

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

the class SCCSRepository method annotate.

/**
 * Annotate the specified file/revision.
 *
 * @param file file to annotate
 * @param revision revision to annotate
 * @return file annotation
 * @throws java.io.IOException if I/O exception occurs
 */
@Override
public Annotation annotate(File file, String revision) throws IOException {
    Map<String, String> authors = getAuthors(file);
    ArrayList<String> argv = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    argv.add(RepoCommand);
    argv.add("get");
    argv.add("-m");
    argv.add("-p");
    if (revision != null) {
        argv.add("-r" + revision);
    }
    argv.add(file.getCanonicalPath());
    Executor executor = new Executor(argv, file.getCanonicalFile().getParentFile(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    SCCSRepositoryAnnotationParser parser = new SCCSRepositoryAnnotationParser(file, authors);
    executor.exec(true, parser);
    return parser.getAnnotation();
}
Also used : 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