Search in sources :

Example 1 with PatchFailedException

use of org.apache.commons.jrcs.diff.PatchFailedException in project OpenGrok by OpenGrok.

the class RCSRepository method annotate.

static Annotation annotate(File file, String revision, File rcsFile) throws IOException {
    try {
        Archive archive = new Archive(rcsFile.getPath());
        // If revision is null, use current revision
        Version version = revision == null ? archive.getRevisionVersion() : archive.getRevisionVersion(revision);
        // Get the revision with annotation
        archive.getRevision(version, true);
        Annotation a = new Annotation(file.getName());
        // considered public API anymore, but it works.
        for (Node n : archive.getRevisionNodes()) {
            String rev = n.getVersion().toString();
            String author = n.getAuthor();
            a.addLine(rev, author, true);
        }
        return a;
    } catch (ParseException pe) {
        throw wrapInIOException("Parse exception annotating RCS repository", pe);
    } catch (InvalidFileFormatException iffe) {
        throw wrapInIOException("File format exception annotating RCS repository", iffe);
    } catch (PatchFailedException pfe) {
        throw wrapInIOException("Patch failed exception annotating RCS repository", pfe);
    }
}
Also used : InvalidFileFormatException(org.apache.commons.jrcs.rcs.InvalidFileFormatException) Archive(org.apache.commons.jrcs.rcs.Archive) Version(org.apache.commons.jrcs.rcs.Version) Node(org.apache.commons.jrcs.rcs.Node) ParseException(org.apache.commons.jrcs.rcs.ParseException) PatchFailedException(org.apache.commons.jrcs.diff.PatchFailedException)

Example 2 with PatchFailedException

use of org.apache.commons.jrcs.diff.PatchFailedException in project OpenGrok by OpenGrok.

the class Node method patch.

/**
     * Apply the deltas in the current node to the given text.
     * @param original the text to be patched
     * @param annotate set to true to have each text line be a
     * {@link Line Line} object that identifies the revision in which
     * the line was changed or added.
     * @throws InvalidFileFormatException if the deltas cannot be parsed.
     * @throws PatchFailedException if the diff engine determines that
     * the deltas cannot apply to the given text.
     */
public void patch(List original, boolean annotate) throws InvalidFileFormatException, org.apache.commons.jrcs.diff.PatchFailedException {
    Revision revision = new Revision();
    for (int it = 0; it < text.length; it++) {
        String cmd = text[it].toString();
        java.util.StringTokenizer t = new StringTokenizer(cmd, "ad ", true);
        char action;
        int n;
        int count;
        try {
            action = t.nextToken().charAt(0);
            n = Integer.parseInt(t.nextToken());
            // skip the space
            t.nextToken();
            count = Integer.parseInt(t.nextToken());
        } catch (Exception e) {
            throw new InvalidFileFormatException(version + ":line:" + ":" + e.getMessage());
        }
        if (action == 'd') {
            revision.addDelta(new DeleteDelta(new Chunk(n - 1, count)));
        } else if (action == 'a') {
            revision.addDelta(new AddDelta(n, new Chunk(getTextLines(it + 1, it + 1 + count), 0, count, n - 1)));
            it += count;
        } else {
            throw new InvalidFileFormatException(version.toString());
        }
    }
    revision.applyTo(original);
}
Also used : StringTokenizer(java.util.StringTokenizer) Revision(org.apache.commons.jrcs.diff.Revision) DeleteDelta(org.apache.commons.jrcs.diff.DeleteDelta) StringTokenizer(java.util.StringTokenizer) AddDelta(org.apache.commons.jrcs.diff.AddDelta) ToString(org.apache.commons.jrcs.util.ToString) Chunk(org.apache.commons.jrcs.diff.Chunk) PatchFailedException(org.apache.commons.jrcs.diff.PatchFailedException)

Aggregations

PatchFailedException (org.apache.commons.jrcs.diff.PatchFailedException)2 StringTokenizer (java.util.StringTokenizer)1 AddDelta (org.apache.commons.jrcs.diff.AddDelta)1 Chunk (org.apache.commons.jrcs.diff.Chunk)1 DeleteDelta (org.apache.commons.jrcs.diff.DeleteDelta)1 Revision (org.apache.commons.jrcs.diff.Revision)1 Archive (org.apache.commons.jrcs.rcs.Archive)1 InvalidFileFormatException (org.apache.commons.jrcs.rcs.InvalidFileFormatException)1 Node (org.apache.commons.jrcs.rcs.Node)1 ParseException (org.apache.commons.jrcs.rcs.ParseException)1 Version (org.apache.commons.jrcs.rcs.Version)1 ToString (org.apache.commons.jrcs.util.ToString)1