Search in sources :

Example 21 with Executor

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

the class PerforceRepository method getHistoryGet.

@Override
InputStream getHistoryGet(String parent, String basename, String rev) {
    ArrayList<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("print");
    cmd.add("-q");
    cmd.add(basename + getRevisionCmd(rev));
    Executor executor = new Executor(cmd, new File(parent));
    executor.exec();
    return new ByteArrayInputStream(executor.getOutputString().getBytes());
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) File(java.io.File)

Example 22 with Executor

use of org.opensolaris.opengrok.util.Executor 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
     * @return true if the given file is in the depot, false otherwise
     */
public static boolean isInP4Depot(File file) {
    boolean status = false;
    if (testRepo.isWorking()) {
        ArrayList<String> cmd = new ArrayList<>();
        String name = file.getName();
        File dir = file.getParentFile();
        if (file.isDirectory()) {
            dir = file;
            name = "*";
            cmd.add(testRepo.RepoCommand);
            cmd.add("dirs");
            cmd.add(name);
            Executor executor = new Executor(cmd, dir);
            executor.exec();
            /* OUTPUT:
                 stdout: //depot_path/name
                 stderr: name - no such file(s).
                 */
            status = (executor.getOutputString().contains("//"));
        }
        if (!status) {
            cmd.clear();
            cmd.add(testRepo.RepoCommand);
            cmd.add("files");
            cmd.add(name);
            Executor executor = new Executor(cmd, dir);
            executor.exec();
            /* OUTPUT:
                 stdout: //depot_path/name
                 stderr: name - no such file(s).
                 */
            status = (executor.getOutputString().contains("//"));
        }
    }
    return status;
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) File(java.io.File)

Example 23 with Executor

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

the class SSCMHistoryParser method parse.

History parse(File file, String sinceRevision) throws HistoryException {
    try {
        Executor executor = repository.getHistoryLogExecutor(file, sinceRevision);
        int status = executor.exec(true, this);
        if (status != 0) {
            throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\" Exit code: " + status);
        }
    } catch (IOException e) {
        throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
    }
    return history;
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) IOException(java.io.IOException)

Example 24 with Executor

use of org.opensolaris.opengrok.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());
    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.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 25 with Executor

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

the class SSCMRepository method update.

@Override
void update() throws IOException {
    File directory = new File(getDirectoryName());
    List<String> argv = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    argv.add(RepoCommand);
    argv.add("get");
    argv.add("/");
    Properties props = getProperties(directory);
    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);
    }
    argv.add("-r");
    argv.add("-q");
    argv.add("-tmodify");
    argv.add("-wreplace");
    Executor executor = new Executor(argv, directory);
    if (executor.exec() != 0) {
        throw new IOException(executor.getErrorString());
    }
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File)

Aggregations

Executor (org.opensolaris.opengrok.util.Executor)56 ArrayList (java.util.ArrayList)43 File (java.io.File)33 IOException (java.io.IOException)33 BufferedReader (java.io.BufferedReader)6 InputStream (java.io.InputStream)4 Properties (java.util.Properties)4 Matcher (java.util.regex.Matcher)4 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Date (java.util.Date)2 RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)2 FileInputStream (java.io.FileInputStream)1 FileReader (java.io.FileReader)1 ParseException (java.text.ParseException)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