Search in sources :

Example 26 with Executor

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

the class SSCMRepository method getHistoryGet.

@Override
InputStream getHistoryGet(String parent, final String basename, String rev) {
    InputStream ret = null;
    File directory = new File(parent);
    Process process = null;
    try {
        final File tmp = File.createTempFile("opengrok", "tmp");
        String tmpName = tmp.getCanonicalPath();
        // cleartool can't get to a previously existing file
        if (tmp.exists() && !tmp.delete()) {
            LOGGER.log(Level.WARNING, "Failed to remove temporary file used by history cache");
        }
        if (!tmp.mkdir()) {
            LOGGER.log(Level.WARNING, "Failed to create temporary directory used by history cache");
        }
        List<String> argv = new ArrayList<>();
        ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
        argv.add(RepoCommand);
        argv.add("get");
        argv.add(basename);
        argv.add("-d" + tmpName);
        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);
        }
        if (rev != null) {
            argv.add("-v" + rev);
        }
        argv.add("-q");
        argv.add("-tmodify");
        argv.add("-wreplace");
        Executor exec = new Executor(argv, directory);
        int status = exec.exec();
        if (status != 0) {
            LOGGER.log(Level.WARNING, "Failed get revision {2} for: \"{0}\" Exit code: {1}", new Object[] { new File(parent, basename).getAbsolutePath(), String.valueOf(status), rev });
            return null;
        }
        ret = new BufferedInputStream(new FileInputStream(new File(tmp, basename))) {

            @Override
            public void close() throws IOException {
                super.close();
                boolean deleteOnExit = false;
                File tmpFile = new File(tmp, basename);
                // delete the temporary file on close
                if (!tmpFile.delete()) {
                    // try on JVM exit
                    deleteOnExit = true;
                    tmpFile.deleteOnExit();
                }
                // delete the temporary directory on close
                if (deleteOnExit || !tmp.delete()) {
                    // try on JVM exit
                    tmp.deleteOnExit();
                }
            }
        };
    } catch (IOException exp) {
        LOGGER.log(Level.SEVERE, "Failed to get file: " + exp.getClass().toString(), exp);
    } finally {
        // Clean up zombie-processes...
        if (process != null) {
            try {
                process.exitValue();
            } catch (IllegalThreadStateException exp) {
                // the process is still running??? just kill it..
                process.destroy();
            }
        }
    }
    return ret;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) Executor(org.opensolaris.opengrok.util.Executor) BufferedInputStream(java.io.BufferedInputStream) File(java.io.File)

Example 27 with Executor

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

the class SubversionHistoryParser method parse.

/**
     * Parse the history for the specified file.
     *
     * @param file the file to parse history for
     * @param repos Pointer to the SubversionReporitory
     * @param sinceRevision the revision number immediately preceding the first
     * revision we want, or {@code null} to fetch the entire history
     * @return object representing the file's history
     */
History parse(File file, SubversionRepository repos, String sinceRevision) throws HistoryException {
    initSaxParser();
    handler = new Handler(repos.getDirectoryName(), repos.reposPath, RuntimeEnvironment.getInstance().getSourceRootPath().length(), repos.getDateFormat());
    Executor executor = repos.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);
    }
    List<HistoryEntry> entries = handler.entries;
    // sinceRevision. Remove it.
    if (sinceRevision != null) {
        repos.removeAndVerifyOldestChangeset(entries, sinceRevision);
    }
    return new History(entries);
}
Also used : Executor(org.opensolaris.opengrok.util.Executor)

Example 28 with Executor

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

the class IndexerTest method testBug11896.

@Test
public void testBug11896() throws Exception {
    boolean test = true;
    if (FileUtilities.findProgInPath("mkfifo") == null) {
        System.out.println("Error: mkfifo not found in PATH !\n");
        test = false;
    }
    if (test) {
        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);
        if (env.validateExuberantCtags()) {
            Project project = new Project();
            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());
        } else {
            System.out.println("Skipping test. Could not find a ctags I could use in path.");
        }
    } else {
        System.out.println("Skipping test for bug 11896. Could not find a mkfifo in path.");
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) Executor(org.opensolaris.opengrok.util.Executor) Test(org.junit.Test)

Example 29 with Executor

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

the class ClearCaseRepository 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
     * @return An Executor ready to be started
     */
Executor getHistoryLogExecutor(final File file) throws IOException {
    String abs = file.getCanonicalPath();
    String filename = "";
    if (abs.length() > directoryName.length()) {
        filename = abs.substring(directoryName.length() + 1);
    }
    List<String> cmd = new ArrayList<>();
    ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
    cmd.add(RepoCommand);
    cmd.add("lshistory");
    if (file.isDirectory()) {
        cmd.add("-dir");
    }
    cmd.add("-fmt");
    cmd.add("%e\n%Nd\n%Fu (%u)\n%Vn\n%Nc\n.\n");
    cmd.add(filename);
    return new Executor(cmd, new File(getDirectoryName()));
}
Also used : Executor(org.opensolaris.opengrok.util.Executor) ArrayList(java.util.ArrayList) File(java.io.File)

Example 30 with Executor

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

the class ClearCaseRepository method runLsvob.

private static String[] runLsvob() {
    if (testRepo.isWorking()) {
        Executor exec = new Executor(new String[] { testRepo.RepoCommand, "lsvob", "-s" });
        int rc;
        if ((rc = exec.exec(true)) == 0) {
            String output = exec.getOutputString();
            if (output == null) {
                LOGGER.log(Level.SEVERE, "\"cleartool lsvob -s\" output was null");
                return new String[0];
            }
            String sep = System.getProperty("line.separator");
            String[] vobs = output.split(Pattern.quote(sep));
            LOGGER.log(Level.CONFIG, "Found VOBs: {0}", Arrays.asList(vobs));
            return vobs;
        }
        LOGGER.log(Level.SEVERE, "\"cleartool lsvob -s\" returned non-zero status: {0}", rc);
    }
    return new String[0];
}
Also used : Executor(org.opensolaris.opengrok.util.Executor)

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