Search in sources :

Example 21 with Executor

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

the class BitKeeperRepository method determineParent.

/**
 * Return the first listed pull parent of this repository BitKeeper can have multiple push parents and pul parents.
 *
 * @return parent a string denoting the parent, or null.
 */
@Override
String determineParent(CommandTimeoutType cmdType) throws IOException {
    final File directory = new File(getDirectoryName());
    final ArrayList<String> argv = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    argv.add(RepoCommand);
    argv.add("parent");
    argv.add("-1il");
    final Executor executor = new Executor(argv, directory, RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
    final int rc = executor.exec(false);
    final String parent = executor.getOutputString().trim();
    if (rc == 0) {
        return parent;
    } else if (parent.equals("This repository has no pull parent.")) {
        return null;
    } else {
        throw new IOException(executor.getErrorString());
    }
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 22 with Executor

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

the class BitKeeperRepository method ensureVersion.

/**
 * Updates working and version member variables by running {@code bk --version}.
 */
private void ensureVersion() {
    if (working == null) {
        ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
        final Executor exec = new Executor(new String[] { RepoCommand, "--version" });
        if (exec.exec(false) == 0) {
            working = Boolean.TRUE;
            final Matcher matcher = VERSION_PATTERN.matcher(exec.getOutputString());
            if (matcher.find()) {
                try {
                    version = new Version(matcher.group(1));
                } catch (final InvalidVersionNumberException e) {
                    assert false : "Failed to parse a version number.";
                }
            }
        } else {
            working = Boolean.FALSE;
        }
        if (version == null) {
            version = new Version(0, 0);
        }
    }
}
Also used : Executor(org.opengrok.indexer.util.Executor) Matcher(java.util.regex.Matcher) Version(org.suigeneris.jrcs.rcs.Version) InvalidVersionNumberException(org.suigeneris.jrcs.rcs.InvalidVersionNumberException)

Example 23 with Executor

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

the class AccuRevHistoryParser method parse.

/**
 * Parse the history for the specified file.
 *
 * @param file the file to parse history for
 * @param repos Pointer to the {@code AccuRevRepository}
 * @return object representing the file's history
 * @throws HistoryException if a problem occurs while executing p4 command
 */
History parse(File file, Repository repos) throws HistoryException {
    repository = (AccuRevRepository) repos;
    history = null;
    String relPath = repository.getDepotRelativePath(file);
    /*
         * When the path given is really just the root to the source
         * workarea, no history is available, create fake.
         */
    String rootRelativePath = File.separator + "." + File.separator;
    if (relPath.equals(rootRelativePath)) {
        List<HistoryEntry> entries = new ArrayList<>();
        entries.add(new HistoryEntry("", new Date(), "OpenGrok", "Workspace Root", true));
        history = new History(entries);
    } else {
        try {
            /*
                 * Errors will be logged, so not bothering to add to the output.
                 */
            Executor executor = repository.getHistoryLogExecutor(file);
            executor.exec(true, this);
        } catch (IOException e) {
            throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"" + e);
        }
    }
    return history;
}
Also used : Executor(org.opengrok.indexer.util.Executor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date)

Example 24 with Executor

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

the class IndexerTest method testBug11896.

/**
 * Test that named pipes are not indexed.
 * @throws Exception
 */
@Test
@EnabledIf("mkfifoInPath")
void testBug11896() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    Executor executor;
    executor = new Executor(new String[] { "mkdir", "-p", repository.getSourceRoot() + "/testBug11896" });
    executor.exec(true);
    executor = new Executor(new String[] { "mkfifo", repository.getSourceRoot() + "/testBug11896/FIFO" });
    executor.exec(true);
    Project project = new Project("testBug11896");
    project.setPath("/testBug11896");
    IndexDatabase idb = new IndexDatabase(project);
    assertNotNull(idb);
    MyIndexChangeListener listener = new MyIndexChangeListener();
    idb.addIndexChangedListener(listener);
    System.out.println("Trying to index a special file - FIFO in this case.");
    idb.update();
    assertEquals(0, listener.files.size());
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Executor(org.opengrok.indexer.util.Executor) Test(org.junit.jupiter.api.Test) EnabledIf(org.junit.jupiter.api.condition.EnabledIf)

Example 25 with Executor

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

the class SubversionRepository method getInfoDocument.

/**
 * Get {@code Document} corresponding to the parsed XML output from
 * {@code svn info} command.
 * @return document with data from {@code info} or null if the {@code svn}
 * command failed
 */
private Document getInfoDocument() {
    Document document = null;
    List<String> cmd = new ArrayList<>();
    cmd.add(RepoCommand);
    cmd.add("info");
    cmd.add(XML_OPTION);
    File directory = new File(getDirectoryName());
    Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
    if (executor.exec() == 0) {
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            // Prohibit the use of all protocols by external entities:
            factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
            factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
            DocumentBuilder builder = factory.newDocumentBuilder();
            document = builder.parse(executor.getOutputStream());
        } 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.", getDirectoryName());
    }
    return document;
}
Also used : Executor(org.opengrok.indexer.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)

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