Search in sources :

Example 16 with Executor

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

the class CVSRepository method update.

@Override
public void update() throws IOException {
    File directory = new File(getDirectoryName());
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("update");
    Executor executor = new Executor(cmd, 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) File(java.io.File)

Example 17 with Executor

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

the class MonotoneRepository method annotate.

/**
     * Annotate the specified file/revision.
     *
     * @param file file to annotate
     * @param revision revision to annotate
     * @return file annotation
     * @throws java.io.IOException
     */
@Override
public Annotation annotate(File file, String revision) throws IOException {
    ArrayList<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("annotate");
    cmd.add(getQuietOption());
    if (revision != null) {
        cmd.add("-r");
        cmd.add(revision);
    }
    cmd.add(file.getName());
    File directory = new File(directoryName);
    Executor executor = new Executor(cmd, directory);
    if (executor.exec() != 0) {
        throw new IOException(executor.getErrorString());
    }
    Annotation ret;
    try (BufferedReader in = new BufferedReader(executor.getOutputReader())) {
        ret = new Annotation(file.getName());
        String line;
        String author = null;
        String rev = null;
        while ((line = in.readLine()) != null) {
            Matcher matcher = ANNOTATION_PATTERN.matcher(line);
            if (matcher.find()) {
                rev = matcher.group(1);
                author = matcher.group(2);
                ret.addLine(rev, author, true);
            } else {
                ret.addLine(rev, author, true);
            }
        }
    }
    return ret;
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) File(java.io.File)

Example 18 with Executor

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

the class MonotoneRepository method update.

@Override
public void update() throws IOException {
    File directory = new File(directoryName);
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    List<String> cmd = new ArrayList<>();
    cmd.add(RepoCommand);
    cmd.add("pull");
    cmd.add(getQuietOption());
    Executor executor = new Executor(cmd, directory);
    if (executor.exec() != 0) {
        throw new IOException(executor.getErrorString());
    }
    cmd.clear();
    cmd.add(RepoCommand);
    cmd.add("update");
    cmd.add(getQuietOption());
    executor = new Executor(cmd, 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) File(java.io.File)

Example 19 with Executor

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

the class SubversionRepository method setDirectoryName.

@Override
public void setDirectoryName(String directoryName) {
    super.setDirectoryName(directoryName);
    if (isWorking()) {
        // set to true if we manage to find the root directory
        Boolean rootFound = Boolean.FALSE;
        List<String> cmd = new ArrayList<>();
        cmd.add(RepoCommand);
        cmd.add("info");
        cmd.add("--xml");
        File directory = new File(getDirectoryName());
        Executor executor = new Executor(cmd, directory);
        if (executor.exec() == 0) {
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.parse(executor.getOutputStream());
                String url = getValue(document.getElementsByTagName("url").item(0));
                if (url == null) {
                    LOGGER.log(Level.WARNING, "svn info did not contain an URL for [{0}]. Assuming remote repository.", directoryName);
                    setRemote(true);
                } else {
                    if (!url.startsWith("file")) {
                        setRemote(true);
                    }
                }
                String root = getValue(document.getElementsByTagName("root").item(0));
                if (url != null && root != null) {
                    reposPath = url.substring(root.length());
                    rootFound = Boolean.TRUE;
                }
            } catch (SAXException saxe) {
                LOGGER.log(Level.WARNING, "Parser error parsing svn output", saxe);
            } catch (ParserConfigurationException pce) {
                LOGGER.log(Level.WARNING, "Parser configuration error parsing svn output", pce);
            } catch (IOException ioe) {
                LOGGER.log(Level.WARNING, "IOException reading from svn process", ioe);
            }
        } else {
            LOGGER.log(Level.WARNING, "Failed to execute svn info for [{0}]. Repository disabled.", directoryName);
        }
        setWorking(rootFound);
    }
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ArrayList(java.util.ArrayList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) File(java.io.File) SAXException(org.xml.sax.SAXException)

Example 20 with Executor

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

the class SubversionRepository method getHistoryGet.

@Override
public InputStream getHistoryGet(String parent, String basename, String rev) {
    InputStream ret = null;
    File directory = new File(directoryName);
    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 null;
    }
    String filename = filepath.substring(directoryName.length() + 1);
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("cat");
    cmd.add("-r");
    cmd.add(rev);
    cmd.add(escapeFileName(filename));
    Executor executor = new Executor(cmd, directory);
    if (executor.exec() == 0) {
        ret = executor.getOutputStream();
    }
    return ret;
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) 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